Skip to content

Commit 8618850

Browse files
committed
Address the latest review comments by:
1. delete constants.go and move NoGID to fileutil 2. Re-include "volume mount with rotation but skipped" in nodeserver_test.go 3. Added comment about why 64 bit word was chosen for FsGroup in filesystem.go 4. Populate FSGroup attribute to non-nil only if the GID is a valid value in writer.go 5. Fixed enable_secret_rotation in e2e-provider.bats to correctly return the name of the pod.
1 parent da34a62 commit 8618850

8 files changed

Lines changed: 38 additions & 42 deletions

File tree

pkg/constants/constants.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

pkg/secrets-store/nodeserver_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func getRequest(t *testing.T, customize func(*csi.NodePublishVolumeRequest)) *cs
9191
customize(request)
9292
return request
9393
}
94+
9495
func TestNodePublishVolume_Errors(t *testing.T) {
9596
tests := []struct {
9697
name string
@@ -268,6 +269,15 @@ func TestNodePublishVolume(t *testing.T) {
268269
rotationCacheDuration: -1 * time.Minute, // Using negative interval to pass the rotation interval check in unit tests
269270
},
270271
},
272+
{
273+
name: "volume mount with rotation but skipped",
274+
nodePublishVolReq: getRequest(t, func(*csi.NodePublishVolumeRequest) {}),
275+
initObjects: getInitObjects(func(*secretsstorev1.SecretProviderClass) {}),
276+
rotationConfig: &rotationConfig{
277+
enabled: true,
278+
rotationCacheDuration: time.Minute,
279+
},
280+
},
271281
{
272282
name: "volume mount with valid FSGroup",
273283
nodePublishVolReq: getRequest(t, func(r *csi.NodePublishVolumeRequest) {

pkg/secrets-store/provider_client_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"testing"
2828
"time"
2929

30-
"sigs.k8s.io/secrets-store-csi-driver/pkg/constants"
3130
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
3231
"sigs.k8s.io/secrets-store-csi-driver/provider/fake"
3332
"sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"
@@ -196,7 +195,7 @@ func TestMountContent(t *testing.T) {
196195
t.Fatalf("expected err to be nil, got: %+v", err)
197196
}
198197

199-
objectVersions, _, err := MountContent(context.TODO(), client, "{}", "{}", targetPath, test.permission, nil, constants.NoGID)
198+
objectVersions, _, err := MountContent(context.TODO(), client, "{}", "{}", targetPath, test.permission, nil, fileutil.NoGID)
200199
if err != nil {
201200
t.Errorf("expected err to be nil, got: %+v", err)
202201
}
@@ -254,7 +253,7 @@ func TestMountContent_TooLarge(t *testing.T) {
254253
}
255254

256255
// rpc error: code = ResourceExhausted desc = grpc: received message larger than max (28 vs. 5)
257-
_, errorCode, err := MountContent(context.TODO(), client, "{}", "{}", targetPath, "777", nil, constants.NoGID)
256+
_, errorCode, err := MountContent(context.TODO(), client, "{}", "{}", targetPath, "777", nil, fileutil.NoGID)
258257
if err == nil {
259258
t.Errorf("expected err to be not nil")
260259
}
@@ -348,7 +347,7 @@ func TestMountContentError(t *testing.T) {
348347
t.Fatalf("expected err to be nil, got: %+v", err)
349348
}
350349

351-
objectVersions, errorCode, err := MountContent(context.TODO(), client, test.attributes, test.secrets, test.targetPath, test.permission, nil, constants.NoGID)
350+
objectVersions, errorCode, err := MountContent(context.TODO(), client, test.attributes, test.secrets, test.targetPath, test.permission, nil, fileutil.NoGID)
352351
if err == nil {
353352
t.Errorf("expected err to be not nil")
354353
}

pkg/util/fileutil/filesystem.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ import (
2323
"regexp"
2424
"strconv"
2525
"strings"
26+
)
2627

27-
"sigs.k8s.io/secrets-store-csi-driver/pkg/constants"
28+
const (
29+
// NoGID is the default gid -1 to indicate no change in FSGroup
30+
NoGID = int64(-1)
2831
)
2932

3033
var (
@@ -132,13 +135,15 @@ func GetVolumeNameFromTargetPath(targetPath string) string {
132135
}
133136

134137
// ParseFSGroup parses the FSGroup string and returns the GID as int64.
135-
// If fsGroupStr is empty, returns constants.NoGID.
138+
// If fsGroupStr is empty, returns NoGID.
136139
// Returns an error if the fsGroupStr cannot be parsed as a valid non-negative int64.
137140
func ParseFSGroup(fsGroupStr string) (int64, error) {
138141
if len(fsGroupStr) == 0 {
139-
return constants.NoGID, nil
142+
return NoGID, nil
140143
}
141144
// Non-sentinel negative GID is invalid and thus we use ParseUint here.
145+
// Though the Linux GID is 32-bit, we use 64 bit int to align with the nodePublishVolume convention for FsGroup
146+
// please see: https://github.com/kubernetes/kubernetes/blob/b910026535af2d8a64d45efefeb8d9efb75a4817/pkg/volume/csi/csi_client.go#L64
142147
gid, err := strconv.ParseUint(fsGroupStr, 10, 63)
143148
return int64(gid), err
144149
}

pkg/util/fileutil/filesystem_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/google/go-cmp/cmp"
2626
"github.com/google/go-cmp/cmp/cmpopts"
27-
"sigs.k8s.io/secrets-store-csi-driver/pkg/constants"
2827
)
2928

3029
func TestGetMountedFiles(t *testing.T) {
@@ -345,7 +344,7 @@ func TestParseFSGroup(t *testing.T) {
345344
{
346345
name: "empty string returns NoGID",
347346
fsGroupStr: "",
348-
want: constants.NoGID,
347+
want: NoGID,
349348
expectedErr: false,
350349
},
351350
{

pkg/util/fileutil/writer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ func WritePayloads(path string, payloads []*v1alpha1.File, gid int64) error {
5858
return err
5959
}
6060

61+
var fsGroup *int64
62+
if gid != NoGID {
63+
fsGroup = &gid
64+
}
65+
6166
// convert v1alpha1.File to FileProjection
6267
files := make(map[string]FileProjection, len(payloads))
6368
for _, payload := range payloads {
6469
files[payload.GetPath()] = FileProjection{
6570
Data: payload.GetContents(),
6671
Mode: payload.GetMode(),
67-
FsGroup: &gid,
72+
FsGroup: fsGroup,
6873
}
6974
}
7075

pkg/util/fileutil/writer_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"strings"
2828
"testing"
2929

30-
"sigs.k8s.io/secrets-store-csi-driver/pkg/constants"
3130
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/runtimeutil"
3231
"sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"
3332
)
@@ -373,7 +372,7 @@ func TestWritePayloads(t *testing.T) {
373372
dir := t.TempDir()
374373

375374
// check that the first write succeeds and the contents match
376-
if err := WritePayloads(dir, tc.first, constants.NoGID); err != nil {
375+
if err := WritePayloads(dir, tc.first, NoGID); err != nil {
377376
t.Errorf("WritePayload(first) got error: %v", err)
378377
}
379378

@@ -383,7 +382,7 @@ func TestWritePayloads(t *testing.T) {
383382

384383
// check that the second write succeeds and the contents match,
385384
// ensuring that the files have the updated values
386-
if err := WritePayloads(dir, tc.second, constants.NoGID); err != nil {
385+
if err := WritePayloads(dir, tc.second, NoGID); err != nil {
387386
t.Errorf("WritePayload(second) got error: %v", err)
388387
}
389388

@@ -422,7 +421,7 @@ func TestWritePayloads_BackwardCompatible(t *testing.T) {
422421

423422
want := []byte("new")
424423

425-
if err := WritePayloads(dir, payload, constants.NoGID); err != nil {
424+
if err := WritePayloads(dir, payload, NoGID); err != nil {
426425
t.Fatalf("could not write new file: %s", err)
427426
}
428427

test/bats/e2e-provider.bats

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fi
1313

1414
# export secret vars
1515
export SECRET_NAME=${SECRET_NAME:-foo}
16-
# defualt version value returned by mock provider
16+
# default version value returned by mock provider
1717
export SECRET_VERSION=${SECRET_VERSION:-"v1"}
1818
# default secret value returned by the mock provider
1919
export SECRET_VALUE=${SECRET_VALUE:-"secret"}
@@ -22,12 +22,12 @@ export SECRET_MODE=${SECRET_MODE:-'"0644"'}
2222

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

3333
# export node selector var
@@ -98,19 +98,20 @@ 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=$POD_NAME --tail -1 -c secrets-store -n kube-system | grep '^E.*failed to clean and unmount target path.*$'"
101+
run bash -c "kubectl -n $NAMESPACE logs -l app=$POD_NAME --tail -1 -c secrets-store | grep '^E.*failed to clean and unmount target path.*$'"
102102
assert_failure
103103
}
104104

105105
function enable_secret_rotation() {
106106
# enable rotation response in mock server
107107
local curl_pod_name=curl-$(openssl rand -hex 5)
108-
kubectl run ${curl_pod_name} -n rotation --image=curlimages/curl:7.75.0 --labels="test=rotation" -- tail -f /dev/null
109-
kubectl wait -n rotation --for=condition=Ready --timeout=60s pod ${curl_pod_name}
108+
kubectl run ${curl_pod_name} -n rotation --image=curlimages/curl:7.75.0 --labels="test=rotation" -- tail -f /dev/null > /dev/null
109+
kubectl wait -n rotation --for=condition=Ready --timeout=60s pod ${curl_pod_name} > /dev/null
110110
local pod_ip=$(kubectl get pod -n kube-system -l app=csi-secrets-store-e2e-provider -o jsonpath="{.items[0].status.podIP}")
111111
run kubectl exec ${curl_pod_name} -n rotation -- curl http://${pod_ip}:8080/rotation?rotated=true
112112
# wait for rotated secret to be mounted
113113
sleep 120
114+
echo "${curl_pod_name}"
114115
}
115116

116117
function disable_secret_rotation() {

0 commit comments

Comments
 (0)