Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v1.34][cherry-pick] Fix security-context for apiserver - audit logs are supported only in Enterprise version #3310

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/render/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,6 @@ func (c *apiServerComponent) apiServerContainer() corev1.Container {
ImagePullPolicy: ImagePullPolicy(),
Args: c.startUpArgs(),
Env: env,
// OpenShift apiserver needs privileged access to write audit logs to host path volume.
// Audit logs are owned by root on hosts so we need to be root user and group.
SecurityContext: securitycontext.NewRootContext(c.cfg.Openshift),
VolumeMounts: volumeMounts,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Expand All @@ -1089,6 +1086,13 @@ func (c *apiServerComponent) apiServerContainer() corev1.Container {
PeriodSeconds: 60,
},
}
// In case of OpenShift, apiserver needs privileged access to write audit logs to host path volume.
// Audit logs are owned by root on hosts so we need to be root user and group. Audit logs are supported only in Enterprise version.
if c.cfg.Installation.Variant == operatorv1.TigeraSecureEnterprise {
apiServer.SecurityContext = securitycontext.NewRootContext(c.cfg.Openshift)
} else {
apiServer.SecurityContext = securitycontext.NewNonRootContext()
}

return apiServer
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/render/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1623,11 +1623,11 @@ var _ = Describe("API server rendering tests (Calico)", func() {
Expect(d.Spec.Template.Spec.Containers[0].ReadinessProbe.HTTPGet.Scheme).To(BeEquivalentTo("HTTPS"))
Expect(d.Spec.Template.Spec.Containers[0].ReadinessProbe.PeriodSeconds).To(BeEquivalentTo(60))

Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation).To(BeTrue())
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.Privileged).To(BeTrue())
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.RunAsGroup).To(BeEquivalentTo(0))
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.RunAsNonRoot).To(BeFalse())
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser).To(BeEquivalentTo(0))
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation).To(BeFalse())
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.Privileged).To(BeFalse())
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.RunAsGroup).To(BeEquivalentTo(10001))
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.RunAsNonRoot).To(BeTrue())
Expect(*d.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser).To(BeEquivalentTo(10001))
Expect(d.Spec.Template.Spec.Containers[0].SecurityContext.Capabilities).To(Equal(
&corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
Expand Down