Skip to content

Commit f589967

Browse files
committed
add changelog, address comments
1 parent d32a568 commit f589967

File tree

11 files changed

+35
-36
lines changed

11 files changed

+35
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
5757
- Added `--no-sts` flag to CLI to support S3-compatible storage systems that do not have Security Token Service available.
5858
- Support credential vending for federated catalogs. `ALLOW_FEDERATED_CATALOGS_CREDENTIAL_VENDING` (default: true) was added to toggle this feature.
5959
- Enhanced catalog federation with SigV4 authentication support, additional authentication types for credential vending, and location-based access restrictions to block credential vending for remote tables outside allowed location lists.
60+
- Added support for including principal name in subscoped credentials. `INCLUDE_PRINCIPAL_NAME_IN_SUBSCOPED_CREDENTIAL` (default: false) can be used to toggle this feature. If enabled, cached credentials issued to one principal will no longer be available for others.
6061

6162
### Changes
6263

polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public StorageAccessConfig getSubscopedCreds(
9898
String roleSessionName =
9999
includePrincipalNameInSubscopedCredential
100100
? "polaris-" + polarisPrincipal.getName()
101-
: "polaris";
101+
: "PolarisAwsCredentialsStorageIntegration";
102102
String cappedRoleSessionName =
103103
roleSessionName.substring(0, Math.min(roleSessionName.length(), 64));
104104

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ public StorageAccessConfig getOrGenerateSubScopeCreds(
129129
allowListOperation,
130130
allowedReadLocations,
131131
allowedWriteLocations,
132+
refreshCredentialsEndpoint,
132133
includePrincipalNameInSubscopedCredential
133134
? Optional.of(polarisPrincipal)
134-
: Optional.empty(),
135-
refreshCredentialsEndpoint);
135+
: Optional.empty());
136136
LOGGER.atDebug().addKeyValue("key", key).log("subscopedCredsCache");
137137
Function<StorageCredentialCacheKey, StorageCredentialCacheEntry> loader =
138138
k -> {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ public interface StorageCredentialCacheKey {
5050
Set<String> allowedWriteLocations();
5151

5252
@Value.Parameter(order = 7)
53-
Optional<String> principalName();
53+
Optional<String> refreshCredentialsEndpoint();
5454

5555
@Value.Parameter(order = 8)
56-
Optional<String> refreshCredentialsEndpoint();
56+
Optional<String> principalName();
5757

5858
static StorageCredentialCacheKey of(
5959
String realmId,
6060
PolarisEntity entity,
6161
boolean allowedListAction,
6262
Set<String> allowedReadLocations,
6363
Set<String> allowedWriteLocations,
64-
Optional<PolarisPrincipal> polarisPrincipal,
65-
Optional<String> refreshCredentialsEndpoint) {
64+
Optional<String> refreshCredentialsEndpoint,
65+
Optional<PolarisPrincipal> polarisPrincipal) {
6666
String storageConfigSerializedStr =
6767
entity
6868
.getInternalPropertiesAsMap()
@@ -74,7 +74,7 @@ static StorageCredentialCacheKey of(
7474
allowedListAction,
7575
allowedReadLocations,
7676
allowedWriteLocations,
77-
polarisPrincipal.map(PolarisPrincipal::getName),
78-
refreshCredentialsEndpoint);
77+
refreshCredentialsEndpoint,
78+
polarisPrincipal.map(PolarisPrincipal::getName));
7979
}
8080
}

polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public void testCacheEvict() throws Exception {
300300
true,
301301
Set.of("s3://bucket1/path", "s3://bucket2/path"),
302302
Set.of("s3://bucket/path"),
303-
Optional.of(polarisPrincipal),
304-
Optional.empty());
303+
Optional.empty(),
304+
Optional.of(polarisPrincipal));
305305

306306
// the entry will be evicted immediately because the token is expired
307307
storageCredentialCache.getOrGenerateSubScopeCreds(

polaris-core/src/test/java/org/apache/polaris/service/storage/aws/AwsCredentialsStorageIntegrationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public String getConfiguration(@Nonnull RealmContext ctx, String configName) {
8686
.build();
8787
public static final String AWS_PARTITION = "aws";
8888
public static final PolarisPrincipal POLARIS_PRINCIPAL =
89-
PolarisPrincipal.of("principal", Map.of(), Set.of());
89+
PolarisPrincipal.of("test-principal", Map.of(), Set.of());
9090

9191
@ParameterizedTest
9292
@ValueSource(strings = {"s3a", "s3"})
@@ -103,7 +103,8 @@ public void testGetSubscopedCreds(String scheme) {
103103
.asInstanceOf(InstanceOfAssertFactories.type(AssumeRoleRequest.class))
104104
.returns(externalId, AssumeRoleRequest::externalId)
105105
.returns(roleARN, AssumeRoleRequest::roleArn)
106-
.returns("polaris", AssumeRoleRequest::roleSessionName)
106+
.returns(
107+
"PolarisAwsCredentialsStorageIntegration", AssumeRoleRequest::roleSessionName)
107108
// ensure that the policy content does not refer to S3A
108109
.extracting(AssumeRoleRequest::policy)
109110
.doesNotMatch(s -> s.contains("s3a"));
@@ -153,7 +154,7 @@ public void testGetSubscopedCredsWithNameInclude() {
153154
.asInstanceOf(InstanceOfAssertFactories.type(AssumeRoleRequest.class))
154155
.returns(externalId, AssumeRoleRequest::externalId)
155156
.returns(roleARN, AssumeRoleRequest::roleArn)
156-
.returns("polaris-principal", AssumeRoleRequest::roleSessionName);
157+
.returns("polaris-test-principal", AssumeRoleRequest::roleSessionName);
157158
return ASSUME_ROLE_RESPONSE;
158159
});
159160
String warehouseDir = "s3://bucket/path/to/warehouse";

runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.concurrent.Executors;
4141
import java.util.concurrent.TimeUnit;
4242
import org.apache.commons.lang3.function.TriConsumer;
43+
import org.apache.polaris.core.auth.ImmutablePolarisPrincipal;
4344
import org.apache.polaris.core.auth.PolarisPrincipal;
4445
import org.apache.polaris.core.context.CallContext;
4546
import org.apache.polaris.core.entity.PolarisBaseEntity;
@@ -72,8 +73,8 @@ public class TaskExecutorImpl implements TaskExecutor {
7273
private final MetaStoreManagerFactory metaStoreManagerFactory;
7374
private final TaskFileIOSupplier fileIOSupplier;
7475
private final RealmContextHolder realmContextHolder;
75-
@Inject PolarisPrincipalHolder polarisPrincipalHolder;
76-
@Inject PolarisPrincipal polarisPrincipal;
76+
private final PolarisPrincipalHolder polarisPrincipalHolder;
77+
private final PolarisPrincipal polarisPrincipal;
7778
private final List<TaskHandler> taskHandlers = new CopyOnWriteArrayList<>();
7879
private final Optional<TriConsumer<Long, Boolean, Throwable>> errorHandler;
7980
private final PolarisEventListener polarisEventListener;
@@ -82,7 +83,7 @@ public class TaskExecutorImpl implements TaskExecutor {
8283

8384
@SuppressWarnings("unused") // Required by CDI
8485
protected TaskExecutorImpl() {
85-
this(null, null, null, null, null, null, null, null, null);
86+
this(null, null, null, null, null, null, null, null, null, null, null);
8687
}
8788

8889
@Inject
@@ -96,7 +97,9 @@ public TaskExecutorImpl(
9697
RealmContextHolder realmContextHolder,
9798
PolarisEventListener polarisEventListener,
9899
PolarisEventMetadataFactory eventMetadataFactory,
99-
@Nullable Tracer tracer) {
100+
@Nullable Tracer tracer,
101+
PolarisPrincipalHolder polarisPrincipalHolder,
102+
PolarisPrincipal polarisPrincipal) {
100103
this.executor = executor;
101104
this.clock = clock;
102105
this.metaStoreManagerFactory = metaStoreManagerFactory;
@@ -105,6 +108,8 @@ public TaskExecutorImpl(
105108
this.polarisEventListener = polarisEventListener;
106109
this.eventMetadataFactory = eventMetadataFactory;
107110
this.tracer = tracer;
111+
this.polarisPrincipalHolder = polarisPrincipalHolder;
112+
this.polarisPrincipal = polarisPrincipal;
108113

109114
if (errorHandler != null && errorHandler.isResolvable()) {
110115
this.errorHandler = Optional.of(errorHandler.get());
@@ -167,10 +172,7 @@ public void addTaskHandlerContext(long taskEntityId, CallContext callContext) {
167172
String realmId = callContext.getRealmContext().getRealmIdentifier();
168173

169174
PolarisPrincipal principalClone =
170-
PolarisPrincipal.of(
171-
polarisPrincipal.getName(),
172-
polarisPrincipal.getProperties(),
173-
polarisPrincipal.getRoles());
175+
ImmutablePolarisPrincipal.builder().from(polarisPrincipal).build();
174176

175177
return CompletableFuture.runAsync(
176178
() -> {
@@ -253,6 +255,9 @@ protected void handleTaskWithTracing(
253255
// Note: each call to this method runs in a new CDI request context
254256

255257
realmContextHolder.set(() -> realmId);
258+
// since this is now a different context we store clone of the principal in a holder object
259+
// which essentially reauthenticates the principal. PolarisPrincipal bean always looks for a
260+
// principal set in PolarisPrincipalHolder first and assumes that identity if set.
256261
polarisPrincipalHolder.set(principal);
257262

258263
if (tracer == null) {

runtime/service/src/test/java/org/apache/polaris/service/catalog/Profiles.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.apache.polaris.service.catalog;
2121

22-
import com.google.common.collect.ImmutableMap;
2322
import io.quarkus.test.junit.QuarkusTestProfile;
2423
import java.util.Map;
2524

@@ -42,14 +41,4 @@ public Map<String, String> getConfigOverrides() {
4241
"true");
4342
}
4443
}
45-
46-
public static class AuthProfile extends DefaultProfile {
47-
@Override
48-
public Map<String, String> getConfigOverrides() {
49-
return ImmutableMap.<String, String>builder()
50-
.putAll(super.getConfigOverrides())
51-
.put("polaris.test.rootAugmentor.enabled", "true")
52-
.build();
53-
}
54-
}
5544
}

runtime/service/src/test/java/org/apache/polaris/service/catalog/generic/PolarisGenericTableCatalogRelationalTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
import org.apache.polaris.service.catalog.Profiles;
2424

2525
@QuarkusTest
26-
@TestProfile(Profiles.AuthProfile.class)
26+
@TestProfile(Profiles.DefaultProfile.class)
2727
public class PolarisGenericTableCatalogRelationalTest
2828
extends AbstractPolarisGenericTableCatalogTest {}

runtime/service/src/test/java/org/apache/polaris/service/catalog/policy/PolicyCatalogRelationalTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
import org.apache.polaris.service.catalog.Profiles;
2424

2525
@QuarkusTest
26-
@TestProfile(Profiles.AuthProfile.class)
26+
@TestProfile(Profiles.DefaultProfile.class)
2727
public class PolicyCatalogRelationalTest extends AbstractPolicyCatalogTest {}

0 commit comments

Comments
 (0)