Repository navigation
[PROTOTYPE][Do Not Merge] External Evaluation (Invoke) policy for azure-core-management - #49701
Weidong Xu (weidongxu-microsoft) wants to merge 12 commits into
Conversation
… draft) Adds ExternalEvaluationPolicy plus the PolicyTokenCredential / PolicyToken / PolicyTokenRequestContext trio to support the Azure Policy external evaluation flow: on a 403 RequestDisallowedByPolicy with missingPolicyTokenDetails, acquire a policy token and retry the operation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copied the TypeSpec-generated Storage management client into azure-core-management test sources to serve as the guarded ARM client for the External Evaluation policy E2E test. Suppressed a deprecation warning on HttpResponse.getHeaderValue(String) to satisfy -Werror. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… propagation The External Evaluation policy set the acquired token header on an early-captured request reference. Because the retry policy below it replaces the context's request with a fresh copy on each attempt, the header was lost on the replay. Set the header on context.getHttpRequest() so the retried request carries it. Add a WireMock-based E2E test that drives a copied Storage management client guarded by the policy and acquires the token via the real acquirePolicyToken API from azure-resourcemanager-resources. Opens the storage model packages to azure-core/azure-json for reflective (de)serialization under JPMS. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…isition fails When ExternalEvaluationPolicy cannot acquire a policy token, the operation remains denied by policy. Re-surface the original 403 as a ManagementException (the exception the caller would otherwise see) with the acquisition failure chained as its cause, in both the async and sync paths. The credential wrapper in the E2E test now errors on a failed/missing token result. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… body The mock ARM service now asserts every aspect of the guarded requests: - both PUTs match the exact URL path, PUT method, and a byte-for-byte identical request body (the External Evaluation flow requires the retried body to be identical to the original); - the denied PUT has no token header while the retried PUT carries the acquired token; - the acquirePolicyToken POST echoes the guarded operation verbatim (same httpMethod, same uri, and byte-for-byte the same content). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace matchingJsonPath/equalToJson on the acquirePolicyToken POST with a single byte-for-byte equalTo against the exact serialized request body. The PolicyTokenRequest serialization order is deterministic (operation -> uri, httpMethod, content), so the whole body can be asserted as an exact UTF-8 string, matching the byte-for-byte requirement on operation.content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…2E test Opt into the External Evaluation flow the way a user would: build the guarded StorageManager through configure().withPolicy(new ExternalEvaluationPolicy(...)) .authenticate(credential, profile) instead of hand-assembling the pipeline and calling authenticate(pipeline, profile). This also verifies the policy is placed correctly (PER_CALL, above retry) within the real manager pipeline. Because the manager pipeline adds a BearerTokenAuthenticationPolicy that requires HTTPS, the mock service is now served over TLS and the clients use a trust-all Netty HTTP client. Adds --add-reads for com.azure.http.netty to the module test args. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The acquired policy token is not an authentication credential (it is a token proving external policy evaluation context, not an AAD token), so 'Credential' was misleading. Rename the interface to PolicyTokenProvider and update the ExternalEvaluationPolicy field/parameter, tests, javadoc and CHANGELOG. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply the external evaluation flow to all resource operations except GET, and skip any request that already carries the x-ms-policy-external-evaluations header. Per the service contract such a request will not produce a 403 with missingPolicyTokenDetails, so this acts as a loop guard (relevant now that non-idempotent POST is in scope). Bodyless operations (e.g. DELETE) acquire a token with null operation.content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Hi Weidong Xu (@weidongxu-microsoft). Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
|
Hi Weidong Xu (@weidongxu-microsoft). Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61e77038-c0b1-4068-864f-8ad207209200
|
The |
| * The body is not logged when this context value is {@code true}. Custom request and response loggers should also | ||
| * honor this value when handling sensitive bodies. | ||
| */ | ||
| public static final String BODY_LOGGING_DISABLED_CONTEXT = "azure-http-body-logging-disabled"; |
There was a problem hiding this comment.
Reason: the acquisition request embeds the original operation body, and its response contains the policy token, so BODY-level pipeline logging could expose sensitive content. Concern: this introduces a public azure-core API for a management-specific prototype and custom loggers must opt in to honoring it. Necessity: this is security hardening, not required for the acquire-and-replay flow; please confirm that a generic core hook is appropriate rather than handling or tracking secure acquisition logging separately.
There was a problem hiding this comment.
🟡 Changes recommended
The PR description and API documentation still misrepresent ExternalEvaluationPolicy’s constructor and token acquisition, leaving the opt-in example unable to compile against the current API.
1 open issue
What changed in this PR
This design-review prototype explores automatic Azure Policy external evaluation for management clients. The reviewed changes support policy-denial parsing, sensitive-body logging suppression, and realistic Storage client test fixtures.
Changes:
- Add parsing for policy violations that require token acquisition.
- Add per-call request and response body logging suppression, with synchronous and asynchronous tests.
- Add generated Storage test fixtures, test-module access settings, and changelog entries.
Paths below are relative to sdk/core/.
| File | Description |
|---|---|
azure-core/src/test/java/com/azure/core/http/policy/HttpLoggingPolicyTests.java |
Tests body logging suppression in async and sync calls. |
azure-core/src/main/java/com/azure/core/http/policy/HttpLoggingPolicy.java |
Adds context-controlled body logging suppression. |
azure-core/CHANGELOG.md |
Documents the logging control. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/package-info.java |
Documents the Storage fixture package. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ZonePlacementPolicy.java |
Adds zone-placement values for fixtures. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/VirtualNetworkRule.java |
Models virtual network rules in fixtures. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/UserAssignedIdentity.java |
Models user-assigned identity responses. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/StorageDataCollaborationPolicyProperties.java |
Adds data collaboration settings to fixtures. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/StorageAccountSkuConversionStatus.java |
Models account SKU conversion status. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/StorageAccountMicrosoftEndpoints.java |
Models Microsoft-routed account endpoints. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/StorageAccountInternetEndpoints.java |
Models internet-routed account endpoints. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/State.java |
Adds virtual network rule states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/SmbOAuthSettings.java |
Models SMB OAuth settings. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/SkuTier.java |
Adds Storage SKU tiers. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/SkuName.java |
Adds Storage SKU names. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/SkuConversionStatus.java |
Adds SKU conversion states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/Sku.java |
Models account SKU serialization. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ServiceSharedKeyAccessProperties.java |
Models service shared-key settings. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/SasPolicy.java |
Models SAS expiration policy. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/RoutingPreference.java |
Models endpoint routing preferences. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/RoutingChoice.java |
Adds routing choices. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ResourceProviders.java |
Defines the fixture resource-creation entry point. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ResourceAccessRule.java |
Models resource access rules. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PublicNetworkAccess.java |
Adds public network access modes. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ProvisioningState.java |
Adds account provisioning states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PrivateLinkServiceConnectionState.java |
Models private-link connection state. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PrivateEndpointServiceConnectionStatus.java |
Adds private endpoint connection statuses. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PrivateEndpointConnectionProvisioningState.java |
Adds private endpoint provisioning states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PrivateEndpointConnection.java |
Models private endpoint connection resources. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PrivateEndpoint.java |
Models private endpoint identifiers. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PostPlannedFailoverRedundancy.java |
Adds planned-failover redundancy values. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/PostFailoverRedundancy.java |
Adds failover redundancy values. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/Placement.java |
Models zonal placement settings. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/package-info.java |
Documents fixture data models. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/MinimumTlsVersion.java |
Adds TLS version values for fixtures. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/LargeFileSharesState.java |
Adds large-file-share states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/Kind.java |
Adds Storage account kinds. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/KeyType.java |
Adds encryption key types. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/KeySource.java |
Adds encryption key sources. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/KeyPolicy.java |
Models key expiration policy. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/KeyCreationTime.java |
Models key creation timestamps. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/IpRule.java |
Models IP access rules. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ImmutableStorageAccount.java |
Models account immutability settings. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/IdentityType.java |
Adds managed identity types. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/Identity.java |
Models account identity configuration. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/GeoReplicationStatus.java |
Adds geo-replication states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/GeoPriorityReplicationStatus.java |
Models priority replication settings. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ExtendedLocationTypes.java |
Adds extended-location types. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ExtendedLocation.java |
Models extended-location configuration. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ExpirationAction.java |
Adds SAS expiration actions. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/EncryptionServices.java |
Groups service encryption settings. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/EncryptionService.java |
Models individual service encryption. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/EncryptionIdentity.java |
Models encryption identity configuration. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/DualStackEndpointPreference.java |
Models IPv6 endpoint preferences. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/DnsEndpointType.java |
Adds DNS endpoint types. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/DirectoryServiceOptions.java |
Adds directory authentication options. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/DefaultSharePermission.java |
Adds default share permissions. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/DefaultAction.java |
Adds default network rule actions. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/CustomDomain.java |
Models custom domain configuration. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/Bypass.java |
Adds network rule bypass values. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/BlobRestoreStatus.java |
Models blob restore status responses. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/BlobRestoreRange.java |
Models blob restore ranges. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/BlobRestoreProgressStatus.java |
Adds blob restore progress states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/BlobRestoreParameters.java |
Models blob restore parameters. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/AllowedCopyScope.java |
Adds permitted copy scopes. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/ActiveDirectoryPropertiesAccountType.java |
Adds directory account types. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/Action.java |
Adds access-rule action values. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/AccountStatus.java |
Adds account availability states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/AccountImmutabilityPolicyState.java |
Adds immutability policy states. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/models/AccessTier.java |
Adds account access tiers. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/implementation/StorageManagementClientBuilder.java |
Builds the generated Storage fixture client. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/implementation/ResourceProvidersImpl.java |
Implements fixture resource definitions. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/implementation/package-info.java |
Documents fixture implementations. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/fluent/StorageManagementClient.java |
Defines the fixture management client contract. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/fluent/ResourceProvidersClient.java |
Defines Storage creation and polling operations. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/fluent/package-info.java |
Documents fixture service clients. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/fluent/models/PrivateEndpointConnectionProperties.java |
Models private endpoint inner properties. |
azure-core-management/src/test/java/com/azure/resourcemanager/storage/fluent/models/package-info.java |
Documents fixture inner models. |
azure-core-management/src/main/java/com/azure/core/management/implementation/evaluation/package-info.java |
Documents internal evaluation types. |
azure-core-management/src/main/java/com/azure/core/management/implementation/evaluation/MissingPolicyTokenDetails.java |
Parses actionable token requirements and change-reference flags. |
azure-core-management/pom.xml |
Adds module access settings for tests. |
azure-core-management/CHANGELOG.md |
Documents external evaluation support. |
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61e77038-c0b1-4068-864f-8ad207209200
| <dependency> | ||
| <groupId>com.github.tomakehurst</groupId> | ||
| <artifactId>wiremock-jre8-standalone</artifactId> | ||
| <version>2.35.2</version> <!-- {x-version-update;com.github.tomakehurst:wiremock-jre8-standalone;external_dependency} --> |


Warning
This is a PROTOTYPE / design-review draft — not intended to merge as-is.
Summary
Prototype of an External Evaluation ("Invoke") policy for
azure-core-management. When a non-GET management operation receives403 RequestDisallowedByPolicy, the policy acquires a policy token through the same downstream HTTP pipeline and replays the original request with thex-ms-policy-external-evaluationsheader.Acquisition occurs only when every blocking
PolicyViolationcontainsevaluationDetails.missingPolicyTokenDetails.shouldDeny=true. The policy uses the hard-coded Policy API version2026-07-01and selects the subscription, resource-group, or management-group acquisition route from the original ARM URL.How a user opts in
Add the policy to the management client pipeline:
What is included
Main:
ExternalEvaluationPolicyincom.azure.core.management.http.policydetects actionable denials, sendsacquirePolicyTokenthrough a cloned downstream continuation, and replays the exact original request.tokentriggers replay. Acquisition failures are chained beneath the original 403ManagementException.HttpLoggingPolicy.BODY_LOGGING_DISABLED_CONTEXTsuppresses acquisition request and response bodies in the default logger. This is security hardening rather than a functional dependency and is included for design review.Tests:
ExternalEvaluationPolicyTestscovers sync and async flows, all three routes, exact body preservation, bodyless requests, violation filtering, token semantics, acquisition errors, loop prevention, and logging-context restoration.ExternalEvaluationPolicyE2ETestsexercises the built-in resource-group acquisition flow through a generated Storage client with ARM simulated by WireMock.HttpLoggingPolicyTestscovers synchronous and asynchronous body suppression.Prototype caveats
pom.xmladd-opens/add-reads and a trust-all Netty client are test-only WireMock-over-HTTPS scaffolding.azure-corefor security hardening that is not required by the acquire-and-replay flow; this may be better handled separately.Validation
HttpLoggingPolicyTests: 47 passed.ExternalEvaluationPolicyTestsandExternalEvaluationPolicyE2ETests: 19 passed.azure-core-managementMavenverify: successful with zero Checkstyle violations and zero SpotBugs findings.