Skip to content

Commit 3071e2d

Browse files
authored
Add instructions for creating a custom Security Context Constraint (#2003)
* update openshift security docs to include custom scc instructions Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com> * update based on review comments Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com> * updates after review with ryan Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com> * updates after review with ryan Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com>
1 parent db44c57 commit 3071e2d

File tree

1 file changed

+93
-25
lines changed

1 file changed

+93
-25
lines changed

docs-source/content/security/openshift.md

Lines changed: 93 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,109 @@ weight: 7
55
description: "OpenShift information for the operator"
66
---
77

8-
#### OpenShift `anyuid` security context
8+
#### Security requirements to run WebLogic in OpenShift
99

10-
The Docker images that Oracle publishes default to the container user
11-
as `oracle`, which is UID `1000` and GID `1000`. When running the
12-
Oracle images or layered images that retain the default user as
13-
`oracle` with OpenShift, the `anyuid` security context constraint
14-
is required to ensure proper access to the file system within the
15-
Docker image. This means that the administrator must:
10+
WebLogic Server Kubernetes Operator Docker images starting with version 3.1 and
11+
WebLogic Server Docker images obtained from Oracle Container Registry after August 2020
12+
have an `oracle` user with UID 1000 with the default group set to `root`.
1613

17-
1. Ensure the `anyuid` security content is granted
18-
2. Ensure that WebLogic containers are annotated with `openshift.io/scc: anyuid`
19-
20-
For example, to update the OpenShift policy, use:
14+
Here is an excerpt from a standard WebLogic [Dockerfile](https://github.com/oracle/docker-images/blob/master/OracleWebLogic/dockerfiles/12.2.1.4/Dockerfile.generic#L89)
15+
that demonstrates how the file system group ownership is configured in the standard WebLogic Server images:
2116

2217
```bash
23-
$ oc adm policy add-scc-to-user anyuid -z default
18+
# Setup filesystem and oracle user
19+
# Adjust file permissions, go to /u01 as user 'oracle' to proceed with WLS installation
20+
# ------------------------------------------------------------
21+
RUN mkdir -p /u01 && \
22+
chmod 775 /u01 && \
23+
useradd -b /u01 -d /u01/oracle -m -s /bin/bash oracle && \
24+
chown oracle:root /u01
25+
26+
COPY --from=builder --chown=oracle:root /u01 /u01
2427
```
2528

26-
To annotate the WebLogic containers, update the WebLogic `Domain` resource
27-
to include `annotations` for the `serverPod`. For example:
29+
OpenShift, by default, enforces the `restricted` security context constraint which
30+
allocates a high, random UID in the `root` group for each container. The standard
31+
images mentioned above are designed to work with the `restricted` security context constraint.
32+
33+
However, if you build your own image, have an older version of an image, or obtain an
34+
image from another source, it may not have the necessary permissions. You may need to
35+
configure similar file system permissions to allow your image to work in OpenShift.
36+
Specifically, you need to make sure the following directories have `root` as their
37+
group, and that the group read, write and execute permissions are set (enabled):
38+
39+
* For the operator, `/operator` and `/logs`.
40+
* For WebLogic Server images, `/u01` (or the ultimate parent directory of your
41+
Oracle Home and domain if you put them in different locations).
42+
43+
If your OpenShift environment has a different default security context constraint,
44+
you may need to configure OpenShift to allow use of UID 1000 by creating
45+
a security context constraint. Oracle recommends that you define
46+
a custom security context constraint that has just the permissions that are required
47+
and apply that to WebLogic pods. Oracle does not recommend using the built-in `anyuid`
48+
Security Context Constraint, because it provides more permissions
49+
than are needed, and is therefore less secure.
50+
51+
#### Create a custom Security Context Constraint
2852

29-
``` yaml
30-
kind: Domain
53+
To create a custom security context constraint, create a YAML file with the following
54+
content. This example assumes that your OpenShift project is called `weblogic` and
55+
that the service account you will use to run the operator and domains
56+
is called `weblogic-operator`. You should change these
57+
in the `groups` and `users` sections to match your environment.
58+
59+
```yaml
60+
kind: SecurityContextConstraints
61+
apiVersion: v1
3162
metadata:
32-
name: domain1
33-
spec:
34-
domainUID: domain1
35-
serverPod:
36-
env:
37-
- name: var1
38-
value: value1
39-
annotations:
40-
openshift.io/scc: anyuid
63+
name: uid1000
64+
allowHostDirVolumePlugin: false
65+
allowHostIPC: false
66+
allowHostNetwork: false
67+
allowHostPID: false
68+
allowHostPorts: false
69+
allowPrivilegeEscalation: true
70+
allowPrivilegedContainer: false
71+
fsGroup:
72+
type: MustRunAs
73+
groups:
74+
- system:serviceaccounts:weblogic
75+
readOnlyRootFilesystem: false
76+
requiredDropCapabilities:
77+
- KILL
78+
- MKNOD
79+
- SETUID
80+
- SETGID
81+
runAsUser:
82+
type: MustRunAs
83+
uid: 1000
84+
seLinuxContext:
85+
type: MustRunAs
86+
supplementalGroups:
87+
type: RunAsAny
88+
users:
89+
- system:serviceaccount:weblogic:weblogic-operator
90+
volumes:
91+
- configMap
92+
- downwardAPI
93+
- emptyDir
94+
- persistentVolumeClaim
95+
- projected
96+
- secret
97+
```
98+
99+
Assuming you called that file `uid1000.yaml`, you can create the security context constraint
100+
using the following command:
101+
102+
```bash
103+
$ oc create -f uid1000.yaml
41104
```
42105

106+
After you have created the security context constraint, you can install the WebLogic Server Kubernetes Operator.
107+
Make sure you use the same service account to which you granted permission in the security
108+
context constraint (`weblogic-operator` in the preceding example). The operator will then run
109+
with UID 1000, and any WebLogic domain it creates will also run with UID 1000.
110+
43111
{{% notice note %}}
44112
For additional information about OpenShift requirements and the operator,
45113
see the [OpenShift]({{<relref "/userguide/introduction/introduction#openshift">}}) section in the User Guide.

0 commit comments

Comments
 (0)