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

Bug 1868976: jsonnet: configure SCCs #981

Merged
merged 3 commits into from Nov 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion assets/alertmanager/alertmanager.yaml
Expand Up @@ -112,6 +112,9 @@ spec:
- alertmanager-main-tls
- alertmanager-main-proxy
- alertmanager-kube-rbac-proxy
securityContext: {}
securityContext:
fsGroup: 65534
runAsNonRoot: true
runAsUser: 65534
serviceAccountName: alertmanager-main
version: v0.21.0
8 changes: 8 additions & 0 deletions assets/alertmanager/cluster-role.yaml
Expand Up @@ -15,3 +15,11 @@ rules:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- security.openshift.io
resourceNames:
- nonroot
resources:
- securitycontextconstraints
verbs:
- use
8 changes: 8 additions & 0 deletions assets/prometheus-k8s/cluster-role.yaml
Expand Up @@ -31,3 +31,11 @@ rules:
- namespaces
verbs:
- get
- apiGroups:
- security.openshift.io
resourceNames:
- nonroot
resources:
- securitycontextconstraints
verbs:
- use
5 changes: 4 additions & 1 deletion assets/prometheus-k8s/prometheus.yaml
Expand Up @@ -155,7 +155,10 @@ spec:
- prometheus-k8s-proxy
- prometheus-k8s-htpasswd
- kube-rbac-proxy
securityContext: {}
securityContext:
fsGroup: 65534
runAsNonRoot: true
runAsUser: 65534
serviceAccountName: prometheus-k8s
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {}
Expand Down
8 changes: 8 additions & 0 deletions assets/prometheus-user-workload/cluster-role.yaml
Expand Up @@ -47,3 +47,11 @@ rules:
- alertmanagers
verbs:
- get
- apiGroups:
- security.openshift.io
resourceNames:
- nonroot
resources:
- securitycontextconstraints
verbs:
- use
5 changes: 4 additions & 1 deletion assets/prometheus-user-workload/prometheus.yaml
Expand Up @@ -101,7 +101,10 @@ spec:
openshift.io/prometheus-rule-evaluation-scope: leaf-prometheus
secrets:
- prometheus-user-workload-tls
securityContext: {}
securityContext:
fsGroup: 65534
runAsNonRoot: true
runAsUser: 65534
serviceAccountName: prometheus-user-workload
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {}
Expand Down
8 changes: 8 additions & 0 deletions assets/thanos-ruler/cluster-role.yaml
Expand Up @@ -15,3 +15,11 @@ rules:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- security.openshift.io
resourceNames:
- nonroot
resources:
- securitycontextconstraints
verbs:
- use
4 changes: 4 additions & 0 deletions assets/thanos-ruler/thanos-ruler.yaml
Expand Up @@ -84,6 +84,10 @@ spec:
operator: NotIn
values:
- leaf-prometheus
securityContext:
fsGroup: 65534
runAsNonRoot: true
runAsUser: 65534
serviceAccountName: thanos-ruler
volumes:
- configmap:
Expand Down
22 changes: 20 additions & 2 deletions jsonnet/alertmanager.jsonnet
Expand Up @@ -21,6 +21,20 @@ local authorizationRole = policyRule.new() +
]) +
policyRule.withVerbs(['create']);

// By default authenticated service accounts are assigned to the `restricted` SCC which implies MustRunAsRange.
// This is problematic with statefulsets as UIDs (and file permissions) can change if SCCs are elevated.
// Instead, this sets the `nonroot` SCC in conjunction with a static fsGroup and runAsUser security context below
// to be immune against UID changes.
local sccRole = policyRule.new() +
s-urbaniak marked this conversation as resolved.
Show resolved Hide resolved
policyRule.withApiGroups(['security.openshift.io']) +
policyRule.withResources([
'securitycontextconstraints',
]) +
policyRule.withResourceNames([
'nonroot',
]) +
policyRule.withVerbs(['use']);

{
alertmanager+:: {

Expand Down Expand Up @@ -96,7 +110,7 @@ local authorizationRole = policyRule.new() +
// requires the `create` action on both of these.

clusterRole:
local rules = [authenticationRole, authorizationRole];
local rules = [authenticationRole, authorizationRole, sccRole];

clusterRole.new() +
clusterRole.mixin.metadata.withName('alertmanager-main') +
Expand Down Expand Up @@ -160,7 +174,11 @@ local authorizationRole = policyRule.new() +
alertmanager+:
{
spec+: {
securityContext: {},
securityContext: {
fsGroup: 65534,
runAsNonRoot: true,
runAsUser: 65534,
},
priorityClassName: 'system-cluster-critical',
secrets: [
'alertmanager-main-tls',
Expand Down
23 changes: 22 additions & 1 deletion jsonnet/prometheus-user-workload.jsonnet
Expand Up @@ -54,6 +54,22 @@ local alertmanagerRole =
]) +
policyRule.withVerbs(['get']);

// By default authenticated service accounts are assigned to the `restricted` SCC which implies MustRunAsRange.
// This is problematic with statefulsets as UIDs (and file permissions) can change if SCCs are elevated.
// Instead, this sets the `nonroot` SCC in conjunction with a static fsGroup and runAsUser security context below
// to be immune against UID changes.
local sccRole =
s-urbaniak marked this conversation as resolved.
Show resolved Hide resolved
policyRule.new() +
policyRule.withApiGroups(['security.openshift.io']) +
policyRule.withResources([
'securitycontextconstraints',
]) +
policyRule.withResourceNames([
'nonroot',
]) +
policyRule.withVerbs(['use']);


{
prometheusUserWorkload+:: $.prometheus {
name:: 'user-workload',
Expand Down Expand Up @@ -104,6 +120,7 @@ local alertmanagerRole =
namespacesRole,
discoveryRole,
alertmanagerRole,
sccRole,
]),

// This avoids creating service monitors which are already managed by the respective operators.
Expand Down Expand Up @@ -197,7 +214,11 @@ local alertmanagerRole =
cpu: '6m',
},
},
securityContext: {},
securityContext: {
fsGroup: 65534,
runAsNonRoot: true,
runAsUser: 65534,
},
secrets: [
'prometheus-user-workload-tls',
],
Expand Down
25 changes: 22 additions & 3 deletions jsonnet/prometheus.jsonnet
Expand Up @@ -33,6 +33,21 @@ local namespacesRole =
]) +
policyRule.withVerbs(['get']);

// By default authenticated service accounts are assigned to the `restricted` SCC which implies MustRunAsRange.
// This is problematic with statefulsets as UIDs (and file permissions) can change if SCCs are elevated.
// Instead, this sets the `nonroot` SCC in conjunction with a static fsGroup and runAsUser security context below
// to be immune against UID changes.
local sccRole =
policyRule.new() +
policyRule.withApiGroups(['security.openshift.io']) +
policyRule.withResources([
'securitycontextconstraints',
]) +
policyRule.withResourceNames([
'nonroot',
]) +
policyRule.withVerbs(['use']);

{
prometheusK8s+:: {
trustedCaBundle:
Expand Down Expand Up @@ -120,7 +135,7 @@ local namespacesRole =
// SubjectAccessReview required by the Alertmanager instances.

clusterRole+:
clusterRole.withRulesMixin([authenticationRole, authorizationRole, namespacesRole]),
clusterRole.withRulesMixin([authenticationRole, authorizationRole, namespacesRole, sccRole]),

// The proxy secret is there to encrypt session created by the oauth proxy.

Expand Down Expand Up @@ -241,7 +256,7 @@ local namespacesRole =
},

// TODO: Adding this to our stack is not as easy
// as sidecar listens on 127.0.0.1:10902 and we
// as sidecar listens on 127.0.0.1:10902 and we
// need kube-rbac-proxy in front of it.

serviceMonitorThanosSidecar:: null,
Expand Down Expand Up @@ -287,7 +302,11 @@ local namespacesRole =
cpu: '70m',
},
},
securityContext: {},
securityContext: {
fsGroup: 65534,
runAsNonRoot: true,
runAsUser: 65534,
},
secrets+: [
'prometheus-k8s-tls',
'prometheus-k8s-proxy',
Expand Down
21 changes: 20 additions & 1 deletion jsonnet/thanos-ruler.jsonnet
Expand Up @@ -25,6 +25,20 @@ local authorizationRole =
]) +
policyRule.withVerbs(['create']);

// By default authenticated service accounts are assigned to the `restricted` SCC which implies MustRunAsRange.
// This is problematic with statefulsets as UIDs (and file permissions) can change if SCCs are elevated.
// Instead, this sets the `nonroot` SCC in conjunction with a static fsGroup and runAsUser security context below
// to be immune against UID changes.
local sccRole = policyRule.new() +
policyRule.withApiGroups(['security.openshift.io']) +
policyRule.withResources([
'securitycontextconstraints',
]) +
policyRule.withResourceNames([
'nonroot',
]) +
policyRule.withVerbs(['use']);

local thanosRulerRules =
(import 'github.com/thanos-io/thanos/mixin/alerts/rule.libsonnet') {
rule+:: {
Expand Down Expand Up @@ -95,7 +109,7 @@ local thanosRulerRules =
clusterRole:
clusterRole.new() +
clusterRole.mixin.metadata.withName('thanos-ruler') +
clusterRole.withRules([authenticationRole, authorizationRole]),
clusterRole.withRules([authenticationRole, authorizationRole, sccRole]),

clusterRoleBinding:
local clusterRoleBinding = k.rbac.v1.clusterRoleBinding;
Expand Down Expand Up @@ -269,6 +283,11 @@ local thanosRulerRules =
},
},
spec: {
securityContext: {
fsGroup: 65534,
runAsNonRoot: true,
runAsUser: 65534,
},
replicas: 2,
image: $._config.imageRepos.openshiftThanos + ':' + $._config.versions.openshiftThanos,
grpcServerTlsConfig: {
Expand Down
8 changes: 8 additions & 0 deletions manifests/0000_50_cluster-monitoring-operator_02-role.yaml
Expand Up @@ -167,6 +167,14 @@ rules:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- security.openshift.io
resourceNames:
- nonroot
resources:
- securitycontextconstraints
verbs:
- use
- apiGroups:
- ''
resources:
Expand Down