-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
78 changed files
with
32,005 additions
and
2 deletions.
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,37 @@ | ||
package ocp | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"fmt" | ||
"text/template" | ||
|
||
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) { | ||
tmpl, err := template.New("scc").Parse(sccYAMLTemplate) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing template: %v", err) | ||
} | ||
|
||
var buf bytes.Buffer | ||
err = tmpl.Execute(&buf, map[string]string{"Name": name, "Namespace": namespace}) | ||
if err != nil { | ||
return nil, fmt.Errorf("error executing template: %v", err) | ||
} | ||
|
||
scc := &secv1.SecurityContextConstraints{} | ||
err = yaml.UnmarshalStrict(buf.Bytes(), scc) | ||
if err != nil { | ||
return nil, fmt.Errorf("error unmarshaling YAML: %v", err) | ||
} | ||
|
||
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,37 @@ | ||
kind: SecurityContextConstraints | ||
metadata: | ||
name: {{ .Name }} | ||
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:{{.Namespace}}:csi-rbd-ctrlplugin-sa | ||
- system:serviceaccount:{{.Namespace}}:csi-cephfs-ctrlplugin-sa | ||
- system:serviceaccount:{{.Namespace}}:csi-nfs-ctrlplugin-sa | ||
- system:serviceaccount:{{.Namespace}}:csi-rbd-nodeplugin-sa | ||
- system:serviceaccount:{{.Namespace}}:csi-cephfs-nodeplugin-sa | ||
- system:serviceaccount:{{.Namespace}}: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.