-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make group ID configurable #11924
feat: make group ID configurable #11924
Conversation
As stated in the PR description the PR depends on this. I have just marked the PR as draft so that it won't be merged accidently at some point before the updated image tag for proxy-init can be used. We should focus on the proxy-init PR first and get it released. Then, we can focus on this PR. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
b6f5b36
to
60d6518
Compare
60d6518
to
4000715
Compare
Now as the changes to proxy-init are merged I would like to give this PR attention again. I have just updated it so that the comits that have been made in the meantime are included. Therefore, I would like to ask the maintainers to review the changes now. @mateiidavid @kflynn I don't know how much you can do here (i.e. if changes to the linkerd2 repos are part of your responsibility) but maybe you can take a look. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nico151999 I put up a PR (#12462) to bump the proxy-init deps in the linkerd2 repo.
Most of the changes look good to me. I mentioned in a comment that my preference would be to have this as something users explicitly opt-in to for their components.
@@ -182,6 +182,8 @@ proxy: | |||
request: "" | |||
# -- User id under which the proxy runs | |||
uid: 2102 | |||
# -- Group id under which the proxy runs | |||
gid: 2102 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an alternative solution here where we introduce a gid
in the manifests explicitly? Your proxy-init change treats gids as optional. Being a bit more risk adverse, I'd prefer it if gids were not implicitly used here.
The only problem I can see with treating gids as optional is that it results in a bigger configuration surface area. Is there anything we can do to keep the config scope narrow and allow people to explicitly use a gid? For example, setting it as 0
would work, but from a UX standpoint seeing gid: 0
in the values.yaml file is not something I'd be a big fan of. I'm sure Helm supports optional args though in some capacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use a special value like -1
for this purpose and add a comment explaining it. Alternatively, we could do something like
gid:
customise: true # tells if the gid should be set to the custom value provided
value: 2102
When I write charts I personally prefer the latter style. So unless you intervene I would implement it this way. What are your thoughts @mateiidavid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to quickly implement it as I suggested. Just take a look and let me know what you think. Thanks!
552ffd8
to
59fd163
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nico151999 I like the way you structured the config. There's a "but" coming :) I think we'd rather avoid having a separate customise: false
(or enabled: true
) option. I don't think our config is set-up well enough to support it at the moment; it's an unfortunate side effect for this PR. It's also hard to keep things consistent with other similar parts of our config because we want to introduce optionality here...
Here's an idea. Can we use KindIs
to infer whether a value has been set for the respective field? We tried it out locally and it seemed to work. A more concrete example:
# values.yaml
proxy:
gid:
# template
{{- if kindIs "int" .Values.proxy.gid }}
- --gid
- {{.Values.proxy.gid }}
cc @alpeb
charts/linkerd2-cni/values.yaml
Outdated
proxyGID: | ||
# -- Tells if the customisation should be applied or not | ||
customise: false | ||
# -- Group id under which the proxy shall be ran | ||
value: 2102 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we nest gid
under each specific container/app?
proxy:
gid:
controller:
gid:
proxyInit:
gid:
cli/cmd/inject.go
Outdated
if proxy.GID.Customise && proxy.GID.Value != baseProxy.GID.Value { | ||
overrideAnnotations[k8s.ProxyGIDAnnotation] = strconv.FormatInt(proxy.GID.Value, 10) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have an explicit check against 0
. Using group: 0
might be a bit more dangerous since packets can be generated by other processes that run under the same group, and they will end not being redirected. This will all be really hard to debug.
charts/linkerd2-cni/values.yaml
Outdated
@@ -20,6 +20,12 @@ logLevel: info | |||
portsToRedirect: "" | |||
# -- User id under which the proxy shall be ran | |||
proxyUID: 2102 | |||
# -- Optional customisation of the group id under which the proxy shall be ran |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to document this a bit more to prevent people from misusing the field.
- We should note that proxy's GID should be unique. No other container should run under the same group as the proxy (including the control plane's containers). Once the group ID is shared, packets can be skipped for processes that are not the proxy and it will result in hard to diagnose issues.
- We should consider using the
fail
function to fail-fast if the proxy's gid == controller gid.
Open to any other suggestions if you have any. Our biggest concern here would be that users unknowingly set the same gid across all containers.
pkg/charts/linkerd2/values.go
Outdated
@@ -29,6 +29,7 @@ type ( | |||
ControllerImage string `json:"controllerImage"` | |||
ControllerReplicas uint `json:"controllerReplicas"` | |||
ControllerUID int64 `json:"controllerUID"` | |||
ControllerGID *Customisable[int64] `json:"controllerGID"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change gid
to be nullable, we could probably just take a pointer to an int here instead of introducing a new type.
5f0885c
to
6adbccb
Compare
@nico151999 thanks for making the changes! I'm afraid I might've led you down the wrong path here. When I tested the change I realised the documentation will look weird... on second thought it might be better to just do |
400d62d
to
26cf299
Compare
b7732db
to
c765eb5
Compare
As discussed with @mateiidavid I refactored the PR so that it now allows to omit the group ID with a negative value instead of null. Signed-off-by: Nico Feulner <nico.feulner@gmail.com>
c765eb5
to
572a6d1
Compare
I took the liberty of rebasing with main and pushing some changes/fixes:
I'll do some manual testing tomorrow; looking good! |
Thanks a lot @alpeb |
viz/charts/linkerd-viz/values.yaml
Outdated
@@ -125,6 +127,9 @@ metricsAPI: | |||
# -- UID for the metrics-api resource | |||
UID: | |||
|
|||
# -- GID for the metrics-api resource | |||
gID: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nitpick but we should go with gID
or GID
(below) for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea good catch, @nico151999 you wanna get that addressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed the change so we can include this in today's edge 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 thanks @nico151999 and @alpeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳
Sorry for the late response. I'm on a short hiking trip and can't test the changes but they look good to my bare eyes and the tests seem to pass. So I would say we are good to go. Thanks for the effort today @alpeb |
Problem
Currently, the sidecar containers do not include a runAsGroup attribute. In some companies, there are security guidelines requiring the runAsGroup attribute to be set.
Solution
This PR causes the group ID to be set and adds the option to set it manually. It depends on this other PR.
Validation
I built the proxy init image with the code in my other pull request and loaded it into my k3d cluster in the dev container. I built the images and loaded them into the k3d cluster as well. Then, I installed the CRDs, Linkerd and Linkerd Viz. I deployed Emojivoto without the
config.linkerd.io/proxy-gid
annotation being set and then with it being set to check if the group ID changes accordingly in the respective containers' security context. Note that I had to tweak my setup a little bit in order to make it work in WSL2 behind an HTTP proxy, so my setup might differ from the reference setup. Still, I assume that my tweaks did not have an impact on the outcome of the tests.Fixes #11773
Signed-off-by: Nico Feulner nico.feulner@gmail.com