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 28, 2021
1 parent 62d66b0 commit afb49b8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions PendingReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ v1.8...

- The Rook Operator does not use "tini" as an init process. Instead, it uses the "rook" and handles
signals on its own.
- 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 @@ -23,6 +23,10 @@ spec:
args: ["-m", "-c", "/usr/local/bin/toolbox.sh"]
imagePullPolicy: IfNotPresent
tty: true
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 @@ -20,5 +20,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 ["/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, 0755); 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 afb49b8

Please sign in to comment.