Skip to content

Commit

Permalink
Changed trident-controller-scc priority from 10 to null and added SCC…
Browse files Browse the repository at this point in the history
… yaml generation
  • Loading branch information
shashank-netapp authored Mar 27, 2024
1 parent 6d71d32 commit 9e0bc85
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
38 changes: 38 additions & 0 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ const (
ControllerServiceAccountFilename = "trident-controller-serviceaccount.yaml"
ControllerPodSecurityPolicyFilename = "trident-controller-podsecuritypolicy.yaml"
ControllerClusterRoleBindingFilename = "trident-controller-clusterrolebinding.yaml"
ControllerSCCFilename = "trident-controller-scc.yaml"

NodeLinuxRoleFilename = "trident-node-linux-role.yaml"
NodeLinuxRoleBindingFilename = "trident-node-linux-rolebinding.yaml"
NodeLinuxServiceAccountFilename = "trident-node-linux-serviceaccount.yaml"
NodeLinuxPodSecurityPolicyFilename = "trident-node-linux-podsecuritypolicy.yaml"
NodeLinuxSCCFilename = "trident-node-linux-scc.yaml"

NodeWindowsRoleFilename = "trident-node-windows-role.yaml"
NodeWindowsRoleBindingFilename = "trident-node-windows-rolebinding.yaml"
NodeWindowsServiceAccountFilename = "trident-node-windows-serviceaccount.yaml"
NodeWindowsPodSecurityPolicyFilename = "trident-node-windows-podsecuritypolicy.yaml"
NodeWindowsSCCFilename = "trident-node-windows-scc.yaml"

CRDsFilename = "trident-crds.yaml"
DaemonSetFilename = "trident-daemonset.yaml"
Expand Down Expand Up @@ -150,6 +153,9 @@ var (
nodeLinuxPodSecurityPolicyPath string
nodeWindowsPodSecurityPolicyPath string
resourceQuotaPath string
controllerSCCPath string
nodeLinuxSCCPath string
nodeWindowsSCCPath string
setupYAMLPaths []string

appLabel string
Expand Down Expand Up @@ -536,6 +542,13 @@ func prepareYAMLFilePaths() error {
nodeWindowsPodSecurityPolicyPath)
}

if client.Flavor() == k8sclient.FlavorOpenShift {
controllerSCCPath = path.Join(setupPath, ControllerSCCFilename)
nodeLinuxSCCPath = path.Join(setupPath, NodeLinuxSCCFilename)
nodeWindowsSCCPath = path.Join(setupPath, NodeWindowsSCCFilename)
setupYAMLPaths = append(setupYAMLPaths, controllerSCCPath, nodeLinuxSCCPath, nodeWindowsSCCPath)
}

return nil
}

Expand Down Expand Up @@ -721,6 +734,23 @@ func prepareYAMLFiles() error {
}
}

// If OpenShift, generate corresponding SCCs
if client.Flavor() == k8sclient.FlavorOpenShift {
// Creating trident controller security context constraint (SCC)
controllerSCCYAML := k8sclient.GetOpenShiftSCCYAML(getControllerRBACResourceName(), getControllerRBACResourceName(), TridentPodNamespace, labels, nil,
isLinuxNodeSCCUser(getControllerRBACResourceName()))
if err = writeFile(controllerSCCPath, controllerSCCYAML); err != nil {
return fmt.Errorf("could not write controller SCC YAML file; %v", err)
}

// Creating trident node security context constraint (SCC)
nodeLinuxSCCYAML := k8sclient.GetOpenShiftSCCYAML(getNodeRBACResourceName(false), getNodeRBACResourceName(false), TridentPodNamespace, daemonSetlabels, nil,
isLinuxNodeSCCUser(getNodeRBACResourceName(false)))
if err = writeFile(nodeLinuxSCCPath, nodeLinuxSCCYAML); err != nil {
return fmt.Errorf("could not write node linux SCC YAML file; %v", err)
}
}

if windows {
daemonArgs = &k8sclient.DaemonsetYAMLArguments{
DaemonsetName: getDaemonSetName(true),
Expand Down Expand Up @@ -775,6 +805,14 @@ func prepareYAMLFiles() error {
return fmt.Errorf("could not write node windows pod security policy YAML file; %v", err)
}
}

if client.Flavor() == k8sclient.FlavorOpenShift {
nodeWindowsSCCYAML := k8sclient.GetOpenShiftSCCYAML(getNodeRBACResourceName(true), getNodeRBACResourceName(true), TridentPodNamespace, daemonSetlabels, nil,
isLinuxNodeSCCUser(getNodeRBACResourceName(true)))
if err = writeFile(nodeWindowsSCCPath, nodeWindowsSCCYAML); err != nil {
return fmt.Errorf("could not write node windows SCC YAML file; %v", err)
}
}
}

return nil
Expand Down
8 changes: 7 additions & 1 deletion cli/k8s_client/yaml_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ spec:
labels:
app: {LABEL_APP}
{LABEL_IDENTITY}
annotations:
openshift.io/required-scc: {SERVICE_ACCOUNT}
spec:
serviceAccount: {SERVICE_ACCOUNT}
containers:
Expand Down Expand Up @@ -913,6 +915,8 @@ spec:
metadata:
labels:
app: {LABEL_APP}
annotations:
openshift.io/required-scc: {SERVICE_ACCOUNT}
spec:
serviceAccount: {SERVICE_ACCOUNT}
hostNetwork: true
Expand Down Expand Up @@ -1115,6 +1119,8 @@ spec:
metadata:
labels:
app: {LABEL_APP}
annotations:
openshift.io/required-scc: {SERVICE_ACCOUNT}
spec:
securityContext:
windowsOptions:
Expand Down Expand Up @@ -1482,7 +1488,7 @@ defaultAddCapabilities: null
fsGroup:
type: RunAsAny
groups: []
priority: 10
priority: null
readOnlyRootFilesystem: false
requiredDropCapabilities:
- MKNOD
Expand Down
3 changes: 1 addition & 2 deletions cli/k8s_client/yaml_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,6 @@ func TestGetOpenShiftSCCYAML_UnprivilegedUser(t *testing.T) {
namespace := "trident"
labels := map[string]string{"app": "controller.trident.netapp.io"}
crdDetails := map[string]string{"kind": "ReplicaSet"}
priority := int32(10)

expected := scc.SecurityContextConstraints{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -1168,7 +1167,7 @@ func TestGetOpenShiftSCCYAML_UnprivilegedUser(t *testing.T) {
Type: "RunAsAny",
},
Groups: []string{},
Priority: &priority,
Priority: nil,
ReadOnlyRootFilesystem: false,
RequiredDropCapabilities: []v1.Capability{"MKNOD"},
RunAsUser: scc.RunAsUserStrategyOptions{
Expand Down

0 comments on commit 9e0bc85

Please sign in to comment.