snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 03:23:42 +05:00
commit 89f5be005d
3997 changed files with 961970 additions and 0 deletions

View File

@@ -0,0 +1,323 @@
// Package tls_rotation exercises HTTPS certificate rotation end-to-end:
// start a real `weed master` with an HTTPS listener, capture the leaf
// served at handshake time, rewrite the cert/key files on disk, and
// assert that a subsequent handshake sees the new leaf — all without
// stopping the master process. The test shortens the reloader's refresh
// window to ~half a second via WEED_TLS_CERT_REFRESH_INTERVAL so it
// completes in seconds rather than hours.
package tls_rotation
import (
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
"net"
"os"
"os/exec"
"path/filepath"
"strconv"
"syscall"
"testing"
"time"
)
// TestMasterHTTPSCertRotation boots `weed master` with HTTPS, confirms
// the initial leaf is served, rotates the cert/key pair on disk, and
// asserts the rotated leaf is served on subsequent TLS handshakes.
func TestMasterHTTPSCertRotation(t *testing.T) {
if testing.Short() {
t.Skip("skipping HTTPS rotation integration test in -short mode")
}
weedBin := findWeedBinary(t)
dir := t.TempDir()
tlsDir := filepath.Join(dir, "tls")
if err := os.MkdirAll(tlsDir, 0o755); err != nil {
t.Fatalf("mkdir tls: %v", err)
}
certPath := filepath.Join(tlsDir, "server.crt")
keyPath := filepath.Join(tlsDir, "server.key")
ca, caKey := generateCA(t)
leafSerial1 := big.NewInt(10001)
leafSerial2 := big.NewInt(10002)
// Initial leaf on disk.
writeLeaf(t, certPath, keyPath, ca, caKey, leafSerial1)
masterDir := filepath.Join(dir, "master")
if err := os.MkdirAll(masterDir, 0o755); err != nil {
t.Fatalf("mkdir master: %v", err)
}
// Empty security.toml so the master doesn't pick up a user's
// ~/.seaweedfs/security.toml during the test.
if err := os.WriteFile(filepath.Join(masterDir, "security.toml"), []byte("# test\n"), 0o644); err != nil {
t.Fatalf("write security.toml: %v", err)
}
// Master auto-derives gRPC port as port+10000 when -port.grpc is
// unset, so both must fit in uint16. Pin both explicitly.
port, grpcPort := getFreeTCPPort(t), getFreeTCPPort(t)
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, weedBin, "master",
"-ip", "127.0.0.1",
"-port", strconv.Itoa(port),
"-port.grpc", strconv.Itoa(grpcPort),
"-mdir", masterDir,
)
cmd.Dir = masterDir
cmd.Env = append(os.Environ(),
// Isolate HOME so the subprocess cannot pick up a developer's
// ~/.seaweedfs/security.toml. Viper's AddConfigPath uses the
// literal string "$HOME/.seaweedfs" without env expansion today,
// so this is only belt-and-braces — but it insures us against a
// future viper upgrade that does expand env vars.
"HOME="+dir,
"WEED_HTTPS_MASTER_CERT="+certPath,
"WEED_HTTPS_MASTER_KEY="+keyPath,
// Short refresh window so rotation completes in seconds.
"WEED_TLS_CERT_REFRESH_INTERVAL=500ms",
)
logPath := filepath.Join(masterDir, "master.log")
logOut, err := os.Create(logPath)
if err != nil {
t.Fatalf("create master log: %v", err)
}
cmd.Stdout = logOut
cmd.Stderr = logOut
if err := cmd.Start(); err != nil {
t.Fatalf("start master: %v", err)
}
t.Cleanup(func() {
if cmd.Process != nil {
_ = cmd.Process.Signal(syscall.SIGTERM)
done := make(chan struct{})
go func() { _ = cmd.Wait(); close(done) }()
select {
case <-done:
case <-time.After(10 * time.Second):
_ = cmd.Process.Kill()
<-done
}
}
_ = logOut.Close()
if t.Failed() {
if b, readErr := os.ReadFile(logPath); readErr == nil {
t.Logf("master.log:\n%s", string(b))
}
}
})
caPool := x509.NewCertPool()
caPool.AddCert(ca)
addr := fmt.Sprintf("127.0.0.1:%d", port)
// 1. Wait for the initial leaf to appear. Master takes a few seconds
// to open its HTTPS listener.
waitForCert(t, addr, caPool, leafSerial1, 30*time.Second, "initial cert")
// Sanity: same handshake twice still observes the initial leaf.
got, err := peekServerCert(addr, caPool)
if err != nil || got == nil || got.SerialNumber.Cmp(leafSerial1) != 0 {
t.Fatalf("second probe before rotation did not return initial leaf: cert=%v err=%v", got, err)
}
// 2. Rotate on disk. pemfile watches mtime, so each file's write is
// an atomic rename (tempfile in the same directory).
writeLeaf(t, certPath, keyPath, ca, caKey, leafSerial2)
// 3. Wait for new leaf to take over. With a 500ms refresh and no
// connection pooling (tls.Dial opens a fresh conn each time), this
// should take a couple of seconds.
waitForCert(t, addr, caPool, leafSerial2, 15*time.Second, "rotated cert")
}
// waitForCert polls until a TLS handshake against addr yields a peer
// cert with the expected serial, or fails the test at the deadline.
// The last handshake error is surfaced in the fatal message so that a
// CI flake makes the root cause obvious (master didn't come up, TLS
// handshake rejected, CA pool mismatch, etc.).
func waitForCert(t *testing.T, addr string, caPool *x509.CertPool, wantSerial *big.Int, within time.Duration, label string) {
t.Helper()
deadline := time.Now().Add(within)
var lastErr error
var lastSerial *big.Int
for time.Now().Before(deadline) {
cert, err := peekServerCert(addr, caPool)
if err != nil {
lastErr = err
} else if cert != nil {
lastSerial = cert.SerialNumber
if cert.SerialNumber.Cmp(wantSerial) == 0 {
return
}
}
time.Sleep(250 * time.Millisecond)
}
t.Fatalf("timeout waiting for %s (want serial %s, last seen %v, last err %v)", label, wantSerial, lastSerial, lastErr)
}
// peekServerCert opens a one-shot TLS connection and returns the leaf.
// Errors (dial failure, handshake rejection, empty peer chain) are
// returned rather than swallowed, so the caller can surface them when
// the test times out.
func peekServerCert(addr string, caPool *x509.CertPool) (*x509.Certificate, error) {
d := &net.Dialer{Timeout: 2 * time.Second}
conn, err := tls.DialWithDialer(d, "tcp", addr, &tls.Config{
RootCAs: caPool,
ServerName: "localhost",
MinVersion: tls.VersionTLS12,
})
if err != nil {
return nil, err
}
defer conn.Close()
state := conn.ConnectionState()
if len(state.PeerCertificates) == 0 {
return nil, fmt.Errorf("handshake returned empty peer chain")
}
return state.PeerCertificates[0], nil
}
func getFreeTCPPort(t *testing.T) int {
t.Helper()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("listen ephemeral: %v", err)
}
port := ln.Addr().(*net.TCPAddr).Port
_ = ln.Close()
return port
}
func findWeedBinary(t *testing.T) string {
t.Helper()
candidates := []string{
"../../weed/weed",
"../weed/weed",
"./weed",
}
for _, c := range candidates {
if _, err := os.Stat(c); err == nil {
abs, absErr := filepath.Abs(c)
if absErr == nil {
return abs
}
return c
}
}
if path, err := exec.LookPath("weed"); err == nil {
return path
}
t.Skip("weed binary not found — build with `cd weed && go build` first")
return ""
}
// --- cert fixtures -------------------------------------------------------
// generateCA returns a self-signed CA cert and its private key.
func generateCA(t *testing.T) (*x509.Certificate, *ecdsa.PrivateKey) {
t.Helper()
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatalf("gen CA key: %v", err)
}
tmpl := &x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{CommonName: "tls-rotation-test-CA"},
NotBefore: time.Now().Add(-time.Hour),
NotAfter: time.Now().Add(24 * time.Hour),
IsCA: true,
BasicConstraintsValid: true,
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign,
}
der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
if err != nil {
t.Fatalf("create CA cert: %v", err)
}
parsed, err := x509.ParseCertificate(der)
if err != nil {
t.Fatalf("parse CA cert: %v", err)
}
return parsed, key
}
// writeLeaf signs a new leaf cert with the given serial and writes it
// plus its key to the given paths via atomic rename — the pattern
// Kubernetes (cert-manager → Secret volume mount) produces in practice.
func writeLeaf(t *testing.T, certPath, keyPath string, ca *x509.Certificate, caKey *ecdsa.PrivateKey, serial *big.Int) {
t.Helper()
leafKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatalf("gen leaf key: %v", err)
}
tmpl := &x509.Certificate{
SerialNumber: serial,
Subject: pkix.Name{
CommonName: "localhost",
},
NotBefore: time.Now().Add(-time.Hour),
NotAfter: time.Now().Add(24 * time.Hour),
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
DNSNames: []string{"localhost"},
IPAddresses: []net.IP{net.ParseIP("127.0.0.1"), net.ParseIP("::1")},
}
der, err := x509.CreateCertificate(rand.Reader, tmpl, ca, &leafKey.PublicKey, caKey)
if err != nil {
t.Fatalf("create leaf cert: %v", err)
}
atomicWritePEM(t, certPath, "CERTIFICATE", der)
keyDER, err := x509.MarshalECPrivateKey(leafKey)
if err != nil {
t.Fatalf("marshal leaf key: %v", err)
}
atomicWritePEM(t, keyPath, "EC PRIVATE KEY", keyDER)
}
// atomicWritePEM writes a PEM file via tempfile-in-same-directory plus
// rename, matching what kubelet does when it swaps the ..data symlink
// for a renewed Secret. Ensures the reader never sees a truncated file.
func atomicWritePEM(t *testing.T, path, blockType string, der []byte) {
t.Helper()
dir := filepath.Dir(path)
tmp, err := os.CreateTemp(dir, ".tls-*")
if err != nil {
t.Fatalf("create tempfile: %v", err)
}
ok := false
defer func() {
if !ok {
_ = os.Remove(tmp.Name())
}
}()
if err := pem.Encode(tmp, &pem.Block{Type: blockType, Bytes: der}); err != nil {
tmp.Close()
t.Fatalf("pem encode: %v", err)
}
if err := tmp.Close(); err != nil {
t.Fatalf("close tempfile: %v", err)
}
if err := os.Chmod(tmp.Name(), 0o600); err != nil {
t.Fatalf("chmod tempfile: %v", err)
}
if err := os.Rename(tmp.Name(), path); err != nil {
t.Fatalf("rename tempfile onto %s: %v", path, err)
}
ok = true
}