From d6ff97012549bfd91396447249297411ccfc79a7 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 3 Jul 2024 13:17:25 -0700 Subject: [PATCH] honor bucket-key S3 feature (#4976) fixes #4973 --- cmd/stat.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/stat.go b/cmd/stat.go index 2587a68d..aa4ed10f 100644 --- a/cmd/stat.go +++ b/cmd/stat.go @@ -109,12 +109,30 @@ func (stat statMessage) String() (msg string) { } if maxKeyEncrypted > 0 { - if keyID, ok := stat.Metadata["X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id"]; ok { + // Handle various AWS S3 headers, behaviors etc. + var found bool + if enabled, ok := stat.Metadata["X-Amz-Server-Side-Encryption-Bucket-Key-Enabled"]; ok { + if enabled == "true" { + msgBuilder.WriteString(fmt.Sprintf("%-10s: SSE-%s\n", "Encryption", "KMS")) + } + // we still need to treat this as 'true' because X-Amz-Server-Side-Encryption-Bucket-Key-Enabled + // can be set to 'false' by the server to indicate there is no SSE enabled on the object + // we shouldn't be printing `unknown` in that scenario. + found = true + } else if keyID, ok := stat.Metadata["X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id"]; ok { msgBuilder.WriteString(fmt.Sprintf("%-10s: SSE-%s (%s)\n", "Encryption", "KMS", keyID)) + found = true } else if _, ok := stat.Metadata["X-Amz-Server-Side-Encryption-Customer-Key-Md5"]; ok { msgBuilder.WriteString(fmt.Sprintf("%-10s: SSE-%s\n", "Encryption", "C")) - } else { + found = true + } else if algo, ok := stat.Metadata["X-Amz-Server-Side-Encryption"]; ok && algo == "AES256" { msgBuilder.WriteString(fmt.Sprintf("%-10s: SSE-%s\n", "Encryption", "S3")) + found = true + } + if !found { + // encryption headers are present but not something we recognize, check `mc stat --debug` + // to obtain more information and understand if we are missing something. + msgBuilder.WriteString(fmt.Sprintf("%-10s: SSE-%s\n", "Encryption", "Unknown")) } }