This is an automated email from the ASF dual-hosted git repository.
siyao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 7847e663c4 HDDS-6836. Fix Ozone http header configuration (#3486)
7847e663c4 is described below
commit 7847e663c45adfc3566679959936da3125474d80
Author: Ritesh H Shukla <[email protected]>
AuthorDate: Wed Jun 8 10:59:31 2022 -0700
HDDS-6836. Fix Ozone http header configuration (#3486)
---
.../hadoop/hdds/conf/OzoneConfiguration.java | 7 +--
.../org/apache/hadoop/hdds/ratis/RatisHelper.java | 2 +-
.../hadoop/hdds/conf/ConfigurationSource.java | 32 ++++++++++++--
.../hadoop/hdds/conf/ConfigurationSourceTest.java | 50 ++++++++++++++++++++++
.../hadoop/hdds/server/http/HttpServer2.java | 29 ++++++++-----
.../ozone/om/ratis/OzoneManagerRatisServer.java | 3 +-
.../scm/ReconStorageContainerManagerFacade.java | 2 +-
7 files changed, 105 insertions(+), 20 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
index 6b7e7c6384..f35073c472 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
@@ -283,13 +283,14 @@ public class OzoneConfiguration extends Configuration
}
@Override
- public Map<String, String> getPropsWithPrefix(String confPrefix) {
+ public Map<String, String> getPropsMatchPrefixAndTrimPrefix(
+ String keyPrefix) {
Properties props = getProps();
Map<String, String> configMap = new HashMap<>();
for (String name : props.stringPropertyNames()) {
- if (name.startsWith(confPrefix)) {
+ if (name.startsWith(keyPrefix)) {
String value = get(name);
- String keyName = name.substring(confPrefix.length());
+ String keyName = name.substring(keyPrefix.length());
configMap.put(keyName, value);
}
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
index 8a6193d329..67a3ac14a4 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
@@ -334,7 +334,7 @@ public final class RatisHelper {
private static Map<String, String> getDatanodeRatisPrefixProps(
ConfigurationSource configuration) {
- return configuration.getPropsWithPrefix(
+ return configuration.getPropsMatchPrefixAndTrimPrefix(
StringUtils.appendIfNotPresent(HDDS_DATANODE_RATIS_PREFIX_KEY, '.'));
}
diff --git
a/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationSource.java
b/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationSource.java
index 9f4d87964c..22c74ff325 100644
---
a/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationSource.java
+++
b/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationSource.java
@@ -105,18 +105,44 @@ public interface ConfigurationSource {
return valueString.trim().split("\\s*[,\n]\\s*");
}
- default Map<String, String> getPropsWithPrefix(String confPrefix) {
+ /**
+ * Gets the configuration entries where the key contains the prefix. This
+ * method will strip the prefix from the key in the return Map.
+ * Example: somePrefix.key->value will be key->value in the returned map.
+ * @param keyPrefix Prefix to search.
+ * @return Map containing keys that match and their values.
+ */
+ default Map<String, String> getPropsMatchPrefixAndTrimPrefix(
+ String keyPrefix) {
Map<String, String> configMap = new HashMap<>();
for (String name : getConfigKeys()) {
- if (name.startsWith(confPrefix)) {
+ if (name.startsWith(keyPrefix)) {
String value = get(name);
- String keyName = name.substring(confPrefix.length());
+ String keyName = name.substring(keyPrefix.length());
configMap.put(keyName, value);
}
}
return configMap;
}
+ /**
+ * Gets the configuration entries where the key contains the prefix.
+ * This method will return the entire key including the predix in the
returned
+ * map.
+ * @param keyPrefix Prefix to search.
+ * @return Map containing keys that match and their values.
+ */
+ default Map<String, String> getPropsMatchPrefix(String keyPrefix) {
+ Map<String, String> configMap = new HashMap<>();
+ for (String name : getConfigKeys()) {
+ if (name.startsWith(keyPrefix)) {
+ String value = get(name);
+ configMap.put(name, value);
+ }
+ }
+ return configMap;
+ }
+
/**
* Create a Configuration object and inject the required configuration
values.
*
diff --git
a/hadoop-hdds/config/src/test/java/org/apache/hadoop/hdds/conf/ConfigurationSourceTest.java
b/hadoop-hdds/config/src/test/java/org/apache/hadoop/hdds/conf/ConfigurationSourceTest.java
new file mode 100644
index 0000000000..291ad9af36
--- /dev/null
+++
b/hadoop-hdds/config/src/test/java/org/apache/hadoop/hdds/conf/ConfigurationSourceTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.hdds.conf;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+class ConfigurationSourceTest {
+
+ @Test
+ void getPropsMatchPrefixAndTrimPrefix() {
+ MutableConfigurationSource c = new InMemoryConfiguration();
+ c.set("somePrefix.key", "value");
+ ConfigurationSource config = c;
+ Map<String, String> entry =
+ config.getPropsMatchPrefixAndTrimPrefix("somePrefix.");
+ Assert.assertEquals("key", entry.keySet().toArray()[0]);
+ Assert.assertEquals("value", entry.values().toArray()[0]);
+ }
+
+ @Test
+ void getPropsMatchPrefix() {
+ MutableConfigurationSource c = new InMemoryConfiguration();
+ c.set("somePrefix.key", "value");
+ ConfigurationSource config = c;
+ Map<String, String> entry =
+ config.getPropsMatchPrefix("somePrefix.");
+ Assert.assertEquals("somePrefix.key",
+ entry.keySet().toArray()[0]);
+ Assert.assertEquals("value", entry.values().toArray()[0]);
+ }
+}
\ No newline at end of file
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
index 90c0709609..9df0ec03f4 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
@@ -195,9 +195,9 @@ public final class HttpServer2 implements FilterContainer {
private final SignerSecretProvider secretProvider;
private XFrameOption xFrameOption;
private boolean xFrameOptionIsEnabled;
- public static final String HTTP_HEADER_PREFIX = "hadoop.http.header.";
+ public static final String HTTP_HEADER_PREFIX = "ozone.http.header.";
private static final String HTTP_HEADER_REGEX =
- "hadoop\\.http\\.header\\.([a-zA-Z\\-_]+)";
+ "ozone\\.http\\.header\\.([a-zA-Z\\-_]+)";
static final String X_XSS_PROTECTION =
"X-XSS-Protection:1; mode=block";
static final String X_CONTENT_TYPE_OPTIONS =
@@ -621,9 +621,8 @@ public final class HttpServer2 implements FilterContainer {
final String appDir = getWebAppsPath(name);
addDefaultApps(contexts, appDir, conf);
webServer.setHandler(handlers);
-
- Map<String, String> xFrameParams = setHeaders(conf);
- addGlobalFilter("safety", QuotingInputFilter.class.getName(),
xFrameParams);
+ Map<String, String> config = generateFilterConfiguration(conf);
+ addGlobalFilter("safety", QuotingInputFilter.class.getName(), config);
final FilterInitializer[] initializers = getFilterInitializers(conf);
if (initializers != null) {
conf.set(BIND_ADDRESS, hostName);
@@ -1743,15 +1742,23 @@ public final class HttpServer2 implements
FilterContainer {
}
}
- private Map<String, String> setHeaders(ConfigurationSource conf) {
- Map<String, String> xFrameParams = new HashMap<>();
-
- xFrameParams.putAll(getDefaultHeaders());
+ /**
+ * Generate the configuration for the Quoting filter used.
+ * @param conf global configuration
+ * @return relevant configuration
+ */
+ private Map<String, String> generateFilterConfiguration(
+ ConfigurationSource conf) {
+ Map<String, String> config = new HashMap<>();
+ // Add headers to the configuration.
+ config.putAll(getDefaultHeaders());
if (this.xFrameOptionIsEnabled) {
- xFrameParams.put(HTTP_HEADER_PREFIX + X_FRAME_OPTIONS,
+ config.put(HTTP_HEADER_PREFIX + X_FRAME_OPTIONS,
this.xFrameOption.toString());
}
- return xFrameParams;
+ // Config overrides default
+ config.putAll(conf.getPropsMatchPrefix(HTTP_HEADER_PREFIX));
+ return config;
}
private Map<String, String> getDefaultHeaders() {
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
index 761c8e120a..5ee7b27c82 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
@@ -724,7 +724,8 @@ public final class OzoneManagerRatisServer {
private static Map<String, String> getOMHAConfigs(
ConfigurationSource configuration) {
- return configuration.getPropsWithPrefix(OZONE_OM_HA_PREFIX + ".");
+ return configuration
+ .getPropsMatchPrefixAndTrimPrefix(OZONE_OM_HA_PREFIX + ".");
}
/**
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java
index 941795e551..b85a751614 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java
@@ -244,7 +244,7 @@ public class ReconStorageContainerManagerFacade
OzoneConfiguration reconScmConfiguration =
new OzoneConfiguration(configuration);
Map<String, String> reconScmConfigs =
- configuration.getPropsWithPrefix(RECON_SCM_CONFIG_PREFIX);
+
configuration.getPropsMatchPrefixAndTrimPrefix(RECON_SCM_CONFIG_PREFIX);
for (Map.Entry<String, String> entry : reconScmConfigs.entrySet()) {
reconScmConfiguration.set(entry.getKey(), entry.getValue());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]