Skip to content

Commit 18b3a75

Browse files
Ensure that the Pod Security Standards are commented in the default scaffold (#5872)
* bump kb to latest commit Signed-off-by: Bryce Palmer <[email protected]> * bump helm-operator-plugins Signed-off-by: Bryce Palmer <[email protected]> * Signed-off-by: Bryce Palmer <[email protected]> bump latest changes on kb * fix sanity Co-authored-by: Bryce Palmer <[email protected]>
1 parent 120ac95 commit 18b3a75

File tree

13 files changed

+58
-61
lines changed

13 files changed

+58
-61
lines changed

changelog/fragments/kb-800fdeec6e5c.yaml

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
11
# entries is a list of entries to include in
22
# release notes and/or the migration guide
33
entries:
4-
- description: >
5-
For Golang/Ansible/Helm/HybridHelm language-based operators (go/v3, ansible/v1, helm/v1, hybrid.helm/v1-alpha): applying restrictive SCC for all containers scaffolded by the tool (will not work with k8s versions < 1.19).
6-
([More info](https://github.com/kubernetes-sigs/kubebuilder/pull/2700)). Important: You might be affected while updating Kubernetes to 1.25, Hence, ensure that the containers
7-
used in your project are restrictive or defined with the property labels `pod-security.kubernetes.io` on clusters ([More info](https://kubernetes.io/docs/concepts/security/pod-security-admission/#pod-security-admission-labels-for-namespaces)). Therefore, we suggest
8-
that you begin to configure the projects according to the best practices. ([More info](https://kubernetes.io/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/))
9-
kind: "change"
10-
11-
# Is this a breaking change?
12-
breaking: false
13-
migration:
14-
header: For Golang/Ansible/Helm/HybridHelm language-based operators (go/v3, ansible/v1, helm/v1, hybrid.helm/v1-alpha)
15-
body: |
16-
Following the steps
17-
1) In `config/kdefault/manager_auth_proxy_patch.go` ensure the following security context:
18-
19-
```yaml
20-
...
21-
spec:
22-
containers:
23-
- name: kube-rbac-proxy
24-
securityContext:
25-
allowPrivilegeEscalation: false
26-
capabilities:
27-
drop:
28-
- ALL
29-
...
30-
```
31-
32-
2) In the `config/manager/manager.yaml` ensure the following security context:
33-
34-
```yaml
35-
spec:
36-
securityContext:
37-
runAsNonRoot: true
38-
seccompProfile:
39-
type: RuntimeDefault
40-
containers:
41-
- command:
42-
- /manager
43-
image: controller:latest
44-
name: manager
45-
securityContext:
46-
allowPrivilegeEscalation: false
47-
capabilities:
48-
drop:
49-
- ALL
50-
```
51-
3) Run make bundle tagert to ensure that the above changes are also applied to
52-
your bundles.
534
- description: >
545
For Golang-based language (go/v2), fix issue introduced by removing the GO111MODULE=on from Dockerfile. ([More info](https://github.com/kubernetes-sigs/kubebuilder/pull/2678))
556

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/onsi/ginkgo v1.16.5
1515
github.com/onsi/gomega v1.18.1
1616
github.com/operator-framework/api v0.15.0
17-
github.com/operator-framework/helm-operator-plugins v0.0.12-0.20220608155702-d3967d2ae2ac
17+
github.com/operator-framework/helm-operator-plugins v0.0.12-0.20220613184440-7329cace347f
1818
github.com/operator-framework/java-operator-plugins v0.5.1
1919
github.com/operator-framework/operator-lib v0.11.0
2020
github.com/operator-framework/operator-manifest-tools v0.2.1
@@ -42,7 +42,7 @@ require (
4242
k8s.io/kubectl v0.24.0
4343
sigs.k8s.io/controller-runtime v0.12.1
4444
sigs.k8s.io/controller-tools v0.9.0
45-
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20220608134342-eea565cb3f50
45+
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20220613215411-7a05e3d4fe6d
4646
sigs.k8s.io/yaml v1.3.0
4747
)
4848

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
867867
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
868868
github.com/operator-framework/api v0.15.0 h1:4f9i0drtqHj7ykLoHxv92GR43S7MmQHhmFQkfm5YaGI=
869869
github.com/operator-framework/api v0.15.0/go.mod h1:scnY9xqSeCsOdtJtNoHIXd7OtHZ14gj1hkDA4+DlgLY=
870-
github.com/operator-framework/helm-operator-plugins v0.0.12-0.20220608155702-d3967d2ae2ac h1:a00NNxt4JF/Cg31c37+DhBzjIurdXUKAoxPdOxpvdV4=
871-
github.com/operator-framework/helm-operator-plugins v0.0.12-0.20220608155702-d3967d2ae2ac/go.mod h1:XRYBnRxeOF8UVOsXj24pL4QMjvd2D72SzKmGCcsoOGs=
870+
github.com/operator-framework/helm-operator-plugins v0.0.12-0.20220613184440-7329cace347f h1:lS/IvqlvEQGIwXE0VlW+mOCmFEXBKywNbGQDrK++r/g=
871+
github.com/operator-framework/helm-operator-plugins v0.0.12-0.20220613184440-7329cace347f/go.mod h1:D7zPPwmIFBqHtWigU2iJiLuZ0v7hOJOb1/VC+/UuBAQ=
872872
github.com/operator-framework/java-operator-plugins v0.5.1 h1:HmiTocc61d/uqVPY/7EUR6ZTHDVeZ5/fgy7uo1QIBFc=
873873
github.com/operator-framework/java-operator-plugins v0.5.1/go.mod h1:UnUHAWY203Xw1j6Xpiirp/psJJaSRYcjenc0NH2+aVw=
874874
github.com/operator-framework/operator-lib v0.11.0 h1:eYzqpiOfq9WBI4Trddisiq/X9BwCisZd3rIzmHRC9Z8=
@@ -1801,8 +1801,8 @@ sigs.k8s.io/controller-tools v0.9.0 h1:b/vSEPpA8hiMiyzDfLbZdCn3hoAcy3/868OHhYtHY
18011801
sigs.k8s.io/controller-tools v0.9.0/go.mod h1:NUkn8FTV3Sad3wWpSK7dt/145qfuQ8CKJV6j4jHC5rM=
18021802
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 h1:kDi4JBNAsJWfz1aEXhO8Jg87JJaPNLh5tIzYHgStQ9Y=
18031803
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY=
1804-
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20220608134342-eea565cb3f50 h1:yPiqoNv2s1zA0BV/+ztL24M4PrnMl9BA8jksK9Ju344=
1805-
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20220608134342-eea565cb3f50/go.mod h1:2o0wAP/Qi4vLA5tlmKOCTZdWUlkdewvkNi3o5Ko6eSw=
1804+
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20220613215411-7a05e3d4fe6d h1:VKHPL8DAxw5EAZyF01fRkSU41Yk+hpYpUEIrstg6e4Y=
1805+
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20220613215411-7a05e3d4fe6d/go.mod h1:2o0wAP/Qi4vLA5tlmKOCTZdWUlkdewvkNi3o5Ko6eSw=
18061806
sigs.k8s.io/kustomize/api v0.11.4 h1:/0Mr3kfBBNcNPOW5Qwk/3eb8zkswCwnqQxxKtmrTkRo=
18071807
sigs.k8s.io/kustomize/api v0.11.4/go.mod h1:k+8RsqYbgpkIrJ4p9jcdPqe8DprLxFUUO0yNOq8C+xI=
18081808
sigs.k8s.io/kustomize/cmd/config v0.10.6/go.mod h1:/S4A4nUANUa4bZJ/Edt7ZQTyKOY9WCER0uBS1SW2Rco=

hack/generate/samples/internal/ansible/memcached.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func (ma *Memcached) Run() {
8181
"#- ../prometheus", "#")
8282
pkg.CheckError("enabling prometheus metrics", err)
8383

84+
err = ma.ctx.UncommentRestrictivePodStandards()
85+
pkg.CheckError("creating the bundle", err)
86+
8487
ma.addingAnsibleTask()
8588
ma.addingMoleculeMockData()
8689

hack/generate/samples/internal/go/v3/memcached_with_webhooks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (mh *Memcached) Run() {
8080
"--resource", "true")
8181
pkg.CheckError("scaffolding apis", err)
8282

83+
err = mh.ctx.UncommentRestrictivePodStandards()
84+
pkg.CheckError("creating the bundle", err)
85+
8386
log.Infof("implementing the API")
8487
mh.implementingAPI()
8588

hack/generate/samples/internal/helm/memcached.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func (mh *Memcached) Run() {
8686
"--helm-chart", helmChartPath)
8787
pkg.CheckError("creating the project", err)
8888

89+
err = mh.ctx.UncommentRestrictivePodStandards()
90+
pkg.CheckError("creating the bundle", err)
91+
8992
log.Infof("customizing the sample")
9093
err = kbutil.ReplaceInFile(
9194
filepath.Join(mh.ctx.Dir, "config", "samples", "cache_v1alpha1_memcached.yaml"),

internal/testutils/utils.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
. "github.com/onsi/ginkgo"
2828
. "github.com/onsi/gomega"
29+
kbutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
2930
kbtestutils "sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
3031
)
3132

@@ -203,3 +204,39 @@ func WrapWarnOutput(_ string, err error) {
203204
func WrapWarn(err error) {
204205
WrapWarnOutput("", err)
205206
}
207+
208+
func (tc TestContext) UncommentRestrictivePodStandards() error {
209+
configManager := filepath.Join(tc.Dir, "config", "manager", "manager.yaml")
210+
managerAuth := filepath.Join(tc.Dir, "config", "default", "manager_auth_proxy_patch.yaml")
211+
212+
if err := kbutil.ReplaceInFile(configManager, `# TODO(user): uncomment for common cases that do not require escalating privileges
213+
# capabilities:
214+
# drop:
215+
# - "ALL"`, ` capabilities:
216+
drop:
217+
- "ALL"`); err != nil {
218+
return err
219+
}
220+
221+
if err := kbutil.ReplaceInFile(managerAuth, `# TODO(user): uncomment for common cases that do not require escalating privileges
222+
# capabilities:
223+
# drop:
224+
# - "ALL"`, ` capabilities:
225+
drop:
226+
- "ALL"`); err != nil {
227+
return err
228+
}
229+
230+
if err := kbutil.ReplaceInFile(configManager, `# TODO(user): For common cases that do not require escalating privileges
231+
# it is recommended to ensure that all your Pods/Containers are restrictive.
232+
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
233+
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
234+
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
235+
# seccompProfile:
236+
# type: RuntimeDefault`, `seccompProfile:
237+
type: RuntimeDefault`); err == nil {
238+
return err
239+
}
240+
241+
return nil
242+
}

testdata/ansible/memcached-operator/config/default/manager_auth_proxy_patch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
allowPrivilegeEscalation: false
1515
capabilities:
1616
drop:
17-
- ALL
17+
- "ALL"
1818
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.11.0
1919
args:
2020
- "--secure-listen-address=0.0.0.0:8443"

testdata/ansible/memcached-operator/config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ spec:
4141
allowPrivilegeEscalation: false
4242
capabilities:
4343
drop:
44-
- ALL
44+
- "ALL"
4545
livenessProbe:
4646
httpGet:
4747
path: /healthz

testdata/go/v3/memcached-operator/config/default/manager_auth_proxy_patch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
allowPrivilegeEscalation: false
1515
capabilities:
1616
drop:
17-
- ALL
17+
- "ALL"
1818
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.11.0
1919
args:
2020
- "--secure-listen-address=0.0.0.0:8443"

0 commit comments

Comments
 (0)