Skip to content

Commit 54d78c3

Browse files
committed
WIP: e2e test fixes
1 parent 61ebc95 commit 54d78c3

File tree

11 files changed

+51
-146
lines changed

11 files changed

+51
-146
lines changed

Makefile

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ e2e-deploy-manifest:
401401
kubectl apply -f manifest_staging/deploy/rbac-secretproviderclass.yaml
402402
kubectl apply -f manifest_staging/deploy/rbac-secretproviderrotation.yaml
403403
kubectl apply -f manifest_staging/deploy/rbac-secretprovidersyncing.yaml
404-
kubectl apply -f manifest_staging/deploy/rbac-secretprovidertokenrequest.yaml
405404
kubectl apply -f manifest_staging/deploy/secrets-store.csi.x-k8s.io_secretproviderclasses.yaml
406405
kubectl apply -f manifest_staging/deploy/secrets-store.csi.x-k8s.io_secretproviderclasspodstatuses.yaml
407406
kubectl apply -f manifest_staging/deploy/role-secretproviderclasses-admin.yaml
@@ -429,6 +428,7 @@ e2e-helm-deploy:
429428
--set syncSecret.enabled=true \
430429
--set enableSecretRotation=true \
431430
--set rotationPollInterval=30s \
431+
--set requiresRepublish=true \
432432
--set tokenRequests[0].audience="aud1" \
433433
--set tokenRequests[1].audience="aud2" \
434434
--set tokenRequests[2].audience="conjur" \
@@ -533,16 +533,6 @@ manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e.g. CRD, RBAC
533533
@sed -i '1s/^/{{ if .Values.enableSecretRotation }}\n/gm; s/namespace: .*/namespace: {{ .Release.Namespace }}/gm; $$s/$$/\n{{ end }}/gm' manifest_staging/charts/secrets-store-csi-driver/templates/role-rotation_binding.yaml
534534
@sed -i '/^roleRef:/i \ \ labels:\n{{ include \"sscd.labels\" . | indent 4 }}' manifest_staging/charts/secrets-store-csi-driver/templates/role-rotation_binding.yaml
535535

536-
# Generate token requests specific RBAC
537-
$(CONTROLLER_GEN) rbac:roleName=secretprovidertokenrequest-role paths="./controllers/tokenrequest" output:dir=config/rbac-tokenrequest
538-
$(KUSTOMIZE) build config/rbac-tokenrequest -o manifest_staging/deploy/rbac-secretprovidertokenrequest.yaml
539-
cp config/rbac-tokenrequest/role.yaml manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest.yaml
540-
cp config/rbac-tokenrequest/role_binding.yaml manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest_binding.yaml
541-
@sed -i '1s/^/{{ if .Values.tokenRequests }}\n/gm; $$s/$$/\n{{ end }}/gm' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest.yaml
542-
@sed -i '/^rules:/i \ \ labels:\n{{ include \"sscd.labels\" . | indent 4 }}' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest.yaml
543-
@sed -i '1s/^/{{ if .Values.tokenRequests }}\n/gm; s/namespace: .*/namespace: {{ .Release.Namespace }}/gm; $$s/$$/\n{{ end }}/gm' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest_binding.yaml
544-
@sed -i '/^roleRef:/i \ \ labels:\n{{ include \"sscd.labels\" . | indent 4 }}' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest_binding.yaml
545-
546536
.PHONY: generate-protobuf
547537
generate-protobuf: $(PROTOC) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) # generates protobuf
548538
@PATH=$(PATH):$(TOOLS_BIN_DIR) $(PROTOC) -I . provider/v1alpha1/service.proto --go-grpc_out=require_unimplemented_servers=false:. --go_out=.

config/rbac-tokenrequest/kustomization.yaml

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

config/rbac-tokenrequest/role.yaml

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

config/rbac-tokenrequest/role_binding.yaml

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

deploy/rbac-secretprovidertokenrequest.yaml

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

docs/book/src/getting-started/installation.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ kubectl apply -f deploy/rbac-secretprovidersyncing.yaml
5050
# required to enable this feature
5151
kubectl apply -f deploy/rbac-secretproviderrotation.yaml
5252

53-
# If using the CSI Driver token requests feature (https://kubernetes-csi.github.io/docs/token-requests.html) to use
54-
# pod/workload identity to request a token and use with providers
55-
kubectl apply -f deploy/rbac-secretprovidertokenrequest.yaml
56-
5753
# [OPTIONAL] To deploy driver on windows nodes
5854
kubectl apply -f deploy/secrets-store-csi-driver-windows.yaml
5955
```

test/bats/e2e-provider.bats

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ export VALIDATE_TOKENS_AUDIENCE=$(get_token_requests_audience)
4040

4141
@test "setup mock provider validation config" {
4242
if [[ -n "${VALIDATE_TOKENS_AUDIENCE}" ]]; then
43-
# configure the mock provider to validate the token requests
4443
kubectl create ns enable-token-requests
45-
local curl_pod_name=curl-$(openssl rand -hex 5)
46-
kubectl run ${curl_pod_name} -n enable-token-requests --image=curlimages/curl:7.75.0 --labels="util=enable-token-requests" -- tail -f /dev/null
47-
kubectl wait -n enable-token-requests --for=condition=Ready --timeout=60s pod ${curl_pod_name}
48-
local pod_ip=$(kubectl get pod -n kube-system -l app=csi-secrets-store-e2e-provider -o jsonpath="{.items[0].status.podIP}")
49-
run kubectl exec ${curl_pod_name} -n enable-token-requests -- curl http://${pod_ip}:8080/validate-token-requests?audience=${VALIDATE_TOKENS_AUDIENCE}
50-
kubectl delete pod -l util=enable-token-requests -n enable-token-requests --force --grace-period 0
44+
kubectl apply -f $BATS_TESTS_DIR/demo-deployment-e2e-provider.yaml
45+
local pod_name=$(kubectl get pod -n enable-token-requests -l app.kubernetes.io/name=demo-pod -o jsonpath="{.items[0].metadata.name}")
46+
kubectl wait -n enable-token-requests --for=condition=Ready --timeout=60s pod ${pod_name}
47+
run kubectl exec ${pod_name} -n enable-token-requests -- cat /mnt/e2e/tokens.json
48+
kubectl delete -f $BATS_TESTS_DIR/demo-deployment-e2e-provider.yaml --timeout=5s
49+
kubectl delete pod -l app.kubernetes.io/name=demo-pod -n enable-token-requests --force --grace-period 0
5150
kubectl delete ns enable-token-requests
5251
fi
5352

@@ -98,14 +97,6 @@ export VALIDATE_TOKENS_AUDIENCE=$(get_token_requests_audience)
9897
run kubectl get clusterrolebinding/secretprovidersyncing-rolebinding
9998
assert_success
10099

101-
# validate token request role and rolebinding only when token requests are set
102-
if [[ -n "${VALIDATE_TOKENS_AUDIENCE}" ]]; then
103-
run kubectl get clusterrole/secretprovidertokenrequest-role
104-
assert_success
105-
106-
run kubectl get clusterrolebinding/secretprovidertokenrequest-rolebinding
107-
assert_success
108-
fi
109100
}
110101

111102
@test "[v1alpha1] deploy e2e-provider secretproviderclass crd" {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: secrets-store.csi.x-k8s.io/v1
2+
kind: SecretProviderClass
3+
metadata:
4+
name: empty-e2e-provider
5+
namespace: enable-token-requests
6+
spec:
7+
provider: e2e-provider
8+
parameters:
9+
objects: |
10+
array:[]
11+
---
12+
apiVersion: apps/v1
13+
kind: Deployment
14+
metadata:
15+
name: demo-pod
16+
namespace: enable-token-requests
17+
spec:
18+
replicas: 1
19+
selector:
20+
matchLabels:
21+
app.kubernetes.io/name: demo-pod
22+
template:
23+
metadata:
24+
labels:
25+
app.kubernetes.io/name: demo-pod
26+
spec:
27+
containers:
28+
- image: registry.k8s.io/e2e-test-images/busybox:1.29-4
29+
command:
30+
- /bin/sleep
31+
- "10000"
32+
imagePullPolicy: Always
33+
name: demo
34+
volumeMounts:
35+
- name: secrets-store-inline
36+
mountPath: /mnt/e2e
37+
readOnly: true
38+
volumes:
39+
- name: secrets-store-inline
40+
csi:
41+
driver: secrets-store.csi.k8s.io
42+
readOnly: true
43+
volumeAttributes:
44+
secretProviderClass: "empty-e2e-provider"

test/e2eprovider/e2e_provider.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func mainErr() error {
7777
os.Setenv("ROTATION_ENABLED", "false")
7878

7979
http.HandleFunc("/rotation", server.RotationHandler)
80-
http.HandleFunc("/validate-token-requests", server.ValidateTokenAudienceHandler)
8180

8281
server := &http.Server{
8382
Addr: ":8080",

test/e2eprovider/server/server.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,6 @@ func (s *Server) Mount(ctx context.Context, req *v1alpha1.MountRequest) (*v1alph
181181
})
182182
}
183183

184-
// if validate token flag is set, we want to check the service account tokens as passed
185-
// as part of the mount attributes.
186-
// In case of 1.21+, kubelet will generate the token and pass it as part of the volume context.
187-
// The driver will pass this to the provider as part of the mount request.
188-
// For 1.20, the driver will generate the token and pass it to the provider as part of the mount request.
189-
// Irrespective of the kubernetes version, the rotation handler in the driver will generate the token
190-
// and pass it to the provider as part of the mount request.
191-
// VALIDATE_TOKENS_AUDIENCE environment variable will be a comma separated list of audiences configured in the csidriver object
192-
// If this env var is not set, this could mean we are running an older version of driver.
193-
tokenAudiences := os.Getenv("VALIDATE_TOKENS_AUDIENCE")
194-
klog.InfoS("tokenAudiences", "tokenAudiences", tokenAudiences)
195-
if tokenAudiences != "" {
196-
if err := validateTokens(tokenAudiences, attrib[serviceAccountTokensAttribute]); err != nil {
197-
return nil, fmt.Errorf("failed to validate token, error: %w", err)
198-
}
199-
}
200-
201184
m.Lock()
202185
podCache[attrib[podUIDAttribute]] = true
203186
m.Unlock()
@@ -249,32 +232,3 @@ func RotationHandler(w http.ResponseWriter, r *http.Request) {
249232
os.Setenv("ROTATION_ENABLED", r.FormValue("rotated"))
250233
klog.InfoS("Rotation response enabled")
251234
}
252-
253-
// ValidateTokenAudienceHandler enables token validation for the mock provider
254-
// This is only required because older version of the driver don't generate a token
255-
// TODO(aramase): remove this after the supported driver releases are v1.1.0+
256-
func ValidateTokenAudienceHandler(w http.ResponseWriter, r *http.Request) {
257-
// enable rotation response
258-
os.Setenv("VALIDATE_TOKENS_AUDIENCE", r.FormValue("audience"))
259-
klog.InfoS("Validation for token requests audience", "audience", os.Getenv("VALIDATE_TOKENS_AUDIENCE"))
260-
}
261-
262-
// validateTokens checks there are tokens for distinct audiences in the
263-
// service account token attribute.
264-
func validateTokens(tokenAudiences, saTokens string) error {
265-
ta := strings.Split(strings.TrimSpace(tokenAudiences), ",")
266-
if saTokens == "" {
267-
return fmt.Errorf("service account tokens is not set")
268-
}
269-
tokens := make(map[string]interface{})
270-
if err := json.Unmarshal([]byte(saTokens), &tokens); err != nil {
271-
return fmt.Errorf("failed to unmarshal service account tokens, error: %w", err)
272-
}
273-
for _, a := range ta {
274-
if _, ok := tokens[a]; !ok {
275-
return fmt.Errorf("service account token for audience %s is not set", a)
276-
}
277-
klog.InfoS("Validated service account token", "audience", a)
278-
}
279-
return nil
280-
}

0 commit comments

Comments
 (0)