Skip to content

Commit e346d24

Browse files
committed
fix: force runasuser for reduce-snapshot
- This is a workaround for a problem observed on a particular cluster where the use-trusted-artifacts step runs with root user causing a file or folder to not be readable in later steps. There might be solution coming related to the security context constraints on the cluster, but setting this explicitly here should probably be harmless either way. - Also add protection for skip-trusted-artifact-operations to better handle permission issues. Signed-off-by: Scott Hebert <[email protected]>
1 parent dba945f commit e346d24

7 files changed

+76
-11
lines changed

stepactions/skip-trusted-artifact-operations/skip-trusted-artifact-operations.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,28 @@ spec:
2727
if [ "${ociStorage:?}" == "empty" ]; then
2828
echo "oci storage not detected via ociStorage...skipping trusted artifacts tasks"
2929
mkdir -p "${workDir:?}"
30-
touch "${workDir:?}/.skip-trusted-artifacts"
30+
31+
# Check if the skip file already exists to avoid permission issues
32+
if [ -f "${workDir:?}/.skip-trusted-artifacts" ]; then
33+
echo "Skip file already exists, continuing..."
34+
else
35+
# Try to create the file, handle permission issues gracefully
36+
if ! touch "${workDir:?}/.skip-trusted-artifacts" 2>/dev/null; then
37+
# If we can't create the file due to permissions, try to fix permissions
38+
if [ -d "${workDir:?}" ]; then
39+
# Try to make the directory writable by the current user
40+
chmod u+w "${workDir:?}" 2>/dev/null || true
41+
# Try again to create the file
42+
if ! touch "${workDir:?}/.skip-trusted-artifacts" 2>/dev/null; then
43+
echo "ERROR: Cannot create .skip-trusted-artifacts file due to permissions"
44+
echo " This may cause issues with trusted artifacts operations"
45+
# Exit with error to surface the permission issue
46+
exit 1
47+
fi
48+
else
49+
echo "ERROR: Work directory ${workDir:?} does not exist"
50+
exit 1
51+
fi
52+
fi
53+
fi
3154
fi

tasks/managed/reduce-snapshot/reduce-snapshot.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ spec:
7878
value: "$(params.orasOptions)"
7979
- name: "DEBUG"
8080
value: "$(params.trustedArtifactsDebug)"
81+
# This is a workaround for a problem observed on a particular cluster where the
82+
# use-trusted-artifacts step runs with root user causing a docker credential file
83+
# to not be readable in later steps. There might be solution coming related to the
84+
# security context constraints on the cluster, but setting this explicitly here
85+
# should probably be harmless either way.
86+
securityContext:
87+
runAsUser: 1001
8188
steps:
8289
- name: skip-trusted-artifact-operations
8390
computeResources:

tasks/managed/reduce-snapshot/tests/test-reduce-snapshot-disabled-single-component-mode.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ spec:
4848
value: "$(params.orasOptions)"
4949
- name: "DEBUG"
5050
value: "$(params.trustedArtifactsDebug)"
51+
# Use the same security context as the main task to avoid permission issues
52+
securityContext:
53+
runAsUser: 1001
5154
steps:
5255
- name: create-crs
5356
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
5457
script: |
5558
#!/usr/bin/env bash
5659
set -eux
5760
58-
cat > snapshot << EOF
61+
# Write to writable directory
62+
cat > /var/workdir/snapshot << EOF
5963
apiVersion: appstudio.redhat.com/v1alpha1
6064
kind: Snapshot
6165
metadata:
@@ -72,7 +76,7 @@ spec:
7276
- name: tom
7377
containerImage: newimage2
7478
EOF
75-
kubectl apply -f snapshot
79+
kubectl apply -f /var/workdir/snapshot
7680
7781
mkdir -p "$(params.dataDir)/$(context.pipelineRun.uid)"
7882
kubectl get snapshot/snapshot-sample -ojson | jq .spec | tee \
@@ -169,6 +173,9 @@ spec:
169173
value: "$(params.orasOptions)"
170174
- name: "DEBUG"
171175
value: "$(params.trustedArtifactsDebug)"
176+
# Use the same security context as the main task to avoid permission issues
177+
securityContext:
178+
runAsUser: 1001
172179
steps:
173180
- name: skip-trusted-artifact-operations
174181
ref:

tasks/managed/reduce-snapshot/tests/test-reduce-snapshot-missing-resource.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ spec:
4949
value: "$(params.orasOptions)"
5050
- name: "DEBUG"
5151
value: "$(params.trustedArtifactsDebug)"
52+
# Use the same security context as the main task to avoid permission issues
53+
securityContext:
54+
runAsUser: 1001
5255
steps:
5356
- name: create-crs
5457
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
5558
script: |
5659
#!/usr/bin/env bash
5760
set -eux
5861
59-
cat > snapshot << EOF
62+
# Write to writable directory
63+
cat > /var/workdir/snapshot << EOF
6064
apiVersion: appstudio.redhat.com/v1alpha1
6165
kind: Snapshot
6266
metadata:
@@ -73,7 +77,7 @@ spec:
7377
- name: tom
7478
containerImage: newimage2
7579
EOF
76-
kubectl apply -f snapshot
80+
kubectl apply -f /var/workdir/snapshot
7781
7882
mkdir -p "$(params.dataDir)/$(context.pipelineRun.uid)"
7983
kubectl get snapshot/snapshot-sample -ojson | jq .spec | tee \
@@ -170,6 +174,9 @@ spec:
170174
value: "$(params.orasOptions)"
171175
- name: "DEBUG"
172176
value: "$(params.trustedArtifactsDebug)"
177+
# Use the same security context as the main task to avoid permission issues
178+
securityContext:
179+
runAsUser: 1001
173180
steps:
174181
- name: skip-trusted-artifact-operations
175182
ref:

tasks/managed/reduce-snapshot/tests/test-reduce-snapshot-no-labels.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ spec:
4848
value: "$(params.orasOptions)"
4949
- name: "DEBUG"
5050
value: "$(params.trustedArtifactsDebug)"
51+
# Use the same security context as the main task to avoid permission issues
52+
securityContext:
53+
runAsUser: 1001
5154
steps:
5255
- name: create-crs
5356
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
5457
script: |
5558
#!/usr/bin/env bash
5659
set -eux
5760
58-
cat > snapshot << EOF
61+
# Write to writable directory
62+
cat > /var/workdir/snapshot << EOF
5963
apiVersion: appstudio.redhat.com/v1alpha1
6064
kind: Snapshot
6165
metadata:
@@ -69,7 +73,7 @@ spec:
6973
- name: tom
7074
containerImage: newimage2
7175
EOF
72-
kubectl apply -f snapshot
76+
kubectl apply -f /var/workdir/snapshot
7377
7478
mkdir -p "$(params.dataDir)/$(context.pipelineRun.uid)"
7579
kubectl get snapshot/snapshot-sample -ojson | jq .spec | \
@@ -166,6 +170,9 @@ spec:
166170
value: "$(params.orasOptions)"
167171
- name: "DEBUG"
168172
value: "$(params.trustedArtifactsDebug)"
173+
# Use the same security context as the main task to avoid permission issues
174+
securityContext:
175+
runAsUser: 1001
169176
steps:
170177
- name: skip-trusted-artifact-operations
171178
ref:

tasks/managed/reduce-snapshot/tests/test-reduce-snapshot-no-namespace-parameter.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ spec:
4848
value: "$(params.orasOptions)"
4949
- name: "DEBUG"
5050
value: "$(params.trustedArtifactsDebug)"
51+
# Use the same security context as the main task to avoid permission issues
52+
securityContext:
53+
runAsUser: 1001
5154
steps:
5255
- name: create-crs
5356
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
5457
script: |
5558
#!/usr/bin/env bash
5659
set -eux
5760
58-
cat > snapshot << EOF
61+
# Write to writable directory
62+
cat > /var/workdir/snapshot << EOF
5963
apiVersion: appstudio.redhat.com/v1alpha1
6064
kind: Snapshot
6165
metadata:
@@ -72,7 +76,7 @@ spec:
7276
- name: tom
7377
containerImage: newimage2
7478
EOF
75-
kubectl apply -f snapshot
79+
kubectl apply -f /var/workdir/snapshot
7680
7781
mkdir -p "$(params.dataDir)/$(context.pipelineRun.uid)"
7882
kubectl get snapshot/snapshot-sample -ojson | jq .spec | tee \
@@ -167,6 +171,9 @@ spec:
167171
value: "$(params.orasOptions)"
168172
- name: "DEBUG"
169173
value: "$(params.trustedArtifactsDebug)"
174+
# Use the same security context as the main task to avoid permission issues
175+
securityContext:
176+
runAsUser: 1001
170177
steps:
171178
- name: skip-trusted-artifact-operations
172179
ref:

tasks/managed/reduce-snapshot/tests/test-reduce-snapshot-wrong-component.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ spec:
4949
value: "$(params.orasOptions)"
5050
- name: "DEBUG"
5151
value: "$(params.trustedArtifactsDebug)"
52+
# Use the same security context as the main task to avoid permission issues
53+
securityContext:
54+
runAsUser: 1001
5255
steps:
5356
- name: create-crs
5457
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
5558
script: |
5659
#!/usr/bin/env bash
5760
set -eux
5861
59-
cat > snapshot << EOF
62+
# Write to writable directory
63+
cat > /var/workdir/snapshot << EOF
6064
apiVersion: appstudio.redhat.com/v1alpha1
6165
kind: Snapshot
6266
metadata:
@@ -73,7 +77,7 @@ spec:
7377
- name: tom
7478
containerImage: newimage2
7579
EOF
76-
kubectl apply -f snapshot
80+
kubectl apply -f /var/workdir/snapshot
7781
7882
mkdir -p "$(params.dataDir)/$(context.pipelineRun.uid)"
7983
kubectl get snapshot/snapshot-sample -ojson | jq .spec | tee \
@@ -170,6 +174,9 @@ spec:
170174
value: "$(params.orasOptions)"
171175
- name: "DEBUG"
172176
value: "$(params.trustedArtifactsDebug)"
177+
# Use the same security context as the main task to avoid permission issues
178+
securityContext:
179+
runAsUser: 1001
173180
steps:
174181
- name: skip-trusted-artifact-operations
175182
ref:

0 commit comments

Comments
 (0)