Skip to content

Commit b22195e

Browse files
committed
Address review comments by
1. pkg/secrets-store/nodeserver.go - Organize the imports as stdlib, internal, external 2. pkg/secrets-store/nodeserver_test.go - Create a deep empty VolumeCapability field in the NodePublishRequest template 3. pkg/util/fileutil/atomic_writer.go - Add comment in the header to explain the change of data type from int64 to int for FSGroup. - Reason for changing FSUser to FSGroup was already mentioned in the header 4. pkg/util/fileutil/filesystem.go and filesystem_test.go - disallow negative FSGroup. - ( Earlier, the intention was to keep complete type compatibility, and let the implementation (os.Chown) handle the full range that it supports. but as fsGroup is validated at API to be in range: 0 to 2147483647, disallowing the negative values) 5. test/bats/e2e-provider.bats - Fix delete_pod() to check the driver logs for unmount errors instead of the created pod logs - Fix enable_secret_rotation() to error out on kubectl errors
1 parent 40f47db commit b22195e

6 files changed

Lines changed: 26 additions & 12 deletions

File tree

pkg/secrets-store/nodeserver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import (
2626
"path/filepath"
2727
"time"
2828

29+
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
30+
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
31+
2932
"github.com/container-storage-interface/spec/lib/go/csi"
3033
"google.golang.org/grpc/codes"
3134
"google.golang.org/grpc/status"
3235
"k8s.io/klog/v2"
3336
mount "k8s.io/mount-utils"
3437
"sigs.k8s.io/controller-runtime/pkg/client"
35-
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
36-
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
3738
)
3839

3940
type nodeServer struct {

pkg/secrets-store/nodeserver_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ func getInitObjects(customize func(*secretsstorev1.SecretProviderClass)) []clien
7777

7878
func getRequest(t *testing.T, customize func(*csi.NodePublishVolumeRequest)) *csi.NodePublishVolumeRequest {
7979
var request = &csi.NodePublishVolumeRequest{
80-
VolumeCapability: &csi.VolumeCapability{},
81-
VolumeId: "testvolid1",
80+
VolumeCapability: &csi.VolumeCapability{
81+
AccessType: &csi.VolumeCapability_Mount{
82+
Mount: &csi.VolumeCapability_MountVolume{},
83+
},
84+
},
85+
VolumeId: "testvolid1",
8286
VolumeContext: map[string]string{
8387
"secretProviderClass": "provider1",
8488
csiPodName: "pod1",

pkg/util/fileutil/atomic_writer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
// * link: https://github.com/kubernetes/kubernetes/blob/8a62859e515889f07e3e3be6a1080413f17cf2c3/pkg/volume/util/atomic_writer.go
2121
// In addition, FileProjection::FSUser has been changed to FileProjection::FSGroup
2222
// to facilitate support for FSGroup csi.NodeServiceCapability_RPC_VOLUME_MOUNT_GROUP
23+
// and the type changed to int to match directly with the os.Chown() function arguments.
2324

2425
package fileutil
2526

pkg/util/fileutil/filesystem.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package fileutil
1919

2020
import (
21+
"fmt"
2122
"os"
2223
"path/filepath"
2324
"regexp"
@@ -140,5 +141,12 @@ func ParseFSGroup(fsGroupStr string) (int, error) {
140141
if len(fsGroupStr) == 0 {
141142
return NoGID, nil
142143
}
143-
return strconv.Atoi(fsGroupStr)
144+
gid, err := strconv.Atoi(fsGroupStr)
145+
if err != nil {
146+
return NoGID, err
147+
}
148+
if gid < 0 {
149+
return NoGID, fmt.Errorf("invalid FSGroup: %d must be non-negative", gid)
150+
}
151+
return gid, nil
144152
}

pkg/util/fileutil/filesystem_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ func TestParseFSGroup(t *testing.T) {
381381
expectedErr: true,
382382
},
383383
{
384-
name: "negative gid",
385-
fsGroupStr: "-23",
386-
want: -23,
384+
name: "negative gid",
385+
fsGroupStr: "-23",
386+
expectedErr: true,
387387
},
388388
}
389389

test/bats/e2e-provider.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ 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 | grep '^E.*failed to clean and unmount target path.*$'"
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.*$'"
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 > /dev/null
109-
kubectl wait -n rotation --for=condition=Ready --timeout=60s pod ${curl_pod_name} > /dev/null
108+
kubectl run ${curl_pod_name} -n rotation --image=curlimages/curl:7.75.0 --labels="test=rotation" -- tail -f /dev/null > /dev/null || return 1
109+
kubectl wait -n rotation --for=condition=Ready --timeout=60s pod ${curl_pod_name} > /dev/null || return 1
110110
local pod_ip=$(kubectl get pod -n kube-system -l app=csi-secrets-store-e2e-provider -o jsonpath="{.items[0].status.podIP}")
111-
run kubectl exec ${curl_pod_name} -n rotation -- curl http://${pod_ip}:8080/rotation?rotated=true
111+
kubectl exec ${curl_pod_name} -n rotation -- curl http://${pod_ip}:8080/rotation?rotated=true > /dev/null || return 1
112112
# wait for rotated secret to be mounted
113113
sleep 120
114114
echo "${curl_pod_name}"

0 commit comments

Comments
 (0)