-
Notifications
You must be signed in to change notification settings - Fork 59
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
control-service: Allow job builder run as non-root #625
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bbb19be
to
007dd7e
Compare
a3455b0
to
0d84723
Compare
mivanov1988
reviewed
Jan 13, 2022
mivanov1988
reviewed
Jan 13, 2022
mivanov1988
reviewed
Jan 13, 2022
0d84723
to
205ace8
Compare
mivanov1988
approved these changes
Jan 14, 2022
LGTM |
527514a
to
55a33f5
Compare
2bc6aac
to
20bd79d
Compare
Currently, the data job builder requires root priviledges to run, which is not ideal in situations, where users may have access to kubernetes clusters which allow pods to run only under SecurityContext. This change allows the job builder pods to run under security context, by assigning the ownership of the working directories to UID 1000, which is the first "normal" user Linux machines create without root priviledges. Testing Done: Manually tested the change by updating the KubernetesService class to set security context to the data job builder pod. The change was made to the createJob() method by adding the following lines and replacing the V1PodTemplateSpecBuilder ``` List<String> addedCapabilities = Arrays.asList( "AUDIT_WRITE", "CHOWN", "DAC_OVERRIDE", "FOWNER", "FSETID", "KILL", "MKNOD", "NET_BIND_SERVICE", "NET_RAW", "SETFCAP", "SETGID", "SETPCAP", "SETUID", "SYS_CHROOT" ); List<String> droppedCapabilities = Arrays.asList( "AUDIT_CONTROL", "BLOCK_SUSPEND", "DAC_READ_SEARCH", "IPC_OWNER", "LEASE", "LINUX_IMMUTABLE", "MAC_ADMIN", "MAC_OVERRIDE", "NET_ADMIN", "NET_BROADCAST", "SYSLOG", "SYS_ADMIN", "SYS_BOOT", "SYS_MODULE", "SYS_NICE", "SYS_PACCT", "SYS_PTRACE", "SYS_RAWIO", "SYS_RESOURCE", "SYS_TIME", "SYS_TTY_CONFIG", "WAKE_ALARM" ); long fsGroup = 2000; long runAsGroup = 2000; long runAsUser = 1000; long supGroup = 1; List<Long> supplementalGroups = Arrays.asList(supGroup); log.debug("Creating k8s job name:{}, image:{}", name, image); var template = new V1PodTemplateSpecBuilder() .withSpec(new V1PodSpecBuilder() .withRestartPolicy("Never") .withContainers(container(name, image, privileged, envs, args, volumeMounts, imagePullPolicy, request, limit, null) .securityContext(new V1SecurityContext() .allowPrivilegeEscalation(false) .capabilities(new V1Capabilities() .add(addedCapabilities) .drop(droppedCapabilities) ) .privileged(false) )) .withVolumes(volumes) .withSecurityContext( new V1PodSecurityContext() .fsGroup(fsGroup) .runAsGroup(runAsGroup) .runAsUser(runAsUser) .supplementalGroups(supplementalGroups) ) .build()) .build(); ``` After the change was made, a local instance of the Control Service was run, and it was verified that the builder job is able to successfully run under SecurityContext. Signed-off-by: Andon Andonov <[email protected]>
20bd79d
to
630a803
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the data job builder requires root priviledges to
run, which is not ideal in situations, where users may have access
to kubernetes clusters which allow pods to run only under SecurityContext.
This change allows the job builder pods to run under security context, by assigning
the ownership of the working directories to UID 1000, which is the first "normal" user
Linux machines create without root priviledges.
Testing Done: Manually tested the change by updating the KubernetesService class
to set security context to the data job builder pod. The change was made to the
createJob() method by adding the following lines and replacing the V1PodTemplateSpecBuilder
After the change was made, a local instance of the Control Service was run, and it was
verified that the builder job is able to successfully run under SecurityContext.
Signed-off-by: Andon Andonov [email protected]