Skip to content

Commit

Permalink
Disable insecure parameters by default
Browse files Browse the repository at this point in the history
This patch sets by default for all test pods:

  - runAsNonRoot: true
  - automountServiceAccountToken: false

These two parameters shouldn't be enabled unless necessary for any
pods in the OCP cluster. The runAsNonRoot parameter ensures that
the container process does not run as root nor does it switch to
root user after it has been spawned.

And the automountServiceAccountToken makes sure that we are not
mounting service account tokens into the test pods. This would
allow them to modify the state of the OCP cluster. As of now the
service account tokens are not required by any of the test pods.

This behavior can be overridden by setting privileged: true.
  • Loading branch information
lpiwowar committed Dec 10, 2024
1 parent b2b1b46 commit 038565e
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 67 deletions.
9 changes: 5 additions & 4 deletions api/bases/test.openstack.org_ansibletests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
storageClass:
default: local-storage
Expand Down
9 changes: 5 additions & 4 deletions api/bases/test.openstack.org_horizontests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
projectName:
default: horizontest
Expand Down
9 changes: 5 additions & 4 deletions api/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
storageClass:
default: local-storage
Expand Down
9 changes: 5 additions & 4 deletions api/bases/test.openstack.org_tobikoes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
publicKey:
default: ""
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ type CommonOptions struct {
// +kubebuilder:default=false
// +optional
// Use with caution! This parameter specifies whether test-operator should spawn test
// pods with allowedPrivilegedEscalation: true and the default capabilities on
// top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
// pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
// automountServiceAccountToken: true, and the default capabilities on top of
// capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
// This parameter is deemed insecure but it is needed for certain test-operator
// functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
// of tobiko tests).
// functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
// set of tobiko tests).
Privileged bool `json:"privileged"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/common_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const (
const (
// WarnPrivilegedModeOn
WarnPrivilegedModeOn = "%s.Spec.Privileged is set to true. This means that test pods " +
"are spawned with allowPrivilegedEscalation: true and default " +
"capabilities on top of those required by the test operator " +
"(NET_ADMIN, NET_RAW)."
"are spawned with allowPrivilegedEscalation: true, runAsNonRoot: false, " +
"automountServiceAccountToken: true and default capabilities on top of " +
"those required by the test operator (NET_ADMIN, NET_RAW)."

// WarnPrivilegedModeOff
WarnPrivilegedModeOff = "%[1]s.Spec.Privileged is set to false. Note, that a certain " +
Expand Down
9 changes: 5 additions & 4 deletions config/crd/bases/test.openstack.org_ansibletests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
storageClass:
default: local-storage
Expand Down
9 changes: 5 additions & 4 deletions config/crd/bases/test.openstack.org_horizontests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
projectName:
default: horizontest
Expand Down
9 changes: 5 additions & 4 deletions config/crd/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
storageClass:
default: local-storage
Expand Down
9 changes: 5 additions & 4 deletions config/crd/bases/test.openstack.org_tobikoes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ spec:
default: false
description: |-
Use with caution! This parameter specifies whether test-operator should spawn test
pods with allowedPrivilegedEscalation: true and the default capabilities on
top of capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
pods with allowedPrivilegedEscalation: true, runAsNonRoot: false,
automountServiceAccountToken: true, and the default capabilities on top of
capabilities that are usually needed by the test pods (NET_ADMIN, NET_RAW).
This parameter is deemed insecure but it is needed for certain test-operator
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain set
of tobiko tests).
functionalities to work properly (e.g.: extraRPMs in Tempest CR, or certain
set of tobiko tests).
type: boolean
publicKey:
default: ""
Expand Down
54 changes: 34 additions & 20 deletions config/manifests/bases/test-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ spec:
displayName: Open Stack Config Secret
path: openStackConfigSecret
- description: 'Use with caution! This parameter specifies whether test-operator
should spawn test pods with allowedPrivilegedEscalation: true and the default
capabilities on top of capabilities that are usually needed by the test
pods (NET_ADMIN, NET_RAW). This parameter is deemed insecure but it is needed
for certain test-operator functionalities to work properly (e.g.: extraRPMs
in Tempest CR, or certain set of tobiko tests).'
should spawn test pods with allowedPrivilegedEscalation: true, runAsNonRoot:
false, automountServiceAccountToken: true, and the default capabilities
on top of capabilities that are usually needed by the test pods (NET_ADMIN,
NET_RAW). This parameter is deemed insecure but it is needed for certain
test-operator functionalities to work properly (e.g.: extraRPMs in Tempest
CR, or certain set of tobiko tests).'
displayName: Privileged
path: privileged
- description: StorageClass used to create any test-operator related PVCs.
Expand Down Expand Up @@ -283,11 +284,12 @@ spec:
displayName: Password
path: password
- description: 'Use with caution! This parameter specifies whether test-operator
should spawn test pods with allowedPrivilegedEscalation: true and the default
capabilities on top of capabilities that are usually needed by the test
pods (NET_ADMIN, NET_RAW). This parameter is deemed insecure but it is needed
for certain test-operator functionalities to work properly (e.g.: extraRPMs
in Tempest CR, or certain set of tobiko tests).'
should spawn test pods with allowedPrivilegedEscalation: true, runAsNonRoot:
false, automountServiceAccountToken: true, and the default capabilities
on top of capabilities that are usually needed by the test pods (NET_ADMIN,
NET_RAW). This parameter is deemed insecure but it is needed for certain
test-operator functionalities to work properly (e.g.: extraRPMs in Tempest
CR, or certain set of tobiko tests).'
displayName: Privileged
path: privileged
- description: ProjectName is the name of the OpenStack project for Horizon
Expand Down Expand Up @@ -380,11 +382,12 @@ spec:
displayName: Parallel
path: parallel
- description: 'Use with caution! This parameter specifies whether test-operator
should spawn test pods with allowedPrivilegedEscalation: true and the default
capabilities on top of capabilities that are usually needed by the test
pods (NET_ADMIN, NET_RAW). This parameter is deemed insecure but it is needed
for certain test-operator functionalities to work properly (e.g.: extraRPMs
in Tempest CR, or certain set of tobiko tests).'
should spawn test pods with allowedPrivilegedEscalation: true, runAsNonRoot:
false, automountServiceAccountToken: true, and the default capabilities
on top of capabilities that are usually needed by the test pods (NET_ADMIN,
NET_RAW). This parameter is deemed insecure but it is needed for certain
test-operator functionalities to work properly (e.g.: extraRPMs in Tempest
CR, or certain set of tobiko tests).'
displayName: Privileged
path: privileged
- description: StorageClass used to create any test-operator related PVCs.
Expand All @@ -398,6 +401,11 @@ spec:
- description: A content of exclude.txt file that is passed to tempest via --exclude-list
displayName: Exclude List
path: tempestRun.excludeList
- description: The expectedFailuresList parameter contains tests that should
not count as failures. When a test from this list fails, the test pod ends
with Completed state rather than with Error state.
displayName: Expected Failures List
path: tempestRun.expectedFailuresList
- description: ExternalPlugin contains information about plugin that should
be installed within the tempest test pod. If this option is specified then
only tests that are part of the external plugin can be executed.
Expand Down Expand Up @@ -662,6 +670,11 @@ spec:
- description: A content of exclude.txt file that is passed to tempest via --exclude-list
displayName: Exclude List
path: workflow[0].tempestRun.excludeList
- description: The expectedFailuresList parameter contains tests that should
not count as failures. When a test from this list fails, the test pod ends
with Completed state rather than with Error state.
displayName: Expected Failures List
path: workflow[0].tempestRun.expectedFailuresList
- description: ExternalPlugin contains information about plugin that should
be installed within the tempest test pod. If this option is specified then
only tests that are part of the external plugin can be executed.
Expand Down Expand Up @@ -904,11 +917,12 @@ spec:
displayName: Private Key
path: privateKey
- description: 'Use with caution! This parameter specifies whether test-operator
should spawn test pods with allowedPrivilegedEscalation: true and the default
capabilities on top of capabilities that are usually needed by the test
pods (NET_ADMIN, NET_RAW). This parameter is deemed insecure but it is needed
for certain test-operator functionalities to work properly (e.g.: extraRPMs
in Tempest CR, or certain set of tobiko tests).'
should spawn test pods with allowedPrivilegedEscalation: true, runAsNonRoot:
false, automountServiceAccountToken: true, and the default capabilities
on top of capabilities that are usually needed by the test pods (NET_ADMIN,
NET_RAW). This parameter is deemed insecure but it is needed for certain
test-operator functionalities to work properly (e.g.: extraRPMs in Tempest
CR, or certain set of tobiko tests).'
displayName: Privileged
path: privileged
- description: Public Key
Expand Down
5 changes: 3 additions & 2 deletions pkg/ansibletest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func Job(
Labels: labels,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
AutomountServiceAccountToken: &instance.Spec.Privileged,
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
Expand Down
5 changes: 3 additions & 2 deletions pkg/horizontest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ func Job(
Labels: labels,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
AutomountServiceAccountToken: &instance.Spec.Privileged,
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
Expand Down
5 changes: 3 additions & 2 deletions pkg/tempest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func Job(
Labels: labels,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
AutomountServiceAccountToken: &instance.Spec.Privileged,
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
Expand Down
5 changes: 3 additions & 2 deletions pkg/tobiko/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func Job(
Labels: labels,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
AutomountServiceAccountToken: &instance.Spec.Privileged,
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: instance.RbacResourceName(),
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func GetSecurityContext(
securityContext := corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsUser,
RunAsNonRoot: &trueVar,
AllowPrivilegeEscalation: &falseVar,
Capabilities: &corev1.Capabilities{},
SeccompProfile: &corev1.SeccompProfile{
Expand All @@ -30,6 +31,11 @@ func GetSecurityContext(
}

if privileged {
// Sometimes we require the test pods run sudo to be able to install
// additional packages or run commands with elevated priveleges (e.g.,
// tcpdump in case of Tobiko)
securityContext.RunAsNonRoot = &falseVar

// We need to run pods with AllowPrivilegedEscalation: true to remove
// nosuid from the pod (in order to be able to run sudo)
securityContext.AllowPrivilegeEscalation = &trueVar
Expand Down

0 comments on commit 038565e

Please sign in to comment.