Skip to content

Commit 37b1017

Browse files
committed
Migrate Tekton-Chains to openshift-pipelines 1/3
This PR leaves the secrets in the tekton-chains namespace, but copies them to the openshift-pipelines namespace. This should guarantee that older attestations can still be decoded, and that new attestations can be decoded if the PR needs to be rolled back. * Move chains configuration to TektonConfig * Revert premature changes on namespaces * Add serviceaccount and job to copy the secrets to the new namespace * A test commented out has been added for when we are ready to do part 2/2 * Improve debugging of test.sh and behavior on some flakiness Part 2/3 will enable the public-key-migration test so that EC can target the new secret. Part 2/3 will deprecate the tekton-chains namespace. Signed-off-by: Romain Arnaud <[email protected]>
1 parent 46c1a3f commit 37b1017

File tree

14 files changed

+286
-51
lines changed

14 files changed

+286
-51
lines changed

operator/gitops/argocd/pipeline-service/openshift-pipelines/allow-argocd-to-manage.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ kind: ClusterRole
44
metadata:
55
name: openshift-gitops-apply-tekton-config-parameters
66
rules:
7+
- apiGroups:
8+
- monitoring.coreos.com
9+
resources:
10+
- servicemonitors
11+
verbs:
12+
- get
13+
- list
14+
- patch
15+
- create
16+
- delete
717
- apiGroups:
818
- operator.tekton.dev
919
resources:

operator/gitops/argocd/pipeline-service/openshift-pipelines/tekton-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
# Docs: https://github.com/tektoncd/operator/blob/main/docs/TektonConfig.md
23
apiVersion: operator.tekton.dev/v1alpha1
34
kind: TektonConfig
45
metadata:
@@ -15,6 +16,22 @@ spec:
1516
openshift:
1617
pipelinesAsCode:
1718
enable: true
19+
chain:
20+
# Configure TaskRun attestation.
21+
# RHTAP does not leverage the TaskRun attestations.
22+
# This tells Tekton Chains to not store them in the OCI registry.
23+
artifacts.taskrun.format: "in-toto"
24+
artifacts.taskrun.storage: ""
25+
26+
# Configure image signing
27+
artifacts.oci.storage: "oci"
28+
29+
# Configure PipelineRun attestation
30+
artifacts.pipelinerun.format: "in-toto"
31+
artifacts.pipelinerun.storage: "oci"
32+
33+
# Rekor integration is disabled for now. It is planned to be re-introduced in the future.
34+
transparency.enabled: "false"
1835
pipeline:
1936
default-service-account: appstudio-pipeline
2037
enable-api-fields: beta

operator/gitops/argocd/pipeline-service/tekton-chains/chains-config.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

operator/gitops/argocd/pipeline-service/tekton-chains/chains-secrets-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ apiVersion: v1
33
kind: ServiceAccount
44
metadata:
55
name: chains-secrets-admin
6-
namespace: openshift-pipelines
6+
namespace: tekton-chains
77
---
88
apiVersion: rbac.authorization.k8s.io/v1
99
kind: Role
1010
metadata:
1111
name: chains-secret-admin
12-
namespace: openshift-pipelines
12+
namespace: tekton-chains
1313
rules:
1414
- apiGroups:
1515
- ""
@@ -39,15 +39,15 @@ apiVersion: rbac.authorization.k8s.io/v1
3939
kind: RoleBinding
4040
metadata:
4141
name: chains-secret-admin
42-
namespace: openshift-pipelines
42+
namespace: tekton-chains
4343
roleRef:
4444
apiGroup: rbac.authorization.k8s.io
4545
kind: Role
4646
name: chains-secret-admin
4747
subjects:
4848
- kind: ServiceAccount
4949
name: chains-secrets-admin
50-
namespace: openshift-pipelines
50+
namespace: tekton-chains
5151
---
5252
apiVersion: rbac.authorization.k8s.io/v1
5353
kind: RoleBinding
@@ -61,13 +61,13 @@ roleRef:
6161
subjects:
6262
- kind: ServiceAccount
6363
name: chains-secrets-admin
64-
namespace: openshift-pipelines
64+
namespace: tekton-chains
6565
---
6666
apiVersion: batch/v1
6767
kind: Job
6868
metadata:
6969
name: tekton-chains-signing-secret
70-
namespace: openshift-pipelines
70+
namespace: tekton-chains
7171
annotations:
7272
argocd.argoproj.io/sync-wave: "1"
7373
spec:
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: tekton-chains-secrets-migrator
6+
namespace: openshift-pipelines
7+
---
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRole
10+
metadata:
11+
name: tekton-chains-secret-migration
12+
rules:
13+
- apiGroups:
14+
- ""
15+
resources:
16+
- secrets
17+
resourceNames:
18+
- public-key
19+
- signing-secrets
20+
verbs:
21+
- get
22+
---
23+
apiVersion: rbac.authorization.k8s.io/v1
24+
kind: RoleBinding
25+
metadata:
26+
name: tekton-chains-secrets-migrator
27+
namespace: tekton-chains
28+
roleRef:
29+
apiGroup: rbac.authorization.k8s.io
30+
kind: ClusterRole
31+
name: tekton-chains-secret-migration
32+
subjects:
33+
- kind: ServiceAccount
34+
name: tekton-chains-secrets-migrator
35+
namespace: openshift-pipelines
36+
---
37+
apiVersion: rbac.authorization.k8s.io/v1
38+
kind: Role
39+
metadata:
40+
name: openshift-pipelines-secret-migration
41+
namespace: openshift-pipelines
42+
rules:
43+
- apiGroups:
44+
- ""
45+
resources:
46+
- secrets
47+
verbs:
48+
- list
49+
- create
50+
- get
51+
- update
52+
- patch
53+
- delete
54+
---
55+
apiVersion: rbac.authorization.k8s.io/v1
56+
kind: RoleBinding
57+
metadata:
58+
name: openshift-pipelines-secret-migration
59+
namespace: openshift-pipelines
60+
roleRef:
61+
apiGroup: rbac.authorization.k8s.io
62+
kind: Role
63+
name: openshift-pipelines-secret-migration
64+
subjects:
65+
- kind: ServiceAccount
66+
name: tekton-chains-secrets-migrator
67+
namespace: openshift-pipelines
68+
---
69+
apiVersion: rbac.authorization.k8s.io/v1
70+
kind: ClusterRole
71+
metadata:
72+
name: openshift-gitops-jobs-admin
73+
rules:
74+
- apiGroups:
75+
- batch
76+
resources:
77+
- jobs
78+
verbs:
79+
- get
80+
- list
81+
- patch
82+
- create
83+
- delete
84+
---
85+
apiVersion: rbac.authorization.k8s.io/v1
86+
kind: ClusterRoleBinding
87+
metadata:
88+
name: openshift-gitops-jobs-admin
89+
roleRef:
90+
apiGroup: rbac.authorization.k8s.io
91+
kind: ClusterRole
92+
name: openshift-gitops-jobs-admin
93+
subjects:
94+
- kind: ServiceAccount
95+
name: openshift-gitops-argocd-application-controller
96+
namespace: openshift-gitops
97+
---
98+
apiVersion: batch/v1
99+
kind: Job
100+
metadata:
101+
name: tekton-chains-secrets-migration
102+
namespace: openshift-pipelines
103+
annotations:
104+
# Must run after tekton-chains-signing-secret during migration
105+
argocd.argoproj.io/sync-wave: "2"
106+
spec:
107+
template:
108+
spec:
109+
containers:
110+
- name: chains-secret-migration
111+
image: quay.io/redhat-appstudio/appstudio-utils:eb94f28fe2d7c182f15e659d0fdb66f87b0b3b6b
112+
imagePullPolicy: Always
113+
command:
114+
- /bin/bash
115+
- -c
116+
- |
117+
cd /tmp
118+
# Once the key-pair has been set it's marked as immutable so it can't be updated.
119+
# Try to handle that nicely. The object is expected to always exist so check the data.
120+
echo "Waiting for tekton-chains/secrets/signing-secrets: "
121+
while [ -z $CHAINS_SIG_KEY_DATA ]; do
122+
echo -n "."
123+
CHAINS_SIG_KEY_DATA=$(kubectl get secret signing-secrets -n tekton-chains -o jsonpath='{.data}')
124+
sleep 3
125+
done
126+
echo "OK"
127+
128+
OSP_SIG_KEY_DATA=$(kubectl get secret signing-secrets -n openshift-pipelines -o jsonpath='{.data}')
129+
if [ -z "$OSP_SIG_KEY_DATA" -o "$OSP_SIG_KEY_DATA" != "$CHAINS_SIG_KEY_DATA" ]; then
130+
echo "openshift-pipelines: copying signing-secrets from tekton-chains"
131+
kubectl create secret generic signing-secrets \
132+
--namespace openshift-pipelines \
133+
--from-literal=cosign.key="$(
134+
echo "$CHAINS_SIG_KEY_DATA" | jq -r '.["cosign.key"]' | base64 -d
135+
)" \
136+
--from-literal=cosign.password="$(
137+
echo "$CHAINS_SIG_KEY_DATA" | jq -r '.["cosign.password"]' | base64 -d
138+
)" \
139+
--from-literal=cosign.pub="$(
140+
echo "$CHAINS_SIG_KEY_DATA" | jq -r '.["cosign.pub"]' | base64 -d
141+
)" \
142+
--dry-run=client \
143+
-o yaml | kubectl apply -f -
144+
else
145+
echo "openshift-pipelines: signing-secrets is up to date"
146+
fi
147+
148+
# Generate/update the secret with the public key
149+
echo "Creating public-key in openshift-pipelines"
150+
kubectl create secret generic public-key \
151+
--namespace openshift-pipelines \
152+
--from-literal=cosign.pub="$(
153+
cosign public-key --key k8s://openshift-pipelines/signing-secrets
154+
)" \
155+
--dry-run=client \
156+
-o yaml | kubectl apply -f -
157+
echo "OK"
158+
dnsPolicy: ClusterFirst
159+
restartPolicy: OnFailure
160+
terminationGracePeriodSeconds: 30
161+
serviceAccountName: tekton-chains-secrets-migrator
162+
---
163+
# public-key access
164+
apiVersion: rbac.authorization.k8s.io/v1
165+
kind: RoleBinding
166+
metadata:
167+
name: openshift-pipelines-public-key-viewer
168+
namespace: openshift-pipelines
169+
roleRef:
170+
apiGroup: rbac.authorization.k8s.io
171+
kind: ClusterRole
172+
name: tekton-chains-public-key-viewer
173+
subjects:
174+
- apiGroup: rbac.authorization.k8s.io
175+
kind: Group
176+
name: system:authenticated

operator/gitops/argocd/pipeline-service/tekton-chains/kustomization.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@ resources:
99
# To list available releases:
1010
# curl -s https://storage.googleapis.com/tekton-releases/ | xq | grep -E 'chains/.*/release.yaml'
1111
#
12+
- namespace.yaml
1213
- chains-secrets-config.yaml
1314
- public-key.yaml
15+
- chains-secrets-migration.yaml
1416

1517
patches:
16-
# Add some chains configuration
17-
- path: chains-config.yaml
18-
#
1918
- target:
2019
kind: Secret
2120
name: signing-secrets
22-
namespace: openshift-pipelines
21+
namespace: tekton-chains
2322
patch: |-
2423
apiVersion: v1
2524
kind: Secret
2625
metadata:
2726
name: signing-secrets
28-
namespace: openshift-pipelines
27+
namespace: tekton-chains
2928
$patch: delete
29+
# Allow openshift-gitops to manage tekton-chains
30+
- target:
31+
kind: Namespace
32+
name: tekton-chains
33+
patch: |-
34+
- op: add
35+
path: "/metadata/labels"
36+
value:
37+
argocd.argoproj.io/managed-by: openshift-gitops
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: tekton-chains

operator/gitops/argocd/pipeline-service/tekton-chains/public-key.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apiVersion: rbac.authorization.k8s.io/v1
1919
kind: RoleBinding
2020
metadata:
2121
name: tekton-chains-public-key-viewer
22-
namespace: openshift-pipelines
22+
namespace: tekton-chains
2323
roleRef:
2424
apiGroup: rbac.authorization.k8s.io
2525
kind: ClusterRole

operator/images/access-setup/content/bin/setup_work_dir.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ tekton_chains_manifest(){
157157
--workdir /workspace \
158158
--entrypoint /usr/bin/cosign \
159159
"$cosign_image" generate-key-pair
160-
kubectl create namespace openshift-pipelines --dry-run=client -o yaml > "$chains_namespace"
161-
kubectl create secret generic -n openshift-pipelines signing-secrets --from-file="$chains_tmp_dir" --dry-run=client -o yaml | \
160+
kubectl create namespace tekton-chains --dry-run=client -o yaml > "$chains_namespace"
161+
kubectl create secret generic -n tekton-chains signing-secrets --from-file="$chains_tmp_dir" --dry-run=client -o yaml | \
162162
yq '. += {"immutable" :true}' | \
163163
yq "sort_keys(.)" > "$chains_secret"
164164
yq e -n '.resources += ["namespace.yaml", "signing-secrets.yaml"]' > "$chains_kustomize"

operator/images/cluster-setup/content/bin/install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ install_clusters() {
154154
install_shared_manifests() {
155155
CREDENTIALS_DIR="$WORKSPACE_DIR/credentials"
156156

157-
# if [ "$(kubectl get secret -n openshift-pipelines signing-secrets --ignore-not-found -o json | jq -r ".immutable")" != "true" ]; then
158-
# kubectl apply -k "$CREDENTIALS_DIR/manifests/compute/tekton-chains"
159-
# fi
157+
# if [ "$(kubectl get secret -n tekton-chains signing-secrets --ignore-not-found -o json | jq -r ".immutable")" != "true" ]; then
158+
# kubectl apply -k "$CREDENTIALS_DIR/manifests/compute/tekton-chains"
159+
# fi
160160
kubectl apply -k "$CREDENTIALS_DIR/manifests/compute/tekton-results"
161161
}
162162

0 commit comments

Comments
 (0)