difin commented on code in PR #6655: URL: https://github.com/apache/hive/pull/6655#discussion_r3825110390
########## itests/util/src/main/java/org/apache/hadoop/hive/cli/GcsOAuthTokenMock.java: ########## @@ -0,0 +1,200 @@ +/* + * 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.hadoop.hive.cli; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import com.sun.net.httpserver.HttpsServer; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyStore; +import java.util.concurrent.TimeUnit; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; + +/** + * Minimal Google OAuth2/STS token endpoint mock for Gravitino {@code gcs-token} credential vending. + * + * <p>Runs two endpoints on separate ports: + * <ul> + * <li>Plain HTTP {@code POST /token} for service-account {@code token_uri}</li> + * <li>HTTPS {@code POST /v1/token} with {@code CN=sts.googleapis.com} for Google STS</li> + * </ul> + * The test wires {@link GcsStsProxyContainer} to forward {@code sts.googleapis.com:443} to the + * HTTPS port, and imports {@link #getCertificatePath()} into the Gravitino container truststore. + */ +public final class GcsOAuthTokenMock implements AutoCloseable { + + /** Token value returned to Gravitino; fake-gcs-server does not validate it. */ + public static final String ACCESS_TOKEN = "gcs-test-access-token"; + private static final String STS_CN = "sts.googleapis.com"; + static final String HOST_GATEWAY = GcsFakeServerContainers.HOST_GATEWAY; + + private static final byte[] OAUTH_TOKEN_RESPONSE = String.format( + "{\"access_token\":\"%s\",\"expires_in\":3600,\"token_type\":\"Bearer\"}", + ACCESS_TOKEN).getBytes(StandardCharsets.UTF_8); + + private static final byte[] STS_TOKEN_RESPONSE = String.format( + "{\"access_token\":\"%s\",\"issued_token_type\":\"urn:ietf:params:oauth:token-type:access_token\"," + + "\"token_type\":\"Bearer\",\"expires_in\":3600}", + ACCESS_TOKEN).getBytes(StandardCharsets.UTF_8); + + private HttpServer httpServer; + private HttpsServer httpsServer; + private Path certificatePath; + private Path workDir; + + /** Starts HTTP and HTTPS servers on ephemeral ports. */ + public void start() throws Exception { + workDir = Files.createTempDirectory("gcs-oauth-mock-"); Review Comment: Good catch. GcsOAuthTokenMock now creates its cert/key work dir under test.tmp.dir (q-test target/tmp) instead of the default system temp directory, since it stores TLS private key material. ########## itests/util/src/main/java/org/apache/hadoop/hive/cli/GcsOAuthTokenMock.java: ########## @@ -0,0 +1,200 @@ +/* + * 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.hadoop.hive.cli; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import com.sun.net.httpserver.HttpsServer; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyStore; +import java.util.concurrent.TimeUnit; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; + +/** + * Minimal Google OAuth2/STS token endpoint mock for Gravitino {@code gcs-token} credential vending. + * + * <p>Runs two endpoints on separate ports: + * <ul> + * <li>Plain HTTP {@code POST /token} for service-account {@code token_uri}</li> + * <li>HTTPS {@code POST /v1/token} with {@code CN=sts.googleapis.com} for Google STS</li> + * </ul> + * The test wires {@link GcsStsProxyContainer} to forward {@code sts.googleapis.com:443} to the + * HTTPS port, and imports {@link #getCertificatePath()} into the Gravitino container truststore. + */ +public final class GcsOAuthTokenMock implements AutoCloseable { + + /** Token value returned to Gravitino; fake-gcs-server does not validate it. */ + public static final String ACCESS_TOKEN = "gcs-test-access-token"; + private static final String STS_CN = "sts.googleapis.com"; + static final String HOST_GATEWAY = GcsFakeServerContainers.HOST_GATEWAY; + + private static final byte[] OAUTH_TOKEN_RESPONSE = String.format( + "{\"access_token\":\"%s\",\"expires_in\":3600,\"token_type\":\"Bearer\"}", + ACCESS_TOKEN).getBytes(StandardCharsets.UTF_8); + + private static final byte[] STS_TOKEN_RESPONSE = String.format( + "{\"access_token\":\"%s\",\"issued_token_type\":\"urn:ietf:params:oauth:token-type:access_token\"," + + "\"token_type\":\"Bearer\",\"expires_in\":3600}", + ACCESS_TOKEN).getBytes(StandardCharsets.UTF_8); + + private HttpServer httpServer; + private HttpsServer httpsServer; + private Path certificatePath; + private Path workDir; + + /** Starts HTTP and HTTPS servers on ephemeral ports. */ + public void start() throws Exception { + workDir = Files.createTempDirectory("gcs-oauth-mock-"); Review Comment: Good catch. `GcsOAuthTokenMock` now creates its cert/key work dir under test.tmp.dir (q-test target/tmp) instead of the default system temp directory, since it stores TLS private key material. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
