-
Notifications
You must be signed in to change notification settings - Fork 122
Add securityContext of ReadOnlyRootFilesystem to steps #1885
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixing tests after adding the default value |
/retest |
@hasanawad94: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/ok-to-test |
@sayan-biswas: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
0ae6b68
to
e9878b0
Compare
fefbd3e
to
ecd8d58
Compare
ecd8d58
to
e411479
Compare
Currently working on Image processing part |
67357d6
to
5c69e96
Compare
0b8da9d
to
fc9ee62
Compare
fc9ee62
to
c229842
Compare
Hey @SaschaSchwarze0 I did a manual testing of using a git private key with buildah strategy using managed push with the changes and the buildrun was successful. |
ensureEnvVar(targetStep, "HOME", homeDir) | ||
|
||
// Volume for the base /shared-home directory | ||
baseHomeVolumeName := "base-home-volume" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All (volume) names that we add should start with shp-
to prevent an overlap with strategy-specified names.
images/base/Dockerfile
Outdated
@@ -8,9 +8,10 @@ RUN \ | |||
microdnf clean all && \ | |||
rm -rf /var/cache/yum && \ | |||
# The following setup is necessary so that this image can run as any user | |||
mkdir -p /shared-home/.docker /shared-home/.ssh && chmod -R 0777 /shared-home && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is a problem. Needs to be discussed. We today build base images only from main but use them also for release-v0.16 builds. This would break them.
docs/configuration.md
Outdated
@@ -37,6 +37,7 @@ The following environment variables are available: | |||
| `KUBE_API_BURST` | Burst to use for the Kubernetes API client. See [Config.Burst]. A value of 0 or lower will use the default from client-go, which currently is 10. Default is 0. | | |||
| `KUBE_API_QPS` | QPS to use for the Kubernetes API client. See [Config.QPS]. A value of 0 or lower will use the default from client-go, which currently is 5. Default is 0. | | |||
| `VULNERABILITY_COUNT_LIMIT` | holds vulnerability count limit if vulnerability scan is enabled for the output image. If it is defined as 10, then it will output only 10 vulnerabilities sorted by severity in the buildrun status.Output. Default is 50. | | |||
| `WRITABLE_HOME_DIR` | Specifies the path to be used as the writable home directory (HOME) for containers. By setting this environment variable, the controller will automatically mount a writable `emptyDir` volume at the specified path, which will then be used as the HOME directory for build steps. This is useful for scenarios where a writable HOME is required, such as when tools or processes need to write to the home directory. If you set `WRITABLE_HOME_DIR` to a custom path (e.g., `/my-writable-home`), ensure that this path is not used for other purposes in your container. Default is `/shared-home`. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like it would be mounted to all containers, but I am not seeing it mounted to the strategy steps, or have I missed that?
// Volume for /shared-home/.docker | ||
dockerVolumeName := "docker-config-volume" | ||
ensureVolume(taskSpec, corev1.Volume{ | ||
Name: dockerVolumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}, | ||
}) | ||
ensureVolumeMount(targetStep, corev1.VolumeMount{ | ||
Name: dockerVolumeName, | ||
MountPath: filepath.Join(homeDir, ".docker"), | ||
}) | ||
|
||
// Volume for /shared-home/.ssh | ||
sshVolumeName := "ssh-keys-volume" | ||
ensureVolume(taskSpec, corev1.Volume{ | ||
Name: sshVolumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}, | ||
}) | ||
ensureVolumeMount(targetStep, corev1.VolumeMount{ | ||
Name: sshVolumeName, | ||
MountPath: filepath.Join(homeDir, ".ssh"), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments:
- Do we still need this ? If we now have a configurable writable HOME dir, then we do we need other empty dirs inside them ? Omitting them would mean that we do not have them present at container start and the logic that needs them would have to make sure that they exist.
- I am not sure if we want them shared. Today, every container runs independently without such a shared emptyDir. The docker config is today still created by Tektons creds-init logic. It is a known issue (causing a warning) that when step 1 runs as user A but step 2 as user B, that there are permission issues if this directory is shared. Would probably be a rare issue since we run our own steps as the same user of the strategy when
spec.securityContext
was introduced. For Git SSH, it would actually mean that we put a private key on disk which is then unnecessarily visible also for the image processing step at least.
c229842
to
761ce91
Compare
Set the root filesystem to read-only for all build-related containers as a security best practice. To support this, steps that require write access now explicitly mount `emptyDir` volumes for paths like `/tmp`. A new `AppendWriteableVolumes` function centralizes the setup for volume mounting , using idempotent helpers (`ensureVolume`, `ensureVolumeMount`) to prevent duplicate entries. The Trivy cache directory for vulnerability scanning can be configured using `TRIVY_CACHE_DIR`. Signed-off-by: Hasan Awad <[email protected]>
761ce91
to
091bcf9
Compare
Changes
Explicitly set readOnlyRootFilesystem to true for taskruns according to security best practice.
Submitter Checklist
See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.
Release Notes