mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* shell: mask every remote secret in remote.configure's listing remote.configure without arguments lists the configured remotes and replaces their secrets with stars, but the list was incomplete: the Azure account key, the Backblaze application key, the Baidu secret key (the access key was masked in its place) and the Contabo secret key were printed in clear, and so were inline gcs service account credentials (the field holds a file path or the JSON itself, private key included). Move the masking into maskRemoteConfSecrets, which covers every secret field of RemoteConf, and test it. An unset secret stays empty, so an Azure remote that authenticates with Entra ID still lists an empty key; a gcs credentials file path stays listed. * shell: compare each masked remote secret with its full-length mask Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
package shell
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/remote_pb"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func TestMaskRemoteConfSecrets(t *testing.T) {
|
|
conf := &remote_pb.RemoteConf{
|
|
Type: "azure",
|
|
Name: "r1",
|
|
S3AccessKey: "AKID",
|
|
S3SecretKey: "s3-secret",
|
|
AzureAccountName: "account",
|
|
AzureAccountKey: "azure-account-key==",
|
|
BackblazeApplicationKey: "b2-secret",
|
|
AliyunSecretKey: "aliyun-secret",
|
|
TencentSecretKey: "tencent-secret",
|
|
BaiduAccessKey: "baidu-ak",
|
|
BaiduSecretKey: "baidu-secret",
|
|
WasabiSecretKey: "wasabi-secret",
|
|
FilebaseSecretKey: "filebase-secret",
|
|
StorjSecretKey: "storj-secret",
|
|
ContaboSecretKey: "contabo-secret",
|
|
}
|
|
original := proto.Clone(conf).(*remote_pb.RemoteConf)
|
|
maskRemoteConfSecrets(conf)
|
|
for name, pair := range map[string][2]string{
|
|
"s3": {original.S3SecretKey, conf.S3SecretKey},
|
|
"azure": {original.AzureAccountKey, conf.AzureAccountKey},
|
|
"backblaze": {original.BackblazeApplicationKey, conf.BackblazeApplicationKey},
|
|
"aliyun": {original.AliyunSecretKey, conf.AliyunSecretKey},
|
|
"tencent": {original.TencentSecretKey, conf.TencentSecretKey},
|
|
"baidu ak": {original.BaiduAccessKey, conf.BaiduAccessKey},
|
|
"baidu sk": {original.BaiduSecretKey, conf.BaiduSecretKey},
|
|
"wasabi": {original.WasabiSecretKey, conf.WasabiSecretKey},
|
|
"filebase": {original.FilebaseSecretKey, conf.FilebaseSecretKey},
|
|
"storj": {original.StorjSecretKey, conf.StorjSecretKey},
|
|
"contabo": {original.ContaboSecretKey, conf.ContaboSecretKey},
|
|
} {
|
|
if want := strings.Repeat("*", len(pair[0])); pair[1] != want {
|
|
t.Errorf("%s secret masked as %q, want %q", name, pair[1], want)
|
|
}
|
|
}
|
|
if conf.AzureAccountName != "account" || conf.S3AccessKey != "AKID" {
|
|
t.Errorf("non-secret fields changed: %q %q", conf.AzureAccountName, conf.S3AccessKey)
|
|
}
|
|
|
|
empty := &remote_pb.RemoteConf{Type: "azure"}
|
|
maskRemoteConfSecrets(empty)
|
|
if empty.AzureAccountKey != "" {
|
|
t.Errorf("an unset key must stay empty (Entra ID), got %q", empty.AzureAccountKey)
|
|
}
|
|
|
|
inline := ` {"type":"service_account","private_key":"-----BEGIN PRIVATE KEY-----"}`
|
|
gcs := &remote_pb.RemoteConf{Type: "gcs", GcsGoogleApplicationCredentials: inline}
|
|
maskRemoteConfSecrets(gcs)
|
|
if want := strings.Repeat("*", len(inline)); gcs.GcsGoogleApplicationCredentials != want {
|
|
t.Errorf("inline gcs credentials masked as %q, want %q", gcs.GcsGoogleApplicationCredentials, want)
|
|
}
|
|
path := &remote_pb.RemoteConf{Type: "gcs", GcsGoogleApplicationCredentials: "/etc/seaweedfs/gcs.json"}
|
|
maskRemoteConfSecrets(path)
|
|
if path.GcsGoogleApplicationCredentials != "/etc/seaweedfs/gcs.json" {
|
|
t.Errorf("a gcs credentials path must stay listed, got %q", path.GcsGoogleApplicationCredentials)
|
|
}
|
|
}
|