generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
14601 authorization api #16495
Merged
Merged
14601 authorization api #16495
Changes from 14 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
d530487
15864 Spring Cloud Gate configuration with Swagger
jalbinson e68207f
Merge branch 'master' into platform/jamie/15864-spring-cloud-swagger
jalbinson 3403b45
add basic healthcheck test
jalbinson cbe8404
Merge branch 'platform/jamie/15864-spring-cloud-swagger' of github.co…
jalbinson 8e64119
Merge branch 'master' into platform/jamie/15864-spring-cloud-swagger
jalbinson 74046c6
Merge branch 'master' into platform/jamie/15864-spring-cloud-swagger
jalbinson 9d0dc6f
PR feedback
jalbinson 2986d9c
Merge branch 'master' into platform/jamie/15864-spring-cloud-swagger
jalbinson 652a45e
Merge branch 'platform/jamie/15864-spring-cloud-swagger' of github.co…
jalbinson a94be0b
config injection cleanup
jalbinson 74a903a
Merge branch 'master' into platform/jamie/15864-spring-cloud-swagger
jalbinson c093548
fix test
jalbinson ceea1f7
Merge branch 'platform/jamie/15864-spring-cloud-swagger' of github.co…
jalbinson df7bac8
14601 authz api
jalbinson da94858
merge main
jalbinson c000475
fix merge issue
jalbinson 9ea32e5
comments
jalbinson c9c2ba7
Merge branch 'main' into platform/jamie/14601-authz-api
emvaldes e24d2a8
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 6ddc157
doc
jalbinson 77efd61
Merge branch 'platform/jamie/14601-authz-api' of github.com:CDCgov/pr…
jalbinson 75862cc
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 74d025d
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson d290bc7
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 1ace3d1
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 3cb1171
Update auth/docs/setup.md
jalbinson 54fb1ba
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 85abc4a
PR review
jalbinson a60f074
Merge branch 'platform/jamie/14601-authz-api' of github.com:CDCgov/pr…
jalbinson f0bf94f
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson dad9f2c
latest version of okta SDK after fix
jalbinson 60f59f7
Merge branch 'platform/jamie/14601-authz-api' of github.com:CDCgov/pr…
jalbinson 6d902c7
revert spring boot update
jalbinson bd308f4
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 3d6faf3
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson f548a03
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson 61b9a8f
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson e5fa576
various changes required for spring boot 3.4.0 on both auth and submi…
jalbinson 494135e
Merge branch 'platform/jamie/14601-authz-api' of github.com:CDCgov/pr…
jalbinson b1339ae
Merge branch 'main' into platform/jamie/14601-authz-api
jalbinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/AuthApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/client/OktaGroupsClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package gov.cdc.prime.reportstream.auth.client | ||
|
||
import com.okta.sdk.resource.api.ApplicationGroupsApi | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.apache.logging.log4j.kotlin.Logging | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class OktaGroupsClient( | ||
private val applicationGroupsApi: ApplicationGroupsApi, | ||
) : Logging { | ||
|
||
/** | ||
* Get all application groups from the Okta Admin API | ||
* | ||
* Group names are found at json path "_embedded.group.profile.name" | ||
* | ||
* @see https://developer.okta.com/docs/api/openapi/okta-management/management/tag/ApplicationGroups/#tag/ApplicationGroups/operation/listApplicationGroupAssignments | ||
*/ | ||
suspend fun getApplicationGroups(appId: String): List<String> { | ||
return withContext(Dispatchers.IO) { | ||
try { | ||
applicationGroupsApi | ||
.listApplicationGroupAssignments(appId, null, null, null, "group") | ||
.map { it.embedded?.get("group") as Map<*, *> } | ||
.map { it["profile"] as Map<*, *> } | ||
.map { it["name"] as String } | ||
} catch (ex: Exception) { | ||
logger.error("Error retrieving application groups from Okta API", ex) | ||
throw ex | ||
} | ||
} | ||
} | ||
} |
26 changes: 10 additions & 16 deletions
26
auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/config/ApplicationConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
package gov.cdc.prime.reportstream.auth.config | ||
|
||
import gov.cdc.prime.reportstream.auth.model.Environment | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import java.time.Clock | ||
import kotlin.time.TimeSource | ||
|
||
/** | ||
* Simple class to automatically read configuration from application.yml (or environment variable overrides) | ||
*/ | ||
@Configuration | ||
@EnableConfigurationProperties(ProxyConfigurationProperties::class) | ||
class ApplicationConfig( | ||
val proxyConfig: ProxyConfigurationProperties, | ||
@ConfigurationProperties(prefix = "app") | ||
data class ApplicationConfig( | ||
val environment: Environment, | ||
) { | ||
|
||
@Bean | ||
fun timeSource(): TimeSource { | ||
return TimeSource.Monotonic | ||
} | ||
} | ||
|
||
@ConfigurationProperties("proxy") | ||
data class ProxyConfigurationProperties( | ||
val pathMappings: List<ProxyPathMapping>, | ||
) | ||
|
||
data class ProxyPathMapping( | ||
val baseUrl: String, | ||
val pathPrefix: String, | ||
) | ||
@Bean | ||
fun clock(): Clock { | ||
return Clock.systemUTC() | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/config/OktaClientConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package gov.cdc.prime.reportstream.auth.config | ||
|
||
import com.okta.sdk.client.AuthorizationMode | ||
import com.okta.sdk.client.Clients | ||
import com.okta.sdk.resource.api.ApplicationGroupsApi | ||
import com.okta.sdk.resource.client.ApiClient | ||
import gov.cdc.prime.reportstream.shared.StringUtilities.base64Decode | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class OktaClientConfig( | ||
private val oktaClientProperties: OktaClientProperties, | ||
) { | ||
|
||
@Bean | ||
fun apiClient(): ApiClient { | ||
return Clients.builder() | ||
.setOrgUrl(oktaClientProperties.orgUrl) | ||
.setAuthorizationMode(AuthorizationMode.PRIVATE_KEY) | ||
.setClientId(oktaClientProperties.clientId) | ||
.setScopes(oktaClientProperties.requiredScopes) | ||
.setPrivateKey(oktaClientProperties.apiPrivateKey) | ||
// .setCacheManager(...) TODO: investigate caching since groups don't often change | ||
.build() | ||
} | ||
|
||
@Bean | ||
fun applicationGroupsApi(): ApplicationGroupsApi { | ||
return ApplicationGroupsApi(apiClient()) | ||
} | ||
|
||
@ConfigurationProperties(prefix = "okta.admin-client") | ||
data class OktaClientProperties( | ||
val orgUrl: String, | ||
val clientId: String, | ||
val requiredScopes: Set<String>, | ||
private val apiEncodedPrivateKey: String, | ||
) { | ||
// PEM encoded format | ||
val apiPrivateKey = apiEncodedPrivateKey.base64Decode() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/controller/AuthController.kt
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
...ain/kotlin/gov/cdc/prime/reportstream/auth/filter/AppendOktaGroupsGatewayFilterFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package gov.cdc.prime.reportstream.auth.filter | ||
|
||
import gov.cdc.prime.reportstream.auth.AuthApplicationConstants | ||
import gov.cdc.prime.reportstream.auth.service.OktaGroupsService | ||
import gov.cdc.prime.reportstream.shared.auth.jwt.OktaGroupsJWTConstants | ||
import kotlinx.coroutines.reactor.mono | ||
import org.springframework.cloud.gateway.filter.GatewayFilter | ||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory | ||
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication | ||
import org.springframework.stereotype.Component | ||
import reactor.core.publisher.Mono | ||
|
||
/** | ||
* This filter defines how the Okta-Groups header is added to requests | ||
*/ | ||
@Component | ||
class AppendOktaGroupsGatewayFilterFactory( | ||
private val oktaGroupsService: OktaGroupsService, | ||
) : AbstractGatewayFilterFactory<Any>() { | ||
|
||
/** | ||
* function used only in testing to create our filter without any configuration | ||
*/ | ||
fun apply(): GatewayFilter { | ||
return apply { _: Any? -> } | ||
} | ||
|
||
override fun apply(config: Any?): GatewayFilter { | ||
return GatewayFilter { exchange, chain -> | ||
exchange | ||
.getPrincipal<BearerTokenAuthentication>() | ||
.flatMap { oktaAccessTokenJWT -> | ||
val appId = oktaAccessTokenJWT | ||
.tokenAttributes[AuthApplicationConstants.Scopes.SUBJECT_SCOPE] as String | ||
val organizations = oktaAccessTokenJWT | ||
.tokenAttributes[AuthApplicationConstants.Scopes.ORGANIZATION_SCOPE] as List<*>? | ||
|
||
// If there is no organization claim present, then we have an application user and | ||
// require appending our custom header | ||
if (organizations == null) { | ||
mono { oktaGroupsService.generateOktaGroupsJWT(appId) } | ||
} else { | ||
Mono.empty() | ||
} | ||
} | ||
.map { oktaGroupsJWT: String -> | ||
exchange.request | ||
.mutate() | ||
.headers { | ||
it.add(OktaGroupsJWTConstants.OKTA_GROUPS_HEADER, oktaGroupsJWT) | ||
} | ||
.build() | ||
} | ||
.switchIfEmpty(Mono.just(exchange.request)) // drop back in original unmodified request if not an app | ||
.flatMap { request -> | ||
chain.filter(exchange.mutate().request(request).build()) | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/model/Environment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package gov.cdc.prime.reportstream.auth.model | ||
|
||
/** | ||
* All possible environments the auth app can be running | ||
*/ | ||
enum class Environment { | ||
LOCAL, | ||
STAGING, | ||
PRODUCTION, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a ticket for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just leave this be for now. Caching is something we can worry about if performance becomes a problem especially since this is currently a POC.