You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fluss.apache.org by ja...@apache.org on 2026/09/08 04:07:26 UTC
(fluss) branch main updated: [server] Restrict superuser credential changes to 'super.users' (#4229)
This is an automated email from the ASF dual-hosted git repository.
wuchong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fluss.git
The following commit(s) were added to refs/heads/main by this push:
new a63e55a204 [server] Restrict superuser credential changes to 'super.users' (#4229)
a63e55a204 is described below
commit a63e55a204fe94b88e3216a50faf3c7727c2905c
Author: Hongshun Wang <12...@users.noreply.github.com>
AuthorDate: Tue Sep 8 12:07:21 2026 +0800
[server] Restrict superuser credential changes to 'super.users' (#4229)
Require CLUSTER ALL permission for security configuration changes.
Only configured superusers may add, remove, or modify credentials
belonging to users in super.users.
---
.../fluss/config/cluster/ServerReconfigurable.java | 19 ++++
.../apache/fluss/security/acl/FlussPrincipal.java | 14 +++
.../flink/procedure/FlinkProcedureITCase.java | 110 ++++++++++++++++++++-
.../rpc/netty/server/FlussProtocolPlugin.java | 89 ++++++++++++++++-
.../rpc/netty/server/FlussProtocolPluginTest.java | 96 ++++++++++++++++++
.../apache/fluss/server/DynamicConfigManager.java | 26 +++--
.../apache/fluss/server/DynamicServerConfig.java | 23 +++--
.../fluss/server/authorizer/DefaultAuthorizer.java | 12 +--
.../server/coordinator/CoordinatorService.java | 23 ++++-
9 files changed, 374 insertions(+), 38 deletions(-)
diff --git a/fluss-common/src/main/java/org/apache/fluss/config/cluster/ServerReconfigurable.java b/fluss-common/src/main/java/org/apache/fluss/config/cluster/ServerReconfigurable.java
index 882263b68b..a93a70645c 100644
--- a/fluss-common/src/main/java/org/apache/fluss/config/cluster/ServerReconfigurable.java
+++ b/fluss-common/src/main/java/org/apache/fluss/config/cluster/ServerReconfigurable.java
@@ -19,6 +19,9 @@ package org.apache.fluss.config.cluster;
import org.apache.fluss.config.Configuration;
import org.apache.fluss.exception.ConfigException;
+import org.apache.fluss.security.acl.FlussPrincipal;
+
+import javax.annotation.Nullable;
/** Server Reconfigurable Interface which can dynamically respond to configuration changes. */
public interface ServerReconfigurable {
@@ -43,6 +46,22 @@ public interface ServerReconfigurable {
*/
void validate(Configuration newConfig) throws ConfigException;
+ /**
+ * Validates the provided configuration on behalf of the requester, which allows implementations
+ * to additionally reject changes the requester is not allowed to make. The default
+ * implementation ignores the requester and delegates to {@link #validate(Configuration)}.
+ *
+ * @param newConfig the new configuration, see {@link #validate(Configuration)}
+ * @param requester the principal that requested the change, or null if the reconfiguration is
+ * triggered by the server itself
+ * @throws ConfigException if the configuration is invalid or cannot be applied to this
+ * component
+ */
+ default void validate(Configuration newConfig, @Nullable FlussPrincipal requester)
+ throws ConfigException {
+ validate(newConfig);
+ }
+
/**
* Reconfigures the component with the provided configuration.
*
diff --git a/fluss-common/src/main/java/org/apache/fluss/security/acl/FlussPrincipal.java b/fluss-common/src/main/java/org/apache/fluss/security/acl/FlussPrincipal.java
index 7a60e9c7b6..5e2ce93917 100644
--- a/fluss-common/src/main/java/org/apache/fluss/security/acl/FlussPrincipal.java
+++ b/fluss-common/src/main/java/org/apache/fluss/security/acl/FlussPrincipal.java
@@ -20,7 +20,10 @@ package org.apache.fluss.security.acl;
import org.apache.fluss.annotation.PublicEvolving;
import java.security.Principal;
+import java.util.Arrays;
import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
/**
* Represents a security principal in Fluss, defined by a {@code name} and {@code type}.
@@ -56,6 +59,17 @@ public class FlussPrincipal implements Principal {
this.type = type;
}
+ /**
+ * Parses principals from a semicolon separated list of {@code <type>:<name>} pairs, e.g. {@code
+ * User:root;Group:admins}.
+ */
+ public static Set<FlussPrincipal> parsePrincipals(String principals) {
+ return Arrays.stream(principals.split(";"))
+ .map(principal -> principal.trim().split(":"))
+ .map(principal -> new FlussPrincipal(principal[1], principal[0]))
+ .collect(Collectors.toSet());
+ }
+
@Override
public String getName() {
return name;
diff --git a/fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/procedure/FlinkProcedureITCase.java b/fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/procedure/FlinkProcedureITCase.java
index f1c71f0c26..a37f02e251 100644
--- a/fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/procedure/FlinkProcedureITCase.java
+++ b/fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/procedure/FlinkProcedureITCase.java
@@ -26,6 +26,7 @@ import org.apache.fluss.cluster.rebalance.ServerTag;
import org.apache.fluss.config.ConfigOptions;
import org.apache.fluss.config.Configuration;
import org.apache.fluss.config.MemorySize;
+import org.apache.fluss.exception.AuthorizationException;
import org.apache.fluss.exception.NoRebalanceInProgressException;
import org.apache.fluss.exception.SecurityDisabledException;
import org.apache.fluss.metadata.DataLakeFormat;
@@ -866,7 +867,7 @@ public abstract class FlinkProcedureITCase {
assertThat(results).hasSize(1);
assertThat(results.stream().map(Row::toString).collect(Collectors.toList()))
.containsExactly(
- "+I[security.sasl.plain.credentials, root:******,guest:******,bob:******, DYNAMIC_SERVER_CONFIG]");
+ "+I[security.sasl.plain.credentials, root:******,super:******,bob:******, DYNAMIC_SERVER_CONFIG]");
}
// Verify "bob" can authenticate by creating a catalog with bob's credentials.
@@ -894,8 +895,93 @@ public abstract class FlinkProcedureITCase {
List<Row> results = CollectionUtil.iteratorToList(resultIterator);
assertThat(results.stream().map(Row::toString).collect(Collectors.toList()))
.containsExactly(
- "+I[security.sasl.plain.credentials, root:******,guest:******,bob:******, DYNAMIC_SERVER_CONFIG]");
+ "+I[security.sasl.plain.credentials, root:******,super:******,bob:******, DYNAMIC_SERVER_CONFIG]");
}
+
+ String credentialsKey = ConfigOptions.SERVER_SASL_CREDENTIALS.key();
+ String credentialsWithAlice = "root:password,super:passwords,bob:bob_pass,alice:alice_pass";
+ String credentialsWithChangedSuperUser =
+ "root:password,super:new-password,bob:bob_pass,alice:alice_pass";
+
+ // Security-related cluster configs require ALL rather than ALTER.
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.add_acl('CLUSTER', 'ALLOW', 'User:bob', 'ALTER', '*')",
+ CATALOG_NAME))
+ .await();
+ assertThatThrownBy(
+ () ->
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.set_cluster_configs('%s', '5min', '%s', '%s')",
+ bobCatalog,
+ ConfigOptions.KV_SNAPSHOT_INTERVAL.key(),
+ credentialsKey,
+ credentialsWithAlice))
+ .await())
+ .rootCause()
+ .isInstanceOf(AuthorizationException.class)
+ .hasMessageContaining("operate ALL");
+
+ // ALL allows Bob to alter ordinary credentials, but not super-user credentials.
+ // The super users of this cluster are "root" and "super" (see initConfig()), so even
+ // though Bob is granted CLUSTER ALL, he may only add/remove/change ordinary users like
+ // "alice"; changing or removing the "super" account is rejected.
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.add_acl('CLUSTER', 'ALLOW', 'User:bob', 'ALL', '*')",
+ CATALOG_NAME))
+ .await();
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.append_cluster_configs('%s', 'alice:alice_pass')",
+ bobCatalog, credentialsKey))
+ .await();
+ // Bob (CLUSTER ALL, but not a super user) cannot change the super user's password.
+ assertThatThrownBy(
+ () ->
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.set_cluster_configs('%s', '%s')",
+ bobCatalog,
+ credentialsKey,
+ credentialsWithChangedSuperUser))
+ .await())
+ .rootCause()
+ .isInstanceOf(AuthorizationException.class)
+ .hasMessageContaining(
+ "cannot modify credentials belonging to users in 'super.users'");
+ // Nor can he remove the super user account.
+ assertThatThrownBy(
+ () ->
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.subtract_cluster_configs('%s', 'super:passwords')",
+ bobCatalog, credentialsKey))
+ .await())
+ .rootCause()
+ .isInstanceOf(AuthorizationException.class)
+ .hasMessageContaining(
+ "cannot modify credentials belonging to users in 'super.users'");
+
+ // A super user may alter another configured super user's credentials: "root" is a super
+ // user, so it can change the password of the "super" account and restore it afterwards.
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.set_cluster_configs('%s', '%s')",
+ CATALOG_NAME, credentialsKey, credentialsWithChangedSuperUser))
+ .await();
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.set_cluster_configs('%s', '%s')",
+ CATALOG_NAME, credentialsKey, credentialsWithAlice))
+ .await();
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.subtract_cluster_configs('%s', 'alice:alice_pass')",
+ bobCatalog, credentialsKey))
+ .await();
+
tEnv.executeSql("drop catalog " + bobCatalog);
// Step 2: Delete user "bob" via subtract_cluster_configs
@@ -916,7 +1002,7 @@ public abstract class FlinkProcedureITCase {
// After subtracting the only dynamically-added entry, the config may be empty
assertThat(results.stream().map(Row::toString).collect(Collectors.toList()))
.containsExactly(
- "+I[security.sasl.plain.credentials, root:******,guest:******, DYNAMIC_SERVER_CONFIG]");
+ "+I[security.sasl.plain.credentials, root:******,super:******, DYNAMIC_SERVER_CONFIG]");
}
// Verify "bob" can no longer authenticate.
@@ -932,6 +1018,16 @@ public abstract class FlinkProcedureITCase {
"Call %s.sys.drop_acl('CLUSTER', 'ALLOW', 'User:bob', 'DESCRIBE', '*')",
CATALOG_NAME))
.await();
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.drop_acl('CLUSTER', 'ALLOW', 'User:bob', 'ALTER', '*')",
+ CATALOG_NAME))
+ .await();
+ tEnv.executeSql(
+ String.format(
+ "Call %s.sys.drop_acl('CLUSTER', 'ALLOW', 'User:bob', 'ALL', '*')",
+ CATALOG_NAME))
+ .await();
// Try to append a map entry with the same key as the existing "root" entry
assertThatThrownBy(
() ->
@@ -1073,9 +1169,13 @@ public abstract class FlinkProcedureITCase {
// set security information.
conf.setString(ConfigOptions.SERVER_SECURITY_PROTOCOL_MAP.key(), "CLIENT:sasl");
conf.setString("security.sasl.enabled.mechanisms", "plain");
+ // Two users are configured statically, and both of them are super users:
+ // "root" is the user the tests' default catalog connects with, and "super" is a second
+ // super user which is only used to verify that even a CLUSTER ALL grant does not allow
+ // altering the credentials of a super user account.
conf.setString(
- ConfigOptions.SERVER_SASL_CREDENTIALS.key(), "root:password,guest:passwords");
- conf.set(ConfigOptions.SUPER_USERS, "User:root");
+ ConfigOptions.SERVER_SASL_CREDENTIALS.key(), "root:password,super:passwords");
+ conf.set(ConfigOptions.SUPER_USERS, "User:root;User:super");
conf.set(ConfigOptions.AUTHORIZER_ENABLED, true);
return conf;
}
diff --git a/fluss-rpc/src/main/java/org/apache/fluss/rpc/netty/server/FlussProtocolPlugin.java b/fluss-rpc/src/main/java/org/apache/fluss/rpc/netty/server/FlussProtocolPlugin.java
index 25ae189414..aba5d99389 100644
--- a/fluss-rpc/src/main/java/org/apache/fluss/rpc/netty/server/FlussProtocolPlugin.java
+++ b/fluss-rpc/src/main/java/org/apache/fluss/rpc/netty/server/FlussProtocolPlugin.java
@@ -21,19 +21,26 @@ import org.apache.fluss.cluster.ServerType;
import org.apache.fluss.config.ConfigOptions;
import org.apache.fluss.config.Configuration;
import org.apache.fluss.config.cluster.ServerReconfigurable;
+import org.apache.fluss.exception.AuthorizationException;
import org.apache.fluss.exception.ConfigException;
import org.apache.fluss.rpc.RpcGatewayService;
import org.apache.fluss.rpc.protocol.ApiManager;
import org.apache.fluss.rpc.protocol.NetworkProtocolPlugin;
+import org.apache.fluss.security.acl.FlussPrincipal;
import org.apache.fluss.security.auth.AuthenticationFactory;
import org.apache.fluss.security.auth.PlainTextAuthenticationPlugin;
import org.apache.fluss.shaded.netty4.io.netty.channel.ChannelHandler;
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -65,6 +72,9 @@ public class FlussProtocolPlugin implements NetworkProtocolPlugin, ServerReconfi
private final List<String> listeners;
private final RequestsMetrics requestsMetrics;
private Configuration conf;
+ private Set<FlussPrincipal> superUsers;
+ private boolean principalIgnoreCase;
+
/** Initial credentials from `security.sasl.plain.jaas.config`. */
private Map<String, String> initialPlainCredentialsFromJaasConfig;
@@ -86,6 +96,8 @@ public class FlussProtocolPlugin implements NetworkProtocolPlugin, ServerReconfi
@Override
public void setup(Configuration conf) {
this.conf = new Configuration(conf);
+ this.principalIgnoreCase = this.conf.get(ConfigOptions.SECURITY_ACL_PRINCIPAL_IGNORE_CASE);
+ this.superUsers = parseSuperUsers(this.conf);
this.initialPlainCredentialsFromJaasConfig = parseCredentialsFromJaasConfig(conf);
enrichWithJaasConfig(conf);
}
@@ -138,6 +150,13 @@ public class FlussProtocolPlugin implements NetworkProtocolPlugin, ServerReconfi
generateMergedJaasConfig(newCredentials);
}
+ @Override
+ public void validate(Configuration newConfig, @Nullable FlussPrincipal requester)
+ throws ConfigException {
+ authorizeSuperUserCredentialChanges(readPlainCredentials(newConfig), requester);
+ validate(newConfig);
+ }
+
@Override
public void reconfigure(Configuration newConfig) throws ConfigException {
enrichWithJaasConfig(newConfig);
@@ -209,11 +228,7 @@ public class FlussProtocolPlugin implements NetworkProtocolPlugin, ServerReconfi
* @return the generated JAAS config string
*/
private String generateMergedJaasConfig(Map<String, String> newCredentials) {
- Map<String, String> mergedCredentials =
- new LinkedHashMap<>(initialPlainCredentialsFromJaasConfig);
- if (newCredentials != null) {
- mergedCredentials.putAll(newCredentials);
- }
+ Map<String, String> mergedCredentials = mergePlainCredentials(newCredentials);
StringBuilder sb =
new StringBuilder(
@@ -225,6 +240,70 @@ public class FlussProtocolPlugin implements NetworkProtocolPlugin, ServerReconfi
return sb.toString();
}
+ private Map<String, String> mergePlainCredentials(Map<String, String> plainCredentials) {
+ Map<String, String> mergedCredentials =
+ new LinkedHashMap<>(initialPlainCredentialsFromJaasConfig);
+ if (plainCredentials != null) {
+ mergedCredentials.putAll(plainCredentials);
+ }
+ return mergedCredentials;
+ }
+
+ /**
+ * Rejects the change if the requester is not a configured super user but the credentials of a
+ * configured super user would be added, removed or modified.
+ */
+ private void authorizeSuperUserCredentialChanges(
+ @Nullable Map<String, String> newCredentials, @Nullable FlussPrincipal requester) {
+ if (requester == null || isSuperUser(requester)) {
+ return;
+ }
+
+ if (!Objects.equals(
+ superUserCredentials(currentPlainCredentials),
+ superUserCredentials(newCredentials))) {
+ throw new AuthorizationException(
+ String.format(
+ "Principal %s cannot modify credentials belonging to users in 'super.users', "
+ + "the requester must itself be a super user.",
+ requester));
+ }
+ }
+
+ /** Returns the merged credentials whose username matches the name of a configured superuser. */
+ private Map<String, String> superUserCredentials(@Nullable Map<String, String> credentials) {
+ Map<String, String> superUserCredentials = new HashMap<>();
+ mergePlainCredentials(credentials)
+ .forEach(
+ (user, password) -> {
+ if (isSuperUserName(user)) {
+ superUserCredentials.put(user, password);
+ }
+ });
+ return superUserCredentials;
+ }
+
+ private boolean isSuperUser(FlussPrincipal principal) {
+ return superUsers.stream()
+ .anyMatch(superUser -> superUser.matches(principal, principalIgnoreCase));
+ }
+
+ private boolean isSuperUserName(String username) {
+ return superUsers.stream()
+ .anyMatch(
+ superUser ->
+ principalIgnoreCase
+ ? username.equalsIgnoreCase(superUser.getName())
+ : username.equals(superUser.getName()));
+ }
+
+ private static Set<FlussPrincipal> parseSuperUsers(Configuration configuration) {
+ return configuration
+ .getOptional(ConfigOptions.SUPER_USERS)
+ .map(FlussPrincipal::parsePrincipals)
+ .orElse(Collections.emptySet());
+ }
+
private static Map<String, String> parseCredentialsFromJaasConfig(Configuration configuration) {
Map<String, String> credentials = new LinkedHashMap<>();
String existingJaas = configuration.getString(ConfigOptions.SERVER_SASL_PLAIN_JAAS_CONFIG);
diff --git a/fluss-rpc/src/test/java/org/apache/fluss/rpc/netty/server/FlussProtocolPluginTest.java b/fluss-rpc/src/test/java/org/apache/fluss/rpc/netty/server/FlussProtocolPluginTest.java
new file mode 100644
index 0000000000..019c634890
--- /dev/null
+++ b/fluss-rpc/src/test/java/org/apache/fluss/rpc/netty/server/FlussProtocolPluginTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.fluss.rpc.netty.server;
+
+import org.apache.fluss.cluster.ServerType;
+import org.apache.fluss.config.ConfigOptions;
+import org.apache.fluss.config.Configuration;
+import org.apache.fluss.exception.AuthorizationException;
+import org.apache.fluss.metrics.groups.MetricGroup;
+import org.apache.fluss.metrics.util.NOPMetricsGroup;
+import org.apache.fluss.security.acl.FlussPrincipal;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link FlussProtocolPlugin}. */
+class FlussProtocolPluginTest {
+
+ private static final FlussPrincipal ROOT = new FlussPrincipal("root", "User");
+ private static final FlussPrincipal OPERATOR = new FlussPrincipal("operator", "User");
+
+ @Test
+ void testAuthorizeSuperUserCredentialChanges() {
+ FlussProtocolPlugin plugin = createPlugin(false);
+
+ // a non-super user may change ordinary credentials
+ Configuration addedAlice = credentials("root:root-pass,operator:new-pass,alice:alice-pass");
+ assertThatCode(() -> plugin.validate(addedAlice, OPERATOR)).doesNotThrowAnyException();
+
+ // but not the credentials of a configured super user
+ Configuration changedRoot = credentials("root:new-root-pass,operator:operator-pass");
+ assertThatThrownBy(() -> plugin.validate(changedRoot, OPERATOR))
+ .isInstanceOf(AuthorizationException.class)
+ .hasMessageContaining(
+ "cannot modify credentials belonging to users in 'super.users'");
+
+ // a super user may, and so may the server itself
+ assertThatCode(() -> plugin.validate(changedRoot, ROOT)).doesNotThrowAnyException();
+ assertThatCode(() -> plugin.validate(changedRoot, null)).doesNotThrowAnyException();
+ }
+
+ @Test
+ void testAuthorizeSuperUserCredentialChangesIgnoringCase() {
+ FlussProtocolPlugin plugin = createPlugin(true);
+
+ // the super user lookup ignores the case of the principal name and type
+ Configuration changedRoot = credentials("root:new-root-pass,operator:operator-pass");
+ assertThatCode(() -> plugin.validate(changedRoot, new FlussPrincipal("ROOT", "USER")))
+ .doesNotThrowAnyException();
+
+ // renaming a super user by case only still changes super user credentials
+ Configuration renamedRoot = credentials("ROOT:root-pass,operator:operator-pass");
+ assertThatThrownBy(() -> plugin.validate(renamedRoot, OPERATOR))
+ .isInstanceOf(AuthorizationException.class);
+ }
+
+ private static FlussProtocolPlugin createPlugin(boolean principalIgnoreCase) {
+ Configuration configuration = credentials("root:root-pass,operator:operator-pass");
+ configuration.set(ConfigOptions.SUPER_USERS, "User:root");
+ configuration.set(ConfigOptions.SECURITY_ACL_PRINCIPAL_IGNORE_CASE, principalIgnoreCase);
+
+ MetricGroup metricGroup = NOPMetricsGroup.newInstance();
+ FlussProtocolPlugin plugin =
+ new FlussProtocolPlugin(
+ ServerType.COORDINATOR,
+ Collections.emptyList(),
+ RequestsMetrics.createCoordinatorServerRequestMetrics(metricGroup));
+ plugin.setup(configuration);
+ return plugin;
+ }
+
+ private static Configuration credentials(String credentials) {
+ Configuration configuration = new Configuration();
+ configuration.setString(ConfigOptions.SERVER_SASL_CREDENTIALS.key(), credentials);
+ return configuration;
+ }
+}
diff --git a/fluss-server/src/main/java/org/apache/fluss/server/DynamicConfigManager.java b/fluss-server/src/main/java/org/apache/fluss/server/DynamicConfigManager.java
index dec53519b2..824de74a8a 100644
--- a/fluss-server/src/main/java/org/apache/fluss/server/DynamicConfigManager.java
+++ b/fluss-server/src/main/java/org/apache/fluss/server/DynamicConfigManager.java
@@ -27,6 +27,7 @@ import org.apache.fluss.config.cluster.ConfigValidator;
import org.apache.fluss.config.cluster.ServerReconfigurable;
import org.apache.fluss.config.provider.ConfigProviders;
import org.apache.fluss.exception.ConfigException;
+import org.apache.fluss.security.acl.FlussPrincipal;
import org.apache.fluss.server.authorizer.ZkNodeChangeNotificationWatcher;
import org.apache.fluss.server.zk.ZooKeeperClient;
import org.apache.fluss.server.zk.data.ZkData.ConfigEntityChangeNotificationSequenceZNode;
@@ -36,6 +37,8 @@ import org.apache.fluss.utils.clock.SystemClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.Nullable;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -88,7 +91,7 @@ public class DynamicConfigManager {
try {
configChangeListener.start();
Map<String, String> entityConfigs = zooKeeperClient.fetchEntityConfig();
- dynamicServerConfig.updateDynamicConfig(entityConfigs, true);
+ dynamicServerConfig.updateDynamicConfig(entityConfigs, true, null);
} catch (Exception e) {
LOG.error("Failed to update dynamic configs from zookeeper", e);
}
@@ -135,7 +138,7 @@ public class DynamicConfigManager {
public void resumeListening() throws Exception {
listeningEnabled = true;
Map<String, String> entityConfigs = zooKeeperClient.fetchEntityConfig();
- dynamicServerConfig.updateDynamicConfig(entityConfigs, true);
+ dynamicServerConfig.updateDynamicConfig(entityConfigs, true, null);
}
public List<ConfigEntry> describeConfigs() {
@@ -168,9 +171,19 @@ public class DynamicConfigManager {
}
public void alterConfigs(List<AlterConfig> clusterConfigChanges) throws Exception {
+ alterConfigs(clusterConfigChanges, null);
+ }
+
+ /**
+ * Alters the cluster configs on behalf of the requester, which is null if the change is
+ * triggered by the server itself.
+ */
+ public void alterConfigs(
+ List<AlterConfig> clusterConfigChanges, @Nullable FlussPrincipal requester)
+ throws Exception {
Map<String, String> persistentProps = zooKeeperClient.fetchEntityConfig();
prepareIncrementalConfigs(clusterConfigChanges, persistentProps);
- alterServerConfigs(persistentProps);
+ alterServerConfigs(persistentProps, requester);
}
private void prepareIncrementalConfigs(
@@ -359,8 +372,9 @@ public class DynamicConfigManager {
}
@VisibleForTesting
- protected void alterServerConfigs(Map<String, String> configsProps) throws Exception {
- dynamicServerConfig.updateDynamicConfig(configsProps, false);
+ protected void alterServerConfigs(
+ Map<String, String> configsProps, @Nullable FlussPrincipal requester) throws Exception {
+ dynamicServerConfig.updateDynamicConfig(configsProps, false, requester);
// Apply to zookeeper only after verification.
zooKeeperClient.upsertServerEntityConfig(configsProps);
@@ -400,7 +414,7 @@ public class DynamicConfigManager {
}
Map<String, String> entityConfig = zooKeeperClient.fetchEntityConfig();
- dynamicServerConfig.updateDynamicConfig(entityConfig, true);
+ dynamicServerConfig.updateDynamicConfig(entityConfig, true, null);
}
}
}
diff --git a/fluss-server/src/main/java/org/apache/fluss/server/DynamicServerConfig.java b/fluss-server/src/main/java/org/apache/fluss/server/DynamicServerConfig.java
index 98d721e152..217253c2a2 100644
--- a/fluss-server/src/main/java/org/apache/fluss/server/DynamicServerConfig.java
+++ b/fluss-server/src/main/java/org/apache/fluss/server/DynamicServerConfig.java
@@ -25,12 +25,15 @@ import org.apache.fluss.config.ConfigurationUtils;
import org.apache.fluss.config.cluster.ConfigValidator;
import org.apache.fluss.config.cluster.ServerReconfigurable;
import org.apache.fluss.exception.ConfigException;
+import org.apache.fluss.security.acl.FlussPrincipal;
import org.apache.fluss.server.config.ConfigRedactor;
import org.apache.fluss.server.config.ConfigRedactors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.Nullable;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -180,9 +183,12 @@ class DynamicServerConfig {
* Update the dynamic configuration and apply to registered ServerReconfigurable. If skipping
* error config, only the error one will be ignored.
*/
- void updateDynamicConfig(Map<String, String> newDynamicConfigs, boolean skipErrorConfig)
+ void updateDynamicConfig(
+ Map<String, String> newDynamicConfigs,
+ boolean skipErrorConfig,
+ @Nullable FlussPrincipal requester)
throws Exception {
- inWriteLock(lock, () -> updateCurrentConfig(newDynamicConfigs, skipErrorConfig));
+ inWriteLock(lock, () -> updateCurrentConfig(newDynamicConfigs, skipErrorConfig, requester));
}
Map<String, String> getDynamicConfigs() {
@@ -206,7 +212,10 @@ class DynamicServerConfig {
return false;
}
- private void updateCurrentConfig(Map<String, String> newDynamicConfigs, boolean skipErrorConfig)
+ private void updateCurrentConfig(
+ Map<String, String> newDynamicConfigs,
+ boolean skipErrorConfig,
+ @Nullable FlussPrincipal requester)
throws Exception {
// Compute effective config changes (merge with initial configs)
Map<String, String> effectiveChanges =
@@ -225,7 +234,7 @@ class DynamicServerConfig {
Configuration newConfig = Configuration.fromMap(newConfigMap);
// Apply changes to all registered ServerReconfigurable instances
- applyToServerReconfigurables(newConfig, skipErrorConfig);
+ applyToServerReconfigurables(newConfig, skipErrorConfig, requester);
// Update internal state
updateInternalState(newConfig, newConfigMap, newDynamicConfigs);
@@ -444,9 +453,11 @@ class DynamicServerConfig {
*
* @param newConfig new configuration to apply
* @param skipErrorConfig whether to skip errors
+ * @param requester the principal that requested the change, or null if triggered by the server
* @throws Exception if apply fails and skipErrorConfig is false
*/
- private void applyToServerReconfigurables(Configuration newConfig, boolean skipErrorConfig)
+ private void applyToServerReconfigurables(
+ Configuration newConfig, boolean skipErrorConfig, @Nullable FlussPrincipal requester)
throws Exception {
Configuration oldConfig = currentConfig;
Set<ServerReconfigurable> appliedSet = new HashSet<>();
@@ -454,7 +465,7 @@ class DynamicServerConfig {
// Validate all first
for (ServerReconfigurable reconfigurable : serverReconfigures.values()) {
try {
- reconfigurable.validate(newConfig);
+ reconfigurable.validate(newConfig, requester);
} catch (ConfigException e) {
LOG.error(
"Validation failed for {}: {}",
diff --git a/fluss-server/src/main/java/org/apache/fluss/server/authorizer/DefaultAuthorizer.java b/fluss-server/src/main/java/org/apache/fluss/server/authorizer/DefaultAuthorizer.java
index 0c38f5d02b..f6e0739ac8 100644
--- a/fluss-server/src/main/java/org/apache/fluss/server/authorizer/DefaultAuthorizer.java
+++ b/fluss-server/src/main/java/org/apache/fluss/server/authorizer/DefaultAuthorizer.java
@@ -594,17 +594,7 @@ public class DefaultAuthorizer extends AbstractAuthorizer implements FatalErrorH
private static Set<FlussPrincipal> parseSuperUsers(Configuration configuration) {
return configuration
.getOptional(ConfigOptions.SUPER_USERS)
- .map(
- config ->
- Arrays.stream(config.split(";"))
- .map(String::trim)
- .map(
- user -> {
- String[] userInfo = user.split(":");
- return new FlussPrincipal(
- userInfo[1], userInfo[0]);
- })
- .collect(Collectors.toSet()))
+ .map(FlussPrincipal::parsePrincipals)
.orElse(Collections.emptySet());
}
diff --git a/fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java b/fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java
index 344839513f..6e0c6f3c99 100644
--- a/fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java
+++ b/fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java
@@ -243,6 +243,7 @@ import static org.apache.fluss.utils.Preconditions.checkNotNull;
public final class CoordinatorService extends RpcServiceBase implements CoordinatorGateway {
private static final Logger LOG = LoggerFactory.getLogger(CoordinatorService.class);
+ private static final String SECURITY_CONFIG_KEY_PREFIX = "security.";
private final int defaultBucketNumber;
private final int defaultReplicationFactor;
@@ -1462,10 +1463,6 @@ public final class CoordinatorService extends RpcServiceBase implements Coordina
return CompletableFuture.completedFuture(new AlterClusterConfigsResponse());
}
- if (authorizer != null) {
- authorizer.authorize(currentSession(), OperationType.ALTER, Resource.cluster());
- }
-
List<AlterConfig> serverConfigChanges =
infos.stream()
.map(
@@ -1477,11 +1474,27 @@ public final class CoordinatorService extends RpcServiceBase implements Coordina
: null,
AlterConfigOpType.from((byte) info.getOpType())))
.collect(Collectors.toList());
+
+ Session session = currentSession();
+ if (authorizer != null) {
+ // altering security related configs (e.g. super user credentials) requires the full
+ // cluster permission instead of ALTER only
+ boolean alterSecurityConfigs =
+ serverConfigChanges.stream()
+ .anyMatch(
+ config -> config.key().startsWith(SECURITY_CONFIG_KEY_PREFIX));
+ authorizer.authorize(
+ session,
+ alterSecurityConfigs ? OperationType.ALL : OperationType.ALTER,
+ Resource.cluster());
+ }
+ FlussPrincipal requester = session.isInternal() ? null : session.getPrincipal();
+
AccessContextEvent<Void> accessContextEvent =
new AccessContextEvent<>(
(context) -> {
try {
- dynamicConfigManager.alterConfigs(serverConfigChanges);
+ dynamicConfigManager.alterConfigs(serverConfigChanges, requester);
future.complete(new AlterClusterConfigsResponse());
} catch (ApiException e) {
future.completeExceptionally(e);