Skip to content

Commit 2578058

Browse files
committed
fix: Goose pod security context
When .spec.storage is configured, Goose uses the mounted volume as its working directory. A root-owned PVC prevents the Goose process, which runs as UID/GID 1000, from writing its home-directory data under /home/goose, including configuration and transcripts: mkdir: cannot create directory '/home/goose/.config': Permission denied Apply the standard restrictive pod and container security contexts with Goose UID/GID 1000, matching openstackclient. Set fsGroup to 1000 so supported PVC-backed working directories are group-writable and Goose can persist its home-directory data. Depends-On: openstack-k8s-operators/lib-common#779
1 parent d08842c commit 2578058

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎go.mod‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,5 @@ replace k8s.io/component-base => k8s.io/component-base v0.33.13 //allow-merging
179179
replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20250627150254-e9823e99808e //allow-merging
180180

181181
replace github.com/cert-manager/cmctl/v2 => github.com/cert-manager/cmctl/v2 v2.3.0 //allow-merging
182+
183+
replace github.com/openstack-k8s-operators/lib-common/modules/users => github.com/lpiwowar/lib-common/modules/users v0.0.0-20261012150018-c417ae7132b9

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
138138
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
139139
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
140140
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
141+
github.com/lpiwowar/lib-common/modules/users v0.0.0-20261012150018-c417ae7132b9 h1:F4VgArdgWmtr9t8ix/nhEMu9vRK1duOkVqROEmhziaE=
142+
github.com/lpiwowar/lib-common/modules/users v0.0.0-20261012150018-c417ae7132b9/go.mod h1:jmVVRfwuFQ3fHLIOAkUrtLgOwEL6j45POzS3PBJuwyM=
141143
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
142144
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
143145
github.com/metal3-io/baremetal-operator/apis v0.11.7 h1:k2ulCHMciv8NdOfUgMrY29E5J78DDozVfaN2QG+XfNQ=
@@ -188,8 +190,6 @@ github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.202610100
188190
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261010081703-9c4377961aa3/go.mod h1:zPIkK2aNVGCxyf8Yg2iAaiCH3Wu2G/kjft+CAVs1cgQ=
189191
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261010081703-9c4377961aa3 h1:MdMKJX/i1N4v8AA3Fb2EcysrBmGEoXJE5QdMltE0s2E=
190192
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261010081703-9c4377961aa3/go.mod h1:enei+rhzWgyEqqcrh/1V42M9exsotXPnmsj48g1nqD0=
191-
github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261010081703-9c4377961aa3 h1:WKWVyxCkEtqHND8TTEiJsl8R8fcDNXZS7zDzmHgFQFQ=
192-
github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261010081703-9c4377961aa3/go.mod h1:jmVVRfwuFQ3fHLIOAkUrtLgOwEL6j45POzS3PBJuwyM=
193193
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20261009185949-45a01e060edc h1:m+T2nPcN3RkV8rnrwLaZzeEu3kTjffOja97IoA4g/F4=
194194
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20261009185949-45a01e060edc/go.mod h1:4ii2iCFBbSd3Ns3OxwmtxLg0Vm/zX+ZGKUDuBRoJ+Xg=
195195
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260927135032-f0eb46b149d8 h1:83bv+O9Xoiio4bUrjno/Z1QgfWF/BnF3TPY25gChU4k=

‎internal/openstackassistant/funcs.go‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import (
2020
"unicode"
2121

2222
env "github.com/openstack-k8s-operators/lib-common/modules/common/env"
23+
"github.com/openstack-k8s-operators/lib-common/modules/common/pod"
2324
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
25+
"github.com/openstack-k8s-operators/lib-common/modules/users"
2426
assistantv1 "github.com/openstack-k8s-operators/openstack-operator/api/assistant/v1beta1"
2527

2628
corev1 "k8s.io/api/core/v1"
@@ -143,23 +145,16 @@ func AssistantPodSpecWithCABundle(
143145
podSpec := corev1.PodSpec{
144146
TerminationGracePeriodSeconds: ptr.To[int64](0),
145147
ServiceAccountName: instance.RbacResourceName(),
148+
SecurityContext: pod.RestrictivePodSecurityContext(users.GooseUID, users.GooseGID),
146149
Volumes: volumes,
147150
Containers: []corev1.Container{
148151
{
149-
Name: "assistant",
150-
Image: instance.Spec.ContainerImage,
151-
SecurityContext: &corev1.SecurityContext{
152-
RunAsNonRoot: ptr.To(true),
153-
AllowPrivilegeEscalation: ptr.To(false),
154-
Capabilities: &corev1.Capabilities{
155-
Drop: []corev1.Capability{
156-
"ALL",
157-
},
158-
},
159-
},
160-
Env: containerEnvs,
161-
VolumeMounts: volumeMounts,
162-
Resources: instance.Spec.Resources,
152+
Name: "assistant",
153+
Image: instance.Spec.ContainerImage,
154+
SecurityContext: pod.RestrictiveSecurityContext(users.GooseUID, users.GooseGID),
155+
Env: containerEnvs,
156+
VolumeMounts: volumeMounts,
157+
Resources: instance.Spec.Resources,
163158
},
164159
},
165160
}

‎internal/openstackassistant/funcs_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import (
1717

1818
"github.com/onsi/gomega"
1919
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
20+
"github.com/openstack-k8s-operators/lib-common/modules/users"
2021

2122
assistantv1 "github.com/openstack-k8s-operators/openstack-operator/api/assistant/v1beta1"
2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/utils/ptr"
2426
)
2527

2628
func newTestInstance() *assistantv1.OpenStackAssistant {
@@ -111,8 +113,17 @@ func TestAssistantPodSpec_SecurityContext(t *testing.T) {
111113
instance := newTestInstance()
112114

113115
spec := AssistantPodSpec(instance, "hash", nil)
116+
podSC := spec.SecurityContext
114117
sc := spec.Containers[0].SecurityContext
115118

119+
g.Expect(podSC.RunAsUser).To(gomega.Equal(ptr.To(users.GooseUID)))
120+
g.Expect(podSC.RunAsGroup).To(gomega.Equal(ptr.To(users.GooseGID)))
121+
g.Expect(podSC.FSGroup).To(gomega.Equal(ptr.To(users.GooseGID)))
122+
g.Expect(podSC.SeccompProfile).To(gomega.Equal(&corev1.SeccompProfile{
123+
Type: corev1.SeccompProfileTypeRuntimeDefault,
124+
}))
125+
g.Expect(sc.RunAsUser).To(gomega.Equal(ptr.To(users.GooseUID)))
126+
g.Expect(sc.RunAsGroup).To(gomega.Equal(ptr.To(users.GooseGID)))
116127
g.Expect(*sc.RunAsNonRoot).To(gomega.BeTrue())
117128
g.Expect(*sc.AllowPrivilegeEscalation).To(gomega.BeFalse())
118129
g.Expect(sc.Capabilities.Drop).To(gomega.ContainElement(corev1.Capability("ALL")))

0 commit comments

Comments
 (0)