From eaac405ece295202fb2a052d23a8225d7e0ecc79 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 5 Dec 2026 14:11:57 -0800 Subject: [PATCH] Allow unused CA alternatives during certificate rotation --- seaweed-block/core/rpc/answer/credentials.go | 15 ++++++++- .../core/rpc/link/ca_rotation_test.go | 33 +++++++++++++++++++ seaweed-block/docs/releases/v1.1.2.md | 6 ++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/rpc/answer/credentials.go b/seaweed-block/core/rpc/answer/credentials.go index 219a5fa217..f789839717 100644 --- a/seaweed-block/core/rpc/answer/credentials.go +++ b/seaweed-block/core/rpc/answer/credentials.go @@ -11,6 +11,8 @@ import ( // any dial. The same provenance is used by RPC and HTTP client constructors. func CertificatePool(raw []byte, now time.Time) (*x509.CertPool, error) { count := 0 + current := 0 + var dateErr error for rest := raw; len(rest) > 0; { block, remaining := pem.Decode(rest) if block == nil { @@ -25,7 +27,11 @@ func CertificatePool(raw []byte, now time.Time) (*x509.CertPool, error) { return nil, LocalCredential(err) } if err := ValidateCertificate(cert, now); err != nil { - return nil, err + if dateErr == nil { + dateErr = err + } + } else { + current++ } count++ } @@ -33,6 +39,13 @@ func CertificatePool(raw []byte, now time.Time) (*x509.CertPool, error) { if count == 0 || !pool.AppendCertsFromPEM(raw) { return nil, LocalCredential(fmt.Errorf("CA bundle holds no valid PEM certificate")) } + // Roots are alternatives during rotation, not one certificate chain. + // An unused stale root does not invalidate a current one. TLS still + // verifies the dates of the chain it actually selects. Preserve the + // local configuration refusal when the bundle has no current entry. + if current == 0 { + return nil, dateErr + } return pool, nil } diff --git a/seaweed-block/core/rpc/link/ca_rotation_test.go b/seaweed-block/core/rpc/link/ca_rotation_test.go index ae346c7e57..3f978d9cc0 100644 --- a/seaweed-block/core/rpc/link/ca_rotation_test.go +++ b/seaweed-block/core/rpc/link/ca_rotation_test.go @@ -17,12 +17,45 @@ import ( "time" "github.com/seaweedfs/seaweed-block/core/auth/authtest" + "github.com/seaweedfs/seaweed-block/core/rpc/answer" "github.com/seaweedfs/seaweed-block/core/rpc/link" "google.golang.org/grpc" "google.golang.org/grpc/health" healthpb "google.golang.org/grpc/health/grpc_health_v1" ) +func TestMasterLinkCARotationRejectsAllInvalidRootsLocally(t *testing.T) { + now := time.Now() + dir := t.TempDir() + good := authtest.NewCA(t, "own-certificate") + cert, key := good.Issue(t, "operator", now.Add(time.Hour)).WriteFiles(t, dir, "own") + expired, _, _ := datedRotationRoot(t, dir, now.Add(-2*time.Hour), now.Add(-time.Hour)) + future, _, _ := datedRotationRoot(t, dir, now.Add(time.Hour), now.Add(2*time.Hour)) + path := filepath.Join(dir, "all-invalid.pem") + if err := os.WriteFile(path, append(expired, future...), 0o600); err != nil { + t.Fatal(err) + } + files := link.TLSFiles{Cert: cert, Key: key, CA: path} + for _, row := range []struct { + name string + build func() error + }{ + {"client", func() error { _, err := link.ClientCredentials(files, ""); return err }}, + {"server", func() error { _, err := link.ServerCredentials(files); return err }}, + } { + t.Run(row.name, func(t *testing.T) { + err := row.build() + if err == nil { + t.Fatal("all-invalid bundle accepted locally") + } + policy, check := answer.PolicyOf(err) + if check != nil || policy.Exit != 78 || policy.Retryable || policy.Retry != answer.Never { + t.Fatalf("all-invalid bundle policy=%+v check=%v err=%v", policy, check, err) + } + }) + } +} + // A CA bundle is a set of alternatives. An unused old/future root must not // prevent startup or a valid mTLS call; selecting that root must still fail. func TestMasterLinkCARotationUsesTheVerifiedChain(t *testing.T) { diff --git a/seaweed-block/docs/releases/v1.1.2.md b/seaweed-block/docs/releases/v1.1.2.md index b398e2c099..9718d7a091 100644 --- a/seaweed-block/docs/releases/v1.1.2.md +++ b/seaweed-block/docs/releases/v1.1.2.md @@ -16,6 +16,12 @@ transport status. A gRPC `Unavailable` after a request may have been sent is before proceeding. It is never proof that a new non-idempotent operation is safe. Typed server refusals retain their own contract. +CA bundles can retain unused expired or not-yet-valid certificates during +rotation when the bundle also contains a certificate valid at the current +time. TLS still checks the chain it selects. A bundle with no currently valid +certificate, or an expired local identity certificate, remains a local +configuration refusal (exit 78). + One global projection gives these exits: | Failure class | Exit | Same-operation action |