Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens default AAD JWT validation behavior in spring-cloud-azure-autoconfigure by enforcing tenant-aware issuer validation for single-tenant resource servers and enabling explicit audience validation by default in AadAuthenticationFilter.
Changes:
- Wire
AadResourceServerConfigurationissuer validation to useAadTrustedIssuerRepositoryfor single-tenant tenant IDs while preserving legacy prefix-based issuer validation forcommon/organizations/consumers. - Change
AadAuthenticationFilterdefault constructors to enable explicit audience checking by default. - Add/update tests covering the new default behaviors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/filter/AadAuthenticationFilter.java | Switch constructor defaults to enable explicit audience validation. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/configuration/AadResourceServerConfiguration.java | Use trusted-issuer exact matching for single-tenant issuer validation; keep multi-tenant legacy behavior. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/filter/AadAuthenticationFilterTests.java | Add tests validating constructor defaults for explicit audience checking. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/configuration/AadResourceServerConfigurationTests.java | Add tests validating single-tenant vs multi-tenant issuer validator wiring. |
| sdk/spring/CHANGELOG.md | Document the hardened defaults in changelog. |
|
@copilot apply changes based on the comments in this thread |
…pplication, fix changelog link Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/ac6fd8b6-366e-4630-bcaf-fee4ad6e62c3 Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Applied all three changes from the review thread in commit
|
|
Ignore the test failure about java - spring - ci (Build Test ubuntu2404_121_NotFromSource_TestsOnly), it's a know issue: #48622 |
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/bf7036ec-7fdf-46d5-8050-b72f537332d4 Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
…ationProperties Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/f49e9a93-8331-49f4-b8f0-2f78dbb7c32a Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/security/jwt/AadJwtIssuerValidatorTests.java:28
- These tests still mock AadAuthenticationProperties and stub getProfile(), but AadJwtIssuerValidator no longer consumes AadAuthenticationProperties/profile. Consider removing the unused mock/stubbings (and the unused AadProfileProperties setup) to keep the tests focused on issuer validation via AadTrustedIssuerRepository.
private final AadAuthenticationProperties aadAuthenticationProperties = mock(AadAuthenticationProperties.class);
private final Jwt jwt = mock(Jwt.class);
private final AadTrustedIssuerRepository aadTrustedIssuerRepository = new AadTrustedIssuerRepository("fake-tenant"
+ "-id");
@Test
void testIssuerSuccessVerify() {
AadProfileProperties profile = new AadProfileProperties();
profile.setTenantId("fake-tenant-id");
when(aadAuthenticationProperties.getProfile()).thenReturn(profile);
when(jwt.getClaim(AadJwtClaimNames.ISS)).thenReturn("https://sts.windows.net/fake-tenant-id/v2.0");
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/5f933fe4-f982-43ca-bf21-aa15b7b6e35d Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Fixed in commit |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/security/jwt/AadJwtIssuerValidatorTests.java:28
- In these tests,
aadAuthenticationPropertiesand theprofilestubbing are unused:AadJwtIssuerValidatoronly consults theissclaim and the providedAadTrustedIssuerRepository. Removing the unused mock/stubbing will make the tests clearer and avoid implying thattenantIdfrom properties participates in issuer validation here.
private final AadAuthenticationProperties aadAuthenticationProperties = mock(AadAuthenticationProperties.class);
private final Jwt jwt = mock(Jwt.class);
private final AadTrustedIssuerRepository aadTrustedIssuerRepository = new AadTrustedIssuerRepository("fake-tenant"
+ "-id");
@Test
void testIssuerSuccessVerify() {
AadProfileProperties profile = new AadProfileProperties();
profile.setTenantId("fake-tenant-id");
when(aadAuthenticationProperties.getProfile()).thenReturn(profile);
when(jwt.getClaim(AadJwtClaimNames.ISS)).thenReturn("https://sts.windows.net/fake-tenant-id/v2.0");
|
@copilot apply changes based on the comments in this thread |
…tespace bypass Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/2a42cd2f-33b4-4aec-b260-e3faedadfb31 Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
…mming Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/2a42cd2f-33b4-4aec-b260-e3faedadfb31 Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Fixed in commits |
| String tenantId = aadAuthenticationProperties.getProfile().getTenantId(); | ||
| if (tenantId != null) { | ||
| tenantId = tenantId.trim(); | ||
| } | ||
| validateTenantId(tenantId); |
|
@copilot apply changes based on the comments in this thread |
…Endpoints Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/43c934ea-32ac-4a47-b018-0b58d11fc30a Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/43c934ea-32ac-4a47-b018-0b58d11fc30a Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Fixed in commit |
This pull request introduces important security improvements and breaking changes to the Azure Spring Cloud AAD resource server integration. The main focus is to enforce explicit tenant restrictions and audience validation for JWT tokens, preventing cross-tenant and cross-application token misuse. These changes align the implementation with Microsoft’s security best practices and include comprehensive test coverage for the new behaviors.
Key changes include:
Breaking Security Changes
spring.cloud.azure.active-directory.profile.tenant-idto be set to a specific (non-reserved) tenant ID. Using empty,common,organizations, orconsumersis now prohibited and will cause application startup to fail with anIllegalArgumentException. This enforces strict tenant isolation and prevents accidental security vulnerabilities. [1] [2]AadAuthenticationFilternow enables explicit audience (aud) validation by default. JWTs must have an audience claim that matches either the configured client ID or App ID URI, preventing tokens issued for other applications from being accepted. [1] [2] [3]JWT Validation Improvements
aud), tenant ID (tid), issuer (iss), and token timestamps. The issuer validator now always requires a trusted issuer repository, and only accepts issuers from the configured tenant. [1] [2]Test Enhancements
Minor Fixes
UserPrincipalManagerfor better clarity.Documentation
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines