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

operator: Set seccomp profile to runtime default for all variants #9457

Merged
merged 8 commits into from
Jun 1, 2023
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
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Main

- [9457](https://github.com/grafana/loki/pull/9457) **Red-GV**: Set seccomp profile to runtime default
- [9448](https://github.com/grafana/loki/pull/9448) **btaani**: Include runtime-config in compiling the SHA1 checksum
- [9511](https://github.com/grafana/loki/pull/9511) **xperimental**: Do not update status after setting degraded condition
- [9405](https://github.com/grafana/loki/pull/9405) **periklis**: Add support for configuring HTTP server timeouts
Expand Down
6 changes: 3 additions & 3 deletions operator/apis/config/v1/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ type FeatureGates struct {
// More details: https://grafana.com/docs/loki/latest/release-notes/v2-5/#usage-reporting
GrafanaLabsUsageReport bool `json:"grafanaLabsUsageReport,omitempty"`

// RuntimeSeccompProfile enables the restricted seccomp profile on all
// Lokistack components.
RuntimeSeccompProfile bool `json:"runtimeSeccompProfile,omitempty"`
// RestrictedPodSecurityStandard enables compliance with the restrictive pod security standard.
// More details: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
RestrictedPodSecurityStandard bool `json:"restrictedPodSecurityStandard,omitempty"`

// LokiStackWebhook enables the LokiStack CR validation and conversion webhooks.
LokiStackWebhook bool `json:"lokiStackWebhook,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data:
# Component feature gates
#
lokiStackGateway: true
runtimeSeccompProfile: true
restrictedPodSecurityStandard: true
defaultNodeAffinity: true
#
# Webhook feature gates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: docker.io/grafana/loki-operator:main-ac1c1fd
createdAt: "2023-05-22T15:22:48Z"
createdAt: "2023-05-24T15:10:18Z"
description: The Community Loki Operator provides Kubernetes native deployment
and management of Loki and related logging components.
operators.operatorframework.io/builder: operator-sdk-unknown
Expand Down Expand Up @@ -1643,6 +1643,8 @@ spec:
kubernetes.io/os: linux
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationGracePeriodSeconds: 10
volumes:
- configMap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data:
resourceName: e3716011.grafana.com
featureGates:
lokiStackGateway: true
runtimeSeccompProfile: false
restrictedPodSecurityStandard: false
#
# Webhook feature gates
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: docker.io/grafana/loki-operator:main-ac1c1fd
createdAt: "2023-05-22T15:22:44Z"
createdAt: "2023-05-24T15:10:16Z"
description: The Community Loki Operator provides Kubernetes native deployment
and management of Loki and related logging components.
operators.operatorframework.io/builder: operator-sdk-unknown
Expand Down Expand Up @@ -1594,11 +1594,6 @@ spec:
initialDelaySeconds: 5
periodSeconds: 10
resources: {}
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: webhook-cert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data:
#
lokiStackGateway: true
grafanaLabsUsageReport: false
runtimeSeccompProfile: false
restrictedPodSecurityStandard: true
defaultNodeAffinity: true
#
# Webhook feature gates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: quay.io/openshift-logging/loki-operator:v0.1.0
createdAt: "2023-05-22T15:22:53Z"
createdAt: "2023-05-24T15:10:20Z"
description: |
The Loki Operator for OCP provides a means for configuring and managing a Loki stack for cluster logging.
## Prerequisites and Requirements
Expand Down Expand Up @@ -1628,6 +1628,8 @@ spec:
kubernetes.io/os: linux
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationGracePeriodSeconds: 10
volumes:
- configMap:
Expand Down
2 changes: 1 addition & 1 deletion operator/cmd/loki-broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *config) registerFlags(f *flag.FlagSet) {
f.BoolVar(&c.featureFlags.ServiceMonitorTLSEndpoints, "with-service-monitor-tls-endpoints", false, "Enable TLS endpoint for service monitors.")
f.BoolVar(&c.featureFlags.LokiStackAlerts, "with-lokistack-alerts", false, "Enables prometheus alerts")
f.BoolVar(&c.featureFlags.LokiStackGateway, "with-lokistack-gateway", false, "Enables the manifest creation for the entire lokistack-gateway.")
f.BoolVar(&c.featureFlags.RuntimeSeccompProfile, "with-runtime-seccomp-profile", false, "Enables the usage of the runtime/default seccomp profile for pods and containers.")
f.BoolVar(&c.featureFlags.RestrictedPodSecurityStandard, "with-restricted-pod-security-standard", false, "Enable restricted security standard settings")
// Object storage options
c.objectStorage = storage.Options{
S3: &storage.S3StorageConfig{},
Expand Down
7 changes: 0 additions & 7 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ spec:
ports:
- containerPort: 8080
name: metrics
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -45,5 +40,3 @@ spec:
nodeSelector:
kubernetes.io/os: linux
terminationGracePeriodSeconds: 10
securityContext:
runAsNonRoot: true
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ featureGates:
# Component feature gates
#
lokiStackGateway: true
runtimeSeccompProfile: true
restrictedPodSecurityStandard: true
defaultNodeAffinity: true
#
# Webhook feature gates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ leaderElection:
resourceName: e3716011.grafana.com
featureGates:
lokiStackGateway: true
runtimeSeccompProfile: false
restrictedPodSecurityStandard: false
#
# Webhook feature gates
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ featureGates:
# Component feature gates
#
lokiStackGateway: true
runtimeSeccompProfile: true
restrictedPodSecurityStandard: false
#
# Webhook feature gates
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ featureGates:
#
lokiStackGateway: true
grafanaLabsUsageReport: false
runtimeSeccompProfile: false
restrictedPodSecurityStandard: true
defaultNodeAffinity: true
#
# Webhook feature gates
Expand Down
1 change: 1 addition & 0 deletions operator/config/overlays/openshift/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ patchesStrategicMerge:
- manager_auth_proxy_patch.yaml
- manager_related_image_patch.yaml
- manager_run_flags_patch.yaml
- manager_security_context_patch.yaml
- manager_webhook_patch.yaml
- prometheus_service_monitor_patch.yaml

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
spec:
template:
spec:
containers:
- name: manager
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
29 changes: 22 additions & 7 deletions operator/internal/manifests/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,15 @@ func TestBuildAll_WithFeatureGates_GRPCEncryption(t *testing.T) {
}
}

func TestBuildAll_WithFeatureGates_RuntimeSeccompProfile(t *testing.T) {
func TestBuildAll_WithFeatureGates_RestrictedPodSecurityStandard(t *testing.T) {
type test struct {
desc string
BuildOptions Options
}

table := []test{
{
desc: "disabled default/runtime seccomp profile",
desc: "disabled restricted security standard",
BuildOptions: Options{
Name: "test",
Namespace: "test",
Expand Down Expand Up @@ -700,13 +700,13 @@ func TestBuildAll_WithFeatureGates_RuntimeSeccompProfile(t *testing.T) {
},
},
Gates: configv1.FeatureGates{
RuntimeSeccompProfile: false,
RestrictedPodSecurityStandard: false,
},
Timeouts: defaultTimeoutConfig,
},
},
{
desc: "enabled default/runtime seccomp profile",
desc: "enabled restricted security standard",
BuildOptions: Options{
Name: "test",
Namespace: "test",
Expand Down Expand Up @@ -743,7 +743,7 @@ func TestBuildAll_WithFeatureGates_RuntimeSeccompProfile(t *testing.T) {
},
},
Gates: configv1.FeatureGates{
RuntimeSeccompProfile: true,
RestrictedPodSecurityStandard: true,
},
Timeouts: defaultTimeoutConfig,
},
Expand Down Expand Up @@ -778,11 +778,26 @@ func TestBuildAll_WithFeatureGates_RuntimeSeccompProfile(t *testing.T) {
}

t.Run(name, func(t *testing.T) {
if tst.BuildOptions.Gates.RuntimeSeccompProfile {
if tst.BuildOptions.Gates.RestrictedPodSecurityStandard {
require.NotNil(t, spec.SecurityContext)

require.True(t, *spec.SecurityContext.RunAsNonRoot)

require.NotNil(t, spec.SecurityContext.SeccompProfile)
require.Equal(t, spec.SecurityContext.SeccompProfile.Type, corev1.SeccompProfileTypeRuntimeDefault)
} else {
require.Nil(t, spec.SecurityContext.SeccompProfile)
require.Nil(t, spec.SecurityContext)
}

for _, c := range spec.Containers {
if tst.BuildOptions.Gates.RestrictedPodSecurityStandard {
require.False(t, *c.SecurityContext.AllowPrivilegeEscalation)

require.Empty(t, c.SecurityContext.Capabilities.Add)
require.Equal(t, c.SecurityContext.Capabilities.Drop, []corev1.Capability{"ALL"})
} else {
require.Nil(t, c.SecurityContext)
}
}
})
}
Expand Down
8 changes: 6 additions & 2 deletions operator/internal/manifests/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func BuildCompactor(opts Options) ([]client.Object, error) {
}
}

if opts.Gates.RestrictedPodSecurityStandard {
if err := configurePodSpecForRestrictedStandard(&statefulSet.Spec.Template.Spec); err != nil {
return nil, err
}
}

if err := configureHashRingEnv(&statefulSet.Spec.Template.Spec, opts); err != nil {
return nil, err
}
Expand Down Expand Up @@ -120,10 +126,8 @@ func NewCompactorStatefulSet(opts Options) *appsv1.StatefulSet {
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: "File",
ImagePullPolicy: "IfNotPresent",
SecurityContext: containerSecurityContext(),
},
},
SecurityContext: podSecurityContext(opts.Gates.RuntimeSeccompProfile),
}

if opts.Stack.Template != nil && opts.Stack.Template.Compactor != nil {
Expand Down
8 changes: 6 additions & 2 deletions operator/internal/manifests/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func BuildDistributor(opts Options) ([]client.Object, error) {
}
}

if opts.Gates.RestrictedPodSecurityStandard {
if err := configurePodSpecForRestrictedStandard(&deployment.Spec.Template.Spec); err != nil {
return nil, err
}
}

if err := configureHashRingEnv(&deployment.Spec.Template.Spec, opts); err != nil {
return nil, err
}
Expand Down Expand Up @@ -117,10 +123,8 @@ func NewDistributorDeployment(opts Options) *appsv1.Deployment {
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: "File",
ImagePullPolicy: "IfNotPresent",
SecurityContext: containerSecurityContext(),
},
},
SecurityContext: podSecurityContext(opts.Gates.RuntimeSeccompProfile),
}

if opts.Stack.Template != nil && opts.Stack.Template.Distributor != nil {
Expand Down
18 changes: 5 additions & 13 deletions operator/internal/manifests/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ViaQ/logerr/v2/kverrors"
"github.com/imdario/mergo"

configv1 "github.com/grafana/loki/operator/apis/config/v1"
"github.com/grafana/loki/operator/internal/manifests/internal/gateway"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -82,7 +81,11 @@ func BuildGateway(opts Options) ([]client.Object, error) {
objs = configureGatewayObjsForMode(objs, opts)
}

configureDeploymentForRestrictedPolicy(dpl, opts.Gates)
if opts.Gates.RestrictedPodSecurityStandard {
if err := configurePodSpecForRestrictedStandard(&dpl.Spec.Template.Spec); err != nil {
return nil, err
}
}

return objs, nil
}
Expand Down Expand Up @@ -598,14 +601,3 @@ func configureGatewayRulesAPI(podSpec *corev1.PodSpec, stackName, stackNs string

return nil
}

func configureDeploymentForRestrictedPolicy(d *appsv1.Deployment, fg configv1.FeatureGates) {
podSpec := d.Spec.Template.Spec

podSpec.SecurityContext = podSecurityContext(fg.RuntimeSeccompProfile)
for i := range podSpec.Containers {
podSpec.Containers[i].SecurityContext = containerSecurityContext()
}

d.Spec.Template.Spec = podSpec
}
8 changes: 6 additions & 2 deletions operator/internal/manifests/indexgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func BuildIndexGateway(opts Options) ([]client.Object, error) {
}
}

if opts.Gates.RestrictedPodSecurityStandard {
if err := configurePodSpecForRestrictedStandard(&statefulSet.Spec.Template.Spec); err != nil {
return nil, err
}
}

if err := configureHashRingEnv(&statefulSet.Spec.Template.Spec, opts); err != nil {
return nil, err
}
Expand Down Expand Up @@ -122,10 +128,8 @@ func NewIndexGatewayStatefulSet(opts Options) *appsv1.StatefulSet {
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: "File",
ImagePullPolicy: "IfNotPresent",
SecurityContext: containerSecurityContext(),
},
},
SecurityContext: podSecurityContext(opts.Gates.RuntimeSeccompProfile),
}

if opts.Stack.Template != nil && opts.Stack.Template.IndexGateway != nil {
Expand Down
8 changes: 6 additions & 2 deletions operator/internal/manifests/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func BuildIngester(opts Options) ([]client.Object, error) {
}
}

if opts.Gates.RestrictedPodSecurityStandard {
if err := configurePodSpecForRestrictedStandard(&statefulSet.Spec.Template.Spec); err != nil {
return nil, err
}
}

if err := configureHashRingEnv(&statefulSet.Spec.Template.Spec, opts); err != nil {
return nil, err
}
Expand Down Expand Up @@ -132,10 +138,8 @@ func NewIngesterStatefulSet(opts Options) *appsv1.StatefulSet {
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: "File",
ImagePullPolicy: "IfNotPresent",
SecurityContext: containerSecurityContext(),
},
},
SecurityContext: podSecurityContext(opts.Gates.RuntimeSeccompProfile),
}

if opts.Stack.Template != nil && opts.Stack.Template.Ingester != nil {
Expand Down
Loading