mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
hdfs3: take filer JWT keys and Basic Auth from the Hadoop configuration
fs.seaweed.filer.jwt.signing.key, fs.seaweed.filer.jwt.signing.read.key (and their expires.after.seconds) and fs.seaweed.filer.basic.auth.user / password override security.toml. The secrets are read with Configuration.getPassword, so a Hadoop credential provider can hold them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d8b9b946a8
commit
725ffa2790
2 files changed
+55
No files matched your search
@@ -10,6 +10,7 @@ import org.apache.hadoop.util.Progressable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seaweedfs.client.FilerProto;
|
||||
import seaweedfs.client.FilerSecurityContext;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -30,6 +31,12 @@ public class SeaweedFileSystem extends FileSystem {
|
||||
public static final String FS_SEAWEED_VOLUME_SERVER_ACCESS = "fs.seaweed.volume.server.access";
|
||||
public static final int FS_SEAWEED_DEFAULT_BUFFER_SIZE = 4 * 1024 * 1024;
|
||||
public static final String FS_SEAWEED_FILER_CN = "fs.seaweed.filer.cn";
|
||||
public static final String FS_SEAWEED_FILER_BASIC_AUTH_USER = "fs.seaweed.filer.basic.auth.user";
|
||||
public static final String FS_SEAWEED_FILER_BASIC_AUTH_PASSWORD = "fs.seaweed.filer.basic.auth.password";
|
||||
public static final String FS_SEAWEED_FILER_JWT_SIGNING_KEY = "fs.seaweed.filer.jwt.signing.key";
|
||||
public static final String FS_SEAWEED_FILER_JWT_SIGNING_EXPIRES = "fs.seaweed.filer.jwt.signing.expires.after.seconds";
|
||||
public static final String FS_SEAWEED_FILER_JWT_SIGNING_READ_KEY = "fs.seaweed.filer.jwt.signing.read.key";
|
||||
public static final String FS_SEAWEED_FILER_JWT_SIGNING_READ_EXPIRES = "fs.seaweed.filer.jwt.signing.read.expires.after.seconds";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SeaweedFileSystem.class);
|
||||
|
||||
@@ -66,9 +73,31 @@ public class SeaweedFileSystem extends FileSystem {
|
||||
|
||||
String cn = conf.get(FS_SEAWEED_FILER_CN, "");
|
||||
|
||||
applyFilerCredentials(conf);
|
||||
seaweedFileSystemStore = new SeaweedFileSystemStore(host, port, grpcPort, cn, conf);
|
||||
}
|
||||
|
||||
// Options set here override the [filer.basic_auth] and [jwt.filer_signing] values of security.toml.
|
||||
static void applyFilerCredentials(Configuration conf) throws IOException {
|
||||
String user = conf.get(FS_SEAWEED_FILER_BASIC_AUTH_USER, "");
|
||||
if (!user.isEmpty()) {
|
||||
FilerSecurityContext.setFilerBasicAuth(user, secret(conf, FS_SEAWEED_FILER_BASIC_AUTH_PASSWORD));
|
||||
}
|
||||
String key = secret(conf, FS_SEAWEED_FILER_JWT_SIGNING_KEY);
|
||||
if (key != null) {
|
||||
FilerSecurityContext.setFilerJwtSigningKey(key, conf.getLong(FS_SEAWEED_FILER_JWT_SIGNING_EXPIRES, 0));
|
||||
}
|
||||
String readKey = secret(conf, FS_SEAWEED_FILER_JWT_SIGNING_READ_KEY);
|
||||
if (readKey != null) {
|
||||
FilerSecurityContext.setFilerJwtReadSigningKey(readKey, 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seaweedfs.client.FilerSecurityContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -87,4 +88,29 @@ public class SeaweedFileSystemConfigTest {
|
||||
// Test default port constant
|
||||
assertEquals(8888, SeaweedFileSystem.FS_SEAWEED_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilerCredentialsFromConfiguration() throws Exception {
|
||||
try {
|
||||
conf.set(SeaweedFileSystem.FS_SEAWEED_FILER_BASIC_AUTH_USER, "alice");
|
||||
conf.set(SeaweedFileSystem.FS_SEAWEED_FILER_BASIC_AUTH_PASSWORD, "s3cret");
|
||||
SeaweedFileSystem.applyFilerCredentials(conf);
|
||||
String basic = "Basic " + java.util.Base64.getEncoder()
|
||||
.encodeToString("alice:s3cret".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
assertEquals(basic, FilerSecurityContext.getFilerAuthorizationHeaderValue(true));
|
||||
|
||||
conf.set(SeaweedFileSystem.FS_SEAWEED_FILER_JWT_SIGNING_KEY, "write-key");
|
||||
SeaweedFileSystem.applyFilerCredentials(conf);
|
||||
assertTrue(FilerSecurityContext.getFilerAuthorizationHeaderValue(true).startsWith("BEARER "));
|
||||
assertEquals(basic, FilerSecurityContext.getFilerAuthorizationHeaderValue(false));
|
||||
|
||||
conf.set(SeaweedFileSystem.FS_SEAWEED_FILER_JWT_SIGNING_READ_KEY, "read-key");
|
||||
SeaweedFileSystem.applyFilerCredentials(conf);
|
||||
assertTrue(FilerSecurityContext.getFilerAuthorizationHeaderValue(false).startsWith("BEARER "));
|
||||
} finally {
|
||||
FilerSecurityContext.setFilerBasicAuth(null, null);
|
||||
FilerSecurityContext.setFilerJwtSigningKey(null, 0);
|
||||
FilerSecurityContext.setFilerJwtReadSigningKey(null, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user