Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti

### New Features

- Added Catalog configuration for S3 and STS endpoints. This also allows using non-AWS S3 implementations.

### Changes

### Deprecations
Expand Down
5 changes: 5 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ This product includes code from Project Nessie.
* tools/config-docs/generator/src/test/java/tests/smallrye/SomeEnum.java
* tools/config-docs/generator/src/test/java/tests/smallrye/VeryNested.java
* tools/container-spec-helper/src/main/java/org/apache/polaris/containerspec/ContainerSpecHelper.java
* tools/minio-testcontainer/src/main/java/org/apache/polaris/test/minio/Minio.java
* tools/minio-testcontainer/src/main/java/org/apache/polaris/test/minio/MinioAccess.java
* tools/minio-testcontainer/src/main/java/org/apache/polaris/test/minio/MinioContainer.java
* tools/minio-testcontainer/src/main/java/org/apache/polaris/test/minio/MinioExtension.java
* runtime/admin/src/main/java/org/apache/polaris/admintool/PolarisAdminTool.java
* runtime/service/src/main/java/org/apache/polaris/service/storage/aws/StsClientsPool.java
* helm/polaris/tests/logging_storage_test.yaml
* helm/polaris/tests/quantity_test.yaml
* helm/polaris/tests/service_monitor_test.yaml
Expand Down
1 change: 1 addition & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
api(project(":polaris-api-management-service"))

api(project(":polaris-container-spec-helper"))
api(project(":polaris-minio-testcontainer"))
api(project(":polaris-immutables"))
api(project(":polaris-misc-types"))
api(project(":polaris-version"))
Expand Down
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ polaris-tests=integration-tests
aggregated-license-report=aggregated-license-report
polaris-immutables=tools/immutables
polaris-container-spec-helper=tools/container-spec-helper
polaris-minio-testcontainer=tools/minio-testcontainer
polaris-version=tools/version
polaris-misc-types=tools/misc-types
polaris-persistence-varint=nosql/persistence/varint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ public Builder setStorageConfigurationInfo(
new ArrayList<>(allowedLocations),
awsConfigModel.getRoleArn(),
awsConfigModel.getExternalId(),
awsConfigModel.getRegion());
awsConfigModel.getRegion(),
awsConfigModel.getEndpoint(),
awsConfigModel.getStsEndpoint());
awsConfig.validateArn(awsConfigModel.getRoleArn());
config = awsConfig;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.polaris.core.storage.InMemoryStorageIntegration;
import org.apache.polaris.core.storage.StorageAccessProperty;
import org.apache.polaris.core.storage.StorageUtil;
import org.apache.polaris.core.storage.aws.StsClientProvider.StsDestination;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.policybuilder.iam.IamConditionOperator;
import software.amazon.awssdk.policybuilder.iam.IamEffect;
Expand All @@ -45,17 +46,21 @@
/** Credential vendor that supports generating */
public class AwsCredentialsStorageIntegration
extends InMemoryStorageIntegration<AwsStorageConfigurationInfo> {
private final StsClient stsClient;
private final StsClientProvider stsClientProvider;
private final Optional<AwsCredentialsProvider> credentialsProvider;

public AwsCredentialsStorageIntegration(StsClient stsClient) {
this(stsClient, Optional.empty());
public AwsCredentialsStorageIntegration(StsClient fixedClient) {
this((destination) -> fixedClient);
}

public AwsCredentialsStorageIntegration(StsClientProvider stsClientProvider) {
this(stsClientProvider, Optional.empty());
}

public AwsCredentialsStorageIntegration(
StsClient stsClient, Optional<AwsCredentialsProvider> credentialsProvider) {
StsClientProvider stsClientProvider, Optional<AwsCredentialsProvider> credentialsProvider) {
super(AwsCredentialsStorageIntegration.class.getName());
this.stsClient = stsClient;
this.stsClientProvider = stsClientProvider;
this.credentialsProvider = credentialsProvider;
}

Expand Down Expand Up @@ -87,6 +92,13 @@ public EnumMap<StorageAccessProperty, String> getSubscopedCreds(
.durationSeconds(storageCredentialDurationSeconds);
credentialsProvider.ifPresent(
cp -> request.overrideConfiguration(b -> b.credentialsProvider(cp)));

@SuppressWarnings("resource")
// Note: stsClientProvider returns "thin" clients that do not need closing
StsClient stsClient =
stsClientProvider.stsClient(
StsDestination.of(storageConfig.getStsEndpointUri(), storageConfig.getRegion()));

AssumeRoleResponse response = stsClient.assumeRole(request.build());
EnumMap<StorageAccessProperty, String> credentialMap =
new EnumMap<>(StorageAccessProperty.class);
Expand All @@ -108,6 +120,11 @@ public EnumMap<StorageAccessProperty, String> getSubscopedCreds(
credentialMap.put(StorageAccessProperty.CLIENT_REGION, storageConfig.getRegion());
}

URI endpointUri = storageConfig.getEndpointUri();
if (endpointUri != null) {
credentialMap.put(StorageAccessProperty.AWS_ENDPOINT, endpointUri.toString());
}

if (storageConfig.getAwsPartition().equals("aws-us-gov")
&& credentialMap.get(StorageAccessProperty.CLIENT_REGION) == null) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.MoreObjects;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.net.URI;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -53,14 +54,38 @@ public class AwsStorageConfigurationInfo extends PolarisStorageConfigurationInfo
@JsonProperty(value = "region")
private @Nullable String region = null;

/** Endpoint URI for S3 API calls */
@JsonProperty(value = "endpoint")
private @Nullable String endpoint;

/** Endpoint URI for STS API calls */
@JsonProperty(value = "stsEndpoint")
private @Nullable String stsEndpoint;

@JsonCreator
public AwsStorageConfigurationInfo(
@JsonProperty(value = "storageType", required = true) @Nonnull StorageType storageType,
@JsonProperty(value = "allowedLocations", required = true) @Nonnull
List<String> allowedLocations,
@JsonProperty(value = "roleARN", required = true) @Nonnull String roleARN,
@JsonProperty(value = "region", required = false) @Nullable String region) {
this(storageType, allowedLocations, roleARN, null, region);
@JsonProperty(value = "externalId") @Nullable String externalId,
@JsonProperty(value = "region", required = false) @Nullable String region,
@JsonProperty(value = "endpoint") @Nullable String endpoint,
@JsonProperty(value = "stsEndpoint") @Nullable String stsEndpoint) {
super(storageType, allowedLocations);
this.roleARN = roleARN;
this.externalId = externalId;
this.region = region;
this.endpoint = endpoint;
this.stsEndpoint = stsEndpoint;
}

public AwsStorageConfigurationInfo(
@Nonnull StorageType storageType,
@Nonnull List<String> allowedLocations,
@Nonnull String roleARN,
@Nullable String region) {
this(storageType, allowedLocations, roleARN, null, region, null, null);
}

public AwsStorageConfigurationInfo(
Expand All @@ -69,10 +94,7 @@ public AwsStorageConfigurationInfo(
@Nonnull String roleARN,
@Nullable String externalId,
@Nullable String region) {
super(storageType, allowedLocations);
this.roleARN = roleARN;
this.externalId = externalId;
this.region = region;
this(storageType, allowedLocations, roleARN, externalId, region, null, null);
}

@Override
Expand Down Expand Up @@ -121,6 +143,19 @@ public void setRegion(@Nullable String region) {
this.region = region;
}

@JsonIgnore
@Nullable
public URI getEndpointUri() {
return endpoint == null ? null : URI.create(endpoint);
}

/** Returns the STS endpoint if set, defaulting to {@link #getEndpointUri()} otherwise. */
@JsonIgnore
@Nullable
public URI getStsEndpointUri() {
return stsEndpoint == null ? getEndpointUri() : URI.create(stsEndpoint);
}

@JsonIgnore
public String getAwsAccountId() {
return parseAwsAccountId(roleARN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.aws;

import jakarta.annotation.Nullable;
import java.net.URI;
import java.util.Optional;
import org.apache.polaris.immutables.PolarisImmutable;
import org.immutables.value.Value;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sts.StsBaseClientBuilder;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.sts.endpoints.StsEndpointProvider;

public interface StsClientProvider {

/**
* Returns an STS client for the given destination (endpoint + region). The returned client may
* not be a fresh instance for every call, however the client is reusable for multiple concurrent
* requests from multiple threads. If the endpoint or region parameters are not specified, AWS SDK
* defaults will be used.
*
* @param destination Endpoint and Region data for the client. Both values are optional.
*/
StsClient stsClient(StsDestination destination);

@PolarisImmutable
interface StsDestination {
/** Corresponds to {@link StsBaseClientBuilder#endpointProvider(StsEndpointProvider)} */
@Value.Parameter(order = 1)
Optional<URI> endpoint();

/** Corresponds to {@link AwsClientBuilder#region(Region)} */
@Value.Parameter(order = 2)
Optional<String> region();

static StsDestination of(@Nullable URI endpoint, @Nullable String region) {
return ImmutableStsDestination.of(Optional.ofNullable(endpoint), Optional.ofNullable(region));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.aws;

import static org.apache.polaris.core.storage.PolarisStorageConfigurationInfo.StorageType.S3;
import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;
import java.util.List;
import org.junit.jupiter.api.Test;

public class AwsStorageConfigurationInfoTest {

private static AwsStorageConfigurationInfo config(String endpoint, String stsEndpoint) {
return new AwsStorageConfigurationInfo(
S3, List.of(), "role", null, null, endpoint, stsEndpoint);
}

@Test
public void testStsEndpoint() {
assertThat(config(null, null))
.extracting(
AwsStorageConfigurationInfo::getEndpointUri,
AwsStorageConfigurationInfo::getStsEndpointUri)
.containsExactly(null, null);
assertThat(config(null, "http://sts.example.com"))
.extracting(
AwsStorageConfigurationInfo::getEndpointUri,
AwsStorageConfigurationInfo::getStsEndpointUri)
.containsExactly(null, URI.create("http://sts.example.com"));
assertThat(config("http://s3.example.com", null))
.extracting(
AwsStorageConfigurationInfo::getEndpointUri,
AwsStorageConfigurationInfo::getStsEndpointUri)
.containsExactly(URI.create("http://s3.example.com"), URI.create("http://s3.example.com"));
assertThat(config("http://s3.example.com", "http://sts.example.com"))
.extracting(
AwsStorageConfigurationInfo::getEndpointUri,
AwsStorageConfigurationInfo::getStsEndpointUri)
.containsExactly(URI.create("http://s3.example.com"), URI.create("http://sts.example.com"));
}
}
5 changes: 5 additions & 0 deletions runtime/service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ dependencies {
implementation("software.amazon.awssdk:sts")
implementation("software.amazon.awssdk:iam-policy-builder")
implementation("software.amazon.awssdk:s3")
implementation("software.amazon.awssdk:apache-client") {
exclude("commons-logging", "commons-logging")
}
implementation(platform(libs.azuresdk.bom))
implementation("com.azure:azure-core")

Expand All @@ -101,6 +104,8 @@ dependencies {
testImplementation(project(":polaris-api-management-model"))
testImplementation(testFixtures(project(":polaris-service-common")))

testImplementation(project(":polaris-minio-testcontainer"))

testImplementation("org.apache.iceberg:iceberg-api:${libs.versions.iceberg.get()}:tests")
testImplementation("org.apache.iceberg:iceberg-core:${libs.versions.iceberg.get()}:tests")

Expand Down
Loading
Loading