Skip to content

Commit 662a47e

Browse files
committed
Make AccessConfigProvider request-scoped
- add `StorageCredentialsVendor` as request-scoped wrapper around `PolarisCredentialVendor` - make `FileIOFactory` request-scoped - make `TaskFileIOSupplier` request-scoped
1 parent 4a2835b commit 662a47e

24 files changed

+238
-238
lines changed

polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ private void revokeGrantRecord(
15941594
@Nonnull PolarisCallContext callCtx,
15951595
long catalogId,
15961596
long entityId,
1597-
PolarisEntityType entityType,
1597+
@Nonnull PolarisEntityType entityType,
15981598
boolean allowListOperation,
15991599
@Nonnull Set<String> allowedReadLocations,
16001600
@Nonnull Set<String> allowedWriteLocations,

polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ public EntitiesResult loadTasks(
338338
}
339339

340340
@Override
341-
public ScopedCredentialsResult getSubscopedCredsForEntity(
341+
public @Nonnull ScopedCredentialsResult getSubscopedCredsForEntity(
342342
@Nonnull PolarisCallContext callCtx,
343343
long catalogId,
344344
long entityId,
345-
PolarisEntityType entityType,
345+
@Nonnull PolarisEntityType entityType,
346346
boolean allowListOperation,
347347
@Nonnull Set<String> allowedReadLocations,
348348
@Nonnull Set<String> allowedWriteLocations,

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20912091
@Nonnull PolarisCallContext callCtx,
20922092
long catalogId,
20932093
long entityId,
2094-
PolarisEntityType entityType,
2094+
@Nonnull PolarisEntityType entityType,
20952095
boolean allowListOperation,
20962096
@Nonnull Set<String> allowedReadLocations,
20972097
@Nonnull Set<String> allowedWriteLocations,

polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ScopedCredentialsResult getSubscopedCredsForEntity(
4949
@Nonnull PolarisCallContext callCtx,
5050
long catalogId,
5151
long entityId,
52-
PolarisEntityType entityType,
52+
@Nonnull PolarisEntityType entityType,
5353
boolean allowListOperation,
5454
@Nonnull Set<String> allowedReadLocations,
5555
@Nonnull Set<String> allowedWriteLocations,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.polaris.core.storage;
21+
22+
import jakarta.annotation.Nonnull;
23+
import java.util.Optional;
24+
import java.util.Set;
25+
import org.apache.polaris.core.config.RealmConfig;
26+
import org.apache.polaris.core.context.CallContext;
27+
import org.apache.polaris.core.context.RealmContext;
28+
import org.apache.polaris.core.entity.PolarisEntity;
29+
import org.apache.polaris.core.persistence.dao.entity.ScopedCredentialsResult;
30+
31+
public class StorageCredentialsVendor {
32+
33+
private final PolarisCredentialVendor polarisCredentialVendor;
34+
private final CallContext callContext;
35+
36+
public StorageCredentialsVendor(
37+
PolarisCredentialVendor polarisCredentialVendor, CallContext callContext) {
38+
this.polarisCredentialVendor = polarisCredentialVendor;
39+
this.callContext = callContext;
40+
}
41+
42+
public RealmContext getRealmContext() {
43+
return callContext.getRealmContext();
44+
}
45+
46+
public RealmConfig getRealmConfig() {
47+
return callContext.getRealmConfig();
48+
}
49+
50+
/**
51+
* Get sub-scoped credentials for an entity against the provided allowed read and write locations.
52+
*
53+
* @param entity the entity
54+
* @param allowListOperation whether to allow LIST operation on the allowedReadLocations and
55+
* allowedWriteLocations
56+
* @param allowedReadLocations a set of allowed to read locations
57+
* @param allowedWriteLocations a set of allowed to write locations
58+
* @param refreshCredentialsEndpoint an optional endpoint to use for refreshing credentials. If
59+
* supported by the storage type it will be returned to the client in the appropriate
60+
* properties. The endpoint may be relative to the base URI and the client is responsible for
61+
* handling the relative path
62+
* @return an enum map containing the scoped credentials
63+
*/
64+
@Nonnull
65+
public ScopedCredentialsResult getSubscopedCredsForEntity(
66+
@Nonnull PolarisEntity entity,
67+
boolean allowListOperation,
68+
@Nonnull Set<String> allowedReadLocations,
69+
@Nonnull Set<String> allowedWriteLocations,
70+
Optional<String> refreshCredentialsEndpoint) {
71+
return polarisCredentialVendor.getSubscopedCredsForEntity(
72+
callContext.getPolarisCallContext(),
73+
entity.getCatalogId(),
74+
entity.getId(),
75+
entity.getType(),
76+
allowListOperation,
77+
allowedReadLocations,
78+
allowedWriteLocations,
79+
refreshCredentialsEndpoint);
80+
}
81+
}

polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
import java.util.Set;
3131
import java.util.function.Function;
3232
import org.apache.iceberg.exceptions.UnprocessableEntityException;
33-
import org.apache.polaris.core.PolarisCallContext;
3433
import org.apache.polaris.core.PolarisDiagnostics;
3534
import org.apache.polaris.core.config.FeatureConfiguration;
3635
import org.apache.polaris.core.config.RealmConfig;
36+
import org.apache.polaris.core.context.RealmContext;
3737
import org.apache.polaris.core.entity.PolarisEntity;
3838
import org.apache.polaris.core.entity.PolarisEntityType;
3939
import org.apache.polaris.core.persistence.dao.entity.ScopedCredentialsResult;
4040
import org.apache.polaris.core.storage.AccessConfig;
41-
import org.apache.polaris.core.storage.PolarisCredentialVendor;
41+
import org.apache.polaris.core.storage.StorageCredentialsVendor;
4242
import org.slf4j.Logger;
4343
import org.slf4j.LoggerFactory;
4444

@@ -95,29 +95,30 @@ private long maxCacheDurationMs(RealmConfig realmConfig) {
9595
/**
9696
* Either get from the cache or generate a new entry for a scoped creds
9797
*
98-
* @param credentialVendor the credential vendor used to generate a new scoped creds if needed
99-
* @param callCtx the call context
98+
* @param storageCredentialsVendor the credential vendor used to generate a new scoped creds if
99+
* needed
100100
* @param polarisEntity the polaris entity that is going to scoped creds
101101
* @param allowListOperation whether allow list action on the provided read and write locations
102102
* @param allowedReadLocations a set of allowed to read locations
103103
* @param allowedWriteLocations a set of allowed to write locations.
104104
* @return the a map of string containing the scoped creds information
105105
*/
106106
public AccessConfig getOrGenerateSubScopeCreds(
107-
@Nonnull PolarisCredentialVendor credentialVendor,
108-
@Nonnull PolarisCallContext callCtx,
107+
@Nonnull StorageCredentialsVendor storageCredentialsVendor,
109108
@Nonnull PolarisEntity polarisEntity,
110109
boolean allowListOperation,
111110
@Nonnull Set<String> allowedReadLocations,
112111
@Nonnull Set<String> allowedWriteLocations,
113112
Optional<String> refreshCredentialsEndpoint) {
113+
RealmContext realmContext = storageCredentialsVendor.getRealmContext();
114+
RealmConfig realmConfig = storageCredentialsVendor.getRealmConfig();
114115
if (!isTypeSupported(polarisEntity.getType())) {
115116
diagnostics.fail(
116117
"entity_type_not_suppported_to_scope_creds", "type={}", polarisEntity.getType());
117118
}
118119
StorageCredentialCacheKey key =
119120
StorageCredentialCacheKey.of(
120-
callCtx.getRealmContext().getRealmIdentifier(),
121+
realmContext.getRealmIdentifier(),
121122
polarisEntity,
122123
allowListOperation,
123124
allowedReadLocations,
@@ -128,17 +129,14 @@ public AccessConfig getOrGenerateSubScopeCreds(
128129
k -> {
129130
LOGGER.atDebug().log("StorageCredentialCache::load");
130131
ScopedCredentialsResult scopedCredentialsResult =
131-
credentialVendor.getSubscopedCredsForEntity(
132-
callCtx,
133-
k.catalogId(),
134-
polarisEntity.getId(),
135-
polarisEntity.getType(),
136-
k.allowedListAction(),
137-
k.allowedReadLocations(),
138-
k.allowedWriteLocations(),
139-
k.refreshCredentialsEndpoint());
132+
storageCredentialsVendor.getSubscopedCredsForEntity(
133+
polarisEntity,
134+
allowListOperation,
135+
allowedReadLocations,
136+
allowedWriteLocations,
137+
refreshCredentialsEndpoint);
140138
if (scopedCredentialsResult.isSuccess()) {
141-
long maxCacheDurationMs = maxCacheDurationMs(callCtx.getRealmConfig());
139+
long maxCacheDurationMs = maxCacheDurationMs(realmConfig);
142140
return new StorageCredentialCacheEntry(
143141
scopedCredentialsResult.getAccessConfig(), maxCacheDurationMs);
144142
}

0 commit comments

Comments
 (0)