Skip to content

Commit 33a0224

Browse files
perdasilvaPer G. da Silva
andauthored
Use dedicated least-privilege service accounts for revision probe e2e tests (#2547)
The revision probe e2e tests previously shared the generic `olm-sa` service account, which had broad permissions that masked potential RBAC issues. This change: - Refactors RBAC template selection to use a convention-based naming pattern: `<service-account>-<helm|boxcutter>-rbac-template.yaml`, replacing the hardcoded constants with `fmt.Sprintf` - Renames existing RBAC templates with `olm-sa-` prefix to follow the new convention (`rbac-template.yaml` → `olm-sa-helm-rbac-template.yaml`, `boxcutter-rbac-template.yaml` → `olm-sa-boxcutter-rbac-template.yaml`) - Introduces a dedicated `pvc-probe-sa` service account for PVC probe scenarios with a least-privilege RBAC template granting only CER finalizer update, PersistentVolume CRUD, PVC CRUD, and ConfigMap CRUD Signed-off-by: Per G. da Silva <pegoncal@redhat.com> Co-authored-by: Per G. da Silva <pegoncal@redhat.com>
1 parent bca7a49 commit 33a0224

5 files changed

Lines changed: 60 additions & 11 deletions

File tree

test/e2e/features/revision.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ Feature: Install ClusterExtensionRevision
55

66
Background:
77
Given OLM is available
8-
And ServiceAccount "olm-sa" with needed permissions is available in ${TEST_NAMESPACE}
98

10-
Scenario: Probe failure for PersistentVolumeClaim halts phase progression
9+
Scenario: Probe failure for PersistentVolumeClaim halts phase progression
10+
Given ServiceAccount "pvc-probe-sa" with needed permissions is available in test namespace
1111
When ClusterExtensionRevision is applied
1212
"""
1313
apiVersion: olm.operatorframework.io/v1
1414
kind: ClusterExtensionRevision
1515
metadata:
1616
annotations:
17-
olm.operatorframework.io/service-account-name: olm-sa
17+
olm.operatorframework.io/service-account-name: pvc-probe-sa
1818
olm.operatorframework.io/service-account-namespace: ${TEST_NAMESPACE}
1919
name: ${CER_NAME}
2020
spec:
@@ -59,13 +59,14 @@ Feature: Install ClusterExtensionRevision
5959
And resource "configmap/test-configmap" is not installed
6060

6161
Scenario: Phases progress when PersistentVolumeClaim becomes "Bound"
62+
Given ServiceAccount "pvc-probe-sa" with needed permissions is available in test namespace
6263
When ClusterExtensionRevision is applied
6364
"""
6465
apiVersion: olm.operatorframework.io/v1
6566
kind: ClusterExtensionRevision
6667
metadata:
6768
annotations:
68-
olm.operatorframework.io/service-account-name: olm-sa
69+
olm.operatorframework.io/service-account-name: pvc-probe-sa
6970
olm.operatorframework.io/service-account-namespace: ${TEST_NAMESPACE}
7071
name: ${CER_NAME}
7172
spec:

test/e2e/steps/steps.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ const (
4444
olmDeploymentName = "operator-controller-controller-manager"
4545
timeout = 5 * time.Minute
4646
tick = 1 * time.Second
47-
48-
helmRBACTemplate = "rbac-template.yaml"
49-
boxcutterRBACTemplate = "boxcutter-rbac-template.yaml"
5047
)
5148

5249
var (
@@ -833,13 +830,13 @@ func ServiceAccountIsAvailableInNamespace(ctx context.Context, serviceAccount st
833830
}
834831

835832
// ServiceAccountWithNeededPermissionsIsAvailableInNamespace creates a ServiceAccount and applies standard RBAC permissions.
836-
// The RBAC template is selected based on the BoxcutterRuntime feature gate: the boxcutter applier does not require
837-
// cluster-scoped list/watch permissions, so a narrower template is used when BoxcutterRuntime is enabled.
833+
// The RBAC template is selected based on the service account and BoxcutterRuntime feature gate: <service-account>-<helm|boxcutter>-rbac-template.yaml
838834
func ServiceAccountWithNeededPermissionsIsAvailableInNamespace(ctx context.Context, serviceAccount string) error {
839-
rbacTemplate := helmRBACTemplate
835+
kernel := "helm"
840836
if enabled, found := featureGates[features.BoxcutterRuntime]; found && enabled {
841-
rbacTemplate = boxcutterRBACTemplate
837+
kernel = "boxcutter"
842838
}
839+
rbacTemplate := fmt.Sprintf("%s-%s-rbac-template.yaml", serviceAccount, kernel)
843840
return applyPermissionsToServiceAccount(ctx, serviceAccount, rbacTemplate)
844841
}
845842

test/e2e/steps/testdata/boxcutter-rbac-template.yaml renamed to test/e2e/steps/testdata/olm-sa-boxcutter-rbac-template.yaml

File renamed without changes.
File renamed without changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: ${TEST_NAMESPACE}-${SERVICEACCOUNT_NAME}-clusterrole
5+
rules:
6+
- apiGroups: [olm.operatorframework.io]
7+
resources: [clusterextensionrevisions/finalizers]
8+
verbs: [update]
9+
- apiGroups: [""]
10+
resources: [persistentvolumes]
11+
verbs: [create, update, get, delete, patch]
12+
---
13+
apiVersion: rbac.authorization.k8s.io/v1
14+
kind: Role
15+
metadata:
16+
name: ${TEST_NAMESPACE}-${SERVICEACCOUNT_NAME}-role
17+
namespace: ${TEST_NAMESPACE}
18+
rules:
19+
- apiGroups: [""]
20+
resources: [persistentvolumeclaims]
21+
verbs: [create, update, get, delete, patch]
22+
- apiGroups: [""]
23+
resources: [configmaps]
24+
verbs: [create, update, get, delete, patch]
25+
---
26+
apiVersion: rbac.authorization.k8s.io/v1
27+
kind: ClusterRoleBinding
28+
metadata:
29+
name: ${TEST_NAMESPACE}-${SERVICEACCOUNT_NAME}-binding
30+
roleRef:
31+
apiGroup: rbac.authorization.k8s.io
32+
kind: ClusterRole
33+
name: ${TEST_NAMESPACE}-${SERVICEACCOUNT_NAME}-clusterrole
34+
subjects:
35+
- kind: ServiceAccount
36+
name: ${SERVICEACCOUNT_NAME}
37+
namespace: ${TEST_NAMESPACE}
38+
---
39+
apiVersion: rbac.authorization.k8s.io/v1
40+
kind: RoleBinding
41+
metadata:
42+
name: ${TEST_NAMESPACE}-${SERVICEACCOUNT_NAME}-binding
43+
namespace: ${TEST_NAMESPACE}
44+
roleRef:
45+
apiGroup: rbac.authorization.k8s.io
46+
kind: Role
47+
name: ${TEST_NAMESPACE}-${SERVICEACCOUNT_NAME}-role
48+
subjects:
49+
- kind: ServiceAccount
50+
name: ${SERVICEACCOUNT_NAME}
51+
namespace: ${TEST_NAMESPACE}

0 commit comments

Comments
 (0)