Files
Chris LuandClaude Opus 5.5 6c54935723 java client, hdfs3: authenticate to a filer that requires filer JWT or Basic Auth (#13053)
* java client: read security.toml without an [https.client] section

toml.getBoolean returns null for a missing key, so unboxing it threw a
NullPointerException in the static initializer and every FilerClient
failed with ExceptionInInitializerError when security.toml held only
other sections, such as [grpc] or [jwt.filer_signing].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client: sign filer JWTs and hold [filer.basic_auth] credentials

FilerSecurityContext reads jwt.filer_signing.key, jwt.filer_signing.read.key
(with their expires_after_seconds, defaulting to 10 and 60 like the Go
clients) and [filer.basic_auth] from security.toml, with setters to set
them in code. getFilerAuthorizationHeaderValue returns the credential for a
request to the filer's HTTP port: an HS256 token for the access level,
minted like security.GenJwtForFilerServer, else the filer Basic Auth, else
the existing [basic_auth] value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client: send the filer credential on filer-proxied chunk requests

With volume server access through the filer proxy, chunk reads and writes
address the filer's HTTP port, which checks the filer JWT or Basic Auth
before proxying. The write sent the AssignVolume token instead, which the
filer rejects with "wrong jwt", and reads sent no filer token. Send the
filer credential on proxy URLs only; direct and publicUrl volume requests
keep the volume token. With no filer credential configured, the old
headers are sent unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 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>

* hdfs3: document a filer secured with JWT or Basic Auth

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client: fail a chunk fetch that answers a non-2xx status

doFetchOneFullChunkData returned the response body whatever the status,
so a 401 "wrong jwt" or a 404 JSON error was taken as chunk data and
cached. Throw instead, so the fetch tries the next location and reports
the error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client, hdfs3: accept filer Basic Auth with an empty user

The filer turns Basic Auth on whenever the password is set, user empty or
not. The client dropped credentials without a user, so a password-only
filer refused every proxied chunk request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* hdfs3: point the secured filer docs at [https.client]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client, hdfs3: keep filer credentials on each filer client

The filer JWT keys and [filer.basic_auth] lived in process-wide fields,
so a second filesystem with its own fs.seaweed.filer.* options replaced
the credentials of the first one, and a filesystem without options
inherited the previous overrides. Each FilerClient now copies the
security.toml values into its own FilerCredentials, and chunk reads and
uploads use the credentials of the client that issued them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 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>

* hdfs3: show [https.client] for a secured filer and per-option overrides

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* hdfs3: note that [https.client] does not check the filer host name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* hdfs3: check filer tokens against the configured key and lifetime

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client: do not follow redirects on filer proxy chunk requests

HttpClient copies the request's Authorization header onto a followed
redirect, even to another origin, so a relayed 3xx would hand the filer
JWT or Basic credential to the redirect target. A 3xx now fails like any
other non-2xx answer and the read moves to the next location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* hdfs3: close the filer client when credential options fail

A credential provider error or a malformed lifetime option threw out of
the store constructor after the client had opened its gRPC channels,
leaving them open on every failed initialization.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* hdfs3: say the filer HTTP credentials apply only to filerProxy mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* java client: pick filer credentials by access mode and filer address

The proxy check matched any URL containing proxyChunkId=, so a volume
url or publicUrl carrying that text would receive the filer JWT or Basic
credential. Only filerProxy-mode URLs that start with this client's own
filer proxy prefix count as filer requests now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 18:50:04 -08:00
..
2025-11-26 18:22:32 -08:00
2026-07-08 06:43:07 +00:00

SeaweedFS Hadoop3 Client

Hadoop FileSystem implementation for SeaweedFS, compatible with Hadoop 3.x.

Building

mvn clean install

Testing

This project includes two types of tests:

1. Configuration Tests (No SeaweedFS Required)

These tests verify configuration handling and initialization logic without requiring a running SeaweedFS instance:

mvn test -Dtest=SeaweedFileSystemConfigTest

2. Integration Tests (Requires SeaweedFS)

These tests verify actual FileSystem operations against a running SeaweedFS instance.

Prerequisites

  1. Start SeaweedFS with default ports:

    # Terminal 1: Start master
    weed master
    
    # Terminal 2: Start volume server
    weed volume -master=localhost:9333
    
    # Terminal 3: Start filer
    weed filer -master=localhost:9333
    
  2. Verify services are running:

Running Integration Tests

# Enable integration tests
export SEAWEEDFS_TEST_ENABLED=true

# Run all tests
mvn test

# Run specific test
mvn test -Dtest=SeaweedFileSystemTest

Test Configuration

Integration tests can be configured via environment variables or system properties:

  • SEAWEEDFS_TEST_ENABLED: Set to true to enable integration tests (default: false)
  • Tests use these default connection settings:
    • Filer Host: localhost
    • Filer HTTP Port: 8888
    • Filer gRPC Port: 18888

Running Tests with Custom Configuration

To test against a different SeaweedFS instance, modify the test code or use Hadoop configuration:

conf.set("fs.seaweed.filer.host", "your-host");
conf.setInt("fs.seaweed.filer.port", 8888);
conf.setInt("fs.seaweed.filer.port.grpc", 18888);

Test Coverage

The test suite covers:

  • Configuration & Initialization

    • URI parsing and configuration
    • Default values
    • Configuration overrides
    • Working directory management
  • File Operations

    • Create files
    • Read files
    • Write files
    • Append to files
    • Delete files
  • Directory Operations

    • Create directories
    • List directory contents
    • Delete directories (recursive and non-recursive)
  • Metadata Operations

    • Get file status
    • Set permissions
    • Set owner/group
    • Rename files and directories

Usage in Hadoop

  1. Copy the built JAR to your Hadoop classpath:

    cp target/seaweedfs-hadoop3-client-*.jar $HADOOP_HOME/share/hadoop/common/lib/
    
  2. Configure core-site.xml:

    <configuration>
      <property>
        <name>fs.seaweedfs.impl</name>
        <value>seaweed.hdfs.SeaweedFileSystem</value>
      </property>
      <property>
        <name>fs.seaweed.filer.host</name>
        <value>localhost</value>
      </property>
      <property>
        <name>fs.seaweed.filer.port</name>
        <value>8888</value>
      </property>
      <property>
        <name>fs.seaweed.filer.port.grpc</name>
        <value>18888</value>
      </property>
      <!-- Optional: Replication configuration with three priority levels:
           1) If set to non-empty value (e.g. "001") - uses that value
           2) If set to empty string "" - uses SeaweedFS filer's default replication
           3) If not configured (property not present) - uses HDFS replication parameter
      -->
      <!-- <property>
        <name>fs.seaweed.replication</name>
        <value>001</value>
      </property> -->
    </configuration>
    
  3. Use SeaweedFS with Hadoop commands:

    hadoop fs -ls seaweedfs://localhost:8888/
    hadoop fs -mkdir seaweedfs://localhost:8888/test
    hadoop fs -put local.txt seaweedfs://localhost:8888/test/
    

Secured filer

With fs.seaweed.volume.server.access set to filerProxy, chunk reads and writes go to the filer's HTTP port, so they need the filer's HTTP credentials. The client signs a filer JWT when it has the filer's jwt.filer_signing key (writes) or jwt.filer_signing.read key (reads), and otherwise sends the [filer.basic_auth] credentials. These credentials are sent only to the filer, never to volume servers. In direct and publicUrl modes chunk requests go straight to volume servers, so the filer's HTTP credentials are not used; writes carry the volume token from the volume assignment as before. gRPC mTLS comes from the [grpc] section as before, but it does not cover these HTTP chunk requests: to keep the credentials off plain HTTP, serve the filer HTTP port over HTTPS ([https.filer] on the filer) and enable [https.client] here. The client checks the certificate chain but not the host name, so set https.client.ca to a CA that issues certificates only for your SeaweedFS servers.

security.toml (read from ./, ~/.seaweedfs/ or /etc/seaweedfs/), using the filer's own values:

[jwt.filer_signing]
key = "<filer write key>"

[jwt.filer_signing.read]
key = "<filer read key>"

# or, for a filer with Basic Auth
[filer.basic_auth]
user = "<user>"
password = "<password>"

[grpc]
ca = "/etc/seaweedfs/ca.crt"

[grpc.client]
cert = "/etc/seaweedfs/client.crt"
key = "/etc/seaweedfs/client.key"

[https.client]
enabled = true
ca = "/etc/seaweedfs/ca.crt"
cert = "/etc/seaweedfs/client.crt"
key = "/etc/seaweedfs/client.key"

The same values can be set in core-site.xml. Each option overrides only its own security.toml value (for example, a password alone keeps the security.toml user), and applies only to that filesystem. The secrets can also come from a Hadoop credential provider:

<property>
  <name>fs.seaweed.volume.server.access</name>
  <value>filerProxy</value>
</property>
<property>
  <name>fs.seaweed.filer.jwt.signing.key</name>
  <value>filer write key</value>
</property>
<property>
  <name>fs.seaweed.filer.jwt.signing.read.key</name>
  <value>filer read key</value>
</property>
<!-- token lifetimes, defaults 10 and 60 seconds:
     fs.seaweed.filer.jwt.signing.expires.after.seconds
     fs.seaweed.filer.jwt.signing.read.expires.after.seconds -->
<!-- or Basic Auth:
     fs.seaweed.filer.basic.auth.user
     fs.seaweed.filer.basic.auth.password -->

Continuous Integration

For CI environments, tests can be run in two modes:

  1. Configuration Tests Only (default, no SeaweedFS required):

    mvn test -Dtest=SeaweedFileSystemConfigTest
    
  2. Full Integration Tests (requires SeaweedFS):

    # Start SeaweedFS in CI environment
    # Then run:
    export SEAWEEDFS_TEST_ENABLED=true
    mvn test
    

Troubleshooting

Tests are skipped

If you see "Skipping test - SEAWEEDFS_TEST_ENABLED not set":

export SEAWEEDFS_TEST_ENABLED=true

Connection refused errors

Ensure SeaweedFS is running and accessible:

curl http://localhost:8888/

gRPC errors

Verify the gRPC port is accessible:

# Should show the port is listening
netstat -an | grep 18888

Contributing

When adding new features, please include:

  1. Configuration tests (no SeaweedFS required)
  2. Integration tests (with SEAWEEDFS_TEST_ENABLED guard)
  3. Documentation updates