Skip to content

Commit

Permalink
Merge pull request #211 from lpiwowar/bugfix/privileges
Browse files Browse the repository at this point in the history
Use the most restrictive service account possible
  • Loading branch information
openshift-merge-bot[bot] authored Oct 21, 2024
2 parents 9b081b3 + ca67497 commit eae3554
Show file tree
Hide file tree
Showing 27 changed files with 390 additions and 209 deletions.
9 changes: 9 additions & 0 deletions api/bases/test.openstack.org_ansibletests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
spec:
description: AnsibleTestSpec defines the desired state of AnsibleTest
properties:
SELinuxLevel:
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
ansibleCollections:
default: ""
description: AnsibleCollections - extra ansible collections to instal
Expand Down Expand Up @@ -191,6 +196,10 @@ spec:
description: A parameter that contains a workflow definition.
items:
properties:
SELinuxLevel:
description: A SELinuxLevel that should be used for test pods
spawned by the test operator.
type: string
ansibleCollections:
description: AnsibleCollections - extra ansible collections
to instal in additionn to the ones exist in the requirements.yaml
Expand Down
5 changes: 5 additions & 0 deletions api/bases/test.openstack.org_horizontests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
spec:
description: HorizonTestSpec defines the desired state of HorizonTest
properties:
SELinuxLevel:
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
adminPassword:
default: admin
description: AdminPassword is the password for the OpenStack admin
Expand Down
10 changes: 7 additions & 3 deletions api/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ spec:
see TempestconfRunSpec.
properties:
SELinuxLevel:
default: s0:c478,c978
description: A SELinuxLevel that is used for all the tempest test
pods.
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
SSHKeySecretName:
default: ""
Expand Down Expand Up @@ -490,6 +490,10 @@ spec:
For specific configuration of tempest see TempestRunSpec and for
discover-tempest-config see TempestconfRunSpec.
properties:
SELinuxLevel:
description: A SELinuxLevel that should be used for test pods
spawned by the test operator.
type: string
SSHKeySecretName:
description: SSHKeySecretName is the name of the k8s secret
that contains an ssh key. The key is mounted to ~/.ssh/id_ecdsa
Expand Down
9 changes: 9 additions & 0 deletions api/bases/test.openstack.org_tobikoes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
spec:
description: TobikoSpec defines the desired state of Tobiko
properties:
SELinuxLevel:
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
backoffLimit:
default: 0
description: BackoffLimit allows to define the maximum number of retried
Expand Down Expand Up @@ -202,6 +207,10 @@ spec:
description: A parameter that contains a workflow definition.
items:
properties:
SELinuxLevel:
description: A SELinuxLevel that should be used for test pods
spawned by the test operator.
type: string
backoffLimit:
default: 0
description: BackoffLimit allows to define the maximum number
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/ansibletest_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (r *AnsibleTest) ValidateCreate() (admission.Warnings, error) {
allWarnings = append(allWarnings, fmt.Sprintf(WarnPrivilegedModeOn, "AnsibleTest"))
}

if r.Spec.Privileged && len(r.Spec.Workflow) > 0 && len(r.Spec.SELinuxLevel) == 0 {
allWarnings = append(allWarnings, fmt.Sprintf(WarnSELinuxLevel, r.Kind))
}

return allWarnings, nil
}

Expand Down
15 changes: 15 additions & 0 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ type CommonOptions struct {
// StorageClass used to create any test-operator related PVCs.
StorageClass string `json:"storageClass"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// +kubebuilder:validation:Optional
// +kubebuilder:default:=""
// +operator-sdk:csv:customresourcedefinitions:type=spec
// A SELinuxLevel that should be used for test pods spawned by the test
// operator.
SELinuxLevel string `json:"SELinuxLevel"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// +kubebuilder:validation:Optional
// +kubebuilder:default:=""
Expand Down Expand Up @@ -136,6 +144,13 @@ type WorkflowCommonParameters struct {
// StorageClass used to create any test-operator related PVCs.
StorageClass *string `json:"storageClass"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// +kubebuilder:validation:Optional
// +optional
// A SELinuxLevel that should be used for test pods spawned by the test
// operator.
SELinuxLevel *string `json:"SELinuxLevel,omitempty"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// +kubebuilder:validation:Optional
// +kubebuilder:default:=""
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/common_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ const (
"set of tests might fail, as this configuration may be " +
"required for the tests to run successfully. Before enabling" +
"this parameter, consult documentation of the %[1]s CR."

// WarnSELinuxLevel
WarnSELinuxLevel = "%[1]s.Spec.Workflow is used and %[1]s.Spec.Privileged is " +
"set to true. Please, consider setting %[1]s.Spec.SELinuxLevel. This " +
"ensures that the copying of the logs to the PV is completed without any " +
"complications."
)
10 changes: 2 additions & 8 deletions api/v1beta1/tempest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,8 @@ type TempestconfRunSpec struct {
// TempestSpec - configuration of execution of tempest. For specific configuration
// of tempest see TempestRunSpec and for discover-tempest-config see TempestconfRunSpec.
type TempestSpec struct {
CommonOptions `json:",inline"`
CommonOpenstackConfig `json:",inline"`

// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +kubebuilder:default:="s0:c478,c978"
// A SELinuxLevel that is used for all the tempest test pods.
SELinuxLevel string `json:"SELinuxLevel"`
CommonOptions `json:",inline"`
CommonOpenstackConfig `json:",inline"`

// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/tempest_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (r *Tempest) ValidateCreate() (admission.Warnings, error) {
allWarnings = append(allWarnings, fmt.Sprintf(WarnPrivilegedModeOn, "Tempest"))
}

if r.Spec.Privileged && len(r.Spec.Workflow) > 0 && len(r.Spec.SELinuxLevel) == 0 {
allWarnings = append(allWarnings, fmt.Sprintf(WarnSELinuxLevel, r.Kind))
}

if len(allErrs) > 0 {
return allWarnings, apierrors.NewInvalid(
schema.GroupKind{
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/tobiko_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (r *Tobiko) ValidateCreate() (admission.Warnings, error) {
}, r.GetName(), allErrs)
}

if r.Spec.Privileged && len(r.Spec.Workflow) > 0 && len(r.Spec.SELinuxLevel) == 0 {
allWarnings = append(allWarnings, fmt.Sprintf(WarnSELinuxLevel, r.Kind))
}

return allWarnings, nil
}

Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions config/crd/bases/test.openstack.org_ansibletests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
spec:
description: AnsibleTestSpec defines the desired state of AnsibleTest
properties:
SELinuxLevel:
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
ansibleCollections:
default: ""
description: AnsibleCollections - extra ansible collections to instal
Expand Down Expand Up @@ -191,6 +196,10 @@ spec:
description: A parameter that contains a workflow definition.
items:
properties:
SELinuxLevel:
description: A SELinuxLevel that should be used for test pods
spawned by the test operator.
type: string
ansibleCollections:
description: AnsibleCollections - extra ansible collections
to instal in additionn to the ones exist in the requirements.yaml
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/test.openstack.org_horizontests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
spec:
description: HorizonTestSpec defines the desired state of HorizonTest
properties:
SELinuxLevel:
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
adminPassword:
default: admin
description: AdminPassword is the password for the OpenStack admin
Expand Down
10 changes: 7 additions & 3 deletions config/crd/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ spec:
see TempestconfRunSpec.
properties:
SELinuxLevel:
default: s0:c478,c978
description: A SELinuxLevel that is used for all the tempest test
pods.
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
SSHKeySecretName:
default: ""
Expand Down Expand Up @@ -490,6 +490,10 @@ spec:
For specific configuration of tempest see TempestRunSpec and for
discover-tempest-config see TempestconfRunSpec.
properties:
SELinuxLevel:
description: A SELinuxLevel that should be used for test pods
spawned by the test operator.
type: string
SSHKeySecretName:
description: SSHKeySecretName is the name of the k8s secret
that contains an ssh key. The key is mounted to ~/.ssh/id_ecdsa
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/test.openstack.org_tobikoes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
spec:
description: TobikoSpec defines the desired state of Tobiko
properties:
SELinuxLevel:
default: ""
description: A SELinuxLevel that should be used for test pods spawned
by the test operator.
type: string
backoffLimit:
default: 0
description: BackoffLimit allows to define the maximum number of retried
Expand Down Expand Up @@ -202,6 +207,10 @@ spec:
description: A parameter that contains a workflow definition.
items:
properties:
SELinuxLevel:
description: A SELinuxLevel that should be used for test pods
spawned by the test operator.
type: string
backoffLimit:
default: 0
description: BackoffLimit allows to define the maximum number
Expand Down
Loading

0 comments on commit eae3554

Please sign in to comment.