Skip to content

Commit fba46aa

Browse files
authored
HADOOP-18499. S3A to support HTTPS web proxies (#5051)
The option "fs.s3a.proxy.ssl.enabled" controls whether the s3a connects to a proxy over HTTP (default) or HTTPS. Set to "true" to use HTTPS. Contributed by Mehakmeet Singh
1 parent 37bff63 commit fba46aa

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ private Constants() {
212212
public static final String PROXY_PASSWORD = "fs.s3a.proxy.password";
213213
public static final String PROXY_DOMAIN = "fs.s3a.proxy.domain";
214214
public static final String PROXY_WORKSTATION = "fs.s3a.proxy.workstation";
215+
/** Is the proxy secured(proxyProtocol = HTTPS)? */
216+
public static final String PROXY_SECURED = "fs.s3a.proxy.ssl.enabled";
215217

216218
/**
217219
* Number of times the AWS client library should retry errors before

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,13 +1351,17 @@ public static void initProxySupport(Configuration conf,
13511351
LOG.error(msg);
13521352
throw new IllegalArgumentException(msg);
13531353
}
1354+
boolean isProxySecured = conf.getBoolean(PROXY_SECURED, false);
13541355
awsConf.setProxyUsername(proxyUsername);
13551356
awsConf.setProxyPassword(proxyPassword);
13561357
awsConf.setProxyDomain(conf.getTrimmed(PROXY_DOMAIN));
13571358
awsConf.setProxyWorkstation(conf.getTrimmed(PROXY_WORKSTATION));
1359+
awsConf.setProxyProtocol(isProxySecured ? Protocol.HTTPS : Protocol.HTTP);
13581360
if (LOG.isDebugEnabled()) {
1359-
LOG.debug("Using proxy server {}:{} as user {} with password {} on " +
1360-
"domain {} as workstation {}", awsConf.getProxyHost(),
1361+
LOG.debug("Using proxy server {}://{}:{} as user {} with password {} "
1362+
+ "on domain {} as workstation {}",
1363+
awsConf.getProxyProtocol(),
1364+
awsConf.getProxyHost(),
13611365
awsConf.getProxyPort(),
13621366
String.valueOf(awsConf.getProxyUsername()),
13631367
awsConf.getProxyPassword(), awsConf.getProxyDomain(),
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.s3a;
20+
21+
import java.io.IOException;
22+
23+
import com.amazonaws.ClientConfiguration;
24+
import com.amazonaws.Protocol;
25+
import org.assertj.core.api.Assertions;
26+
import org.junit.Test;
27+
28+
import org.apache.hadoop.conf.Configuration;
29+
import org.apache.hadoop.test.AbstractHadoopTestBase;
30+
31+
import static org.apache.hadoop.fs.s3a.Constants.PROXY_HOST;
32+
import static org.apache.hadoop.fs.s3a.Constants.PROXY_PORT;
33+
import static org.apache.hadoop.fs.s3a.Constants.PROXY_SECURED;
34+
import static org.apache.hadoop.fs.s3a.S3AUtils.initProxySupport;
35+
36+
/**
37+
* Tests to verify {@link S3AUtils} translates the proxy configurations
38+
* are set correctly to Client configurations which are later used to construct
39+
* the proxy in AWS SDK.
40+
*/
41+
public class TestS3AProxy extends AbstractHadoopTestBase {
42+
43+
/**
44+
* Verify Http proxy protocol.
45+
*/
46+
@Test
47+
public void testProxyHttp() throws IOException {
48+
Configuration proxyConfigForHttp = createProxyConfig(false);
49+
verifyProxy(proxyConfigForHttp, false);
50+
}
51+
52+
/**
53+
* Verify Https proxy protocol.
54+
*/
55+
@Test
56+
public void testProxyHttps() throws IOException {
57+
Configuration proxyConfigForHttps = createProxyConfig(true);
58+
verifyProxy(proxyConfigForHttps, true);
59+
}
60+
61+
/**
62+
* Verify default proxy protocol.
63+
*/
64+
@Test
65+
public void testProxyDefault() throws IOException {
66+
Configuration proxyConfigDefault = new Configuration();
67+
proxyConfigDefault.set(PROXY_HOST, "testProxyDefault");
68+
verifyProxy(proxyConfigDefault, false);
69+
}
70+
71+
/**
72+
* Assert that the configuration set for a proxy gets translated to Client
73+
* configuration with the correct protocol to be used by AWS SDK.
74+
* @param proxyConfig Configuration used to set the proxy configs.
75+
* @param isExpectedSecured What is the expected protocol for the proxy to
76+
* be? true for https, and false for http.
77+
* @throws IOException
78+
*/
79+
private void verifyProxy(Configuration proxyConfig,
80+
boolean isExpectedSecured)
81+
throws IOException {
82+
ClientConfiguration awsConf = new ClientConfiguration();
83+
initProxySupport(proxyConfig, "test-bucket", awsConf);
84+
Assertions.assertThat(awsConf.getProxyProtocol())
85+
.describedAs("Proxy protocol not as expected")
86+
.isEqualTo(isExpectedSecured ? Protocol.HTTPS : Protocol.HTTP);
87+
}
88+
89+
/**
90+
* Create a configuration file with proxy configs.
91+
* @param isSecured Should the configured proxy be secured or not?
92+
* @return configuration.
93+
*/
94+
private Configuration createProxyConfig(boolean isSecured) {
95+
Configuration conf = new Configuration();
96+
conf.set(PROXY_HOST, "testProxy");
97+
conf.set(PROXY_PORT, "1234");
98+
conf.setBoolean(PROXY_SECURED, isSecured);
99+
return conf;
100+
}
101+
}

0 commit comments

Comments
 (0)