Skip to content

Add admin authentication for version updates and enhance AppVersionService#44

Merged
subsub97 merged 1 commit intomainfrom
app-version
Mar 23, 2026
Merged

Add admin authentication for version updates and enhance AppVersionService#44
subsub97 merged 1 commit intomainfrom
app-version

Conversation

@subsub97
Copy link
Copy Markdown
Collaborator

This pull request introduces an admin API key authentication mechanism and adds an endpoint for updating app version information, restricted to admin users. It does so by implementing a custom annotation and interceptor for admin authentication, updating the Swagger configuration for API key documentation, and extending the version management functionality.

Admin Authentication Implementation:

  • Added @AdminAuth annotation and AdminAuthInterceptor to restrict certain endpoints to requests with a valid admin API key (X-Admin-Key header), with configuration properties loaded from admin.yml. [1] [2] [3] [4]
  • Registered the AdminAuthInterceptor in WebConfig to enforce admin authentication on annotated endpoints.

API Documentation Updates:

  • Updated SwaggerConfig to document the new X-Admin-Key API key security scheme, allowing API consumers to understand and test admin-protected endpoints.

App Version Management Enhancements:

  • Added AppVersionUpdateRequest DTO and a new updateVersion method in AppVersionService to allow updating app version data. [1] [2] [3]
  • Updated VersionController to include a new PUT /version endpoint for updating app version information, protected by the new admin authentication mechanism. [1] [2]

Configuration Changes:

  • Updated secret management to include moa-secret/admin.yml for admin API key configuration. [1] [2]…rvice

Copilot AI review requested due to automatic review settings March 23, 2026 15:16
@github-actions
Copy link
Copy Markdown

Test Results

46 tests   46 ✅  0s ⏱️
 6 suites   0 💤
 6 files     0 ❌

Results for commit d03c8ff.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an admin API-key gate for privileged endpoints and introduces an admin-only version update API for app version metadata.

Changes:

  • Introduced @AdminAuth + AdminAuthInterceptor and registered the interceptor via WebConfig.
  • Added Swagger/OpenAPI API-key security scheme (X-Admin-Key) and annotated the new endpoint with a security requirement.
  • Implemented app version update flow via AppVersionUpdateRequest, AppVersionService.updateVersion, and PUT /version.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/main/resources/moa-secret Updates the secrets submodule pointer to pick up new admin secret config.
src/main/resources/application.yml Loads moa-secret/admin.yml into Spring config imports.
src/main/kotlin/com/moa/service/dto/AppVersionUpdateRequest.kt Adds DTO for admin version update requests.
src/main/kotlin/com/moa/service/AppVersionService.kt Adds transactional update method for app versions.
src/main/kotlin/com/moa/controller/VersionController.kt Adds admin-protected PUT /version endpoint.
src/main/kotlin/com/moa/common/config/WebConfig.kt Registers the new admin auth interceptor.
src/main/kotlin/com/moa/common/config/SwaggerConfig.kt Documents the X-Admin-Key security scheme in OpenAPI.
src/main/kotlin/com/moa/common/auth/AdminProperties.kt Adds @ConfigurationProperties holder for the admin key.
src/main/kotlin/com/moa/common/auth/AdminAuthInterceptor.kt Implements header-based API key enforcement for @AdminAuth.
src/main/kotlin/com/moa/common/auth/AdminAuth.kt Adds the annotation used to mark admin-only endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +8
@ConfigurationProperties(prefix = "admin")
data class AdminProperties(
val apiKey: String,
)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ConfigurationProperties classes are not automatically registered as beans unless the project has @ConfigurationPropertiesScan enabled (or uses @EnableConfigurationProperties(AdminProperties::class)). Since AdminAuthInterceptor injects AdminProperties, missing registration will fail app startup. Fix by registering this properties class via @ConfigurationPropertiesScan in the application/config package, adding @EnableConfigurationProperties(AdminProperties::class) in a @Configuration class, or annotating this class with a Spring stereotype (least preferred vs scan/enable).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application.kt에서 Scan 하는디?..

Comment on lines +15 to +23
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
if (handler is HandlerMethod && handler.hasMethodAnnotation(AdminAuth::class.java)) {
val key = request.getHeader(ADMIN_KEY_HEADER)
if (key != adminProperties.apiKey) {
throw UnauthorizedException()
}
}
return true
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, admin-protected endpoints can fail CORS preflight requests because OPTIONS requests typically won't include X-Admin-Key, causing UnauthorizedException and blocking browsers. Consider bypassing auth for OPTIONS (or handling CORS at a higher level) before checking @AdminAuth.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +20
if (key != adminProperties.apiKey) {
throw UnauthorizedException()
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct string comparison can leak timing information about the admin key (especially if this endpoint is exposed publicly). Use a constant-time comparison (e.g., compare byte arrays with a constant-time primitive) to reduce timing-attack surface.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,5 @@
package com.moa.common.auth

@Target(AnnotationTarget.FUNCTION)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limiting @AdminAuth to FUNCTION prevents protecting an entire controller/class with a single annotation. If you want class-level protection, include AnnotationTarget.CLASS in @Target and update the interceptor to also check the declaring class (e.g., handler.beanType) for the annotation.

Suggested change
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 나중에 할게 필요할때...

@subsub97 subsub97 merged commit 5b5de62 into main Mar 23, 2026
6 of 7 checks passed
@subsub97 subsub97 deleted the app-version branch March 23, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants