snazy commented on code in PR #2280:
URL: https://github.com/apache/polaris/pull/2280#discussion_r2259531408
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -797,4 +812,24 @@ public Response getConfig(
.build())
.build();
}
+
+ @Override
+ public Response signS3Request(
Review Comment:
I think it makes sense to have this in a separate class to avoid the
overhead of having unneeded things just for signing purposes. We can emit a
separate signing-endpoint in a load-table, if necessary.
##########
runtime/service/src/main/java/org/apache/polaris/service/storage/aws/signer/S3RequestSignerImpl.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.service.storage.aws.signer;
+
+import java.net.URI;
+import java.util.Set;
+import org.apache.iceberg.aws.s3.signer.ImmutableS3SignResponse;
+import org.apache.iceberg.aws.s3.signer.S3SignResponse;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.AccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration;
+import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.apache.polaris.service.types.S3SignRequest;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.http.ContentStreamProvider;
+import software.amazon.awssdk.http.SdkHttpFullRequest;
+import software.amazon.awssdk.http.SdkHttpMethod;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
+import software.amazon.awssdk.http.auth.spi.signer.SignRequest;
+import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
+import software.amazon.awssdk.services.s3.S3Client;
+
+/**
+ * S3 request signer that creates presigned URLs for S3 operations using AWS
credentials obtained
+ * from the storage integration.
+ */
+public class S3RequestSignerImpl implements S3RequestSigner {
Review Comment:
```suggestion
class S3RequestSignerImpl implements S3RequestSigner {
```
##########
runtime/service/src/main/java/org/apache/polaris/service/storage/aws/signer/S3RequestSignerImpl.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.service.storage.aws.signer;
+
+import java.net.URI;
+import java.util.Set;
+import org.apache.iceberg.aws.s3.signer.ImmutableS3SignResponse;
+import org.apache.iceberg.aws.s3.signer.S3SignResponse;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.AccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration;
+import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.apache.polaris.service.types.S3SignRequest;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.http.ContentStreamProvider;
+import software.amazon.awssdk.http.SdkHttpFullRequest;
+import software.amazon.awssdk.http.SdkHttpMethod;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
+import software.amazon.awssdk.http.auth.spi.signer.SignRequest;
+import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
+import software.amazon.awssdk.services.s3.S3Client;
+
+/**
+ * S3 request signer that creates presigned URLs for S3 operations using AWS
credentials obtained
+ * from the storage integration.
+ */
+public class S3RequestSignerImpl implements S3RequestSigner {
+
+ private final AwsV4HttpSigner signer = AwsV4HttpSigner.create();
+
+ private final AwsCredentialsStorageIntegration storageIntegration;
+ private final StorageCredentialCache storageCredentialCache;
+
+ public S3RequestSignerImpl(
+ AwsCredentialsStorageIntegration storageIntegration,
+ StorageCredentialCache storageCredentialCache) {
+ this.storageIntegration = storageIntegration;
+ this.storageCredentialCache = storageCredentialCache;
+ }
+
+ @Override
+ public S3SignResponse signRequest(
+ RealmConfig realmConfig,
+ AwsStorageConfigurationInfo storageConfig,
+ S3SignRequest signingRequest) {
+
+ SdkHttpMethod method = SdkHttpMethod.valueOf(signingRequest.method());
+ URI uri = signingRequest.uri();
+ String body = signingRequest.body();
+
+ SdkHttpFullRequest.Builder requestToSign =
+ SdkHttpFullRequest.builder()
+ .uri(uri)
+ .protocol(uri.getScheme())
+ .method(method)
+ .headers(signingRequest.headers());
+
+ // FIXME is this correct?
+ boolean allowListOperation = isReadMethod(method);
+ Set<String> allowedReadLocations = isReadMethod(method) ?
Set.of(uri.toString()) : Set.of();
+ Set<String> allowedWriteLocations = isWriteMethod(method) ?
Set.of(uri.toString()) : Set.of();
+
+ // TODO use the storageCredentialCache to get or generate subscoped
credentials
Review Comment:
how? request-signing is (mostly) used in environments that don't have sts.
##########
runtime/service/src/main/java/org/apache/polaris/service/storage/aws/signer/S3RequestSignerImpl.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.service.storage.aws.signer;
+
+import java.net.URI;
+import java.util.Set;
+import org.apache.iceberg.aws.s3.signer.ImmutableS3SignResponse;
+import org.apache.iceberg.aws.s3.signer.S3SignResponse;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.AccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration;
+import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.apache.polaris.service.types.S3SignRequest;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.http.ContentStreamProvider;
+import software.amazon.awssdk.http.SdkHttpFullRequest;
+import software.amazon.awssdk.http.SdkHttpMethod;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
+import software.amazon.awssdk.http.auth.spi.signer.SignRequest;
+import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
+import software.amazon.awssdk.services.s3.S3Client;
+
+/**
+ * S3 request signer that creates presigned URLs for S3 operations using AWS
credentials obtained
+ * from the storage integration.
+ */
+public class S3RequestSignerImpl implements S3RequestSigner {
+
+ private final AwsV4HttpSigner signer = AwsV4HttpSigner.create();
+
+ private final AwsCredentialsStorageIntegration storageIntegration;
+ private final StorageCredentialCache storageCredentialCache;
+
+ public S3RequestSignerImpl(
Review Comment:
```suggestion
S3RequestSignerImpl(
```
##########
runtime/service/src/main/java/org/apache/polaris/service/storage/aws/signer/S3RequestSignerImpl.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.service.storage.aws.signer;
+
+import java.net.URI;
+import java.util.Set;
+import org.apache.iceberg.aws.s3.signer.ImmutableS3SignResponse;
+import org.apache.iceberg.aws.s3.signer.S3SignResponse;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.AccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration;
+import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.apache.polaris.service.types.S3SignRequest;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.http.ContentStreamProvider;
+import software.amazon.awssdk.http.SdkHttpFullRequest;
+import software.amazon.awssdk.http.SdkHttpMethod;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
+import software.amazon.awssdk.http.auth.spi.signer.SignRequest;
+import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
+import software.amazon.awssdk.services.s3.S3Client;
+
+/**
+ * S3 request signer that creates presigned URLs for S3 operations using AWS
credentials obtained
+ * from the storage integration.
+ */
+public class S3RequestSignerImpl implements S3RequestSigner {
+
+ private final AwsV4HttpSigner signer = AwsV4HttpSigner.create();
+
+ private final AwsCredentialsStorageIntegration storageIntegration;
+ private final StorageCredentialCache storageCredentialCache;
+
+ public S3RequestSignerImpl(
+ AwsCredentialsStorageIntegration storageIntegration,
+ StorageCredentialCache storageCredentialCache) {
+ this.storageIntegration = storageIntegration;
+ this.storageCredentialCache = storageCredentialCache;
+ }
+
+ @Override
+ public S3SignResponse signRequest(
+ RealmConfig realmConfig,
+ AwsStorageConfigurationInfo storageConfig,
+ S3SignRequest signingRequest) {
+
+ SdkHttpMethod method = SdkHttpMethod.valueOf(signingRequest.method());
+ URI uri = signingRequest.uri();
+ String body = signingRequest.body();
+
+ SdkHttpFullRequest.Builder requestToSign =
+ SdkHttpFullRequest.builder()
+ .uri(uri)
+ .protocol(uri.getScheme())
+ .method(method)
+ .headers(signingRequest.headers());
+
+ // FIXME is this correct?
Review Comment:
nope.
See
[ListObjects](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html)
+
[ListObjectsV2](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html)
REST spec.
*Be careful:* Not all `GET /{bucket/` requests are list-objects requests!
The "v1" list-objects has no required parameter, so you cannot just check
for the presence of a req param. It could also be a get-bucket-cors or
get-bucket-encryption or ...-policy or ...-website or ......
Nice, no?
_Maybe_ it's okay to assume that every client uses the v2 api, which has a
unique, required request param.
##########
runtime/service/src/main/java/org/apache/polaris/service/storage/aws/signer/S3RequestSignerImpl.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.service.storage.aws.signer;
+
+import java.net.URI;
+import java.util.Set;
+import org.apache.iceberg.aws.s3.signer.ImmutableS3SignResponse;
+import org.apache.iceberg.aws.s3.signer.S3SignResponse;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.AccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration;
+import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.apache.polaris.service.types.S3SignRequest;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.http.ContentStreamProvider;
+import software.amazon.awssdk.http.SdkHttpFullRequest;
+import software.amazon.awssdk.http.SdkHttpMethod;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
+import software.amazon.awssdk.http.auth.spi.signer.SignRequest;
+import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
+import software.amazon.awssdk.services.s3.S3Client;
+
+/**
+ * S3 request signer that creates presigned URLs for S3 operations using AWS
credentials obtained
+ * from the storage integration.
+ */
+public class S3RequestSignerImpl implements S3RequestSigner {
+
+ private final AwsV4HttpSigner signer = AwsV4HttpSigner.create();
+
+ private final AwsCredentialsStorageIntegration storageIntegration;
+ private final StorageCredentialCache storageCredentialCache;
+
+ public S3RequestSignerImpl(
+ AwsCredentialsStorageIntegration storageIntegration,
+ StorageCredentialCache storageCredentialCache) {
+ this.storageIntegration = storageIntegration;
+ this.storageCredentialCache = storageCredentialCache;
+ }
+
+ @Override
+ public S3SignResponse signRequest(
+ RealmConfig realmConfig,
+ AwsStorageConfigurationInfo storageConfig,
+ S3SignRequest signingRequest) {
+
+ SdkHttpMethod method = SdkHttpMethod.valueOf(signingRequest.method());
+ URI uri = signingRequest.uri();
+ String body = signingRequest.body();
+
+ SdkHttpFullRequest.Builder requestToSign =
+ SdkHttpFullRequest.builder()
Review Comment:
also need the request parameters here
##########
runtime/service/src/main/java/org/apache/polaris/service/storage/aws/signer/S3RequestSignerImpl.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.service.storage.aws.signer;
+
+import java.net.URI;
+import java.util.Set;
+import org.apache.iceberg.aws.s3.signer.ImmutableS3SignResponse;
+import org.apache.iceberg.aws.s3.signer.S3SignResponse;
+import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.storage.AccessConfig;
+import org.apache.polaris.core.storage.StorageAccessProperty;
+import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration;
+import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.apache.polaris.service.types.S3SignRequest;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.http.ContentStreamProvider;
+import software.amazon.awssdk.http.SdkHttpFullRequest;
+import software.amazon.awssdk.http.SdkHttpMethod;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
+import software.amazon.awssdk.http.auth.spi.signer.SignRequest;
+import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
+import software.amazon.awssdk.services.s3.S3Client;
+
+/**
+ * S3 request signer that creates presigned URLs for S3 operations using AWS
credentials obtained
+ * from the storage integration.
+ */
+public class S3RequestSignerImpl implements S3RequestSigner {
+
+ private final AwsV4HttpSigner signer = AwsV4HttpSigner.create();
+
+ private final AwsCredentialsStorageIntegration storageIntegration;
+ private final StorageCredentialCache storageCredentialCache;
+
+ public S3RequestSignerImpl(
+ AwsCredentialsStorageIntegration storageIntegration,
+ StorageCredentialCache storageCredentialCache) {
+ this.storageIntegration = storageIntegration;
+ this.storageCredentialCache = storageCredentialCache;
+ }
+
+ @Override
+ public S3SignResponse signRequest(
+ RealmConfig realmConfig,
+ AwsStorageConfigurationInfo storageConfig,
+ S3SignRequest signingRequest) {
+
+ SdkHttpMethod method = SdkHttpMethod.valueOf(signingRequest.method());
+ URI uri = signingRequest.uri();
+ String body = signingRequest.body();
+
+ SdkHttpFullRequest.Builder requestToSign =
+ SdkHttpFullRequest.builder()
+ .uri(uri)
+ .protocol(uri.getScheme())
+ .method(method)
+ .headers(signingRequest.headers());
+
+ // FIXME is this correct?
+ boolean allowListOperation = isReadMethod(method);
+ Set<String> allowedReadLocations = isReadMethod(method) ?
Set.of(uri.toString()) : Set.of();
+ Set<String> allowedWriteLocations = isWriteMethod(method) ?
Set.of(uri.toString()) : Set.of();
+
+ // TODO use the storageCredentialCache to get or generate subscoped
credentials
+ // AccessConfig accessConfig1 =
storageCredentialCache.getOrGenerateSubScopeCreds();
+
+ AccessConfig accessConfig =
+ storageIntegration.getSubscopedCreds(
+ realmConfig, allowListOperation, allowedReadLocations,
allowedWriteLocations);
+
+ AwsCredentials credentials = extractCredentials(accessConfig);
+
+ // FIXME is this correct?
Review Comment:
clients may request a different region (hello path-style vs hostname bucket
resolution)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]