Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: strip log secret #1281

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ func (d *controllerService) ListVolumes(ctx context.Context, req *csi.ListVolume
// ValidateVolumeCapabilities validates volume capabilities
func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
log := klog.NewKlogr().WithName("ValidateVolumeCapabilities")
log.V(1).Info("called with args", "args", req)
secrets := req.Secrets
req.Secrets = nil
log.V(1).Info("called with args", "args", req, "secrets", util.StripSecret(secrets))
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
Expand Down Expand Up @@ -269,7 +271,9 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap
// ControllerExpandVolume adjusts quota according to capacity settings
func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
log := klog.NewKlogr().WithName("ControllerExpandVolume")
log.V(1).Info("request", "request", req)
secrets := req.Secrets
req.Secrets = nil
log.V(1).Info("called with args", "args", req, "secrets", util.StripSecret(secrets))

volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
Expand Down Expand Up @@ -309,7 +313,6 @@ func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi
if err != nil {
return nil, status.Errorf(codes.Internal, "get quotaPath error: %v", err)
}
secrets := req.GetSecrets()
settings, err := d.juicefs.Settings(ctx, volumeID, volumeID, secrets["name"], secrets, nil, options)
if err != nil {
return nil, status.Errorf(codes.Internal, "get settings: %v", err)
Expand Down
7 changes: 3 additions & 4 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
log = log.WithValues("volumeId", volumeID)

ctxWithLog := util.WithLog(ctx, log)

// WARNING: debug only, secrets included
log.V(1).Info("called with args", "args", req)
secrets := req.Secrets
req.Secrets = nil
log.V(1).Info("called with args", "args", req, "secrets", util.StripSecret(secrets))

target := req.GetTargetPath()
if len(target) == 0 {
Expand Down Expand Up @@ -154,7 +154,6 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis

log.Info("get volume context", "volCtx", volCtx)

secrets := req.Secrets
mountOptions := []string{}
// get mountOptions from PV.volumeAttributes or StorageClass.parameters
if opts, ok := volCtx["mountOptions"]; ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/juicefs/juicefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type jfs struct {
Name string
MountPath string
Options []string
Setting *config.JfsSetting
Setting *config.JfsSetting `json:"-"`
}

// Jfs is the interface of a mounted file system
Expand Down
39 changes: 39 additions & 0 deletions pkg/util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package util

import (
"context"
"encoding/json"

"k8s.io/klog/v2"
)
Expand All @@ -40,3 +41,41 @@ func GenLog(ctx context.Context, log klog.Logger, name string) klog.Logger {
}
return log
}

var stripKeys = []string{
"token",
"accesskey",
"access-key",
"accesskey2",
"access-key2",
"secretkey",
"secret-key",
"secretkey2",
"secret-key2",
"passphrase",
"password",
}

func StripSecret(secret map[string]string) map[string]string {
s := make(map[string]string)
for k, v := range secret {
s[k] = v
}
if len(s) == 0 {
return s
}
for _, key := range stripKeys {
if _, ok := s[key]; ok {
s[key] = "***"
}
}
if _, ok := s["initconfig"]; ok {
var initconfig map[string]string
_ = json.Unmarshal([]byte(s["initconfig"]), &initconfig)

stripped := StripSecret(initconfig)
b, _ := json.Marshal(stripped)
s["initconfig"] = string(b)
}
return s
}
Loading