-
Notifications
You must be signed in to change notification settings - Fork 140
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
Run as non-privilege and non-root user #2037
Conversation
1a69e50
to
4673e1a
Compare
// Non-system UID and GID range is normally from 1000 to 60000 (Debian derived systems define this | ||
// in /etc/login.defs). On a normal Linux host, it is unlikely to have more than 10k non-system users. | ||
// 10001 is chosen based on this assumption. | ||
RunAsUserID int64 = 10001 |
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.
Preferably, I want this UID and GID consistent across all components. It is not possible to make the Operator only change because some components chown
folders to a hard-coded UID in Dockerfile
. When running as a different user, I got permission errors. 10001 is chosen for the reason mentioned in the comments. The UIDs we are currently using (999 or 1001 etc.) may not be desired because they will collide with system or non-system users. Do we want to make them consistent? @caseydavenport or @tmjd WDYT?
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.
Consistency would be nice, but like you point out it would require some extra work. I don't think we have any special attachment to 999 or 1001, but there are probably other places where we (or users) make assumptions based on those, so I might be inclined to leave them as-is for now. I don't think we've had any reports of those values causing issues.
Maybe just make these configurable for now and each component can pass in the user / group that it expects to be run as, and we can then do a follow-up series of PRs to standardize?
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.
Made uid and gid configurable in NewBaseContext
. The UID and GID are taken from Dockerfiles (unchanged) for each component.
@@ -1,15 +0,0 @@ | |||
package podsecuritycontext |
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.
Renamed. This is a SecurityContext
not PodSecurityContext
.
CC @mgleung |
@@ -532,7 +534,7 @@ func (c *intrusionDetectionComponent) intrusionDetectionControllerContainer() co | |||
}, | |||
} | |||
|
|||
privileged := false | |||
sc := securitycontext.NewBaseContext(securitycontext.RunAsUserID, securitycontext.RunAsGroupID) |
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.
Nothing is set in IDS controller Dockerfile
so we are safe to set UID and GID to 10001. This is also fixed in IDS master as a fallback.
7d61dd8
to
79ef6c2
Compare
Changes are tests on a CIS-1.6 profile hardened RKE2 cluster and normal GCP kubeadm cluster. |
The UID/GID for cloud controller, dex, guardian, packetcapture are copied from |
The PR lgtm, except that it would be good to have a check in each _test.go to verify the security context. |
ce743a2
to
8407442
Compare
UTs for |
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.
lgtm
8463de4
to
0ddc7be
Compare
This changeset set `securityContext` as non-privilege and non-root user for IDS controller, prometheus, and kibana pods. It fixes an enterprise component developmend issue on CIS profile hardened RKE2 cluster. When the container is running as root or non-numeric user (nobody or kibana), it failed non-root validation.
0ddc7be
to
d9f3110
Compare
/merge-when-ready delete-branch |
OK, I will merge the pull request when it's ready, leave the commits as is when I merge it, and delete the branch after I've merged it. |
Description
This changeset set
securityContext
as non-privilege and non-root userfor IDS controller, prometheus, and kibana pods. It fixes an enterprise
component developmend issue on CIS profile hardened RKE2 cluster. When
the container is running as root or non-numeric user (nobody or kibana),
it failed non-root validation.
For PR author
make gen-files
make gen-versions
For PR reviewers
A note for code reviewers - all pull requests must have the following:
kind/bug
if this is a bugfix.kind/enhancement
if this is a a new feature.enterprise
if this PR applies to Calico Enterprise only.