From 0b7bd23647c35e9418da4eae174d36d6618840f9 Mon Sep 17 00:00:00 2001 From: Tiago Posse Date: Fri, 4 Dec 2026 20:07:11 +0100 Subject: [PATCH] s3api: stop at startup when the -s3.config KMS block doesn't load (#13380) * s3api: stop at startup when the -s3.config KMS block doesn't load A kms block in the -s3.config file that failed to load was only logged, so S3 came up healthy with SSE-KMS off. Every SSE-KMS write and every read of an SSE-KMS object then failed with 500, and nothing at startup pointed at the config. loadS3ApiConfigurationFromFile now returns the KMS error once it has applied the identities, and startup already stops on any error it returns. A SIGHUP reload still applies the identities, so a revoked key stops working, keeps the previous KMS providers and logs the error. Co-Authored-By: Claude Opus 5.5 * s3api: shorten the KMS load-order comment Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: Chris Lu --- weed/s3api/auth_credentials.go | 9 +++++---- weed/s3api/auth_credentials_kms_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/weed/s3api/auth_credentials.go b/weed/s3api/auth_credentials.go index 8b32826aab..eae774e587 100644 --- a/weed/s3api/auth_credentials.go +++ b/weed/s3api/auth_credentials.go @@ -714,10 +714,8 @@ func (iam *IdentityAccessManagement) loadS3ApiConfigurationFromFile(fileName str return err } - // Initialize KMS if configuration contains KMS settings - if err := iam.initializeKMSFromConfig(content); err != nil { - glog.Errorf("KMS initialization failed: %v", err) - } + // The identities still apply when the KMS block fails, so a reload can revoke access. + kmsErr := iam.initializeKMSFromConfig(content) // fromStaticFile=true: this file is the source of truth for its static // identities, so a reload overwrites them (e.g. a rotated secretKey). @@ -731,6 +729,9 @@ func (iam *IdentityAccessManagement) loadS3ApiConfigurationFromFile(fileName str // later dynamic merges. iam.markStaticIdentities(config) iam.updateCredentialManagerStaticIdentities() + if kmsErr != nil { + return fmt.Errorf("load KMS: %w", kmsErr) + } return nil } diff --git a/weed/s3api/auth_credentials_kms_test.go b/weed/s3api/auth_credentials_kms_test.go index a7491110ac..38aff27492 100644 --- a/weed/s3api/auth_credentials_kms_test.go +++ b/weed/s3api/auth_credentials_kms_test.go @@ -73,6 +73,19 @@ func TestIdentitiesThatDontParseLeaveKMSAlone(t *testing.T) { } } +func TestKMSThatDoesntLoadFailsTheFileAfterItsIdentities(t *testing.T) { + resetKMS(t) + s3a := newTestS3ApiServerWithMemoryIAM(t, []*iam_pb.Identity{}) + + err := s3a.iam.loadS3ApiConfigurationFromFile(writeTempIamConfig(t, `{"kms": {"default_provider": "missing"}, "identities": [{"name": "a", "credentials": [{"accessKey": "AKIAKMSFAILED", "secretKey": "c2VjcmV0"}]}]}`)) + if err == nil { + t.Fatal("a kms section that doesn't load was reported as loaded") + } + if _, _, found := s3a.iam.lookupByAccessKey("AKIAKMSFAILED"); !found { + t.Fatal("a kms section that doesn't load held back the identities") + } +} + func TestKMSConfigWithANumberOutOfRangeKeepsItOutOfTheError(t *testing.T) { resetKMS(t) iam := &IdentityAccessManagement{}