Skip to content

Commit e5fe8c9

Browse files
authored
Back out the default security context functionality as this breaks on OpenShift (#771)
1 parent 3afecb1 commit e5fe8c9

16 files changed

+4
-559
lines changed

api/v1/coherenceresourcespec_types.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,6 @@ type CoherenceResourceSpec struct {
193193
// +optional
194194
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
195195
// SecurityContext is the PodSecurityContext that will be added to all the Pods in this deployment.
196-
// If no security context is specified the Operator will create one with the following spec
197-
//
198-
// securityContext:
199-
// runAsNonRoot: true
200-
// runAsUser: 1000
201-
// runAsGroup: 2000
202-
// fsGroup: 2000
203-
// fsGroupChangePolicy: "OnRootMismatch"
204-
//
205196
// See: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
206197
// +optional
207198
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
@@ -748,7 +739,7 @@ func (in *CoherenceResourceSpec) CreatePodTemplateSpec(deployment CoherenceResou
748739
ReadinessGates: in.ReadinessGates,
749740
RuntimeClassName: in.RuntimeClassName,
750741
SchedulerName: notNilString(in.SchedulerName),
751-
SecurityContext: in.GetSecurityContext(),
742+
SecurityContext: in.SecurityContext,
752743
ServiceAccountName: in.GetServiceAccountName(),
753744
ShareProcessNamespace: in.ShareProcessNamespace,
754745
Tolerations: in.Tolerations,
@@ -830,14 +821,6 @@ func (in *CoherenceResourceSpec) GetImagePullSecrets() []corev1.LocalObjectRefer
830821
return secrets
831822
}
832823

833-
// GetSecurityContext returns the Pod security context to use.
834-
func (in *CoherenceResourceSpec) GetSecurityContext() *corev1.PodSecurityContext {
835-
if in == nil || in.SecurityContext == nil {
836-
return operator.DefaultSecurityContext()
837-
}
838-
return in.SecurityContext
839-
}
840-
841824
// GetServiceAccountName returns the service account name for the cluster.
842825
func (in *CoherenceResourceSpec) GetServiceAccountName() string {
843826
if in != nil {

api/v1/common_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ func createMinimalExpectedPodSpec(deployment coh.CoherenceResource) corev1.PodTe
503503
VolumeSource: emptyVolume,
504504
},
505505
},
506-
SecurityContext: operator.DefaultSecurityContext(),
507506
TopologySpreadConstraints: spec.EnsureTopologySpreadConstraints(deployment),
508507
Affinity: spec.CreateDefaultPodAffinity(deployment),
509508
ServiceAccountName: spec.GetServiceAccountName(),

api/v1/constants.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
package v1
88

9-
import (
10-
"github.com/oracle/coherence-operator/pkg/operator"
11-
corev1 "k8s.io/api/core/v1"
12-
)
9+
import "github.com/oracle/coherence-operator/pkg/operator"
1310

1411
const (
1512
// DefaultReplicas is the default number of replicas that will be created for a deployment if no value is specified in the spec
@@ -77,17 +74,6 @@ const (
7774
// DefaultServiceAccount is the default k8s service account name.
7875
DefaultServiceAccount = "default"
7976

80-
// DefaultRunAsNonRoot is the default value for the runAsNonRoot field in the Pod security context
81-
DefaultRunAsNonRoot = true
82-
// DefaultRunAsUser is the default value for the runAsUser field in the Pod security context
83-
DefaultRunAsUser int64 = 1000
84-
// DefaultRunAsGroup is the default value for the runAsGroup field in the Pod security context
85-
DefaultRunAsGroup int64 = 2000
86-
// DefaultFsGroup is the default value for the fsGroup field in the Pod security context
87-
DefaultFsGroup int64 = DefaultRunAsGroup
88-
// DefaultFSGroupChangePolicy is the default value for the fsGroup field in the Pod security context
89-
DefaultFSGroupChangePolicy = corev1.FSGroupChangeOnRootMismatch
90-
9177
// ContainerNameCoherence is the Coherence container name
9278
ContainerNameCoherence = "coherence"
9379
// ContainerNameOperatorInit is the Operator init-container name

controllers/coherence_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (in *CoherenceReconciler) Reconcile(ctx context.Context, request ctrl.Reque
185185
in.GetEventRecorder().Event(deployment, coreV1.EventTypeNormal, reconciler.EventReasonUpdated, "added finalizer")
186186
}
187187
// we need to requeue as we have updated the Coherence resource
188-
return ctrl.Result{Requeue: true}, err
188+
return ctrl.Result{RequeueAfter: time.Minute}, err
189189
}
190190
}
191191

docs/about/04_coherence_spec.adoc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,7 @@ For example: +
332332
effect: "NoSchedule" + +
333333
+
334334
ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + m| []https://{k8s-doc-link}/#toleration-v1-core[corev1.Toleration] | false
335-
m| securityContext | SecurityContext is the PodSecurityContext that will be added to all the Pods in this deployment. If no security context is specified the Operator will create one with the following spec +
336-
+
337-
securityContext: + +
338-
runAsNonRoot: true + +
339-
runAsUser: 1000 + +
340-
runAsGroup: 2000 + +
341-
fsGroup: 2000 + +
342-
fsGroupChangePolicy: "OnRootMismatch" + +
343-
+
344-
See: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ m| *https://{k8s-doc-link}/#podsecuritycontext-v1-core[corev1.PodSecurityContext] | false
335+
m| securityContext | SecurityContext is the PodSecurityContext that will be added to all the Pods in this deployment. See: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ m| *https://{k8s-doc-link}/#podsecuritycontext-v1-core[corev1.PodSecurityContext] | false
345336
m| containerSecurityContext | ContainerSecurityContext is the SecurityContext that will be added to the Coherence container in each Pod in this deployment. See: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ m| *https://{k8s-doc-link}/#securitycontext-v1-core[corev1.SecurityContext] | false
346337
m| shareProcessNamespace | Share a single process namespace between all the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set. Optional: Default to false. m| *bool | false
347338
m| hostIPC | Use the host's ipc namespace. Optional: Default to false. m| *bool | false

docs/installation/011_install_manifests.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,3 @@ Or on MacOS, where `sed` is slightly different:
130130
----
131131
sed -i '' -e 's/replicas: 3/replicas: 1/g' coherence-operator.yaml
132132
----
133-

docs/other/045_security_context.adoc

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,6 @@ Kubernetes allows you to configure a https://kubernetes.io/docs/tasks/configure-
1616
1717
For more details see the Kubernetes https://kubernetes.io/docs/tasks/configure-pod-container/security-context/[Security Context] documentation.
1818
19-
=== The Default Security Context
20-
21-
The Coherence Operator configures a default security context for the Coherence Pods is none is specified in the `Coherence` resource yaml.
22-
The default security context looks like this:
23-
[source,yaml]
24-
----
25-
securityContext:
26-
runAsNonRoot: true
27-
runAsUser: 1000650000
28-
runAsGroup: 1000650000
29-
fsGroup: 1000650000
30-
fsGroupChangePolicy: "OnRootMismatch"
31-
----
32-
33-
It is possible to change the values used for the default security context by specifying them when the Operator is installed.
34-
See the <<config,Configure The Default Security Context>> section below.
35-
36-
It is possible to override this as described below.
37-
3819
=== Setting the Pod Security Context
3920
4021
To specify security settings for a Pod, include the `securityContext` field in the Coherence resource specification.
@@ -77,116 +58,3 @@ spec:
7758
capabilities:
7859
add: ["NET_ADMIN", "SYS_TIME"]
7960
----
80-
81-
[#config]
82-
=== Configure The Default Security Context
83-
84-
As already mentioned above the default security context created by the operator looks like this:
85-
86-
[source,yaml]
87-
----
88-
securityContext:
89-
runAsNonRoot: true
90-
runAsUser: 1000650000
91-
runAsGroup: 1000650000
92-
fsGroup: 1000650000
93-
fsGroupChangePolicy: "OnRootMismatch"
94-
----
95-
96-
The default values used for `runAsUser`, `runAsGroup` and `fsGroup` can be configured using the Operator's configuration file.
97-
98-
When the Operator is installed using the default installation it will read an optional configuration file from
99-
an optional `ConfigMap`. The `ConfigMap` must be created in the same namespace as the operator is running and
100-
should be named `coherence-operator`. The config map should contain a yaml file named `coherence-operator.yaml`.
101-
102-
[IMPORTANT]
103-
====
104-
The `coherence-operator` config map MUST be created before the Operator is installed, even if the yaml file
105-
that it contains is empty.
106-
107-
The Operator will watch the config file for changes, so if the `ConfigMap` is updated after the Operator is started,
108-
the changes will take effect. If the `ConfigMap` does not exist when the Operator is started then the config file
109-
cannot be mounted for the Operator to watch.
110-
====
111-
112-
113-
==== Disable The Default Security Context
114-
115-
To disable the creation of a default Pod security context for Coherence Pods, create a configuration file
116-
name `coherence-operator.yaml` with the following contents.
117-
118-
[source]
119-
.coherence-operator.yaml
120-
----
121-
coherenceSecurityContext:
122-
enabled: false
123-
----
124-
125-
Create the `ConfigMap` using the configuration file in the same namespace that the operator will be installed into.
126-
For example, if the operator is to be installed into a namespace named `coherence` the `ConfigMap` can be created
127-
using the following command:
128-
129-
[source,bash]
130-
----
131-
kubectl -n coherence create configmap coherence-operator \
132-
--from-file=coherence-operator.yaml
133-
----
134-
135-
With the `coherenceSecurityContext.enabled` field set to false, the Operator will not apply a default security context
136-
to the Coherence Pods. This may be useful in environments such as OpenShift which already apply a default security
137-
configuration to Pods.
138-
139-
==== Change The Default Security Context
140-
141-
In the configuration file, any field under the `coherenceSecurityContext` section will be applied to
142-
the default security context and override the operators default values.
143-
144-
For example, a `ConfigMap` could be created with the following file:
145-
146-
[source]
147-
.coherence-operator.yaml
148-
----
149-
coherenceSecurityContext:
150-
runAsUser: 1000
151-
----
152-
153-
This will override the `runAsUser` field to be set to `1000` resulting in a default security context as shown below:
154-
155-
[source,yaml]
156-
----
157-
securityContext:
158-
runAsNonRoot: true
159-
runAsUser: 1000
160-
runAsGroup: 1000650000
161-
fsGroup: 1000650000
162-
fsGroupChangePolicy: "OnRootMismatch"
163-
----
164-
165-
If the config file contains an empty value, this will result in the corresponding value being unset in the
166-
security context.
167-
This is useful for unsetting fields that the operator has default values for such as `runAsUser`, `runAsGroup`,
168-
`runAsNonRoot`, `fsGroup` and `fsGroupChangePolicy`.
169-
170-
171-
For example, the default `runAsUser` value is `1000650000`.
172-
The configuration file can be created with a `runAsUser` field with no value as shown below
173-
174-
[source]
175-
.coherence-operator.yaml
176-
----
177-
coherenceSecurityContext:
178-
runAsUser:
179-
----
180-
181-
This will result in a security context with the `runAsUser` unset.
182-
183-
[source,yaml]
184-
----
185-
securityContext:
186-
runAsNonRoot: true
187-
runAsUser:
188-
runAsGroup: 1000650000
189-
fsGroup: 1000650000
190-
fsGroupChangePolicy: "OnRootMismatch"
191-
----
192-

pkg/operator/operator.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/spf13/viper"
2020
corev1 "k8s.io/api/core/v1"
2121
"k8s.io/apimachinery/pkg/util/version"
22-
"k8s.io/utils/ptr"
2322
"os"
2423
"path/filepath"
2524
ctrl "sigs.k8s.io/controller-runtime"
@@ -47,25 +46,6 @@ const (
4746
CertTypeManual = "manual"
4847
CertManagerIssuerName = "coherence-webhook-server-issuer"
4948

50-
// DefaultRunAsNonRoot is the default value for the runAsNonRoot field in the Pod security context
51-
DefaultRunAsNonRoot = true
52-
// DefaultRunAsUser is the default value for the runAsUser field in the Pod security context
53-
DefaultRunAsUser int64 = 1000650000
54-
// DefaultRunAsGroup is the default value for the runAsGroup field in the Pod security context
55-
DefaultRunAsGroup int64 = 1000650000
56-
// DefaultFsGroup is the default value for the fsGroup field in the Pod security context
57-
DefaultFsGroup int64 = DefaultRunAsGroup
58-
// DefaultFSGroupChangePolicy is the default value for the fsGroup field in the Pod security context
59-
DefaultFSGroupChangePolicy = corev1.FSGroupChangeOnRootMismatch
60-
61-
ConfigKeyCoherenceSecurityContext = "coherenceSecurityContext"
62-
ConfigKeyCoherenceSecurityContextEnabled = "enabled"
63-
ConfigKeyCoherenceSecurityContextRunAsUser = "runAsUser"
64-
ConfigKeyCoherenceSecurityContextRunAsGroup = "runAsGroup"
65-
ConfigKeyCoherenceSecurityContextRunAsNonRoot = "runAsNonRoot"
66-
ConfigKeyCoherenceSecurityContextFsGroup = "fsGroup"
67-
ConfigKeyCoherenceSecurityContextFSGroupChangePolicy = "fSGroupChangePolicy"
68-
6949
DefaultMutatingWebhookName = "coherence-operator-mutating-webhook-configuration"
7050
DefaultValidatingWebhookName = "coherence-operator-validating-webhook-configuration"
7151

@@ -641,46 +621,3 @@ func RemoveFromUInt16Array(arr []uint16, toRemove uint16) []uint16 {
641621
}
642622
return arr
643623
}
644-
645-
// DefaultSecurityContext returns the default Pod security context that the Operator will apply
646-
// to Coherence pods. The values used can be overridden using command line args.
647-
func DefaultSecurityContext() *corev1.PodSecurityContext {
648-
v := GetViper()
649-
650-
m := v.GetStringMap(ConfigKeyCoherenceSecurityContext)
651-
if m == nil {
652-
m = make(map[string]interface{})
653-
}
654-
655-
enabled, found := m[strings.ToLower(ConfigKeyCoherenceSecurityContextEnabled)]
656-
if found && enabled == false {
657-
return nil
658-
}
659-
660-
sc := &corev1.PodSecurityContext{}
661-
662-
if v.IsSet(ConfigKeyCoherenceSecurityContext) {
663-
err := v.UnmarshalKey(ConfigKeyCoherenceSecurityContext, sc)
664-
if err != nil {
665-
setupLog.Error(err, "unable to unmarshal coherenceSecurityContext from Operator config file")
666-
}
667-
}
668-
669-
if _, found := m[strings.ToLower(ConfigKeyCoherenceSecurityContextRunAsUser)]; !found {
670-
sc.RunAsUser = ptr.To(DefaultRunAsUser)
671-
}
672-
if _, found := m[strings.ToLower(ConfigKeyCoherenceSecurityContextRunAsGroup)]; !found {
673-
sc.RunAsGroup = ptr.To(DefaultRunAsGroup)
674-
}
675-
if _, found := m[strings.ToLower(ConfigKeyCoherenceSecurityContextRunAsNonRoot)]; !found {
676-
sc.RunAsNonRoot = ptr.To(DefaultRunAsNonRoot)
677-
}
678-
if _, found := m[strings.ToLower(ConfigKeyCoherenceSecurityContextFsGroup)]; !found {
679-
sc.FSGroup = ptr.To(DefaultFsGroup)
680-
}
681-
if _, found := m[strings.ToLower(ConfigKeyCoherenceSecurityContextFSGroupChangePolicy)]; !found {
682-
sc.FSGroupChangePolicy = ptr.To(DefaultFSGroupChangePolicy)
683-
}
684-
685-
return sc
686-
}

pkg/runner/TestOperatorWithDefaultSecurityContextFsGroup.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

pkg/runner/TestOperatorWithDefaultSecurityContextFsGroupChangePolicy.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)