Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59937

Container and Pod template runAsGroup and runAsUser default to root on config roundtrip

    • kubernetes-1.21.0

      version 1.20.2 introduced runAsUser and runAsGroup properties but the config round trip defaults the value to 0 which is the root user. This is probably not what is intended and happens to breaks certain environments where the containers are expected to run with default user and group ids. This can be demonstrated with a simple test in KubernetesCloudTest.java

      @Test
          public void defaultRoundTrip() throws Exception {
              KubernetesCloud cloud = new KubernetesCloud("kubernetes");
              ContainerTemplate ct = new ContainerTemplate("jnlp", "jenkins:jnlp");
              assertNull(ct.getRunAsUser());
              assertNull(ct.getRunAsGroup());
              PodTemplate pt = new PodTemplate("default", new ArrayList<>(), Arrays.asList(ct));
              cloud.addTemplate(pt);
              j.jenkins.clouds.add(cloud);
              j.jenkins.save();
              // roundtrip
              j.configRoundtrip();
              cloud = j.jenkins.clouds.get(KubernetesCloud.class);
              PodTemplate podTemplate = cloud.getTemplates().get(0);
              assertNull(podTemplate.getRunAsGroup());
              assertNull(podTemplate.getRunAsUser());
              ContainerTemplate containerTemplate = podTemplate.getContainers().get(0);
              assertNull(podTemplate.getRunAsUser());
              assertNull(containerTemplate.getRunAsUser());
          }
      

          [JENKINS-59937] Container and Pod template runAsGroup and runAsUser default to root on config roundtrip

          Kyle Cronin added a comment - - edited

          This appears to be the default behavior of Stapler for Long types. vlatombe I can submit a fix for this, I just don't know how to make Stapler do the right thing. I tried looking at the stapler docs and code but nothing was really helpful, do you have any suggestions?

          Kyle Cronin added a comment - - edited This appears to be the default behavior of Stapler for Long types. vlatombe I can submit a fix for this, I just don't know how to make Stapler do the right thing. I tried looking at the stapler docs and code but nothing was really helpful, do you have any suggestions?

          Hi kylecronin I submitted a fix for this using String instead of Long for getter/setter. Not sure if changing default stapler behaviour is the right thing as others may rely on current behaviour.

          Vincent Latombe added a comment - Hi kylecronin I submitted a fix for this using String instead of Long for getter/setter. Not sure if changing default stapler behaviour is the right thing as others may rely on current behaviour.

            vlatombe Vincent Latombe
            kylecronin Kyle Cronin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: