Skip to content

Commit

Permalink
ceph: run operator with rook user
Browse files Browse the repository at this point in the history
The rook operator as well as the toolbox pod run with the "rook" user
with UID 2016. The UID was chosen based on the year of the initial
commit in the rook/rook repository.
No more root user running.

Closes: #8734
Signed-off-by: Sébastien Han <seb@redhat.com>
  • Loading branch information
leseb committed Sep 24, 2021
1 parent 12506c7 commit 9745ef0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions PendingReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ v1.8...
to update to a newer version before updating to Rook v1.8.

## Features

- The Rook Operator and the toolbox now run under the "rook" user and does not use "root" anymore.
4 changes: 4 additions & 0 deletions cluster/charts/rook-ceph/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: ["ceph", "operator"]
securityContext:
runAsNonRoot: true
runAsUser: 2016
runAsGroup: 2016
volumeMounts:
- mountPath: /var/lib/rook
name: rook-config
Expand Down
4 changes: 4 additions & 0 deletions cluster/examples/kubernetes/ceph/operator-openshift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ spec:
- name: rook-ceph-operator
image: rook/ceph:master
args: ["ceph", "operator"]
securityContext:
runAsNonRoot: true
runAsUser: 2016
runAsGroup: 2016
volumeMounts:
- mountPath: /var/lib/rook
name: rook-config
Expand Down
4 changes: 4 additions & 0 deletions cluster/examples/kubernetes/ceph/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ spec:
- name: rook-ceph-operator
image: rook/ceph:master
args: ["ceph", "operator"]
securityContext:
runAsNonRoot: true
runAsUser: 2016
runAsGroup: 2016
volumeMounts:
- mountPath: /var/lib/rook
name: rook-config
Expand Down
4 changes: 4 additions & 0 deletions cluster/examples/kubernetes/ceph/toolbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ spec:
command: ["/tini"]
args: ["-g", "--", "/usr/local/bin/toolbox.sh"]
imagePullPolicy: IfNotPresent
securityContext:
runAsNonRoot: true
runAsUser: 2016
runAsGroup: 2016
env:
- name: ROOK_CEPH_USERNAME
valueFrom:
Expand Down
5 changes: 5 additions & 0 deletions images/ceph/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ COPY rook toolbox.sh set-ceph-debug-level /usr/local/bin/
COPY ceph-monitoring /etc/ceph-monitoring
COPY rook-external /etc/rook-external/
COPY ceph-csv-templates /etc/ceph-csv-templates
RUN useradd rook -u 2016 # 2016 is the UID of the rook user and also the year of the first commit in the project
RUN mkdir -p /var/lib/rook /etc/webhook
RUN chown rook:rook /var/lib/rook /etc/webhook
RUN chmod 755 /var/lib/rook /etc/webhook
USER 2016
ENTRYPOINT ["/tini", "--", "/usr/local/bin/rook"]
CMD [""]
2 changes: 1 addition & 1 deletion pkg/operator/ceph/cr_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
)

const (
certDir = "/etc/webhook"
certDir = "/etc/webhook/certs"
)

var (
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/ceph/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func isSecretPresent(ctx context.Context, context *clusterd.Context) (bool, erro

logger.Infof("admission webhook secret %q found", admissionControllerAppName)
for k, data := range s.Data {
if err = os.MkdirAll(certDir, 0700); err != nil {
return false, errors.Wrapf(err, "failed to create webhook certificate directory %q", certDir)
}
path := fmt.Sprintf("%s/%s", certDir, k)
err := ioutil.WriteFile(path, data, 0400)
if err != nil {
Expand Down

0 comments on commit 9745ef0

Please sign in to comment.