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

Use jenkins user inside docker jobs instead of root #494

Merged
merged 16 commits into from
Aug 13, 2021

Conversation

scpeters
Copy link
Contributor

@scpeters scpeters commented Aug 7, 2021

I have noticed some times when Jenkins fails to clear a workspace for a job. After investigating the machines over ssh, I have noticed the remaining folders contain files owned by root. This is caused by our use of the root user in the docker-based Ubuntu CI jobs. To avoid using the root user, this pull request creates a user in the Dockerfile that matches the current user, and switch to this user before using commands that touch the workspace folders.

I have tested with the following job:

In order for this job to pass, I had to manually call sudo chown -R jenkins:jenkins on both the build machine's workspace folder and on the shared /srv/ccache folder. To merge this; I recommend taking all the Linux nodes of build.osrfoundation.org offline, then sanitizing the workspace and /srv/ccache folders of each Linux node, then bringing them back online.

edit
commands to run on migration:

sudo find /var/lib/jenkins/workspace -user root -exec chown jenkins {} \;
# chown symbolic links too
sudo find /var/lib/jenkins/workspace -user root -exec chown -h jenkins {} \;
sudo chown jenkins -R /srv/ccache

Create a user in the Dockerfile that matches the current
user, and switch to this user before using commands
that touch the workspace folders.

Signed-off-by: Steve Peters <[email protected]>
@scpeters scpeters requested a review from j-rivero August 7, 2021 08:45
@j-rivero j-rivero changed the title Run docker jobs without root Use jenkins user inside docker jobs instead of root Aug 9, 2021
@j-rivero
Copy link
Contributor

j-rivero commented Aug 9, 2021

I think that the PR is a good step forward to reduce the use of root in the CI pipeline. It is probably the easiest one (more complicate would probably be the execution of docker without sudo) but this one is important. Thank Steve.

Code looks good to me. I would like to check a couple of things more: GPU build with this branch and debbuilder with this branch. My goal is to execute the merge and do the manual operations in the next two days.

@scpeters
Copy link
Contributor Author

scpeters commented Aug 9, 2021

I think that the PR is a good step forward to reduce the use of root in the CI pipeline. It is probably the easiest one (more complicate would probably be the execution of docker without sudo) but this one is important. Thank Steve.

Code looks good to me. I would like to check a couple of things more: GPU build with this branch and debbuilder with this branch. My goal is to execute the merge and do the manual operations in the next two days.

sounds good. It might be useful to schedule a meeting with you, me and the current build farmer @mjcarroll to coordinate the merge and manual operations

@j-rivero
Copy link
Contributor

j-rivero commented Aug 9, 2021

I made some changes to this PR:

  • Remove workarounds in place inside Jenkins DSL 61f11d6
  • Remove workarounds inside the docker_run script
  • Add some missing entries for sudo when using make install b864fef

@j-rivero
Copy link
Contributor

j-rivero commented Aug 9, 2021

sounds good. It might be useful to schedule a meeting with you, me and the current build farmer @mjcarroll to coordinate the merge and manual operations

I was thinking on performing all the operations during Wednesday Europe morning if we have a clear plan with the steps ready. I'm happy to take any help.

@scpeters
Copy link
Contributor Author

have you run any test builds with these latest changes?

@j-rivero
Copy link
Contributor

Made some modifications to this PR (sorry I should have used a different branch) and run a battery of tests:

  • debbuilder job: Build Status
  • ci job with GPU: Build Status
  • abichecker job: Build Status
  • install job: Build Status
  • ros2 ci job: Build Status
  • gazebo job: Build Status

I think we are ready to re-review @scpeters

echo '# END SECTION'

echo '# BEGIN SECTION: install nvidia-docker1 (in docker)'
apt-get install -y wget nvidia-340 nvidia-modprobe
sudo apt-get install -y wget nvidia-340 nvidia-modprobe
wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb
dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this line and the apt-key and add-apt-repository commands may need sudo as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right 079a093

@scpeters
Copy link
Contributor Author

thanks for the additional testing. I think we can merge soon and catch further issues when they arise

@j-rivero
Copy link
Contributor

j-rivero commented Aug 11, 2021

thanks for the additional testing. I think we can merge soon and catch further issues when they arise

+1. I'll plan the migration via slack.

@j-rivero j-rivero closed this Aug 11, 2021
@j-rivero j-rivero reopened this Aug 11, 2021
# Create a user with passwordless sudo
ARG USERID
ARG USER
RUN adduser --uid \$USERID --gecos "Developer" --disabled-password \$USER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend a slightly more complete arguments to the user. In particular set the group ID as well.

I have a good example at: https://github.com/osrf/rocker/blob/acbbff59d6aef6a9654eabc0ff7e3f823936d6e3/src/rocker/templates/user_snippet.Dockerfile.em#L9

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've included GID handlng in ef59662

@j-rivero
Copy link
Contributor

Another short round of tests:

  • ign-rendering Build Status
  • ign-msgs8-debbuilder: Build Status

@j-rivero
Copy link
Contributor

Changed machines:

  • drogon
  • maria
  • optimus
  • r2d2

Merging-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants