Skip to content

Commit

Permalink
Merge pull request #4251 from camilamacedo86/remove-comment-line-ensu…
Browse files Browse the repository at this point in the history
…re-all-restricted

✨  (go/v4): Enable `seccompProfile.type: RuntimeDefault` by default in scaffolded projects
  • Loading branch information
k8s-ci-robot authored Nov 9, 2024
2 parents 4ea479c + 75ac2fb commit 0df6220
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4156,6 +4156,8 @@ spec:
readOnly: true
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: project-controller-manager
terminationGracePeriodSeconds: 10
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ spec:
- ALL
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: project-controller-manager
terminationGracePeriodSeconds: 10
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7970,6 +7970,8 @@ spec:
readOnly: true
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: project-controller-manager
terminationGracePeriodSeconds: 10
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
31 changes: 0 additions & 31 deletions test/e2e/v4/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ func GenerateV4(kbc *utils.TestContext) {
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "cmd", "main.go"),
tlsConfigManager, "// ")).To(Succeed())

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
}
}

// GenerateV4WithoutMetrics implements a go/v4 plugin project defined by a TestContext.
Expand Down Expand Up @@ -121,11 +116,6 @@ func GenerateV4WithoutMetrics(kbc *utils.TestContext) {
ExpectWithOffset(1, pluginutil.CommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
metricsTarget, "#")).To(Succeed())

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
}
}

// GenerateV4WithoutMetrics implements a go/v4 plugin project defined by a TestContext.
Expand Down Expand Up @@ -204,11 +194,6 @@ func GenerateV4WithoutWebhooks(kbc *utils.TestContext) {
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../prometheus", "#")).To(Succeed())

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
}
}

func creatingAPI(kbc *utils.TestContext) {
Expand Down Expand Up @@ -378,22 +363,6 @@ const certManagerTarget = `#replacements:
# index: 1
# create: true`

func uncommentPodStandards(kbc *utils.TestContext) {
configManager := filepath.Join(kbc.Dir, "config", "manager", "manager.yaml")

//nolint:lll
if err := pluginutil.ReplaceInFile(configManager, `# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault`, `seccompProfile:
type: RuntimeDefault`); err == nil {
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}
}

// scaffoldConversionWebhook sets up conversion webhooks for testing the ConversionTest API
func scaffoldConversionWebhook(kbc *utils.TestContext) {
By("scaffolding conversion webhooks for testing ConversionTest v1 to v2 conversion")
Expand Down
20 changes: 5 additions & 15 deletions test/e2e/v4/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,27 @@ var _ = Describe("kubebuilder", func() {
kbc.Destroy()
})
It("should generate a runnable project", func() {
kbc.IsRestricted = false
GenerateV4(kbc)
Run(kbc, true, false, true, false)
})
It("should generate a runnable project with the Installer", func() {
kbc.IsRestricted = false
GenerateV4(kbc)
Run(kbc, true, true, true, false)
})
It("should generate a runnable project without metrics exposed", func() {
kbc.IsRestricted = false
GenerateV4WithoutMetrics(kbc)
Run(kbc, true, false, false, false)
})
It("should generate a runnable project with metrics protected by network policies", func() {
kbc.IsRestricted = false
GenerateV4WithNetworkPoliciesWithoutWebhooks(kbc)
Run(kbc, false, false, true, true)
})
It("should generate a runnable project with webhooks and metrics protected by network policies", func() {
kbc.IsRestricted = false
GenerateV4WithNetworkPolicies(kbc)
Run(kbc, true, false, true, true)
})
It("should generate a runnable project with the manager running "+
"as restricted and without webhooks", func() {
kbc.IsRestricted = true
GenerateV4WithoutWebhooks(kbc)
Run(kbc, false, false, true, false)
})
Expand All @@ -110,11 +104,9 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, hasMetrics bool,
err = kbc.CreateManagerNamespace()
ExpectWithOffset(1, err).NotTo(HaveOccurred())

if kbc.IsRestricted {
By("labeling all namespaces to warn about restricted")
err = kbc.LabelNamespacesToWarnAboutRestricted()
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}
By("labeling all namespaces to warn about restricted")
err = kbc.LabelNamespacesToWarnAboutRestricted()
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("updating the go.mod")
err = kbc.Tidy()
Expand Down Expand Up @@ -149,10 +141,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, hasMetrics bool,
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}

if kbc.IsRestricted {
By("validating that manager Pod/container(s) are restricted")
ExpectWithOffset(1, output).NotTo(ContainSubstring("Warning: would violate PodSecurity"))
}
By("validating that manager Pod/container(s) are restricted")
ExpectWithOffset(1, output).NotTo(ContainSubstring("Warning: would violate PodSecurity"))

By("Checking controllerManager and getting the name of the Pod")
controllerPodName = getControllerName(kbc)
Expand Down
12 changes: 5 additions & 7 deletions testdata/project-v4-multigroup/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
2 changes: 2 additions & 0 deletions testdata/project-v4-multigroup/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,8 @@ spec:
readOnly: true
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: project-v4-multigroup-controller-manager
terminationGracePeriodSeconds: 10
volumes:
Expand Down
12 changes: 5 additions & 7 deletions testdata/project-v4-with-plugins/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
2 changes: 2 additions & 0 deletions testdata/project-v4-with-plugins/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ spec:
readOnly: true
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: project-v4-with-plugins-controller-manager
terminationGracePeriodSeconds: 10
volumes:
Expand Down
12 changes: 5 additions & 7 deletions testdata/project-v4/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ spec:
# values:
# - linux
securityContext:
# Projects are configured by default to adhere to the "restricted" Pod Security Standards.
# This ensures that deployments meet the highest security requirements for Kubernetes.
# For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault
seccompProfile:
type: RuntimeDefault
containers:
- command:
- /manager
Expand Down
2 changes: 2 additions & 0 deletions testdata/project-v4/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ spec:
readOnly: true
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: project-v4-controller-manager
terminationGracePeriodSeconds: 10
volumes:
Expand Down

0 comments on commit 0df6220

Please sign in to comment.