Fix rootless image usage with enhanced security-context #160

Merged
luhahn merged 1 commits from justusbunsi/helm-chart:master into master 2021-06-07 13:27:26 +00:00
Member

I've noticed that the commented securityContext is not really useable with the rootless image due to different directory structure compared to the default image.

Important for the readOnlyRootFilesystem is to declare the TMPDIR environment variable, so that the tmp directory (which is readonly in this case) won't be used. Instead, another writeable directory can be used.

Another thing is the explicit hint that all these security options cannot be used with the default (root-based) image, because of its design.

Although this PR would fix the referenced issue, I am not totally happy with the current implementation. It would be more straight forward to use the same mount points for both image variants. Unfortunately, this is not possible right now due to hard coded paths in the default (root) image startup scripts.

Anyone have suggestions on how this could be more simple?


Sum-up:
As mentioned in Discord, this PR tried to make too many changes. The necessary changes made in 1f331a7e6577fc798196a84a957330aca0d663cd will fix an error that occurs due to restricted access to the /tmp directory in a rootless image with all the securityContext options enabled.

I also updated the default image to 1.14.2.

Fixes: #158

I've noticed that the commented `securityContext` is not really useable with the rootless image due to different directory structure compared to the default image. Important for the `readOnlyRootFilesystem` is to declare the `TMPDIR` environment variable, so that the tmp directory (which is readonly in this case) won't be used. Instead, another writeable directory can be used. Another thing is the explicit hint that all these security options cannot be used with the default (root-based) image, because of its design. ~~Although this PR would fix the referenced issue, I am not totally happy with the current implementation. It would be more straight forward to use the same mount points for both image variants. Unfortunately, this is not possible right now due to hard coded paths in the default (root) image startup scripts.~~ ~~Anyone have suggestions on how this could be more simple?~~ ------- **Sum-up:** As mentioned in Discord, this PR tried to make too many changes. The necessary changes made in 1f331a7e6577fc798196a84a957330aca0d663cd will fix an error that occurs due to restricted access to the `/tmp` directory in a rootless image with all the `securityContext` options enabled. I also updated the default image to 1.14.2. Fixes: #158
justusbunsi changed title from WIP: Fix rootless image usage with enhanced security-context to Fix rootless image usage with enhanced security-context 2021-05-22 12:20:40 +00:00
Member

Thanks for the PR.

Will look at your changes this week.

Thanks for the PR. Will look at your changes this week.
Author
Member

Maybe I found a solution for my mentioned worries regarding the current fix. But it includes a patch for the rootful docker image in the Gitea project. Currently, this root based image has hard coded /data references in its setup scripts and templates. Making this part of the image configurable during runtime by setting the GITEA_WORK_DIR environment variable inside the image to /data allows us to handle both image variants the same way in this helm chart.

I am currently working on these modifications in Gitea and provide a PR; it's useful anyway to allow such configuration ?. After it's merged, my suggested changes for this helm chart will be less complex since both images can use the same paths configured from inside the chart.

What do you say @luhahn? Shall we wait for the necessary modification in Gitea before making any further actions in this PR?

EDIT: Without having it tested yet, this is how this PR could be simplified.

Maybe I found a solution for my mentioned worries regarding the current fix. But it includes a patch for the rootful docker image in the Gitea project. Currently, this root based image has hard coded `/data` references in its setup scripts and templates. Making this part of the image configurable during runtime by setting the `GITEA_WORK_DIR` environment variable inside the image to `/data` allows us to handle both image variants the same way in this helm chart. I am currently working on these modifications in Gitea and provide a PR; it's useful anyway to allow such configuration ?. After it's merged, my suggested changes for this helm chart will be less complex since both images can use the same paths configured from inside the chart. What do you say @luhahn? Shall we wait for the necessary modification in Gitea before making any further actions in this PR? EDIT: Without having it tested yet, [this is how this PR could be simplified](https://gitea.com/justusbunsi/helm-chart/commit/2c5493d0fcc176a3814f7805e7c9a5ad4715dd45).
Member

sorry again, our cluster had some major issues, which caused me to have no time at all. I will try to get back to you this week!

sorry again, our cluster had some major issues, which caused me to have no time at all. I will try to get back to you this week!
justusbunsi force-pushed master from 648e168f3b to 1f331a7e65 2021-06-05 14:46:08 +00:00 Compare
luhahn reviewed 2021-06-07 07:37:44 +00:00
luhahn left a comment
Member

Hi, I finally got some time to spend on gitea :)

I've got some questions regarding your PR.

Hi, I finally got some time to spend on gitea :) I've got some questions regarding your PR.
@ -77,6 +77,8 @@ spec:
value: /data
- name: GITEA_TEMP
value: /tmp/gitea
- name: TMPDIR
Member

Little bit confused here.
Why do we need a second env variable for a tmp directory?

- name: GITEA_TEMP
  value: /tmp/gitea

GITEA_TEMP is already existing and pointing to the exact same directory

Little bit confused here. Why do we need a second env variable for a tmp directory? ```yaml - name: GITEA_TEMP value: /tmp/gitea ``` GITEA_TEMP is already existing and pointing to the exact same directory
luhahn marked this conversation as resolved
@ -135,3 +137,3 @@
volumeMounts:
- name: temp
mountPath: /tmp/gitea
mountPath: /tmp
Member

why storing all the tmp data directly into tmp and not into a seperate directory?

why storing all the tmp data directly into tmp and not into a seperate directory?
luhahn marked this conversation as resolved
Member

sorry, should've read your explanation before :D

sorry, should've read your explanation before :D
luhahn approved these changes 2021-06-07 07:57:34 +00:00
luhahn left a comment
Member

Looks good to me, tested on my cluster

Looks good to me, tested on my cluster
6543 approved these changes 2021-06-07 11:52:23 +00:00
Owner

@justusbunsi please "update branch" se we can merge it

@justusbunsi please "update branch" se we can merge it
justusbunsi force-pushed master from 1f331a7e65 to 2d43ae9c3c 2021-06-07 12:33:46 +00:00 Compare
Author
Member

@6543 Done.

@6543 Done.
luhahn merged commit 5ab596937a into master 2021-06-07 13:27:26 +00:00
Sign in to join this conversation.
No description provided.