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

feat!: allow docker image use for non-root users #122

Merged
merged 3 commits into from Sep 14, 2022
Merged

feat!: allow docker image use for non-root users #122

merged 3 commits into from Sep 14, 2022

Conversation

maxrake
Copy link
Contributor

@maxrake maxrake commented Sep 13, 2022

The Dockerfile has been updated to install the phylum package in a
Python virtual environment, which is accessible by non-root users of the
image. These changes were inspired by the Python black project, which
did basically the same thing: psf/black#3202

The phylum-init script was updated to provide a hidden option
for installing the CLI in a globally accessible directory. That option
is meant to be used in very limited circumstances, namely the Dockerfile
for image creation.

The minimum supported CLI version is currently v3.8.0-rc2 and enough
time has passed that CLI versions prior to v2.2.0 are no longer expected
to exist in the wild. That is when the Phylum config and binary paths
changed, to adhere to the XDG Base Directory Spec. This change removes
support for use of these legacy CLI version paths.

Some refactoring was done to make it easier to update the minimum
supported CLI versions as they progress and make changes that require
different minimum versions for both new and existing installations.

BREAKING CHANGE: CLI installs prior to v2.2.0 are no longer supported.

Closes #118

Checklist

  • Does this PR have an associated issue?
  • Have you ensured that you have met the expected acceptance criteria?
    • GHA integration was tested with TestGHA
    • GitLab integration was tested manually
  • Have you created sufficient tests?
    • Still no automated tests
  • Have you updated all affected documentation?

Screenshots

Both root and non-root users have access to the phylum-ci and phylum binaries now:

image


root can continue to use phylum-ci but non-root users must have an corresponding user account created in the container layer to work:

image


Using this image in Azure Pipelines, where the user vsts_azpcontainer is created during Job provisioning and used...successfully this time to run phylum-ci:

image

The minimum supported CLI version is currently v3.8.0-rc2 and enough
time has passed that CLI versions prior to v2.2.0 are no longer expected
to exist in the wild. That is when the Phylum config and binary paths
changed, to adhere to the XDG Base Directory Spec.

This change removes support for use of these legacy CLI version paths.

BREAKING CHANGE: CLI installs prior to v2.2.0 are no longer supported.
This change should make it easier to update the minimum supported CLI versions as they progress and make changes that require different minimum versions for both new and existing installations.
The Dockerfile has been updated to install the `phylum` package in a
Python virtual environment, which is accessible by non-root users of the
image. The `phylum-init` script was updated to provide a hidden option
for installing the CLI in a globally accessible directory. That option
is meant to be used in very limited circumstances, namely the Dockerfile
for image creation.

Closes #118
@maxrake maxrake requested a review from a team as a code owner September 13, 2022 23:46
@maxrake maxrake self-assigned this Sep 13, 2022
Copy link
Contributor

@kylewillmon kylewillmon left a comment

Choose a reason for hiding this comment

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

Interesting idea to split the minimum required CLI version. I don't see documentation for that anywhere, but the output from the tool is clear enough that it's probably not necessary to document it elsewhere.

@maxrake maxrake merged commit 3e87aa9 into main Sep 14, 2022
@maxrake maxrake deleted the free_port branch September 14, 2022 15:46
kylewillmon referenced this pull request Oct 17, 2023
Some tools get installed and used based on a home directory. This can
cause trouble when using a container started from this image with a
UID:GID that does not map to a user/group account in the container.
Examples include:

* The install directory is `/root` and the container user has no access
* The tool relies on a $HOME directory, which may not exist
  * https://medium.com/redbubble/running-a-docker-container-as-a-non-root-user-7d2e00f8ee15

The following tools are susceptible to this issue and therefore have
been provided with explicit install/home directories that allow them to
be globally accessible:

* Corepack, Yarn, and pnpm
* Rust, Cargo, and rustup
* Gradle

This issue was first discovered by @marvin-hansen and documented here:
#310 (comment)

In that case, GitHub Actions was used and it was found that `HOME` is
[overridden for containers](actions/runner#863)
and set to `/github/home`, which is a directory that is unknown during
image creation. Instead of attempting to create a custom solution for
GitHub Actions specifically, the solution presented here is meant to be
useful for any environment that starts a container from the `phylum-ci`
image. Since there are many CI environments already supported, each with
their own methods of running containers, this approach was deemed to be
the most prudent.

Tests have been added to ensure all the required tools can function when
a container is started from the `phylum-ci` image with a user that is
unknown to that image and therefore does not have a `$HOME` directory.
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.

Allow Docker image use for non-root users
2 participants