Skip to content

Commit c4113c7

Browse files
committed
Fix further code review comments
1. pkg/secrets-store/nodeserver.go - update the log to just log VolumeMountGroup instead of VolumeCapabilities - Here, not using the parsed value but the value obtained in the NodePublishVolume arguments as it could help in better debugging when somehow the parse function is not working as expected 2. pkg/util/fileutil/atomic_writer.go - update the comment in FileProjection structure explaining divergence from upstream - update the error message on chown failure to reflect that group ownership change is what failed 3. test/bats/e2e-provider.bats - correct the namespace while getting logs from the driver - simplify the filePermission configuration (e2e_provider_secretproviderclass.yaml) 4. test/e2eprovider/server/server.go - make error logging more explicit above case where filePermission is > 0777 - changed the comparison from 511 to 0o777 for readability
1 parent b22195e commit c4113c7

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

pkg/secrets-store/nodeserver.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
161161
return &csi.NodePublishVolumeResponse{}, nil
162162
}
163163

164-
klog.V(2).InfoS("node publish volume", "target", targetPath, "volumeId", volumeID, "mount flags", mountFlags, "volumeCapabilities", req.VolumeCapability.String())
165-
166164
// Group ID to Chown the volume contents to
167-
mountVol := req.VolumeCapability.GetMount()
165+
mountVol := req.GetVolumeCapability().GetMount()
166+
klog.V(2).InfoS("node publish volume", "target", targetPath, "volumeId", volumeID, "mount flags", mountFlags, "volumeMountGroup", mountVol.GetVolumeMountGroup())
168167
gid, err := fileutil.ParseFSGroup(mountVol.GetVolumeMountGroup())
169168
if err != nil {
170169
klog.ErrorS(err, "failed to mount secrets store object content due to invalid FSGroup", "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName}, "fsGroup", mountVol.GetVolumeMountGroup())

pkg/util/fileutil/atomic_writer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ type AtomicWriter struct {
6868
logContext string
6969
}
7070

71-
// FileProjection contains file Data and access Mode
71+
// FileProjection contains file Data and access Mode.
72+
// FsGroup diverges from upstream's FsUser (*int64) — see file header for rationale.
7273
type FileProjection struct {
7374
Data []byte
7475
Mode int32
@@ -417,7 +418,7 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
417418
continue
418419
}
419420
if err := os.Chown(fullPath, -1, *fileProjection.FsGroup); err != nil {
420-
klog.ErrorS(err, "unable to change file with owner", "logContext", w.logContext, "fullPath", fullPath, "owner", *fileProjection.FsGroup)
421+
klog.ErrorS(err, "unable to change file group ownership", "logContext", w.logContext, "fullPath", fullPath, "group", *fileProjection.FsGroup)
421422
return err
422423
}
423424
}

test/bats/e2e-provider.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export SECRET_VERSION=${SECRET_VERSION:-"v1"}
1818
# default secret value returned by the mock provider
1919
export SECRET_VALUE=${SECRET_VALUE:-"secret"}
2020
# default secret mode returned by the mock provider
21-
export SECRET_MODE=${SECRET_MODE:-'"0644"'}
21+
export SECRET_MODE=${SECRET_MODE:-0644}
2222

2323
# export key vars
2424
export KEY_NAME=${KEY_NAME:-fookey}
@@ -28,7 +28,7 @@ export KEY_VERSION=${KEY_VERSION:-"v1"}
2828
# base64 encoded content comparision is easier in case of very long multiline string.
2929
export KEY_VALUE_CONTAINS=${KEY_VALUE:-"LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KVGhpcyBpcyBtb2NrIGtleQotLS0tLUVORCBQVUJMSUMgS0VZLS0tLS0K"}
3030
# default version value returned by mock provider
31-
export KEY_MODE=${KEY_MODE:-'"0644"'}
31+
export KEY_MODE=${KEY_MODE:-0644}
3232

3333
# export node selector var
3434
export NODE_SELECTOR_OS=$NODE_SELECTOR_OS
@@ -98,7 +98,7 @@ function delete_pod() {
9898
# On Windows, the failed unmount calls from: https://github.com/kubernetes-sigs/secrets-store-csi-driver/pull/545
9999
# do not prevent the pod from being deleted. Search through the driver logs
100100
# for the error.
101-
run bash -c "kubectl -n $NAMESPACE logs -l app=secrets-store-csi-driver --tail -1 -c secrets-store | grep '^E.*failed to clean and unmount target path.*$'"
101+
run bash -c "kubectl -n kube-system logs -l app=secrets-store-csi-driver --tail -1 -c secrets-store | grep '^E.*failed to clean and unmount target path.*$'"
102102
assert_failure
103103
}
104104

@@ -223,7 +223,7 @@ function disable_secret_rotation() {
223223
}
224224

225225
@test "deploy e2e-provider v1 secretproviderclass crd with restricted permissions" {
226-
SPC_NAME="e2e-provider-640" SECRET_MODE='"0640"' KEY_MODE='"0640"' create_spc
226+
SPC_NAME="e2e-provider-640" SECRET_MODE=0640 KEY_MODE=0640 create_spc
227227
}
228228

229229
@test "Non-root POD with no FSGroup - create" {

test/bats/tests/e2e_provider/e2e_provider_secretproviderclass.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ spec:
1010
- |
1111
objectName: $SECRET_NAME
1212
objectVersion: $SECRET_VERSION
13-
filePermission: $SECRET_MODE
13+
filePermission: "$SECRET_MODE"
1414
- |
1515
objectName: $KEY_NAME
1616
objectVersion: $KEY_VERSION
17-
filePermission: $KEY_MODE
17+
filePermission: "$KEY_MODE"

test/e2eprovider/server/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ func (s *Server) Mount(ctx context.Context, req *v1alpha1.MountRequest) (*v1alph
180180
klog.InfoS("Secret Object with", "name", mockSecretsStoreObject.ObjectName, "permission", mockSecretsStoreObject.FilePermission)
181181
if len(mockSecretsStoreObject.FilePermission) > 0 {
182182
mode, err := strconv.ParseUint(mockSecretsStoreObject.FilePermission, 8, 32)
183-
if err != nil || mode > 511 {
183+
if err != nil {
184184
return nil, fmt.Errorf("invalid filePermission: %s, error: %w for file: %s", mockSecretsStoreObject.FilePermission, err, mockSecretsStoreObject.ObjectName)
185185
}
186+
if mode > 0o777 {
187+
return nil, fmt.Errorf("invalid filePermission: %s exceeds 0777 for file: %s", mockSecretsStoreObject.FilePermission, mockSecretsStoreObject.ObjectName)
188+
}
186189
secretFile.Mode = int32(mode)
187190
klog.InfoS("Set file mode", "file", secretFile.Path, "mode", os.FileMode(mode))
188191
}

0 commit comments

Comments
 (0)