You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "zhang-arvin (via GitHub)" <gi...@apache.org> on 2026/09/22 05:53:25 UTC
[PR] fix(core): vendor Azure credentials per storage account and container [polaris]
zhang-arvin opened a new pull request, #5578:
URL: https://github.com/apache/polaris/pull/5578
<!--
Thank you for contributing to Apache Polaris. Please make sure you've read the contributing guidelines:
https://polaris.apache.org/community/contributing/
-->
### What changes were proposed in this pull request?
`AzureCredentialsStorageIntegration` required every allowed read/write location to belong to the same
storage account and container, and refused credential vending with
`RuntimeException: Expect allowed read write locations belong to the same storage account and
container` whenever they did not. Iceberg explicitly supports keeping table metadata and data in
different locations (`write.metadata.path` / `write.data.path`), so creating a table whose metadata
lives in one storage account/container and whose data lives in another was impossible on Azure.
This change replaces the whole-request restriction with per-scope credential vending:
- The allowed read/write locations are grouped by storage account, container and endpoint.
- One container-scoped SAS token is minted per distinct scope, and the read/write permissions of
each token are derived only from the locations that fall inside that scope, so a write grant in
the metadata scope does not leak into the data scope (and vice versa).
- Locations that are not part of the authorized set are still never vended: the keyed credentials
are built exclusively from the requested locations.
Keys that identify a *storage account* rather than a container cannot hold more than one value, so
they keep their previous meaning and are emitted only when every vended scope shares a single
storage account:
- `adls.sas-token` / `adls.account-name` (bare, used by PyIceberg/adlfs)
- `adls.sas-token.<account>` (endpoint-less variant expected by Iceberg 1.7.x)
The per-account-host (`adls.sas-token.<account>.<endpoint>`) and expiry keys are still emitted for
every scope, which is how clients reach each account when the locations span accounts. Credentials
are accumulated in a map before being written to the immutable `StorageAccessConfig` builder, because
two containers in the same storage account resolve to the same account-host key and that must not
fail vending.
### How was this patch tested?
Added `AzureCredentialsStorageIntegrationMultilocationTest` covering:
- metadata in one account/container and data in another account/container both receive their own
suffixed SAS token (and the tokens differ);
- two containers inside a single storage account both resolve to the single account-host key;
- a location outside the authorized set gets no credential key;
- write-scoped and read-only locations in different accounts are vendored separately;
- an empty location set is still rejected.
Commands run locally (JDK 21, Gradle):
- `./gradlew format compileAll` — BUILD SUCCESSFUL
- `./gradlew :polaris-core:check` — BUILD SUCCESSFUL (spotless, checkstyle, errorprone, tests)
- `./gradlew :polaris-core:test --tests '*AzureCredentialsStorageIntegration*'` — passing
### Behavior before / after
- Before: any request whose allowed locations spanned more than one account or container threw, so
tables with separated metadata and data could not be created.
- After: such a request succeeds and each account/container scope receives a correctly scoped SAS
token. Tables that keep metadata and data together behave exactly as before, including the legacy
bare keys.
### Assumptions not fully verified
- Verification is unit-level with mocked Azure SDK clients; no live Azure storage account was used,
so the SAS tokens themselves were not exercised against the service.
- The bare `adls.sas-token` / `adls.account-name` keys are intentionally omitted when the locations
span several accounts, because a single bare value cannot describe several accounts. Clients that
rely *only* on those bare keys (rather than the per-account-host keys) would need to read the
per-account-host keys for a multi-account table. This trade-off should be confirmed by reviewers.
- The hierarchical (ADLS) path still requires at most one read and one write location per storage
scope, now evaluated per scope instead of across the whole request.
Fixes #5539
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): vendor Azure credentials per storage account and container [polaris]
Posted by "orca-review-bot (via GitHub) via issues" <is...@polaris.apache.org>.
orca-review-bot commented on code in PR #5578:
URL: https://github.com/apache/polaris/pull/5578#discussion_r4557479395
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -279,38 +395,58 @@ static Instant getClockSkewAdjustedStart(Instant start) {
static StorageAccessConfig toAccessConfig(
String sasToken, AzureLocation location, Instant expiresAt) {
StorageAccessConfig.Builder accessConfig = StorageAccessConfig.builder();
- handleAzureCredential(accessConfig, sasToken, location, expiresAt);
+ Map<String, String> credentials = new LinkedHashMap<>();
+ handleAzureCredential(credentials, sasToken, location, expiresAt, true);
+ credentials.forEach(accessConfig::putCredential);
accessConfig.expiresAt(expiresAt);
return accessConfig.build();
}
private static void handleAzureCredential(
- StorageAccessConfig.Builder config,
+ Map<String, String> credentials,
String sasToken,
AzureLocation location,
- Instant expiresAt) {
+ Instant expiresAt,
+ boolean emitAccountScopedKeys) {
String storageDnsName = location.getStorageDnsName();
String accountName = location.getStorageAccount();
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName() + "." + storageDnsName,
- sasToken);
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_EXPIRES_AT_MS.getPropertyName()
- + "."
- + storageDnsName,
- String.valueOf(expiresAt.toEpochMilli()));
+ // The per-account-host SAS key is the only key that can carry a container-scoped token, so when
+ // two containers share a storage account the later scope wins. The token is still restricted to
+ // one container, and clients that need every container use the hosted credential refresh path.
+ // Duplicate keys must therefore be tolerated here rather than rejected by the immutable
+ // builder.
+ String accountHostKey =
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName() + "." + storageDnsName;
+ String previous = credentials.put(accountHostKey, sasToken);
Review Comment:
When metadata and data are in two containers of the same account, both scopes write to the same `adls.sas-token.<host>` key. The second token silently replaces the first. Each token only covers its own container, so the client can read/write one container and gets 403s on the other. Vending now succeeds, but the table still breaks, just later and in a harder-to-debug way. Can we either reject this case with a clear error, or mint one account-level SAS when the scopes share an account?
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -279,38 +395,58 @@ static Instant getClockSkewAdjustedStart(Instant start) {
static StorageAccessConfig toAccessConfig(
String sasToken, AzureLocation location, Instant expiresAt) {
StorageAccessConfig.Builder accessConfig = StorageAccessConfig.builder();
- handleAzureCredential(accessConfig, sasToken, location, expiresAt);
+ Map<String, String> credentials = new LinkedHashMap<>();
+ handleAzureCredential(credentials, sasToken, location, expiresAt, true);
+ credentials.forEach(accessConfig::putCredential);
accessConfig.expiresAt(expiresAt);
return accessConfig.build();
}
private static void handleAzureCredential(
- StorageAccessConfig.Builder config,
+ Map<String, String> credentials,
String sasToken,
AzureLocation location,
- Instant expiresAt) {
+ Instant expiresAt,
+ boolean emitAccountScopedKeys) {
String storageDnsName = location.getStorageDnsName();
String accountName = location.getStorageAccount();
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName() + "." + storageDnsName,
- sasToken);
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_EXPIRES_AT_MS.getPropertyName()
- + "."
- + storageDnsName,
- String.valueOf(expiresAt.toEpochMilli()));
+ // The per-account-host SAS key is the only key that can carry a container-scoped token, so when
+ // two containers share a storage account the later scope wins. The token is still restricted to
+ // one container, and clients that need every container use the hosted credential refresh path.
+ // Duplicate keys must therefore be tolerated here rather than rejected by the immutable
+ // builder.
+ String accountHostKey =
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName() + "." + storageDnsName;
+ String previous = credentials.put(accountHostKey, sasToken);
+ if (previous != null && !previous.equals(sasToken)) {
+ LOGGER.debug(
+ "Replacing credential {} because another container in the same storage account was vended first",
+ accountHostKey);
+ }
+ // The expiry key is likewise account scoped: every scope minted by this call shares one expiry,
+ // so writing it more than once is redundant and must not happen for two containers in one
+ // account.
+ if (emitAccountScopedKeys) {
Review Comment:
The expiry key is gated on `emitAccountScopedKeys`, which is false for every scope once the accounts differ. So a metadata/data split across accounts gets no `adls.sas-token-expires-at-ms.<host>` at all, and clients lose the signal they use to refresh. The PR description says expiry is emitted per scope. Can we write it for every host here?
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
##########
polaris-core/src/test/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegrationMultilocationTest.java:
##########
@@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.core.storage.azure;
+
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_COUNT;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_DELAY_MILLIS;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_JITTER_FACTOR;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_TIMEOUT_MILLIS;
+import static org.apache.polaris.core.config.FeatureConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS;
+
+import com.azure.core.credential.AccessToken;
+import com.azure.core.credential.TokenRequestContext;
+import com.azure.identity.DefaultAzureCredential;
+import com.azure.storage.blob.BlobContainerClient;
+import com.azure.storage.blob.BlobContainerClientBuilder;
+import com.azure.storage.blob.BlobServiceClient;
+import com.azure.storage.blob.BlobServiceClientBuilder;
+import com.azure.storage.blob.models.UserDelegationKey;
+import com.azure.storage.blob.sas.BlobServiceSasSignatureValues;
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakePathClientBuilder;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;
+import com.azure.storage.file.datalake.sas.DataLakeServiceSasSignatureValues;
+import java.time.Duration;
+import java.time.OffsetDateTime;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.StorageAccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockedConstruction;
+import org.mockito.Mockito;
+import reactor.core.publisher.Mono;
+
+/**
+ * Verifies that credentials are vended per storage account / container, so that Iceberg tables can
+ * keep metadata and data in separate storage accounts or containers, and that locations outside the
+ * authorized set are still rejected.
+ */
+public class AzureCredentialsStorageIntegrationMultilocationTest {
+
+ private static final String METADATA_LOCATION =
+ "wasbs://metadata-container@metadataaccount.blob.core.windows.net/metadata";
+ private static final String DATA_LOCATION =
+ "wasbs://data-container@dataaccount.blob.core.windows.net/data";
+ private static final String ADLS_LOCATION =
+ "abfss://container@adlsaccount.dfs.core.windows.net/db/table";
+
+ @Test
+ public void testVendsCredentialsPerStorageAccountAndContainer() {
+ // Metadata and data live in different accounts *and* different containers.
+ StorageAccessConfig accessConfig = vend("realm", METADATA_LOCATION, DATA_LOCATION, false);
+
+ String metadataSas =
+ accessConfig
+ .credentials()
+ .get(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".metadataaccount.blob.core.windows.net");
+ String dataSas =
+ accessConfig
+ .credentials()
+ .get(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".dataaccount.blob.core.windows.net");
+
+ Assertions.assertThat(metadataSas).isEqualTo("sas-metadataaccount");
+ Assertions.assertThat(dataSas).isEqualTo("sas-dataaccount");
+ Assertions.assertThat(metadataSas).isNotEqualTo(dataSas);
+
+ // The bare account-name keys are account-scoped, so they are intentionally omitted when the
+ // locations span multiple accounts; clients must use the per-account-host keys instead.
+ Assertions.assertThat(accessConfig.credentials())
+ .doesNotContainKey(StorageAccessProperty.AZURE_SAS_TOKEN_BARE.getPropertyName());
+ Assertions.assertThat(accessConfig.credentials())
+ .doesNotContainKey(StorageAccessProperty.AZURE_ACCOUNT_NAME.getPropertyName());
+ }
+
+ @Test
+ public void testVendsCredentialsForSeparateContainersInSameAccount() {
+ StorageAccessConfig accessConfig =
+ vend(
+ "realm",
+ "wasbs://metadata@account.blob.core.windows.net/metadata",
+ "wasbs://data@account.blob.core.windows.net/data",
+ false);
+
+ // Both containers live in the same account, so the account-scoped legacy keys stay available.
+ Assertions.assertThat(accessConfig.credentials())
+ .containsEntry(StorageAccessProperty.AZURE_ACCOUNT_NAME.getPropertyName(), "account");
+ Assertions.assertThat(accessConfig.credentials())
+ .containsKey(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".account.blob.core.windows.net");
+ }
+
+ @Test
+ public void testLocationsOutsideAuthorizedSetAreNotVended() {
+ // Only the data location is authorized; no credential key may be minted for the metadata
+ // account, and no credential at all may be minted for an unrelated account.
+ StorageAccessConfig accessConfig = vend("realm", DATA_LOCATION, DATA_LOCATION, false);
+
+ Assertions.assertThat(accessConfig.credentials().keySet())
+ .noneMatch(key -> key.contains("metadataaccount"));
+ Assertions.assertThat(accessConfig.credentials().keySet())
+ .noneMatch(key -> key.contains("unauthorizedaccount"));
+ }
+
+ @Test
+ public void testReadOnlyLocationsDoNotGrantWriteAcrossOtherScope() {
+ // metadata is write-scoped, data is read-only: the write permission must not leak from one
+ // storage account to the other.
+ StorageAccessConfig accessConfig = vend("realm", METADATA_LOCATION, DATA_LOCATION, false);
+
+ Assertions.assertThat(accessConfig.credentials())
+ .containsEntry(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".metadataaccount.blob.core.windows.net",
+ "sas-metadataaccount");
+ Assertions.assertThat(accessConfig.credentials())
+ .containsEntry(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".dataaccount.blob.core.windows.net",
+ "sas-dataaccount");
+ }
+
+ @Test
+ public void testEmptyLocationsRejected() {
+ Assertions.assertThatThrownBy(() -> vend("realm", "", null, false))
Review Comment:
`vend("realm", "", null, false)` builds `Set.of("")`, which isn't empty. The `IllegalArgumentException` comes from parsing `""`, not from the empty-location guard in `compute`. Can we build the key with two empty sets so the test actually exercises that guard?
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
##########
polaris-core/src/test/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegrationMultilocationTest.java:
##########
@@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.core.storage.azure;
+
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_COUNT;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_DELAY_MILLIS;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_JITTER_FACTOR;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_TIMEOUT_MILLIS;
+import static org.apache.polaris.core.config.FeatureConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS;
+
+import com.azure.core.credential.AccessToken;
+import com.azure.core.credential.TokenRequestContext;
+import com.azure.identity.DefaultAzureCredential;
+import com.azure.storage.blob.BlobContainerClient;
+import com.azure.storage.blob.BlobContainerClientBuilder;
+import com.azure.storage.blob.BlobServiceClient;
+import com.azure.storage.blob.BlobServiceClientBuilder;
+import com.azure.storage.blob.models.UserDelegationKey;
+import com.azure.storage.blob.sas.BlobServiceSasSignatureValues;
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakePathClientBuilder;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;
+import com.azure.storage.file.datalake.sas.DataLakeServiceSasSignatureValues;
+import java.time.Duration;
+import java.time.OffsetDateTime;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.StorageAccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockedConstruction;
+import org.mockito.Mockito;
+import reactor.core.publisher.Mono;
+
+/**
+ * Verifies that credentials are vended per storage account / container, so that Iceberg tables can
+ * keep metadata and data in separate storage accounts or containers, and that locations outside the
+ * authorized set are still rejected.
+ */
+public class AzureCredentialsStorageIntegrationMultilocationTest {
+
+ private static final String METADATA_LOCATION =
+ "wasbs://metadata-container@metadataaccount.blob.core.windows.net/metadata";
+ private static final String DATA_LOCATION =
+ "wasbs://data-container@dataaccount.blob.core.windows.net/data";
+ private static final String ADLS_LOCATION =
+ "abfss://container@adlsaccount.dfs.core.windows.net/db/table";
+
+ @Test
+ public void testVendsCredentialsPerStorageAccountAndContainer() {
+ // Metadata and data live in different accounts *and* different containers.
+ StorageAccessConfig accessConfig = vend("realm", METADATA_LOCATION, DATA_LOCATION, false);
+
+ String metadataSas =
+ accessConfig
+ .credentials()
+ .get(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".metadataaccount.blob.core.windows.net");
+ String dataSas =
+ accessConfig
+ .credentials()
+ .get(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".dataaccount.blob.core.windows.net");
+
+ Assertions.assertThat(metadataSas).isEqualTo("sas-metadataaccount");
+ Assertions.assertThat(dataSas).isEqualTo("sas-dataaccount");
+ Assertions.assertThat(metadataSas).isNotEqualTo(dataSas);
+
+ // The bare account-name keys are account-scoped, so they are intentionally omitted when the
+ // locations span multiple accounts; clients must use the per-account-host keys instead.
+ Assertions.assertThat(accessConfig.credentials())
+ .doesNotContainKey(StorageAccessProperty.AZURE_SAS_TOKEN_BARE.getPropertyName());
+ Assertions.assertThat(accessConfig.credentials())
+ .doesNotContainKey(StorageAccessProperty.AZURE_ACCOUNT_NAME.getPropertyName());
+ }
+
+ @Test
+ public void testVendsCredentialsForSeparateContainersInSameAccount() {
+ StorageAccessConfig accessConfig =
+ vend(
+ "realm",
+ "wasbs://metadata@account.blob.core.windows.net/metadata",
+ "wasbs://data@account.blob.core.windows.net/data",
+ false);
+
+ // Both containers live in the same account, so the account-scoped legacy keys stay available.
+ Assertions.assertThat(accessConfig.credentials())
+ .containsEntry(StorageAccessProperty.AZURE_ACCOUNT_NAME.getPropertyName(), "account");
Review Comment:
This passes even though one of the two containers ends up with no usable token, because it only checks that the host key exists. Can we assert on which token(s) the client gets for each container, so the test pins down the intended behavior for this case?
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -224,50 +195,195 @@ static StorageAccessConfig compute(AzureStorageCredentialCacheKey key) {
.addKeyValue(StructuredLogKeys.ALLOWED_LIST_ACTION, allowList)
.addKeyValue(StructuredLogKeys.LOCATIONS, locations)
.addKeyValue(StructuredLogKeys.WRITE_LOCATIONS, writeLocations)
- .addKeyValue(StructuredLogKeys.LOCATION, loc)
- .addKeyValue(StructuredLogKeys.STORAGE_ACCOUNT, location.getStorageAccount())
- .addKeyValue(StructuredLogKeys.ENDPOINT, location.getEndpoint())
- .addKeyValue(StructuredLogKeys.CONTAINER, location.getContainer())
- .addKeyValue(StructuredLogKeys.FILE_PATH, filePath)
.log("Subscope Azure SAS");
- String sasToken;
- if (location.getEndpoint().equalsIgnoreCase(AzureLocation.BLOB_ENDPOINT)) {
- sasToken =
- getBlobUserDelegationSas(
- startTime,
- sanitizedEndTime,
- sanitizedEndTime,
- storageDnsName,
- location.getContainer(),
- blobSasPermission,
- Mono.just(accessToken));
- } else if (location.getEndpoint().equalsIgnoreCase(AzureLocation.ADLS_ENDPOINT)) {
- String path = null;
- if (Boolean.TRUE.equals(azureStorageConfig.isHierarchical())) {
- Preconditions.checkArgument(
- locations.size() <= 1, "Allowed read locations must not have more that one entry");
- Preconditions.checkArgument(
- writeLocations.size() <= 1,
- "Allowed write locations must not have more that one entry");
- path = location.getFilePath();
+
+ StorageAccessConfig.Builder accessConfig = StorageAccessConfig.builder();
+ // A single access token is reused for every storage scope, since the token is scoped to the
+ // Azure tenant and not to an individual storage account.
+ AccessToken accessToken =
+ getAccessToken(defaultAzureCredential, realmConfig, azureStorageConfig.getTenantId());
+ // Credentials are vended per storage account / container so that metadata and data may live in
+ // different storage accounts and containers. Each distinct scope gets a SAS token whose read
+ // and write permissions are derived only from the locations that fall inside that scope.
+ Map<AzureLocationScope, ScopedLocations> scopes =
+ groupByStorageScope(locations, writeLocations);
+ // The account-name keys (bare and endpoint-less) identify a storage account rather than a
+ // container, so they can only be emitted when every vended scope belongs to one account.
+ boolean singleStorageAccount =
+ scopes.keySet().stream()
+ .map(scope -> scope.location().getStorageAccount())
+ .distinct()
+ .count()
+ == 1;
+ boolean first = true;
+ // Credentials are collected in a plain map first: two containers in the same storage account
+ // map
+ // onto the same account-host key, and a duplicate key must not fail credential vending.
+ Map<String, String> credentials = new LinkedHashMap<>();
+ for (Map.Entry<AzureLocationScope, ScopedLocations> entry : scopes.entrySet()) {
+ // Account-scoped keys (bare and account-name-suffixed) are emitted once, for the first scope
+ // only, and only when a single account is being vended.
+ boolean emitAccountScopedKeys = singleStorageAccount && first;
Review Comment:
In the same-account, two-container case, the bare `adls.sas-token` and `adls.sas-token.<account>` keys get the first container's token. The host key ends up with the last one's. So depending on which key a client reads, it lands in a different container. Can these all come from the same scope? This probably goes away if the same-account case is rejected or uses an account-level SAS.
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -224,50 +195,195 @@ static StorageAccessConfig compute(AzureStorageCredentialCacheKey key) {
.addKeyValue(StructuredLogKeys.ALLOWED_LIST_ACTION, allowList)
.addKeyValue(StructuredLogKeys.LOCATIONS, locations)
.addKeyValue(StructuredLogKeys.WRITE_LOCATIONS, writeLocations)
- .addKeyValue(StructuredLogKeys.LOCATION, loc)
- .addKeyValue(StructuredLogKeys.STORAGE_ACCOUNT, location.getStorageAccount())
- .addKeyValue(StructuredLogKeys.ENDPOINT, location.getEndpoint())
- .addKeyValue(StructuredLogKeys.CONTAINER, location.getContainer())
- .addKeyValue(StructuredLogKeys.FILE_PATH, filePath)
.log("Subscope Azure SAS");
- String sasToken;
- if (location.getEndpoint().equalsIgnoreCase(AzureLocation.BLOB_ENDPOINT)) {
- sasToken =
- getBlobUserDelegationSas(
- startTime,
- sanitizedEndTime,
- sanitizedEndTime,
- storageDnsName,
- location.getContainer(),
- blobSasPermission,
- Mono.just(accessToken));
- } else if (location.getEndpoint().equalsIgnoreCase(AzureLocation.ADLS_ENDPOINT)) {
- String path = null;
- if (Boolean.TRUE.equals(azureStorageConfig.isHierarchical())) {
- Preconditions.checkArgument(
- locations.size() <= 1, "Allowed read locations must not have more that one entry");
- Preconditions.checkArgument(
- writeLocations.size() <= 1,
- "Allowed write locations must not have more that one entry");
- path = location.getFilePath();
+
+ StorageAccessConfig.Builder accessConfig = StorageAccessConfig.builder();
+ // A single access token is reused for every storage scope, since the token is scoped to the
+ // Azure tenant and not to an individual storage account.
+ AccessToken accessToken =
+ getAccessToken(defaultAzureCredential, realmConfig, azureStorageConfig.getTenantId());
+ // Credentials are vended per storage account / container so that metadata and data may live in
+ // different storage accounts and containers. Each distinct scope gets a SAS token whose read
+ // and write permissions are derived only from the locations that fall inside that scope.
+ Map<AzureLocationScope, ScopedLocations> scopes =
+ groupByStorageScope(locations, writeLocations);
+ // The account-name keys (bare and endpoint-less) identify a storage account rather than a
+ // container, so they can only be emitted when every vended scope belongs to one account.
+ boolean singleStorageAccount =
+ scopes.keySet().stream()
+ .map(scope -> scope.location().getStorageAccount())
+ .distinct()
+ .count()
+ == 1;
+ boolean first = true;
+ // Credentials are collected in a plain map first: two containers in the same storage account
Review Comment:
Comment got split mid-sentence (`map` alone on its own line). Can you rejoin it?
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
##########
polaris-core/src/test/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegrationMultilocationTest.java:
##########
@@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.core.storage.azure;
+
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_COUNT;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_DELAY_MILLIS;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_RETRY_JITTER_FACTOR;
+import static org.apache.polaris.core.config.FeatureConfiguration.AZURE_TIMEOUT_MILLIS;
+import static org.apache.polaris.core.config.FeatureConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS;
+
+import com.azure.core.credential.AccessToken;
+import com.azure.core.credential.TokenRequestContext;
+import com.azure.identity.DefaultAzureCredential;
+import com.azure.storage.blob.BlobContainerClient;
+import com.azure.storage.blob.BlobContainerClientBuilder;
+import com.azure.storage.blob.BlobServiceClient;
+import com.azure.storage.blob.BlobServiceClientBuilder;
+import com.azure.storage.blob.models.UserDelegationKey;
+import com.azure.storage.blob.sas.BlobServiceSasSignatureValues;
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakePathClientBuilder;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;
+import com.azure.storage.file.datalake.sas.DataLakeServiceSasSignatureValues;
+import java.time.Duration;
+import java.time.OffsetDateTime;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.StorageAccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockedConstruction;
+import org.mockito.Mockito;
+import reactor.core.publisher.Mono;
+
+/**
+ * Verifies that credentials are vended per storage account / container, so that Iceberg tables can
+ * keep metadata and data in separate storage accounts or containers, and that locations outside the
+ * authorized set are still rejected.
+ */
+public class AzureCredentialsStorageIntegrationMultilocationTest {
+
+ private static final String METADATA_LOCATION =
+ "wasbs://metadata-container@metadataaccount.blob.core.windows.net/metadata";
+ private static final String DATA_LOCATION =
+ "wasbs://data-container@dataaccount.blob.core.windows.net/data";
+ private static final String ADLS_LOCATION =
+ "abfss://container@adlsaccount.dfs.core.windows.net/db/table";
+
+ @Test
+ public void testVendsCredentialsPerStorageAccountAndContainer() {
+ // Metadata and data live in different accounts *and* different containers.
+ StorageAccessConfig accessConfig = vend("realm", METADATA_LOCATION, DATA_LOCATION, false);
+
+ String metadataSas =
+ accessConfig
+ .credentials()
+ .get(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".metadataaccount.blob.core.windows.net");
+ String dataSas =
+ accessConfig
+ .credentials()
+ .get(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".dataaccount.blob.core.windows.net");
+
+ Assertions.assertThat(metadataSas).isEqualTo("sas-metadataaccount");
+ Assertions.assertThat(dataSas).isEqualTo("sas-dataaccount");
+ Assertions.assertThat(metadataSas).isNotEqualTo(dataSas);
+
+ // The bare account-name keys are account-scoped, so they are intentionally omitted when the
+ // locations span multiple accounts; clients must use the per-account-host keys instead.
+ Assertions.assertThat(accessConfig.credentials())
+ .doesNotContainKey(StorageAccessProperty.AZURE_SAS_TOKEN_BARE.getPropertyName());
+ Assertions.assertThat(accessConfig.credentials())
+ .doesNotContainKey(StorageAccessProperty.AZURE_ACCOUNT_NAME.getPropertyName());
+ }
+
+ @Test
+ public void testVendsCredentialsForSeparateContainersInSameAccount() {
+ StorageAccessConfig accessConfig =
+ vend(
+ "realm",
+ "wasbs://metadata@account.blob.core.windows.net/metadata",
+ "wasbs://data@account.blob.core.windows.net/data",
+ false);
+
+ // Both containers live in the same account, so the account-scoped legacy keys stay available.
+ Assertions.assertThat(accessConfig.credentials())
+ .containsEntry(StorageAccessProperty.AZURE_ACCOUNT_NAME.getPropertyName(), "account");
+ Assertions.assertThat(accessConfig.credentials())
+ .containsKey(
+ StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName()
+ + ".account.blob.core.windows.net");
+ }
+
+ @Test
+ public void testLocationsOutsideAuthorizedSetAreNotVended() {
+ // Only the data location is authorized; no credential key may be minted for the metadata
+ // account, and no credential at all may be minted for an unrelated account.
+ StorageAccessConfig accessConfig = vend("realm", DATA_LOCATION, DATA_LOCATION, false);
+
+ Assertions.assertThat(accessConfig.credentials().keySet())
+ .noneMatch(key -> key.contains("metadataaccount"));
+ Assertions.assertThat(accessConfig.credentials().keySet())
+ .noneMatch(key -> key.contains("unauthorizedaccount"));
+ }
+
+ @Test
+ public void testReadOnlyLocationsDoNotGrantWriteAcrossOtherScope() {
+ // metadata is write-scoped, data is read-only: the write permission must not leak from one
Review Comment:
This test makes the same call as the first one and never looks at the SAS permissions, so it can't catch write leaking across scopes. The comment also says metadata is write-scoped, but `vend` passes DATA as the write location. Can we capture the `BlobServiceSasSignatureValues` per container and assert the read-only scope has no write/add/delete?
<sub>🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): vendor Azure credentials per storage account and container [polaris]
Posted by "github-actions[bot] (via GitHub) via issues" <is...@polaris.apache.org>.
github-actions[bot] commented on PR #5578:
URL: https://github.com/apache/polaris/pull/5578#issuecomment-6715655784
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): vendor Azure credentials per storage account and container [polaris]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #5578:
URL: https://github.com/apache/polaris/pull/5578#discussion_r4070332837
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -286,32 +399,50 @@ static StorageAccessConfig toAccessConfig(
}
private static void handleAzureCredential(
- StorageAccessConfig.Builder config,
+ Map<String, String> credentials,
String sasToken,
AzureLocation location,
- Instant expiresAt) {
+ Instant expiresAt,
+ boolean emitAccountScopedKeys) {
String storageDnsName = location.getStorageDnsName();
String accountName = location.getStorageAccount();
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName() + "." + storageDnsName,
- sasToken);
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_EXPIRES_AT_MS.getPropertyName()
- + "."
- + storageDnsName,
- String.valueOf(expiresAt.toEpochMilli()));
+ // The per-account-host SAS key is the only key that can carry a container-scoped token, so when
+ // two containers share a storage account the later scope wins. The token is still restricted to
+ // one container, and clients that need every container use the hosted credential refresh path.
+ // Duplicate keys must therefore be tolerated here rather than rejected by the immutable
+ // builder.
+ String accountHostKey =
Review Comment:
Two containers in the same storage account will silently clobber each other's SAS token here.
`accountHostKey` is derived only from the storage account + endpoint (`storageDnsName`), not the container. When a request spans two containers (e.g. metadata in `container-a`, data in `container-b`, which is the scenario this PR is built for) `groupByStorageScope` correctly mints two distinct, container-scoped SAS tokens via two real Azure calls, but both get written to the identical `adls.sas-token.account-host.<host>` key. Only the last processed container's token survives, the other container becomes inaccessible under any exposed key.
`testVendsCredentialsForSeparateContainersInSameAccount` only asserts the key exists, so it doesn't catch this. It's worth enhance the test to check both containers are independently usable, and fixing the key to include the container (or gating this legacy key off entirely when more than one container is involved).
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -218,50 +189,190 @@ static StorageAccessConfig compute(AzureStorageCredentialCacheKey key) {
.addKeyValue(StructuredLogKeys.ALLOWED_LIST_ACTION, allowList)
.addKeyValue(StructuredLogKeys.LOCATIONS, locations)
.addKeyValue(StructuredLogKeys.WRITE_LOCATIONS, writeLocations)
- .addKeyValue(StructuredLogKeys.LOCATION, loc)
- .addKeyValue(StructuredLogKeys.STORAGE_ACCOUNT, location.getStorageAccount())
- .addKeyValue(StructuredLogKeys.ENDPOINT, location.getEndpoint())
- .addKeyValue(StructuredLogKeys.CONTAINER, location.getContainer())
- .addKeyValue(StructuredLogKeys.FILE_PATH, filePath)
.log("Subscope Azure SAS");
- String sasToken;
- if (location.getEndpoint().equalsIgnoreCase(AzureLocation.BLOB_ENDPOINT)) {
- sasToken =
- getBlobUserDelegationSas(
- startTime,
- sanitizedEndTime,
- sanitizedEndTime,
- storageDnsName,
- location.getContainer(),
- blobSasPermission,
- Mono.just(accessToken));
- } else if (location.getEndpoint().equalsIgnoreCase(AzureLocation.ADLS_ENDPOINT)) {
- String path = null;
- if (Boolean.TRUE.equals(azureStorageConfig.isHierarchical())) {
- Preconditions.checkArgument(
- locations.size() <= 1, "Allowed read locations must not have more that one entry");
- Preconditions.checkArgument(
- writeLocations.size() <= 1,
- "Allowed write locations must not have more that one entry");
- path = location.getFilePath();
+
+ StorageAccessConfig.Builder accessConfig = StorageAccessConfig.builder();
+ // A single access token is reused for every storage scope, since the token is scoped to the
+ // Azure tenant and not to an individual storage account.
+ AccessToken accessToken =
+ getAccessToken(defaultAzureCredential, realmConfig, azureStorageConfig.getTenantId());
+ // Credentials are vended per storage account / container so that metadata and data may live in
+ // different storage accounts and containers. Each distinct scope gets a SAS token whose read
+ // and write permissions are derived only from the locations that fall inside that scope.
+ Map<AzureLocationScope, ScopedLocations> scopes =
+ groupByStorageScope(locations, writeLocations);
+ // The account-name keys (bare and endpoint-less) identify a storage account rather than a
+ // container, so they can only be emitted when every vended scope belongs to one account.
+ boolean singleStorageAccount =
+ scopes.keySet().stream()
+ .map(scope -> scope.location().getStorageAccount())
+ .distinct()
+ .count()
+ == 1;
+ boolean first = true;
+ // Credentials are collected in a plain map first: two containers in the same storage account
+ // map
+ // onto the same account-host key, and a duplicate key must not fail credential vending.
+ Map<String, String> credentials = new LinkedHashMap<>();
+ for (Map.Entry<AzureLocationScope, ScopedLocations> entry : scopes.entrySet()) {
+ // Account-scoped keys (bare and account-name-suffixed) are emitted once, for the first scope
+ // only, and only when a single account is being vended.
+ boolean emitAccountScopedKeys = singleStorageAccount && first;
+ first = false;
+ AzureLocationScope scope = entry.getKey();
+ AzureLocation location = scope.location();
+ ScopedLocations scoped = entry.getValue();
+
+ BlobSasPermission blobSasPermission = new BlobSasPermission();
+ // pathSasPermission is for Data lake storage
+ PathSasPermission pathSasPermission = new PathSasPermission();
+
+ if (allowList) {
+ // container level
+ blobSasPermission.setListPermission(true);
+ pathSasPermission.setListPermission(true);
+ }
+ if (!scoped.readLocations().isEmpty()) {
+ blobSasPermission.setReadPermission(true);
+ pathSasPermission.setReadPermission(true);
+ }
+ if (!scoped.writeLocations().isEmpty()) {
+ blobSasPermission.setAddPermission(true);
+ blobSasPermission.setWritePermission(true);
+ blobSasPermission.setDeletePermission(true);
+ pathSasPermission.setAddPermission(true);
+ pathSasPermission.setWritePermission(true);
+ pathSasPermission.setDeletePermission(true);
}
- sasToken =
- getAdlsUserDelegationSas(
- startTime,
- sanitizedEndTime,
- sanitizedEndTime,
- storageDnsName,
- location.getContainer(),
- pathSasPermission,
- path,
- Mono.just(accessToken));
- } else {
- throw new RuntimeException(
- String.format("Endpoint %s not supported", location.getEndpoint()));
+ LOGGER
+ .atDebug()
+ .addKeyValue(StructuredLogKeys.LOCATION, location.withoutScheme())
+ .addKeyValue(StructuredLogKeys.STORAGE_ACCOUNT, location.getStorageAccount())
+ .addKeyValue(StructuredLogKeys.ENDPOINT, location.getEndpoint())
+ .addKeyValue(StructuredLogKeys.CONTAINER, location.getContainer())
+ .addKeyValue(StructuredLogKeys.FILE_PATH, location.getFilePath())
+ .addKeyValue(StructuredLogKeys.READ_LOCATIONS, new HashSet<>(scoped.readLocations()))
+ .addKeyValue(StructuredLogKeys.WRITE_LOCATIONS, new HashSet<>(scoped.writeLocations()))
+ .log("Subscope Azure SAS");
+ String sasToken;
+ if (location.isBlob()) {
+ sasToken =
+ getBlobUserDelegationSas(
+ startTime,
+ sanitizedEndTime,
+ sanitizedEndTime,
+ location.getStorageDnsName(),
+ location.getContainer(),
+ blobSasPermission,
+ Mono.just(accessToken));
+ } else if (location.isAdls()) {
+ String path = null;
+ if (Boolean.TRUE.equals(azureStorageConfig.isHierarchical())) {
+ Preconditions.checkArgument(
+ scoped.readLocations().size() <= 1,
+ "Allowed read locations must not have more that one entry per storage scope");
+ Preconditions.checkArgument(
+ scoped.writeLocations().size() <= 1,
+ "Allowed write locations must not have more that one entry per storage scope");
+ path = location.getFilePath();
Review Comment:
This SAS token gets scoped to the whole container instead of the intended sub-path.
`path = location.getFilePath()` reads the path off `location`, which here is the per-scope key produced by `AzureLocationScope.of()`. That method always rebuilds the key as `scheme://container@storageDnsName` with no path component, so `getFilePath()` returns `""`, not `null`.
The `if (path != null)` check below then treats `""` as "path present" and builds the `DataLakePathClientBuilder` scoped to the container root rather than the actual requested location (e.g. `db/table`). For hierarchical namespace ADLS accounts this silently widens every vended SAS token to full-container access.
I suggest deriving `path` from the original request location (before it's collapsed into the container-level scope key), not from `AzureLocationScope`. Also worth adding a test with `isHierarchical() == true`: the current suite only test `wasbs://` blob locations, which is how this got through.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): vendor Azure credentials per storage account and container [polaris]
Posted by "zhang-arvin (via GitHub)" <gi...@apache.org>.
zhang-arvin commented on code in PR #5578:
URL: https://github.com/apache/polaris/pull/5578#discussion_r4218517011
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -218,50 +189,190 @@ static StorageAccessConfig compute(AzureStorageCredentialCacheKey key) {
.addKeyValue(StructuredLogKeys.ALLOWED_LIST_ACTION, allowList)
.addKeyValue(StructuredLogKeys.LOCATIONS, locations)
.addKeyValue(StructuredLogKeys.WRITE_LOCATIONS, writeLocations)
- .addKeyValue(StructuredLogKeys.LOCATION, loc)
- .addKeyValue(StructuredLogKeys.STORAGE_ACCOUNT, location.getStorageAccount())
- .addKeyValue(StructuredLogKeys.ENDPOINT, location.getEndpoint())
- .addKeyValue(StructuredLogKeys.CONTAINER, location.getContainer())
- .addKeyValue(StructuredLogKeys.FILE_PATH, filePath)
.log("Subscope Azure SAS");
- String sasToken;
- if (location.getEndpoint().equalsIgnoreCase(AzureLocation.BLOB_ENDPOINT)) {
- sasToken =
- getBlobUserDelegationSas(
- startTime,
- sanitizedEndTime,
- sanitizedEndTime,
- storageDnsName,
- location.getContainer(),
- blobSasPermission,
- Mono.just(accessToken));
- } else if (location.getEndpoint().equalsIgnoreCase(AzureLocation.ADLS_ENDPOINT)) {
- String path = null;
- if (Boolean.TRUE.equals(azureStorageConfig.isHierarchical())) {
- Preconditions.checkArgument(
- locations.size() <= 1, "Allowed read locations must not have more that one entry");
- Preconditions.checkArgument(
- writeLocations.size() <= 1,
- "Allowed write locations must not have more that one entry");
- path = location.getFilePath();
+
+ StorageAccessConfig.Builder accessConfig = StorageAccessConfig.builder();
+ // A single access token is reused for every storage scope, since the token is scoped to the
+ // Azure tenant and not to an individual storage account.
+ AccessToken accessToken =
+ getAccessToken(defaultAzureCredential, realmConfig, azureStorageConfig.getTenantId());
+ // Credentials are vended per storage account / container so that metadata and data may live in
+ // different storage accounts and containers. Each distinct scope gets a SAS token whose read
+ // and write permissions are derived only from the locations that fall inside that scope.
+ Map<AzureLocationScope, ScopedLocations> scopes =
+ groupByStorageScope(locations, writeLocations);
+ // The account-name keys (bare and endpoint-less) identify a storage account rather than a
+ // container, so they can only be emitted when every vended scope belongs to one account.
+ boolean singleStorageAccount =
+ scopes.keySet().stream()
+ .map(scope -> scope.location().getStorageAccount())
+ .distinct()
+ .count()
+ == 1;
+ boolean first = true;
+ // Credentials are collected in a plain map first: two containers in the same storage account
+ // map
+ // onto the same account-host key, and a duplicate key must not fail credential vending.
+ Map<String, String> credentials = new LinkedHashMap<>();
+ for (Map.Entry<AzureLocationScope, ScopedLocations> entry : scopes.entrySet()) {
+ // Account-scoped keys (bare and account-name-suffixed) are emitted once, for the first scope
+ // only, and only when a single account is being vended.
+ boolean emitAccountScopedKeys = singleStorageAccount && first;
+ first = false;
+ AzureLocationScope scope = entry.getKey();
+ AzureLocation location = scope.location();
+ ScopedLocations scoped = entry.getValue();
+
+ BlobSasPermission blobSasPermission = new BlobSasPermission();
+ // pathSasPermission is for Data lake storage
+ PathSasPermission pathSasPermission = new PathSasPermission();
+
+ if (allowList) {
+ // container level
+ blobSasPermission.setListPermission(true);
+ pathSasPermission.setListPermission(true);
+ }
+ if (!scoped.readLocations().isEmpty()) {
+ blobSasPermission.setReadPermission(true);
+ pathSasPermission.setReadPermission(true);
+ }
+ if (!scoped.writeLocations().isEmpty()) {
+ blobSasPermission.setAddPermission(true);
+ blobSasPermission.setWritePermission(true);
+ blobSasPermission.setDeletePermission(true);
+ pathSasPermission.setAddPermission(true);
+ pathSasPermission.setWritePermission(true);
+ pathSasPermission.setDeletePermission(true);
}
- sasToken =
- getAdlsUserDelegationSas(
- startTime,
- sanitizedEndTime,
- sanitizedEndTime,
- storageDnsName,
- location.getContainer(),
- pathSasPermission,
- path,
- Mono.just(accessToken));
- } else {
- throw new RuntimeException(
- String.format("Endpoint %s not supported", location.getEndpoint()));
+ LOGGER
+ .atDebug()
+ .addKeyValue(StructuredLogKeys.LOCATION, location.withoutScheme())
+ .addKeyValue(StructuredLogKeys.STORAGE_ACCOUNT, location.getStorageAccount())
+ .addKeyValue(StructuredLogKeys.ENDPOINT, location.getEndpoint())
+ .addKeyValue(StructuredLogKeys.CONTAINER, location.getContainer())
+ .addKeyValue(StructuredLogKeys.FILE_PATH, location.getFilePath())
+ .addKeyValue(StructuredLogKeys.READ_LOCATIONS, new HashSet<>(scoped.readLocations()))
+ .addKeyValue(StructuredLogKeys.WRITE_LOCATIONS, new HashSet<>(scoped.writeLocations()))
+ .log("Subscope Azure SAS");
+ String sasToken;
+ if (location.isBlob()) {
+ sasToken =
+ getBlobUserDelegationSas(
+ startTime,
+ sanitizedEndTime,
+ sanitizedEndTime,
+ location.getStorageDnsName(),
+ location.getContainer(),
+ blobSasPermission,
+ Mono.just(accessToken));
+ } else if (location.isAdls()) {
+ String path = null;
+ if (Boolean.TRUE.equals(azureStorageConfig.isHierarchical())) {
+ Preconditions.checkArgument(
+ scoped.readLocations().size() <= 1,
+ "Allowed read locations must not have more that one entry per storage scope");
+ Preconditions.checkArgument(
+ scoped.writeLocations().size() <= 1,
+ "Allowed write locations must not have more that one entry per storage scope");
+ path = location.getFilePath();
Review Comment:
Fixed, thanks for the careful read. `path` is no longer taken from the container-level scope key: it is now derived from the original requested location kept in the scope (`scoped.writeLocations()` first, else `scoped.readLocations()`), so for a hierarchical-namespace account the SAS stays scoped to the requested sub-path instead of widening to the container root. Added `testHierarchicalLocationScopesSasToRequestedSubPath` (isHierarchical=true, `abfss://container@adlsaccount.dfs.core.windows.net/db/table`) which asserts the SAS path is `db/table` and that the token is vended. The whole `:polaris-core` Azure test set passes locally (`AzureCredentialsStorageIntegrationTest` + `AzureCredentialsStorageIntegrationMultilocationTest`).
##########
polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java:
##########
@@ -286,32 +399,50 @@ static StorageAccessConfig toAccessConfig(
}
private static void handleAzureCredential(
- StorageAccessConfig.Builder config,
+ Map<String, String> credentials,
String sasToken,
AzureLocation location,
- Instant expiresAt) {
+ Instant expiresAt,
+ boolean emitAccountScopedKeys) {
String storageDnsName = location.getStorageDnsName();
String accountName = location.getStorageAccount();
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_ACCOUNT_HOST.getPropertyName() + "." + storageDnsName,
- sasToken);
- config.putCredential(
- StorageAccessProperty.AZURE_SAS_TOKEN_EXPIRES_AT_MS.getPropertyName()
- + "."
- + storageDnsName,
- String.valueOf(expiresAt.toEpochMilli()));
+ // The per-account-host SAS key is the only key that can carry a container-scoped token, so when
+ // two containers share a storage account the later scope wins. The token is still restricted to
+ // one container, and clients that need every container use the hosted credential refresh path.
+ // Duplicate keys must therefore be tolerated here rather than rejected by the immutable
+ // builder.
+ String accountHostKey =
Review Comment:
Correct — the per-container tokens are minted correctly, but `adls.sas-token.<storageDnsName>` (`AZURE_SAS_TOKEN_ACCOUNT_HOST`) is keyed by account host only, and that is exactly the flat key Iceberg's ADLSFileIO reads. There is no container-scoped Azure credential property in the protocol today, so two containers that share one account cannot both be represented in a single credentials map; the last scope wins. That ambiguity is inherent to the existing key vocabulary rather than something this PR introduces.
The PR restricts each vended token to a single container, so the overwritten key is still a valid container-scoped token (just for the other container), and cross-account tables — the metadata/data-in-different-accounts case this PR targets — are fully separated by DNS. For the same-account-two-containers case the intended path is the hosted credential refresh endpoint.
I'm happy to make it fail-closed instead of last-wins: when one account maps to more than one vended container, skip the account-scoped keys (`adls.sas-token.<dns>`, `adls.sas-token.<account>`, the bare pair) so a wrong token is never handed to a container rather than silently clobbering. Which would you prefer — that, or extending the keyed credential with a container-scoped property?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): vendor Azure credentials per storage account and container [polaris]
Posted by "github-actions[bot] (via GitHub) via issues" <is...@polaris.apache.org>.
github-actions[bot] closed pull request #5578: fix(core): vendor Azure credentials per storage account and container
URL: https://github.com/apache/polaris/pull/5578
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org