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

[SYCL][Devops] Fix DockerFile linting issues discovered by trivy #16361

Conversation

AlexeySachkov
Copy link
Contributor

This is a re-submit of #16290 with fixes from #16324 and some more extra changes.

Issues addressed:

Issues remaining:

I didn't add HEALTHCHECK command to our containers, because I don't know if that makes sense and which command to launch. I.e. our containers they only provide some pre-installed tools, but they don't launch any services which we could check.

Other notable changes:

  • sycl user creation was outlined into a separate helper script and that user requires password to use sudo.

See https://avd.aquasec.com/misconfig/ds017

Docker best practices says that running `update` and `install` commands
separately may lead to situations where Docker skips `update` step and
re-uses cache leading to outdated versions of packages being installed.
See https://avd.aquasec.com/misconfig/ds002

Made it so that the last `USER` command in `base` and `build` is not
`root`.
See https://avd.aquasec.com/misconfig/ds002

Made it so our docker files have at least one `USER` command which is
not `root`.
Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

sorry for late review, looks really good, just some minor comments

devops/actions/build_container/action.yml Outdated Show resolved Hide resolved
devops/scripts/create-sycl-user.sh Outdated Show resolved Hide resolved
devops/containers/ubuntu2204_preinstalled.Dockerfile Outdated Show resolved Hide resolved
Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

lgtm with root thing fixed

AlexeySachkov added a commit to AlexeySachkov/llvm that referenced this pull request Dec 16, 2024
Extended build containers action with an extra argument which specifies
a password that will be assigned to the `sycl_ci` user created within
containers.

For now this new secret is unused, so this changes is expected to have
no impact on our CI.

This is outlined from intel#16361 to improve testing for that PR: for
security reasons actions are only invoked from the default branch and
never from a PR branch. Therefore, to actually test that this secret is
properly used without errors we need to update the action first.
Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

lgtm, minor comments again, thx

@@ -196,9 +196,9 @@ jobs:
run: |
if [ "${{ inputs.install_dev_igc_driver }}" = "true" ]; then
# If libllvm14 is already installed (dev igc docker), still return true.
sudo apt-get install -yqq libllvm14 || true;
cat /run/secrets/sycl_passwd | sudo -S apt-get install -yqq libllvm14 || true;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need parens here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my local experiments:

$ cat /run/secrets/sycl_ci_passwd | sudo -S echo "I'm root!" || echo "second"
I'm root!
$ cat /run/secrets/sycl_ci_passwd | sudo -S false || echo "second"
second

So, it seems to work correctly, but I can add parens for clarity if that's a preference


if [[ $# -eq 0 ]]; then
# When launched without arguments, we assume that it was launched as part of
# CI workflow and therefore a different kind of user is created
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Considering that all our containers are only for the purposes of CI and local development, I decided that they will all use sycl_ci by default.

Those, who need sycl user are able to create it using that script manually as documented (8d931df). Considering that sycl user won't be created by us anymore, I think that it is actually better to have this script react to an arguments instead of the environment (i.e. I want everything to be explicit)


if [[ $SET_PASSWD == true ]]; then
if [[ ! -f /run/secrets/sycl_ci_passwd ]]; then
echo "Password is requested, but /run/secrtes/sycl_ci_passwd doesn't exists!"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
echo "Password is requested, but /run/secrtes/sycl_ci_passwd doesn't exists!"
echo "Password is requested, but /run/secrtes/sycl_ci_passwd doesn't exist!"

SET_PASSWD=false

# Some user id which is different from the one assigned to sycl_ci user
USER_ID=1234
Copy link
Contributor

Choose a reason for hiding this comment

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

also sorry, you might have to rebase because i added a 24.04 oneapi docker image today

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, see be4e0c6 for merge conflicts resolution and ff333a1 for changes to that new dockerfile

@bader
Copy link
Contributor

bader commented Dec 16, 2024

Other notable changes:

  • sycl user creation was outlined into a separate helper script and that user requires password to use sudo.

Do we need to update anything in https://github.com/intel/llvm/blob/sycl/sycl/doc/developer/DockerBKMs.md#changing-docker-user?

AlexeySachkov added a commit that referenced this pull request Dec 17, 2024
Extended build containers action with an extra argument which specifies
a password that will be assigned to the `sycl_ci` user created within
containers.

For now this new secret is unused, so this changes is expected to have
no impact on our CI.

This is outlined from #16361 to improve testing for that PR: for
security reasons actions are only invoked from the default branch and
never from a PR branch. Therefore, to actually test that this secret is
properly used without errors we need to update the action first.
@AlexeySachkov
Copy link
Contributor Author

Other notable changes:

  • sycl user creation was outlined into a separate helper script and that user requires password to use sudo.

Do we need to update anything in https://github.com/intel/llvm/blob/sycl/sycl/doc/developer/DockerBKMs.md#changing-docker-user?

Good point, I wasn't aware of that documentation, I will update it as well. In general, this change warrants a discussion, I believe, because short summary of what I do is making those images less useable for anyone else. I will initiate some discussion about that.

@AlexeySachkov
Copy link
Contributor Author

Other notable changes:

  • sycl user creation was outlined into a separate helper script and that user requires password to use sudo.

Do we need to update anything in https://github.com/intel/llvm/blob/sycl/sycl/doc/developer/DockerBKMs.md#changing-docker-user?

Good point, I wasn't aware of that documentation, I will update it as well. In general, this change warrants a discussion, I believe, because short summary of what I do is making those images less useable for anyone else. I will initiate some discussion about that.

Documentation was updated in 8d931df. The concern I had is resolved, so no extra discussions are necessary besides this code review.

@AlexeySachkov
Copy link
Contributor Author

So, due to the way GH operates which has to do with security, there is no way to test this PR (more or less properly) when its submitted from a fork. #16411 is a re-submit which is made from within the repo to properly test this.

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