Skip to content

Support storage-scoped Azure credentials - #5952

Merged
dimas-b merged 19 commits into
apache:mainfrom
sririshindra:named-storage-azure-credentials
Nov 24, 2026
Merged

dimas-b merged 19 commits into
apache:mainfrom
sririshindra:named-storage-azure-credentials

Conversation

@sririshindra

@sririshindra sririshindra commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

A deployment can already select AWS credentials per storage through storageName (#3409, which fixed #2970), but every Azure catalog has to use the single server default. Teams whose storage accounts belong to different identities can't share one Polaris server without giving one identity access to everything.

With RESOLVE_CREDENTIALS_BY_STORAGE_NAME enabled, an Azure storage configuration's storageName now selects a service principal:

polaris.features."RESOLVE_CREDENTIALS_BY_STORAGE_NAME"=true
polaris.storage.azure.team-a.tenant-id=<tenant>
polaris.storage.azure.team-a.client-id=<appId>
polaris.storage.azure.team-a.client-secret=<password>

When no storageName selects a named service principal, the new unnamed polaris.storage.azure.tenant-id, client-id and client-secret are used if all three are set, like polaris.storage.aws.access-key and secret-key on AWS; otherwise the DefaultAzureCredential chain is used as before. An unknown name fails with no fallback, as on AWS. The credentials are selected in AzureCredentialsFactory, a CDI bean that vending, refresh and cleanup tasks all go through. A credential is built for each vend; the vended credentials themselves are cached as before. Two names never share a cached vended credential, because the cache key's identity includes the storage configuration and therefore its storageName. Nothing changes for a deployment that sets none of the new properties and either doesn't set storageName on Azure storages or leaves the flag off. The Helm chart keys for the unnamed properties are in #6095, stacked on this PR.

DefaultAzureCredential is widened to TokenCredential in the integration and its cache key so they can hold either kind, and the cache key's defaultAzureCredential() accessor is renamed credential(). runtime/service now declares com.azure:azure-identity, because ClientSecretCredentialBuilder is used there. That library already ships through polaris-core, and the module's runtime classpath is unchanged by this line.

Behavior to review:

  • An Azure catalog that already has a storageName, on a deployment with the flag enabled, now fails instead of ignoring the name. CHANGELOG.md has an upgrade note.
  • The catalog's tenantId must match the name's tenant-id, ignoring case, or the request fails with an error that doesn't reveal the configured tenant. The SDK would refuse the request anyway, but its message advises enabling additionallyAllowedTenants, which would let a catalog's tenantId choose where a named identity signs in. The credential is built without that setting. A tenant's domain name doesn't match its ID, so both places need the same form.
  • A name missing any of the three properties stops the server at startup, like the required AWS named properties. Any other problem with a name's values fails only the storages that use it.
  • Only client secrets are accepted. Access tokens renew by themselves, and the secret itself is rotated by changing the property and restarting. There's no named bearer token, because a fixed token dies when it expires, and no storage account keys, because user delegation SAS tokens need an Entra identity. Certificates and workload identity can be added later without changing these properties.
  • As on AWS, names apply to the whole deployment, not to one realm. On Azure there is no role to assume after selecting a name: Polaris uses that service principal directly on the catalog's allowed locations. The docs say so.
  • POLARIS_STORAGE_AZURE_TEAM_A_CLIENT_SECRET alone doesn't define team-a, because the name can't be recovered from the variable. It does supply the secret when the other properties define the name, which is the Kubernetes setup in the docs: advancedConfig for the IDs and extraEnv with a secretKeyRef for the secret.

This relates to #5943, which relies on storageName selecting credentials for any storage type, but it works with a catalog's own storage configuration and doesn't depend on that PR. It will conflict slightly with #5951 in the same files, and whichever lands second rebases.

Testing: unit tests cover named and default credentials, no fallback, unknown names, the flag on and off, tenant mismatch, catalogs and cleanup tasks, separate cache entries per name, each name passing its own tenant, client ID and secret to the credential builder, a bad entry failing only its own name without its secret in the error, an incomplete entry failing at startup, and the environment variable form used in the Kubernetes setup. Like the AWS tests, they stop at Polaris's side and don't exercise the Azure SDK itself; the real Azure run below covers that.

:polaris-core:check passes. In :polaris-runtime-service I ran the new test classes and StorageConfigurationTest locally and am relying on CI for the rest of the module. The generated docs were produced on JDK 26, which changes whitespace in unrelated rows, so only the real rows are committed.

I also ran it against real Azure: two ADLS Gen2 accounts, a service principal per account plus a default one with no data role, and Spark 4.1 with Iceberg 1.12 using vended credentials. Each name could create, write and read tables only on its own account. A name used on the other account got a 403 from Azure, and the first name still worked afterwards, so there's no shared cache entry. An unknown name and a tenant mismatch returned 400 without falling back or revealing the configured tenant. A storage without a name used the default credential. With the flag off, the name was ignored. A name missing its secret stopped the server at startup. No secret appeared in the server or Spark logs. (floci-az can't show any of this: it accepts any bearer token.)

Checklist

A deployment can select AWS credentials per storage through storageName,
but every Azure catalog has to use the single server default. With
RESOLVE_CREDENTIALS_BY_STORAGE_NAME enabled, an Azure storage configuration's
storageName now selects the service principal set by
polaris.storage.azure.<storage>.tenant-id, client-id and client-secret.

A storage without a name keeps using the default credentials, and an unknown
name fails with no fallback. The storage configuration's tenantId must match
the name's tenant-id. Each credential is built on first use and then shared,
because its token cache lives inside the credential object.
The cause stays out of the message, which can reach API clients, but is now
kept for the server log. The docs now say that selecting a name requires the
feature flag in that realm and that names are case-sensitive.
Keep the tests in proportion with the AWS named credential tests. They now
check what Polaris passes to the credential builder instead of faking
Microsoft Entra, and no longer test token caching, SDK error text or
configuration library behavior.
…redentials

# Conflicts:
#	runtime/service/src/main/java/org/apache/polaris/service/storage/StorageConfiguration.java
#	site/content/in-dev/unreleased/configuration/config-sections/smallrye-polaris_storage.md
@sririshindra
sririshindra marked this pull request as ready for review November 7, 2026 16:24

@dimas-b dimas-b 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.

Thanks for your contribution, @sririshindra !

The changes LGTM overall with some comments.

* is retried on the next use. Each call builds a new map with new credentials, so call this once
* and keep the result.
*/
default Map<String, AzureNamedCredential> azureNamedCredentials() {

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.

Do we need to materialize the whole map for each call? My impression is that we need to resolve only one particular name per call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. The map was built once, in the application-scoped provider's constructor, but a method that returns every credential isn't the right shape when each call needs only one, and the javadoc had to ask callers to use it only once. In cdda307 I removed the map. The provider now looks up the one name it needs and keeps each built credential in a ConcurrentHashMap, so a credential is still built once per name and shared, and a failed build isn't kept.

new AzureNamedCredential(
storageConfig.tenantId(),
Suppliers.memoize(
() -> buildAzureCredential(storageName, storageConfig)))));

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.

Does memoize help when we rebuild the whole Map?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With the old code, yes, because the map was built once at startup, so every request saw the same suppliers. It only held as long as nobody called the method twice, which is what you're pointing at. cdda307 removes the memoize and the map.

@dimas-b dimas-b mentioned this pull request Nov 9, 2026
6 of 8 tasks
Comment thread CHANGELOG.md Outdated

### New Features

- Added storage-scoped Azure credentials. With `RESOLVE_CREDENTIALS_BY_STORAGE_NAME` enabled, an Azure

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.

FYI: #5967

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the pointer. #5967 isn't merged yet, so I've left the entries in CHANGELOG.md. I'll move them to a changelog.d/ fragment if it lands first.

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.

#5967 has been merged, pls use changelog.d/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks. Merged main, reverted CHANGELOG.md and moved both entries to changelog.d/azure-storage-name-credentials.md (26a9382).

The provider needs one credential per call, so look up the single storage
name instead of building a map of every configured name. Each built
credential is kept in a ConcurrentHashMap and shared, because its access
tokens are cached inside it. A failed build stores nothing and is retried
on the next use.
@sririshindra
sririshindra requested a review from dimas-b November 9, 2026 22:33

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good overall. This closely follows the AWS named-storage design, and the tests are thorough.

Things I checked that are fine:

  • The provider is @ApplicationScoped, so the named-credential map really is shared across requests.
  • A failed build isn't cached, and the next use retries it.
  • The cache key identity comes from the storage config, so two names never share a SAS.
  • The client-facing build error only includes the exception class name. IcebergExceptionMapper still logs the full cause on the server.

One small test ask: can we add a case where two realms have different values of RESOLVE_CREDENTIALS_BY_STORAGE_NAME and use the same storageName? The memo map is app-wide while the flag is per-realm, and that test would lock the behavior down.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

+ "'");
}
// A failed build stores nothing, so the next use builds it again.
return namedCredentials.computeIfAbsent(storageName, storageConfiguration::azureCredential);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We already have named here, but azureCredential(storageName) looks the name up again and repeats the same 'not configured' throw. That branch can't be hit from this path. Can we build from named directly? Or we could move the lookup and tenant check into StorageConfiguration, like stsCredentials(String) does for AWS, so there's just one place.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: the lookup and tenant check moved into StorageConfiguration.azureStorage(storageName, tenantId), and the provider builds from the result. See the reply above on why the check isn't inside the cached loader.


Named credentials apply to the whole deployment, not to one realm. An administrator who can set
`storageName` on a catalog in any realm where `RESOLVE_CREDENTIALS_BY_STORAGE_NAME` is enabled can
select any configured name, and can set the catalog's allowed locations. Polaris then uses that service principal directly on those locations. Only

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This line isn't wrapped like the rest of the section. Can we rewrap it?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rewrapped.

dimas-b
dimas-b previously approved these changes Nov 9, 2026
}
// A client secret credential only obtains tokens for its own tenant. This message can reach API
// clients, so it does not include the tenant configured on the server.
if (!named.tenantId().equalsIgnoreCase(storageConfig.getTenantId())) {

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.

optional: It is a bit awkward to check tenant ID here, but reuse the opaque result of storageConfiguration::azureCredential... How do we know the latter uses the same or different tenant?

WYDT about passing the tenant ID to storageConfiguration::azureCredential and doing the validation there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, done. The name lookup and tenant check now live in StorageConfiguration.azureStorage(storageName, tenantId), like stsCredentials(String) for AWS, and the provider no longer repeats the lookup. I kept the check separate from the credential build rather than putting it inside the computeIfAbsent loader: the credential is shared per name, so a check inside the loader would run only on the first use, and a later catalog with the same name and a different tenant would skip it. The check runs on every call, and only the build is cached.

}

Mockito.verify(teamA).getToken(Mockito.any(TokenRequestContext.class));
Mockito.verify(teamB).getToken(Mockito.any(TokenRequestContext.class));

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.

How does this test prove that the cached credential was not shared?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It didn't show it well: it only counted getToken calls, and both names returned the same SAS. I changed it so each SAS carries the token of the credential that minted it. The test now asserts that team-a gets sas-of-token-a and team-b gets sas-of-token-b on both rounds, and the getToken verifies show the second round was served from the cache.

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Nov 9, 2026
@dimas-b
dimas-b requested a review from adutra November 10, 2026 00:41
The name lookup and tenant check now live in StorageConfiguration, and the
provider builds from the validated configuration instead of looking the name up
again. The checks run on every use; only the built credential is shared per name.

Strengthen the cache test so each SAS shows which credential minted it, add a
test for the realm flag with a shared named credential, and rewrap a doc line.
dimas-b
dimas-b previously approved these changes Nov 10, 2026

@dimas-b dimas-b 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.

Thanks for the update, @sririshindra !

Just one minor doc comment... mostly for the sake of completeness.

key: client-secret
```

Environment variables alone cannot define a name containing a dash, because the name cannot be

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.

They can. The limitation is specific to some shells, not to the environment. For example, one can set env. variables with dashes in their names in k8s.

So, the admin user can configure the same names in java -D properties and in k8s env. vars. and they will work.

Cf. https://polaris.apache.org/releases/1.8.0/configuration/configuring-polaris/

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.

Correct. You don't need to use uppercase environment variables, afaik. The following should work:

  - name: polaris.storage.azure."team-a".client-secret

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks both. That sentence was only true for the uppercase form a shell needs. The Helm example now uses polaris.storage.azure.team-a.client-secret directly, and the paragraph points to the Configuring Polaris page for the shell case. I left the quotes out, since team-a has no dot in it.

new GcpCredentialsStorageIntegration(
gcpCredsProvider.get(), gcpTransportFactory, cache, storageConfig, realmConfig);
// Each named credential holds its own access token cache, so it is built once and shared.
Map<String, TokenCredential> azureNamedCredentials = new ConcurrentHashMap<>();

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.

This creates a closure that I find a bit error-prone. It would be cleaner to introduce a separate class AzureCredentialsFactory and move the Azure code there.

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.

Also the memoization pattern is different between Azure and GCP: gcpNamedCredentialsSuppliers() enumerates the configured storage names eagerly, then creates a (lazily-evaluated) supplier for each credential. Azure instead is doing everything lazily.

Also, GCP's cache lives in the config interface, so the memoization is bundled with the config. Azure's lives in the provider.

It could be good to harmonize things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, done in f07db6f. The Azure code now lives in a package-private AzureCredentialsFactory that the provider creates once, and the cache is a field there instead of a local captured by the lambda.

On harmonizing with GCP, I'd rather bring #5951 in line with this than go the other way. The eager map of memoized suppliers is pretty much what this PR had before, and @dimas-b questioned it earlier in this review. I'll make the same change in #5951 once this one is in.

@dimas-b dimas-b Nov 11, 2026 •

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.

Yes, let's merge this PR first, then do GCP changes similarly :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll follow up in #5951 once this is merged.

Map<String, TokenCredential> namedCredentials) {
String storageName = storageConfig.getStorageName();
// The checks run on every use. Only the credential, which belongs to the name alone, is shared.
AzureNamedStorageConfig named =

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.

nit: named could be constructed inside computeIfAbsent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kept the lookup outside on purpose. It also does the tenant check, and that has to run on every call. The computeIfAbsent loader only runs the first time a name is used, so a later catalog using the same name with a different tenantId would skip the check. It's in AzureCredentialsFactory now, but it works the same way: check every time, build once.

* tokens for its own tenant. The messages can reach API clients, so they do not include the
* tenant configured on the server.
*/
default AzureNamedStorageConfig azureStorage(String storageName, String tenantId) {

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.

TBH I'm not convinced that all these methods belong in this class, which is just a configuration class. But since we're doing the same for AWS and GCP, I'm OK. There is some potential for cleanup here.

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.

I tend to agree, actually.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. After f07db6f StorageConfiguration only has the Azure properties; the lookup, the checks and the build are in AzureCredentialsFactory. I didn't touch the existing AWS and GCP helpers here, since that feels like its own cleanup.

*/
default TokenCredential azureCredential(
String storageName, AzureNamedStorageConfig storageConfig) {
return buildAzureCredential(storageName, storageConfig);

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.

Can't we just inline this method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was only there so the provider could reach the private builder. It's gone now; the build is a private method of AzureCredentialsFactory.

Optional<Instant> gcpAccessTokenExpiry();

@WithName("azure")
AzureStorageConfig azure();

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.

Something is not symmetric with how we handle AWS credentials:

  • In AWS when no named storage is present, we first inspect the "unnamed" properties polaris.storage.aws.access-key and polaris.storage.aws.secret-key. Only if those unnamed properties are missing, we build a default credentials provider from the environment:

default AwsCredentialsProvider stsCredentials() {
if (aws().accessKey().isPresent() && aws().secretKey().isPresent()) {
LoggerFactory.getLogger(StorageConfiguration.class)
.warn("Using hard-coded AWS credentials - this is not recommended for production");
return StaticCredentialsProvider.create(
AwsBasicCredentials.create(aws().accessKey().get(), aws().secretKey().get()));
} else {
return DefaultCredentialsProvider.builder().build();
}
}

  • In Azure, it seems that the absence of named config falls back to credentials built from the environment directly; IOW, there are no "unnamed" properties like polaris.storage.azure.tenant-id.

Why is that? I think it would be good to provide the same resolution logic across cloud providers, which makes Polaris behavior more predictable, imo. Besides, adding support for unnamed Azure properties is safe, since it's a new thing so no existing deployment can be affected by that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No good reason, I had only done the named case. I agree it's better if the clouds resolve the same way, so f07db6f adds polaris.storage.azure.tenant-id, client-id and client-secret. When all three are set, they're used whenever no storageName picks a named principal (also with the flag off). Otherwise it falls back to DefaultAzureCredential as today.

Two differences from AWS: if only some of the three are set, the request fails and the error lists the missing ones, instead of quietly using the default chain. And the catalog's tenantId has to match tenant-id, same as for named ones. Happy to change either if you'd rather match AWS exactly.


The following rules apply:

- A storage without a `storageName` uses the default credentials.

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.

See my previous comment. What "default credentials" mean here is not what I expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair, that was vague. The bullet now links to the section at the top of the page, which covers both the new polaris.storage.azure.* properties and the DefaultAzureCredential fallback.

name's values fails only the storages that use it.
- A credential is created the first time its name is used, and then kept until Polaris restarts.

In Kubernetes, do not put the client secret in the pod spec or in a `ConfigMap` as plain text. Set

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.

Shouldn't we provide a better UX here? I see that we currently have support only for unnamed credentials for AWS and GCP and no support for Azure at all:

# Storage credentials for the server. If the following properties are unset, default credentials
# will be used, in which case the pod must have the necessary permissions to access the storage.
storage:
# The secret to pull storage credentials from.
secret:
# -- The name of the secret to pull storage credentials from.
# @section -- Storage
name: ""
# -- The key in the secret to pull the AWS access key ID from. Only required when using AWS.
# @section -- Storage
awsAccessKeyId: ""
# -- The key in the secret to pull the AWS secret access key from. Only required when using AWS.
# @section -- Storage
awsSecretAccessKey: ""
# -- The key in the secret to pull the GCP token from. Only required when using GCP.
# @section -- Storage
gcpToken: ""
# -- The key in the secret to pull the GCP token expiration time from. Only required when using GCP. Must be a valid ISO 8601 duration. The default is PT1H (1 hour).
# @section -- Storage
gcpTokenLifespan: ""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I added storage.secret.azureTenantId, azureClientId and azureClientSecret, mapped to the new unnamed properties the same way the AWS and GCP keys are. Named storages still go through advancedConfig / extraEnv as in the example. That's the case for AWS today too, so I left it as is.

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.

OK to move this change to #6095 .

key: client-secret
```

Environment variables alone cannot define a name containing a dash, because the name cannot be

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.

Correct. You don't need to use uppercase environment variables, afaik. The following should work:

  - name: polaris.storage.azure."team-a".client-secret

@dimas-b

dimas-b commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@sririshindra : This is big behaviour change, so I started a dev discussion for community awareness: https://lists.apache.org/thread/42hgrj6oz0xhvhqvjo8jjgp2m08d0kts

…ection out of StorageConfiguration

Azure had no Polaris properties for its default service principal: without a
storage name, it always used the DefaultAzureCredential chain, while AWS first
checks polaris.storage.aws.access-key and secret-key. Add
polaris.storage.azure.tenant-id, client-id and client-secret. When all three
are set, they are used whenever no storage name selects a named service
principal, including with RESOLVE_CREDENTIALS_BY_STORAGE_NAME off. When only
some are set, the request fails and names the missing properties. As for named
credentials, the storage configuration's tenantId must match. The Helm chart
can load the three properties from a Secret.

The selection, the checks and the credential cache move from
StorageConfiguration and a lambda in the provider into a package-private
AzureCredentialsFactory, so StorageConfiguration only holds properties.

The docs now say that Kubernetes accepts property names as environment
variable names; the uppercase form is only needed in a shell.
Comment thread helm/polaris/templates/deployment.yaml Outdated
{{- include "polaris.secretToEnv" (list .Values.storage.secret "awsAccessKeyId" "polaris.storage.aws.access-key") | indent 12 -}}
{{- include "polaris.secretToEnv" (list .Values.storage.secret "awsSecretAccessKey" "polaris.storage.aws.secret-key") | indent 12 -}}
{{- include "polaris.secretToEnv" (list .Values.storage.secret "gcpToken" "polaris.storage.gcp.token") | indent 12 -}}
{{- include "polaris.secretToEnv" (list .Values.storage.secret "azureTenantId" "polaris.storage.azure.tenant-id") | indent 12 -}}

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.

Would you mind moving helm changes to another PR?... just for ease of review 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, done in 45684b1. The chart keys are now in #6095, stacked on this branch because they map to the new polaris.storage.azure.tenant-id, client-id and client-secret properties. @adutra, that's where the Helm support you asked for went.

@dimas-b dimas-b 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.

A few fresh minor comments on top of the request to isolate helm changes, please 😉

azureCredentials
.credential(
storageConfig,
realmConfig.getConfig(FeatureConfiguration.RESOLVE_CREDENTIALS_BY_STORAGE_NAME))

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.

Would it be nicer to make AzureCredentialsFactory a proper CDI bean and inject storageConfiguration + realmConfig into it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, done in 0c2064d. AzureCredentialsFactory is now an @ApplicationScoped bean with StorageConfiguration and RealmConfig injected, like StsCredentialVendingMechanism, and it reads the storage-name flag itself.


private final AzureStorageConfig azure;
private final Supplier<TokenCredential> unnamedCredential;
private final Map<String, TokenCredential> namedCredentials = new ConcurrentHashMap<>();

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.

Do we gain much by caching TokenCredential? They are not costly to construct, and we already have a higher-level vended credentials cache 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point. A credential is cheap to build, and the only thing the cache saved was one token request on a vended-credential cache miss, which is also what main does today with the default chain. In 0c2064d the factory builds the credential on each call, and the map and memoization are gone (986bb51 drops the doc line that said otherwise).

credential, cache, storageConfig, realmConfig))
.orElseGet(
() ->
new AzureCredentialsStorageIntegration(cache, storageConfig, realmConfig));

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.

I think AzureCredentialsFactory can handle the DefaultAzureCredential case too... WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. In 0c2064d the factory always returns a credential and falls back to DefaultAzureCredential itself, so the provider has a single path.

The storage.secret.azureTenantId, azureClientId and azureClientSecret chart
keys, their schema, test and reference rows go to their own pull request.
The Azure page and the CHANGELOG no longer mention them.
…edential

AzureCredentialsFactory is now an @ApplicationScoped bean with
StorageConfiguration and RealmConfig injected, like
StsCredentialVendingMechanism, and reads RESOLVE_CREDENTIALS_BY_STORAGE_NAME
itself. It always returns a credential: the named one, else the unnamed
one, else the DefaultAzureCredential chain, so the provider has a single
path.

Credentials are no longer cached. They are cheap to build, and vended
credentials are already cached by StorageCredentialCache; main builds the
default chain per integration in the same way.
…start

Credentials are now built on each use.
}
if (missing.size() == 3) {
// Reads the AZURE_* environment variables, among other sources.
return new DefaultAzureCredentialBuilder().build();

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.

Should this be memoized / cached?

@dimas-b dimas-b Nov 18, 2026 •

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.

If it performs I/O (e.g. file reads) it would make sense to cache it (static singleton), I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, done in ba0a729. Building it does little I/O, but the instance keeps state. DefaultAzureCredential remembers which credential in its chain worked, and that credential caches its tokens. A new instance per call repeated the chain walk on every vended-credential cache miss, including the managed-identity probe when running outside Azure. The factory now builds it lazily, once, and reuses it. I kept it as a field of the @ApplicationScoped factory rather than a static, so it is still one per server but tests do not share it. theDefaultCredentialIsBuiltOnce covers it.

name's values fails only the storages that use it.
- A credential is created the first time its name is used, and then kept until Polaris restarts.

In Kubernetes, do not put the client secret in the pod spec or in a `ConfigMap` as plain text. Set

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.

OK to move this change to #6095 .

@adutra

adutra commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #5967 has been merged, so CHANGELOG.md is no longer edited directly. Changelog entries now go in a fragment file under changelog.d/, which avoids merge conflicts on CHANGELOG.md. See changelog.d/README.md for the format.

Could you rebase onto main, revert your changes to CHANGELOG.md, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!

The chain remembers which of its credentials works, and that credential
caches its tokens, so building a new one per call repeated the chain walk
on every vended-credential cache miss.

@sririshindra sririshindra left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dimas-b @adutra, I think everything from the last round is addressed: the changelog entries are in changelog.d/azure-storage-name-credentials.md (), and DefaultAzureCredential is now built once and reused (). Could you take another look when you have a moment

}

@Test
void theFlagIsReadPerRealm() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On the two-realm question from the earlier automated review: this test covers it. One AzureCredentialsFactory handles the same storageName while the realm's RESOLVE_CREDENTIALS_BY_STORAGE_NAME value goes on, off, then on. Both calls with the flag on build team-a's credential, and the call with it off uses the default credential, so the flag is read on every call and never kept in the shared bean.

@jbonofre
jbonofre self-requested a review November 23, 2026 17:17

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

A few non-blocking comments:

  1. when a named client secret expires or a client ID is wrong, Entra returns ADDSTS errors. Their messages include the client ID and sometimes the tenant. As far as I can tell, these are rethrown unwrapped and can end up in the API response. The build path already wraps errors to avoid exposing configured values. It would be good to do the same here.
  2. If only some of polaris.storage.azure.tenant-id / client-id / client-secret are set, every request fails with a 500. That includes catalogs that previously worked with DefaultAzureCredential. Incomplete named entries fail at startup. Could the unnamed properties be validated the same way?
  3. with RESOLVE_CREDENTIALS_BY_STORAGE_NAME enabled, a catalog with "storageName": "" fails with Storage name '' is not configured on the server. The SigV4 paths treat null or empty as absent. Should Azure do the same?
  4. the incomplete-confiiguration error returns polaris.storage.azure.* property names to the client. The R2 path (CloudflareR2ParentTokenResolver) logs them at WARN and returns a generic message instead. It would be nice to align.

@sririshindra

Copy link
Copy Markdown
Contributor Author

LGTM, thanks!

A few non-blocking comments:

  1. when a named client secret expires or a client ID is wrong, Entra returns ADDSTS errors. Their messages include the client ID and sometimes the tenant. As far as I can tell, these are rethrown unwrapped and can end up in the API response. The build path already wraps errors to avoid exposing configured values. It would be good to do the same here.
  2. If only some of polaris.storage.azure.tenant-id / client-id / client-secret are set, every request fails with a 500. That includes catalogs that previously worked with DefaultAzureCredential. Incomplete named entries fail at startup. Could the unnamed properties be validated the same way?
  3. with RESOLVE_CREDENTIALS_BY_STORAGE_NAME enabled, a catalog with "storageName": "" fails with Storage name '' is not configured on the server. The SigV4 paths treat null or empty as absent. Should Azure do the same?
  4. the incomplete-confiiguration error returns polaris.storage.azure.* property names to the client. The R2 path (CloudflareR2ParentTokenResolver) logs them at WARN and returns a generic message instead. It would be nice to align.

Thank you JB! I will address your comments in a follow up PR right after this merges to main.

@dimas-b

dimas-b commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Merging current changes with follow-up planned as discussed in review comments.

@dimas-b
dimas-b merged commit f3aa440 into apache:main Nov 24, 2026
28 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Per-Catalog AWS Credentials in MinIO Deployments

5 participants