Skip to content
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

[JENKINS-73513] Fix inheritance of container capabilities and and pod shareProcessNamespace settings #1592

Conversation

cfraenkel
Copy link
Contributor

@cfraenkel cfraenkel commented Jul 26, 2024

This PR fixes two bugs related to the usage and overriding of pod shareProcessNamespace and container securityContext.capabilities settings.

  • for shareProcessNamespace it makes sure this setting can be overwritten in combined pods.
  • for securityContext.capabilities it introduces merging of the fields to the current logic in PodTemplateUtils

see https://issues.jenkins.io/browse/JENKINS-73513

Testing done

  • I've added unit tests to PodTemplateUtils that cover the changed fields
  • I've built the hpi locally and deployed it to a minikube cluster and verified the behavior with the following pipeline script
    • all expected settings (capabilities, shareProcessNamespace) where present in the final pod.
Jenkinsfile
podTemplate(yaml:'''
spec:
  containers:
  - name: jnlp
    env:
    - name: HELLO
      value: "WORLD!"
  - name: inner
    securityContext:
      capabilities:
        drop:
        - CHOWN
''') {
    podTemplate(yamlMergeStrategy: merge(), yaml: '''
spec:
  shareProcessNamespace: true
  containers:
  - name: inner
    image: eclipse-temurin:17-jdk-jammy
    imagePullPolicy: IfNotPresent
    command:
    - cat 
    - '-'
    tty: true
    volumeMounts:
    - name: workspace-volume
      mountPath: /home/jenkins/agent
    securityContext:
      runAsUser: 1000
      runAsGroup: 1000
      capabilities:
        add:
        - SYS_PTRACE
        drop: null
''') {
        node (POD_LABEL) {
            sh '''
            echo running from jnlp
            '''
            container("inner") {
                sh '''
                echo running from inner
                ps aux
                jcmd
                jcmd agent.jar GC.heap_info
                '''
            }
        }
    }
}

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@cfraenkel cfraenkel requested a review from a team as a code owner July 26, 2024 16:18
@cfraenkel cfraenkel force-pushed the bugfix/JENKINS-73513-fix-inheritance-of-capabilities-and-shareProcessNamespace branch from 0fe8dff to df6fc58 Compare July 26, 2024 16:36
@cfraenkel cfraenkel changed the title Fix inheritance of container capabilities and and pod shareProcessNamespace settings [JENKINS-73513] Fix inheritance of container capabilities and and pod shareProcessNamespace settings Jul 29, 2024
@jglick
Copy link
Member

jglick commented Jul 31, 2024

FYI

  • The maintainer is not available currently.
  • It is generally discouraged to rely on pod template inheritance. Use whatever logic you need (e.g., in a library) to define the pod you actually want, then request it directly.

@cfraenkel
Copy link
Contributor Author

Thanks for the update.
I do hope this fix will get merged eventually - I've been testing the incremental built from this PR successfully.

It is generally discouraged to rely on pod template inheritance. Use whatever logic you need (e.g., in a library) to define the pod you actually want, then request it directly.

Thanks for that information. I do not think this is currently reflected in the readme which goes into some detail on nested podtemplates (which means inheritance).

@Vlatombe Vlatombe added the bug Bug Fixes label Aug 12, 2024
@Vlatombe Vlatombe merged commit 0889b96 into jenkinsci:master Aug 12, 2024
8 checks passed
@cfraenkel cfraenkel deleted the bugfix/JENKINS-73513-fix-inheritance-of-capabilities-and-shareProcessNamespace branch August 12, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants