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

SHIP-0036: Proposal to set runAs user/group for supporting steps to the runAs configuration of the build strategy steps #131

Conversation

SaschaSchwarze0
Copy link
Member

The proposal explains the background on why we currently have a prepare step that runs as root in some sample build strategies and aims to get rid of them by running all steps (shipwright-injected and strategy steps) as the same user.

@openshift-ci openshift-ci bot requested review from gabemontero and sbose78 March 24, 2023 14:15
@SaschaSchwarze0 SaschaSchwarze0 requested review from adambkaplan, HeavyWombat, otaviof and qu1queee and removed request for sbose78 and gabemontero March 24, 2023 14:15
Copy link
Contributor

@qu1queee qu1queee left a comment

Choose a reason for hiding this comment

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

Left a comment, the rest sounds good to me.

ships/0036-runAs-for-supporting-steps.md Show resolved Hide resolved
@qu1queee qu1queee self-requested a review March 27, 2023 07:59
Copy link
Contributor

@qu1queee qu1queee left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
@SaschaSchwarze0 SaschaSchwarze0 force-pushed the sascha-0036-runas-user branch from 04c33b6 to c50c06b Compare March 27, 2023 13:58
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
@SaschaSchwarze0 SaschaSchwarze0 force-pushed the sascha-0036-runas-user branch from c50c06b to 56193ed Compare April 3, 2023 14:00
@qu1queee
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 12, 2023
@SaschaSchwarze0 SaschaSchwarze0 force-pushed the sascha-0036-runas-user branch from 56193ed to e3f87bd Compare April 13, 2023 10:16
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 13, 2023
@SaschaSchwarze0
Copy link
Member Author

Proposal was updated to reflect the result of investigations on how to run the ssh binary as an arbitrary user as it relies on the user to be present in /etc/passwd.

@SaschaSchwarze0 SaschaSchwarze0 changed the title Add proposal to set runAs user/group for supporting steps to the runAs configuration of the build strategy steps SHIP-0036: Proposal to set runAs user/group for supporting steps to the runAs configuration of the build strategy steps Apr 13, 2023
Copy link
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

In general I am +1 on this feature. Since the status on this SHIP is "implementable", I would like to discuss the API and behavior a bit more before adding "approve" here.

ships/0036-runAs-for-supporting-steps.md Outdated Show resolved Hide resolved
ships/0036-runAs-for-supporting-steps.md Outdated Show resolved Hide resolved
ships/0036-runAs-for-supporting-steps.md Outdated Show resolved Hide resolved
ships/0036-runAs-for-supporting-steps.md Outdated Show resolved Hide resolved
@SaschaSchwarze0 SaschaSchwarze0 force-pushed the sascha-0036-runas-user branch 3 times, most recently from 192c21b to 0a98971 Compare April 17, 2023 12:02
@SaschaSchwarze0
Copy link
Member Author

Added strategy-level securityContext, and clarified how we setup the groups and passwd files.

Copy link
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/lgtm

I think that some of the details in this proposal only apply to Shipwright-provided steps (like 95% confident). I'm not going to hold back on merging this SHIP given its age and prior iterations.

@SaschaSchwarze0 if I have time, I may write a follow-up PR that adds more to the "non-goals" section.

ships/0036-runAs-for-supporting-steps.md Show resolved Hide resolved

### Base image changes

Container images define which users and groups exist in the container by specifying the content of `/etc/passwd` and `/etc/group`. Though, it is generally possible to run a container with as a user or group that is not included in the container image.
Copy link
Member

Choose a reason for hiding this comment

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

it is generally possible to run a container with as a user or group that is not included in the container image.

OpenShift does this by default - containers that don't specify runAsUser and runAsGroup get assigned a random, high-value UID/GID.


We therefore must ensure that those files contain proper information.

We will change the base image to contain `/etc/passwd` and `/etc/group` files with the content that applies to the default Shipwright configuration. That will be for `/etc/passwd`:
Copy link
Member

Choose a reason for hiding this comment

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

We will change the base image...

Is this the base image for user workloads? Or is this only referencing the base image we use for our "provided" steps (git-clone, etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Our steps, we have no control at all over the (base) image of strategy steps.


The BuildRun reconciler is changed to check the strategy-level `securityContext`. If it is defined, then their `runAsUser` and `runAsGroup` override those settings from the container templates of Shipwright-managed steps in the configuration. They are also defaults for the strategy steps' securityContext.

If the strategy-level `securityContext` is defined, then the reconciler will setup the `/etc/passwd` and `/etc/group` files to match this configuration. The following annotations are added to the TaskRun (assuming a build strategy that runs as user 1010 and group 1020):
Copy link
Member

Choose a reason for hiding this comment

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

Again, I think we need to be clear here on which containers we are modifying /etc/passwd and /etc/group. If these are for the Shipwright pre/post steps, this is fine. For arbitrary build strategy steps provided by users, this almost certainly will break things.

Comment on lines +64 to +66
### Non-Goals

- Read the runAsUser and runAsGroup from the step image when they are not defined directly on the step. This can be a future extension, but for now we expect the build strategy author to specify runAsUser and runAsGroup even if they match the image configuration.
Copy link
Member

Choose a reason for hiding this comment

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

If we are not modifying /etc/group and /etc/passwd on build strategy steps themselves, this should be called out as a non-goal.


> **Note**: A container using the downward API as a subPath volume mount does not receive updates when field values change.

This can be considered a current limitation in Kubernetes and could change in the future. Even when this is lifted, we will still be safe because a Kubernetes user who is allowed to update the pod, can only change the content of `/etc/passwd` but not the `runAsUser` and `runAsGroup` of the container as we will also reduce the default configuration of our supporting steps to not allow privilege escalation and to drop all capabilities (`SETGID` and `SETUID` would be required to switch the user). We actually should have configured them like this all the time already to give them no unnecessary privileges.
Copy link
Member

Choose a reason for hiding this comment

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

Same as above - proposal just needs to clarify that the /etc/group and /etc/passwd machinations only applies to Shipwright-provided steps.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 15, 2023
@qu1queee
Copy link
Contributor

I spoke with @SaschaSchwarze0 , we will be adding a new update after merging this PR, thanks @adambkaplan .

/approve

@openshift-ci
Copy link

openshift-ci bot commented Jun 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qu1queee

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2023
@openshift-merge-robot openshift-merge-robot merged commit e772bda into shipwright-io:main Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants