feat(deployment): make securityContext configurable for initContainers only #715
Reference in New Issue
Block a user
No description provided.
Delete Branch "dti-horvath/feat/sec-context-for-init"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description of the change
Add a new parameter to set the
securityContext
forinitContainers
only.Benefits
initContainers
may need other rights for setting up Gitea. E.g.: special userid which is allowed to write to a specific volume or is allowed to connect to a specific network.Additional information
This change rose from the need to set a specific userid for
initContainers
when running with Istio. Istio handlesinitContainers
differently, so that it is needed to define security constraints to them.Applicable issues
Checklist
values.yaml
and added to theREADME.md
using readme-generator-for-helmPlease add some unit tests to verify that combining
initContainerSecurityContext
andcontainerSecurityContext
works as expected.First of all: Thanks for contributing to this repository. We appreciate your efforts.
Also thanks for adding the requested tests. Looking at the changes from Helm and Kubernetes point-of-view, they are valid and I was tempted to merge this Pull Request.
However, reviewing the added tests I doubted that the current solution would result in a working Gitea application. Trying to apply those values as a Helm release confirms my concerns:
Using following values lead to a crash-looping Gitea container, stating missing permissions to create '/data/gitea/git`
We have hard-coded
chown 1000:1000
in our scripts1. Most of them are executed in the first init container (init-directories
) which requires that particular init container to run as root - without having arunAsUser
at all.Mixing different
initContainerSecurityContext.runAsUser
andcontainerSecurityContext.runAsUser
lead to the same error, and make thehard-coded vs. default values
even worse: The rootless Gitea image uses1000:1000
as default uid:gid mapping, leading to a filesystem that is owned by e.g. 1001:1000. So Gitea is not able to start.My first thought on fixing this was to just overwrite
UID
andGID
envs for Gitea container and replace the hard-coded1000
with placeholders for these envs. But this doesn't resolve the root-cause of doing too many different things in different contexts as init containers. This is not only an Istio-related issue2.A real long-term solution is moving the init container logic into Helm hook jobs prior to starting Gitea itself. That way, no init container exists and e.g. Istio doesn't handle them differently.
A solution for the current init container way might be to support separate
securityContext
s for every init container without hidden defaults in the templates or shell scripts. But we have to make the configuration resistent to user configuration errors, or we cause avoidable issues.To be honest, I am not sure if we should directly long for the job-based solution or have the per-init-container-context solution first. Right now, your proposed solution is not ready to be merged. I welcome your (@dti-horvath) thoughts on this topic - and those of anyone else reading this.
https://gitea.com/gitea/helm-chart/issues/338#issuecomment-756745 ↩︎
https://gitea.com/gitea/helm-chart/issues?state=open&type=all&q=runAsUser (excluding 643) ↩︎
Checkout
From your project repository, check out a new branch and test the changes.