danielcweeks commented on code in PR #11995: URL: https://github.com/apache/iceberg/pull/11995#discussion_r1945167254
########## aws/src/main/java/org/apache/iceberg/aws/RESTSigV4AuthSession.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.iceberg.aws; + +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.commons.io.IOUtils; +import org.apache.iceberg.rest.HTTPHeaders; +import org.apache.iceberg.rest.HTTPHeaders.HTTPHeader; +import org.apache.iceberg.rest.HTTPRequest; +import org.apache.iceberg.rest.ImmutableHTTPHeaders; +import org.apache.iceberg.rest.ImmutableHTTPRequest; +import org.apache.iceberg.rest.auth.AuthSession; +import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; +import software.amazon.awssdk.auth.signer.Aws4Signer; +import software.amazon.awssdk.auth.signer.internal.SignerConstant; +import software.amazon.awssdk.auth.signer.params.Aws4SignerParams; +import software.amazon.awssdk.auth.signer.params.SignerChecksumParams; +import software.amazon.awssdk.core.checksums.Algorithm; +import software.amazon.awssdk.http.SdkHttpFullRequest; +import software.amazon.awssdk.http.SdkHttpMethod; +import software.amazon.awssdk.regions.Region; + +/** + * An AuthSession that signs requests with SigV4. + * + * <p>The request is first authenticated by the delegate AuthSession, then signed with SigV4. In + * case of conflicting headers, the Authorization header set by delegate AuthSession will be + * relocated, then included in the canonical headers to sign. + * + * <p>See <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html">Signing AWS + * API requests</a> for details about the SigV4 protocol. + */ +public class RESTSigV4AuthSession implements AuthSession { + + static final String EMPTY_BODY_SHA256 = + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + static final String RELOCATED_HEADER_PREFIX = "Original-"; + + private final Aws4Signer signer; + private final AuthSession delegate; + private final Region signingRegion; + private final String signingName; + private final AwsCredentialsProvider credentialsProvider; + + public RESTSigV4AuthSession( + Aws4Signer aws4Signer, AuthSession delegateAuthSession, AwsProperties awsProperties) { + this.signer = aws4Signer; + this.delegate = delegateAuthSession; + this.signingRegion = awsProperties.restSigningRegion(); + this.signingName = awsProperties.restSigningName(); + this.credentialsProvider = awsProperties.restCredentialsProvider(); + } + + @Override + public HTTPRequest authenticate(HTTPRequest request) { + return sign(delegate.authenticate(request)); Review Comment: We don't appear to have a precondition check or protect against the `delegate` being null. -- 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org