Skip to content

Commit aacbd40

Browse files
committed
Merge branch 'jwt' into main
2 parents c73e83e + d7ad47c commit aacbd40

File tree

26 files changed

+675
-55
lines changed

26 files changed

+675
-55
lines changed

api/src/integrationTest/resources/application-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ management:
1616
# key: "ZmFrZS1rZXkK"
1717
# uri: "https://faketestaccount.documents.azure.com:443/"
1818
csm:
19+
platform:
20+
authorization:
21+
tenant-id-jwt-claim: "iss"
22+
# Note that the way @Value works in Spring does not make it possible to inject this sole YAML list.
23+
# Use CsmPlatformProperties instead !
24+
allowed-tenants: ["test"]
1925
vendor: azure
2026
argo:
2127
base-uri: "https://argo-server.argo.svc.cluster.local:2746"

api/src/main/resources/application-azure.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@ management:
1010
readiness:
1111
include: "readinessState,cosmos,blobStorage"
1212

13+
csm:
14+
platform:
15+
authorization:
16+
principal-jwt-claim: "oid"
17+
tenant-id-jwt-claim: "tid"
18+
1319
azure:
14-
# Required to auto-configure the beans provided by the Azure CosmosDB Spring Boot AutoConfiguration
20+
# Required to auto-configure the beans provided by the Azure Spring Boot AutoConfigurations
21+
activedirectory:
22+
# tenantId is 'common' to use the login process of multi-tenant access
23+
# See https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-starter-active-directory/ACCESS_TO_MULTI_TENANT_APP.md
24+
tenant-id: common
25+
client-id: ${csm.platform.azure.credentials.clientId}
26+
client-secret: ${csm.platform.azure.credentials.clientSecret}
27+
session-stateless: true
28+
app-id-uri: ${csm.platform.azure.appIdUri}
1529
cosmos:
1630
allowTelemetry: ${csm.platform.azure.cosmos.allowTelemetry}
1731
connectionMode: ${csm.platform.azure.cosmos.connectionMode}

api/src/main/resources/application.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ spring:
1212
enabled: false
1313
kubernetes:
1414
enabled: false
15+
security:
16+
oauth2:
17+
resource:
18+
user-info-uri: https://graph.microsoft.com/oidc/userinfo
19+
jwk:
20+
key-set-uri: https://login.microsoftonline.com/common/discovery/v2.0/keys
1521

1622
management:
1723
endpoint:
@@ -56,8 +62,15 @@ csm:
5662
images:
5763
scenario-fetch-parameters: cosmo-tech/fetch-scenario-parameters
5864
send-datawarehouse: cosmo-tech/azure-data-explorer-connector
65+
authorization:
66+
principal-jwt-claim: "sub"
67+
tenant-id-jwt-claim: "iss"
68+
# Note that the way @Value works in Spring does not make it possible to inject this sole YAML list.
69+
# Use CsmPlatformProperties instead !
70+
allowed-tenants: []
5971
vendor: azure
6072
azure:
73+
appIdUri: "http://dev.api.cosmotech.com"
6174
credentials:
6275
tenantId:
6376
clientId:

build.gradle.kts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ plugins {
1717
id("com.diffplug.spotless") version "5.12.5"
1818

1919
id("org.springframework.boot") version "2.4.5" apply false
20-
id("io.spring.dependency-management") version "1.0.11.RELEASE" apply false
20+
id("io.spring.dependency-management") version "1.0.11.RELEASE"
2121

2222
id("org.openapi.generator") version "5.1.1" apply false
2323

@@ -76,6 +76,8 @@ subprojects {
7676
apply(plugin = "org.springframework.boot")
7777
apply(plugin = "io.spring.dependency-management")
7878

79+
dependencyManagement { imports { mavenBom("com.azure.spring:azure-spring-boot-bom:3.5.0") } }
80+
7981
// Apply some plugins to all projects except 'common'
8082
if (name != "cosmotech-api-common") {
8183
apply(plugin = "org.openapi.generator")
@@ -119,9 +121,22 @@ subprojects {
119121

120122
// TODO Extract those dependencies in a 'common/azure' sub-project,
121123
// included dynamically if the 'platform' build property is 'azure'
122-
implementation("com.azure.spring:azure-spring-boot-starter-cosmos:3.5.0")
123-
implementation("com.azure.spring:azure-spring-boot-starter-storage:3.5.0")
124124
implementation("com.azure:azure-storage-blob-batch:12.9.1")
125+
implementation("org.springframework.boot:spring-boot-starter-security")
126+
implementation(
127+
"org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.4.5")
128+
implementation("org.springframework.security:spring-security-jwt:1.1.1.RELEASE")
129+
implementation("com.azure.spring:azure-spring-boot-starter-cosmos")
130+
implementation("com.azure.spring:azure-spring-boot-starter-storage")
131+
implementation("com.azure.spring:azure-spring-boot-starter-active-directory")
132+
// com.azure.spring:azure-spring-boot-starter-active-directory provides this dependency
133+
// transitively,
134+
// but its version is incompatible at runtime with what is expected by
135+
// spring-security-oauth2-jose
136+
implementation("com.nimbusds:nimbus-jose-jwt:9.9.3")
137+
implementation("org.springframework.security:spring-security-oauth2-jose:5.5.0")
138+
implementation("org.springframework.security:spring-security-oauth2-resource-server:5.5.0")
139+
// implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
125140

126141
testImplementation(kotlin("test"))
127142
testImplementation("io.mockk:mockk:1.11.0")

common/src/main/kotlin/com/cosmotech/api/config/CsmPlatformProperties.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,26 @@ data class CsmPlatformProperties(
4141

4242
/** Cosmo Tech core images */
4343
val images: CsmImages,
44+
45+
/** Authorization Configuration */
46+
val authorization: Authorization = Authorization(),
4447
) {
4548

49+
data class Authorization(
50+
51+
/** The JWT Claim to use to extract a unique identifier for the user account */
52+
val principalJwtClaim: String = "sub",
53+
54+
/** The JWT Claim where the tenant id information is stored */
55+
val tenantIdJwtClaim: String = "iss",
56+
57+
/**
58+
* List of additional tenants allowed to register, besides the configured
59+
* `csm.platform.azure.credentials.tenantId`
60+
*/
61+
val allowedTenants: List<String> = emptyList()
62+
)
63+
4664
data class CsmImages(
4765
/** Container image to fetch Scenario Parameters */
4866
val scenarioFetchParameters: String,

0 commit comments

Comments
 (0)