hdfs3: let each filer credential option override only its own value

A password-only or token-lifetime-only option in core-site.xml was
ignored or dropped the security.toml user and key. Each option now
replaces just the security.toml value it names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-27 03:55:48 -08:00
1 parent 362e4c61d6
commit f322b123f5
2 files changed
+33 -15

No files matched your search

@@ -76,26 +76,19 @@ public class SeaweedFileSystem extends FileSystem {
seaweedFileSystemStore = new SeaweedFileSystemStore(host, port, grpcPort, cn, conf);
}
// Options set here override the [filer.basic_auth] and [jwt.filer_signing] values of security.toml.
// Each option set here overrides only its own [filer.basic_auth] or [jwt.filer_signing] value of security.toml.
static void applyFilerCredentials(Configuration conf, FilerCredentials credentials) throws IOException {
String user = conf.get(FS_SEAWEED_FILER_BASIC_AUTH_USER, "");
String password = secret(conf, FS_SEAWEED_FILER_BASIC_AUTH_PASSWORD);
if (!user.isEmpty() || password != null) {
credentials.setBasicAuth(user, password);
}
String key = secret(conf, FS_SEAWEED_FILER_JWT_SIGNING_KEY);
if (key != null) {
credentials.setJwtSigningKey(key, conf.getLong(FS_SEAWEED_FILER_JWT_SIGNING_EXPIRES, 0));
}
String readKey = secret(conf, FS_SEAWEED_FILER_JWT_SIGNING_READ_KEY);
if (readKey != null) {
credentials.setJwtReadSigningKey(readKey, conf.getLong(FS_SEAWEED_FILER_JWT_SIGNING_READ_EXPIRES, 0));
}
credentials.setBasicAuth(conf.get(FS_SEAWEED_FILER_BASIC_AUTH_USER),
secret(conf, FS_SEAWEED_FILER_BASIC_AUTH_PASSWORD));
credentials.setJwtSigningKey(secret(conf, FS_SEAWEED_FILER_JWT_SIGNING_KEY),
conf.getLong(FS_SEAWEED_FILER_JWT_SIGNING_EXPIRES, 0));
credentials.setJwtReadSigningKey(secret(conf, FS_SEAWEED_FILER_JWT_SIGNING_READ_KEY),
conf.getLong(FS_SEAWEED_FILER_JWT_SIGNING_READ_EXPIRES, 0));
}
private static String secret(Configuration conf, String name) throws IOException {
char[] value = conf.getPassword(name);
return value == null || value.length == 0 ? null : new String(value);
return value == null ? null : new String(value);
}
@Override
@@ -108,4 +108,29 @@ public class SeaweedFileSystemConfigTest {
SeaweedFileSystem.applyFilerCredentials(conf, credentials);
assertTrue(credentials.getAuthorizationHeaderValue(false).startsWith("BEARER "));
}
@Test
public void testFilerCredentialOptionsOverrideOneValueEach() throws Exception {
FilerCredentials credentials = new FilerCredentials();
credentials.setBasicAuth("toml-user", "toml-pass");
credentials.setJwtReadSigningKey("toml-read-key", 0);
conf.set(SeaweedFileSystem.FS_SEAWEED_FILER_BASIC_AUTH_PASSWORD, "new-pass");
conf.setLong(SeaweedFileSystem.FS_SEAWEED_FILER_JWT_SIGNING_READ_EXPIRES, 300);
SeaweedFileSystem.applyFilerCredentials(conf, credentials);
assertEquals("Basic " + java.util.Base64.getEncoder()
.encodeToString("toml-user:new-pass".getBytes(java.nio.charset.StandardCharsets.UTF_8)),
credentials.getAuthorizationHeaderValue(true));
String[] read = credentials.getAuthorizationHeaderValue(false).substring("BEARER ".length()).split("\\.");
javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA256");
mac.init(new javax.crypto.spec.SecretKeySpec(
"toml-read-key".getBytes(java.nio.charset.StandardCharsets.UTF_8), "HmacSHA256"));
assertEquals(java.util.Base64.getUrlEncoder().withoutPadding().encodeToString(mac.doFinal(
(read[0] + "." + read[1]).getBytes(java.nio.charset.StandardCharsets.UTF_8))), read[2]);
String payload = new String(java.util.Base64.getUrlDecoder().decode(read[1]),
java.nio.charset.StandardCharsets.UTF_8);
long exp = Long.parseLong(payload.replaceAll("[^0-9]", ""));
assertTrue(exp - System.currentTimeMillis() / 1000 >= 299);
}
}