Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 409b9de

Browse files
authored
Merge pull request #117 from darkowlzz/ocp-scc
Add OCP SCC support
2 parents ec56a94 + 5475f9e commit 409b9de

17 files changed

+276
-13
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ before_install:
2323
fi
2424
fi
2525
- sudo apt -y update && sudo apt install -y jq
26+
- curl -Lo yq https://github.com/mikefarah/yq/releases/download/2.3.0/yq_linux_amd64 && chmod +x yq && sudo mv yq /usr/local/bin/
2627
- curl -Lo storageos https://github.com/storageos/go-cli/releases/download/1.0.0/storageos_linux_amd64 && chmod +x storageos && sudo mv storageos /usr/local/bin/
2728
# - docker run -d -p 2399:2399 quay.io/coreos/etcd:v3.3.10 /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2399 -listen-client-urls http://0.0.0.0:2399
2829

@@ -38,6 +39,13 @@ jobs:
3839
- "INSTALL_METHOD=olm"
3940
name: OLM on KinD (k8s-1.13)
4041
script: ./test/e2e.sh $TEST_CLUSTER $INSTALL_METHOD
42+
- go: "1.11"
43+
sudo: required
44+
env:
45+
- "TEST_CLUSTER=openshift"
46+
- "INSTALL_METHOD=olm"
47+
name: OLM on OpenShift (k8s-1.11)
48+
script: ./test/e2e.sh $TEST_CLUSTER $INSTALL_METHOD
4149
- &base-test
4250
go: "1.11"
4351
sudo: required

deploy/olm/csv-rhel/storageos.clusterserviceversion.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ spec:
287287
verbs:
288288
- create
289289
- delete
290+
- apiGroups:
291+
- security.openshift.io
292+
resources:
293+
- securitycontextconstraints
294+
verbs:
295+
- create
296+
- delete
297+
- update
298+
- get
299+
- use
300+
resourceNames:
301+
- privileged
290302
deployments:
291303
- name: storageos-operator
292304
spec:

deploy/olm/storageos/storageos.clusterserviceversion.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ spec:
287287
verbs:
288288
- create
289289
- delete
290+
- apiGroups:
291+
- security.openshift.io
292+
resources:
293+
- securitycontextconstraints
294+
verbs:
295+
- create
296+
- delete
297+
- update
298+
- get
299+
- use
300+
resourceNames:
301+
- privileged
290302
deployments:
291303
- name: storageos-operator
292304
spec:

deploy/role.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,16 @@ rules:
9393
verbs:
9494
- create
9595
- delete
96+
# OpenShift specific rule.
97+
- apiGroups:
98+
- security.openshift.io
99+
resources:
100+
- securitycontextconstraints
101+
verbs:
102+
- create
103+
- delete
104+
- update
105+
- get
106+
- use
107+
resourceNames:
108+
- privileged

deploy/storageos-operators.configmap.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,18 @@ data:
495495
verbs:
496496
- create
497497
- delete
498+
- apiGroups:
499+
- security.openshift.io
500+
resources:
501+
- securitycontextconstraints
502+
verbs:
503+
- create
504+
- delete
505+
- update
506+
- get
507+
- use
508+
resourceNames:
509+
- privileged
498510
deployments:
499511
- name: storageos-operator
500512
spec:

pkg/storageos/delete.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package storageos
22

3+
import "strings"
4+
35
// Delete deletes all the storageos resources.
46
// This explicit delete is implemented instead of depending on the garbage
57
// collector because sometimes the garbage collector deletes the resources
@@ -78,6 +80,17 @@ func (s *Deployment) Delete() error {
7880
}
7981
}
8082

83+
// Delete cluster role for openshift security context constraints.
84+
if strings.Contains(s.stos.Spec.K8sDistro, k8sDistroOpenShift) {
85+
if err := s.deleteClusterRoleBinding(OpenShiftSCCClusterBindingName); err != nil {
86+
return err
87+
}
88+
89+
if err := s.deleteClusterRole(OpenShiftSCCClusterRoleName); err != nil {
90+
return err
91+
}
92+
}
93+
8194
// Delete role for Pod Fencing.
8295
if !s.stos.Spec.DisableFencing {
8396
if err := s.deleteClusterRoleBinding(FencingClusterBindingName); err != nil {

pkg/storageos/deploy.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"strings"
78

89
"github.com/blang/semver"
910
storageosv1 "github.com/storageos/cluster-operator/pkg/apis/storageos/v1"
@@ -65,6 +66,9 @@ const (
6566

6667
defaultUsername = "storageos"
6768
defaultPassword = "storageos"
69+
70+
// k8s distribution vendor specific keywords.
71+
k8sDistroOpenShift = "openshift"
6872
)
6973

7074
// Deploy deploys storageos by creating all the resources needed to run storageos.
@@ -156,6 +160,17 @@ func (s *Deployment) Deploy() error {
156160
}
157161
}
158162

163+
// Add openshift security context constraints.
164+
if strings.Contains(s.stos.Spec.K8sDistro, k8sDistroOpenShift) {
165+
if err := s.createClusterRoleForSCC(); err != nil {
166+
return err
167+
}
168+
169+
if err := s.createClusterRoleBindingForSCC(); err != nil {
170+
return err
171+
}
172+
}
173+
159174
// Create role for Pod Fencing.
160175
if !s.stos.Spec.DisableFencing {
161176
if err := s.createClusterRoleForFencing(); err != nil {

pkg/storageos/rbac.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const (
2121
CSIDriverRegistrarClusterBindingName = "storageos:driver-registrar"
2222
CSIK8SDriverRegistrarClusterBindingName = "storageos:k8s-driver-registrar"
2323

24+
// OpenShift Security Context Constraints role and role binding names.
25+
OpenShiftSCCClusterRoleName = "storageos:openshift-scc"
26+
OpenShiftSCCClusterBindingName = "storageos:openshift-scc"
27+
2428
KeyManagementRoleName = "storageos:key-management"
2529
KeyManagementBindingName = "storageos:key-management"
2630

@@ -393,3 +397,46 @@ func (s *Deployment) createClusterRoleBindingForAttacher() error {
393397
}
394398
return s.createClusterRoleBinding(CSIAttacherClusterBindingName, subjects, roleRef)
395399
}
400+
401+
// createClusterRoleForSCC creates cluster role with api group and resource
402+
// specific to openshift. This permission is required for by daemonsets and
403+
// statefulsets.
404+
func (s *Deployment) createClusterRoleForSCC() error {
405+
rules := []rbacv1.PolicyRule{
406+
{
407+
APIGroups: []string{"security.openshift.io"},
408+
Resources: []string{"securitycontextconstraints"},
409+
Verbs: []string{"use"},
410+
ResourceNames: []string{"privileged"},
411+
},
412+
}
413+
return s.createClusterRole(OpenShiftSCCClusterRoleName, rules)
414+
}
415+
416+
// createClusterRoleBindingForSCC creates a cluster role binding of the
417+
// openshift SCC role with daemonset and statefulset service account.
418+
func (s *Deployment) createClusterRoleBindingForSCC() error {
419+
subjects := []rbacv1.Subject{
420+
{
421+
Kind: rbacv1.ServiceAccountKind,
422+
Name: DaemonsetSA,
423+
Namespace: s.stos.Spec.GetResourceNS(),
424+
},
425+
}
426+
427+
// Add Statefulset service account if CSI is enabled.
428+
if s.stos.Spec.CSI.Enable {
429+
subjects = append(subjects, rbacv1.Subject{
430+
Kind: rbacv1.ServiceAccountKind,
431+
Name: StatefulsetSA,
432+
Namespace: s.stos.Spec.GetResourceNS(),
433+
})
434+
}
435+
436+
roleRef := rbacv1.RoleRef{
437+
Kind: "ClusterRole",
438+
Name: OpenShiftSCCClusterRoleName,
439+
APIGroup: "rbac.authorization.k8s.io",
440+
}
441+
return s.createClusterRoleBinding(OpenShiftSCCClusterBindingName, subjects, roleRef)
442+
}

scripts/openshift/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vagrant

scripts/openshift/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Setup OpenShift Test Environment
2+
3+
`Vagrantfile` contains configuration for creating an ubuntu trusty VM with
4+
enough memory and diskspace to setup openshift and run the operator tests.
5+
6+
Create the VM:
7+
```console
8+
$ vagrant up
9+
```
10+
11+
Once the VM is ready, ssh into the VM and run the setup scripts in it to setup
12+
everything. Read the comments in the scripts for reasons why things are done
13+
in certain ways. Most of the parts of the scripts is a combination of the travis
14+
CI configuration file and e2e.sh file, but only the parts that apply to
15+
openshift setup.
16+
17+
```console
18+
$ vagrant ssh
19+
$ bash /vagrant/openshift-seutp-1.sh
20+
21+
# Re-login
22+
$ exit
23+
$ vagrant ssh
24+
25+
# Continue setup
26+
$ bash /vagrant/openshift-seutp-2.sh
27+
```

0 commit comments

Comments
 (0)