Skip to content

Commit 8d04540

Browse files
committed
feat(RELEASE-2031): use pubtools-sign to sign in blob-signing-pipeline
Added debug cert check Signed-off-by: Jindrich Luza <jluza@redhat.com>
1 parent 83a8c0e commit 8d04540

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

tasks/internal/request-blob-signature/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Tekton task to request a simple signature.
88

99
| Name | Description | Optional | Default value |
1010
|--------------------------|-----------------------------------------------------------------------|----------|-----------------------------------------------------------------------------------|
11-
| pipeline_image | A docker image of operator-pipeline-images for the steps to run in | Yes | quay.io/konflux-ci/release-service-utils:82012e03002128f2a226acb23dc5c6fc1c37f5b6 |
11+
| pipeline_image | A docker image of operator-pipeline-images for the steps to run in | Yes | quay.io/konflux-ci/release-service-utils:13e379cb498293f8f7b8b9c84c57d9e8ab141be2 |
1212
| requester | Name of the user that requested the signing, for auditing purposes | No | - |
1313
| blob | Blob content to be signed, base64 encoded | No | - |
1414
| sig_key_names | NL separated signing key names that the content is signed with | Yes | containerisvsign |

tasks/internal/request-blob-signature/request-blob-signature.yaml

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
params:
1515
- description: A docker image of operator-pipeline-images for the steps to run in
1616
name: pipeline_image
17-
default: "quay.io/konflux-ci/release-service-utils:82012e03002128f2a226acb23dc5c6fc1c37f5b6"
17+
default: "quay.io/konflux-ci/release-service-utils:13e379cb498293f8f7b8b9c84c57d9e8ab141be2"
1818
type: string
1919
- description: Name of the user that requested the signing, for auditing purposes
2020
name: requester
@@ -98,6 +98,7 @@ spec:
9898
computeResources:
9999
limits:
100100
memory: 128Mi
101+
cpu: 100m
101102
requests:
102103
memory: 128Mi
103104
cpu: 100m
@@ -124,6 +125,7 @@ spec:
124125
computeResources:
125126
limits:
126127
memory: 128Mi
128+
cpu: 100m
127129
requests:
128130
memory: 128Mi
129131
cpu: 100m
@@ -236,6 +238,7 @@ spec:
236238
computeResources:
237239
limits:
238240
memory: 128Mi
241+
cpu: 100m
239242
requests:
240243
memory: 128Mi
241244
cpu: 100m
@@ -260,14 +263,67 @@ spec:
260263
echo $(context.taskRun.uid)
261264
fi
262265
}
266+
PY_SCRIPT=$(cat <<'END_HEREDOC'
267+
import os
268+
import sys
269+
from cryptography import x509
270+
from cryptography.hazmat.primitives import serialization
271+
from cryptography.hazmat.primitives.asymmetric import rsa
272+
273+
def validate_ssl_pair(cert_path, key_path):
274+
try:
275+
# 1. Load and Validate Certificate
276+
with open(cert_path, "rb") as f:
277+
cert_data = f.read()
278+
cert = x509.load_pem_x509_certificate(cert_data)
279+
280+
# 2. Load and Validate Private Key
281+
with open(key_path, "rb") as f:
282+
key_data = f.read()
283+
# If your key has a password, provide it in 'password='
284+
private_key = serialization.load_pem_private_key(key_data, password=None)
285+
286+
# 3. Check if they match
287+
# We compare the public key derived from the cert vs the one from the private key
288+
cert_pub_key = cert.public_key().public_bytes(
289+
encoding=serialization.Encoding.PEM,
290+
format=serialization.PublicFormat.SubjectPublicKeyInfo
291+
)
292+
key_pub_key = private_key.public_key().public_bytes(
293+
encoding=serialization.Encoding.PEM,
294+
format=serialization.PublicFormat.SubjectPublicKeyInfo
295+
)
296+
297+
if cert_pub_key == key_pub_key:
298+
return True, "Valid pair: Private key matches certificate."
299+
else:
300+
return False, "Mismatch: Private key does not belong to this certificate."
301+
302+
except Exception as e:
303+
return False, f"Validation error: {str(e)}"
304+
305+
print(f'Cert exists: {os.path.exists(sys.argv[1])}');
306+
print(f'Cert is readable: {os.access(sys.argv[1], os.R_OK)}');
307+
is_valid, message = validate_ssl_pair(sys.argv[1], sys.argv[1])
308+
print(message)
309+
END_HEREDOC
310+
)
311+
echo "$PY_SCRIPT" > /tmp/validate_ssl.py
263312
264313
umb_cert="$(cat "/mnt/umb_ssl_cert_secret/$(params.umb_ssl_cert_file_name)")"
265314
umb_key="$(cat "/mnt/umb_ssl_cert_secret/$(params.umb_ssl_key_file_name)")"
266315
267316
echo "${umb_cert:?}" > /tmp/umb.pem.$(get-task-id)
268317
echo "${umb_key:?}" >> /tmp/umb.pem.$(get-task-id)
269318
set -xe
270-
python3 -c "import proton;
319+
cert="/tmp/umb.pem.$(get-task-id)"
320+
321+
python3 /tmp/validate_ssl.py "${cert}"
322+
python3 -c "import proton; import os;
323+
cert='/tmp/umb.pem.$(get-task-id)';
324+
print(f'Cert exists: {os.path.exists(cert)}');
325+
print(f'Cert is readable: {os.access(cert, os.R_OK)}');
326+
print(f'Proton SSL ready: {proton.SSL.present()}');
271327
ssl_domain=proton.SSLDomain(proton.SSLDomain.MODE_CLIENT);
272328
cert='/tmp/umb.pem.$(get-task-id)';
273329
ssl_domain.set_credentials(cert, cert, None)"
@@ -276,6 +332,7 @@ spec:
276332
computeResources:
277333
limits:
278334
memory: 128Mi
335+
cpu: 100m
279336
requests:
280337
memory: 128Mi
281338
cpu: 100m
@@ -344,6 +401,7 @@ spec:
344401
computeResources:
345402
limits:
346403
memory: 128Mi
404+
cpu: 100m
347405
requests:
348406
memory: 128Mi
349407
cpu: 100m

tasks/managed/sign-base64-blob/sign-base64-blob.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ spec:
163163
exit 1
164164
fi
165165
166-
default_pipeline_image="quay.io/konflux-ci/release-service-utils:9d57cd95e60f0c61a118fe9261f5941815d33469"
166+
default_pipeline_image="quay.io/konflux-ci/release-service-utils:13e379cb498293f8f7b8b9c84c57d9e8ab141be2"
167167
pipeline_image=$(jq -r --arg default_pipeline_image ${default_pipeline_image} \
168168
'.sign.pipelineImage // $default_pipeline_image' "${DATA_FILE}")
169169
config_map_name=$(jq -r '.sign.configMapName // "signing-config-map"' "${DATA_FILE}")

tasks/managed/sign-base64-blob/tests/test-sign-base64-blob.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ spec:
170170
fi
171171
172172
if [ "$(jq -r '.pipeline_image' <<< "${params}")" != \
173-
"quay.io/konflux-ci/release-service-utils:9d57cd95e60f0c61a118fe9261f5941815d33469" ]
173+
"quay.io/konflux-ci/release-service-utils:13e379cb498293f8f7b8b9c84c57d9e8ab141be2" ]
174174
then
175175
echo "pipeline_image does not match"
176176
exit 1

0 commit comments

Comments
 (0)