Skip to content

[PROTOTYPE][Do Not Merge] External Evaluation (Invoke) policy for azure-core-management - #49701

Draft
Weidong Xu (weidongxu-microsoft) wants to merge 12 commits into
Azure:mainfrom
weidongxu-microsoft:core-mgmt-external-evaluation-policy
Draft

Weidong Xu (weidongxu-microsoft) wants to merge 12 commits into
Azure:mainfrom
weidongxu-microsoft:core-mgmt-external-evaluation-policy

Conversation

@weidongxu-microsoft

@weidongxu-microsoft Weidong Xu (weidongxu-microsoft) commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

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 receives 403 RequestDisallowedByPolicy, the policy acquires a policy token through the same downstream HTTP pipeline and replays the original request with the x-ms-policy-external-evaluations header.

Acquisition occurs only when every blocking PolicyViolation contains evaluationDetails.missingPolicyTokenDetails.shouldDeny=true. The policy uses the hard-coded Policy API version 2026-07-01 and 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:

StorageManager.configure()
    .withPolicy(new ExternalEvaluationPolicy())
    .authenticate(credential, profile);

What is included

Main:

  • ExternalEvaluationPolicy in com.azure.core.management.http.policy detects actionable denials, sends acquirePolicyToken through a cloned downstream continuation, and replays the exact original request.
  • Internal policy-violation parsing requires all blocking violations to need a policy token and rejects ChangeSafety challenges.
  • Any successful acquisition response containing a non-blank top-level token triggers replay. Acquisition failures are chained beneath the original 403 ManagementException.
  • HttpLoggingPolicy.BODY_LOGGING_DISABLED_CONTEXT suppresses 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:

  • ExternalEvaluationPolicyTests covers sync and async flows, all three routes, exact body preservation, bodyless requests, violation filtering, token semantics, acquisition errors, loop prevention, and logging-context restoration.
  • ExternalEvaluationPolicyE2ETests exercises the built-in resource-group acquisition flow through a generated Storage client with ARM simulated by WireMock.
  • HttpLoggingPolicyTests covers synchronous and asynchronous body suppression.

Prototype caveats

  • Copied fixtures: generated Storage sources are copied under test to provide a realistic guarded management client.
  • JPMS test plumbing: pom.xml add-opens/add-reads and a trust-all Netty client are test-only WireMock-over-HTTPS scaffolding.
  • Core logging API: the public body-suppression context key broadens azure-core for security hardening that is not required by the acquire-and-replay flow; this may be better handled separately.
  • API placement, policy ordering, opt-in versus default behavior, and production logging behavior remain design-review questions.

Validation

  • HttpLoggingPolicyTests: 47 passed.
  • ExternalEvaluationPolicyTests and ExternalEvaluationPolicyE2ETests: 19 passed.
  • azure-core-management Maven verify: successful with zero Checkstyle violations and zero SpotBugs findings.

… 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>
@github-actions github-actions Bot added the Azure.Core azure-core label Jul 2, 2026
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>
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the no-recent-activity There has been no recent activity on this issue. label Sep 4, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 /reopen if you'd like to continue working on these changes. Please be sure to use the command to reopen or remove the no-recent-activity label; otherwise, this is likely to be closed again with the next cleanup pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 61e77038-c0b1-4068-864f-8ad207209200
@azure-sdk-automation

Copy link
Copy Markdown
Contributor

The sdk-api-review-ready label cannot create a review PR for this working PR because its branch is in a fork repository. Prefer a working branch in the registered upstream repository, or reach out to the ARH maintainers for help. Fork reviews are supported through the Azure SDK CLI (azsdk apireview create), but the fork requires its own ARH registration and the review PR is created in the fork rather than the upstream repository.

@github-actions github-actions Bot removed the no-recent-activity There has been no recent activity on this issue. label Nov 24, 2026
* 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";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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
Copilot AI balanced review requested due to automatic review settings November 24, 2026 07:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The external_dependency marker lacks a matching catalog entry for WireMock, causing version-update runs that process this POM to fail.

1 open issue
1 resolved since last review

Review effort: Balanced

<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} -->

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core azure-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants