-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: export default SecurityContextConstraints in OCP clusters
this commit exports SecurityContextConstraints to let the user deploy the ceph-csi-operator in OCP clusters Signed-off-by: Divyansh Kamboj <dkamboj@redhat.com>
- Loading branch information
Showing
78 changed files
with
32,004 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ocp | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"strings" | ||
|
||
secv1 "github.com/openshift/api/security/v1" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
//go:embed scc.yaml | ||
var sccYAMLTemplate string | ||
|
||
// NewSecurityContextConstraints loads the embedded SCC YAML template, replaces the namespace, | ||
// and returns it as a SecurityContextConstraints object | ||
func NewSecurityContextConstraints(name string, namespace string) (*secv1.SecurityContextConstraints, error) { | ||
scc := &secv1.SecurityContextConstraints{} | ||
err := yaml.Unmarshal([]byte(sccYAMLTemplate), scc) | ||
if err != nil { | ||
return nil, fmt.Errorf("error unmarshaling YAML: %v", err) | ||
} | ||
scc.Name = name | ||
scc.Namespace = namespace | ||
var users []string | ||
for _, user := range scc.Users { | ||
serviceAccount := strings.Split(user, ":") | ||
if len(serviceAccount) != 4 { | ||
return nil, fmt.Errorf("invalid service account name") | ||
} | ||
serviceAccount[2] = namespace | ||
users = append(users, strings.Join(serviceAccount, ":")) | ||
} | ||
scc.Users = users | ||
return scc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
kind: SecurityContextConstraints | ||
metadata: | ||
name: csi-scc | ||
namespace: ceph-csi-operator-system | ||
allowHostDirVolumePlugin: true | ||
allowHostIPC: true | ||
allowHostNetwork: false | ||
allowHostPID: true | ||
allowHostPorts: true | ||
allowPrivilegedContainer: true | ||
allowedCapabilities: | ||
- SYS_ADMIN | ||
apiVersion: security.openshift.io/v1 | ||
defaultAddCapabilities: [] | ||
fsGroup: | ||
type: RunAsAny | ||
priority: | ||
readOnlyRootFilesystem: false | ||
requiredDropCapabilities: | ||
- ALL | ||
runAsUser: | ||
type: RunAsAny | ||
seLinuxContext: | ||
type: RunAsAny | ||
supplementalGroups: | ||
type: RunAsAny | ||
users: | ||
- system:serviceaccount:ceph-csi-operator-system:csi-rbd-ctrlplugin-sa | ||
- system:serviceaccount:ceph-csi-operator-system:csi-cephfs-ctrlplugin-sa | ||
- system:serviceaccount:ceph-csi-operator-system:csi-nfs-ctrlplugin-sa | ||
- system:serviceaccount:ceph-csi-operator-system:csi-rbd-nodeplugin-sa | ||
- system:serviceaccount:ceph-csi-operator-system:csi-cephfs-nodeplugin-sa | ||
- system:serviceaccount:ceph-csi-operator-system:csi-nfs-nodeplugin-sa | ||
volumes: | ||
- configMap | ||
- emptyDir | ||
- hostPath | ||
- projected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ocp | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewSecurityContextConstraints(t *testing.T) { | ||
testNamespace := "test-namespace" | ||
testName := "test" | ||
scc, err := NewSecurityContextConstraints(testName, testNamespace) | ||
require.NoError(t, err, "NewSecurityContextConstraints should not return an error") | ||
assert.NotNil(t, scc, "SCC should not be nil") | ||
|
||
assert.Equal(t, scc.Name, testName) | ||
assert.NotEmpty(t, scc.Users, "Users should not be empty") | ||
for _, user := range scc.Users { | ||
assert.True(t, strings.Contains(user, testNamespace), | ||
"Each user should contain the specified namespace") | ||
assert.False(t, strings.Contains(user, "{{.Namespace}}"), | ||
"Template placeholders should be replaced") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.