Skip to content

Commit 1b4db73

Browse files
authored
MGMT-22814: day 2 sync of clair vulnerability data (import execution in tekton) (#28)
* day 2 sync of clair vulnerability data (import execution in tekton) * ai suggested fixes * workingDir * fix pull secret path
1 parent 104fb13 commit 1b4db73

4 files changed

Lines changed: 118 additions & 21 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
- name: Get OpenShift CLI image from OpenShift release
3+
ansible.builtin.command: >
4+
{{ workingDir }}/bin/oc adm release info --registry-config={{ pullSecretPath }} --image-for cli
5+
quay.io/openshift-release-dev/ocp-release:{{ mgmt_openshift_version }}-x86_64
6+
register: r_oc_cli_image
7+
changed_when: false
8+
9+
- name: Set image facts
10+
ansible.builtin.set_fact:
11+
oc_cli_image: "{{ r_oc_cli_image.stdout }}"
12+
13+
- name: Create Clair Import ServiceAccount
14+
kubernetes.core.k8s:
15+
state: present
16+
definition:
17+
apiVersion: v1
18+
kind: ServiceAccount
19+
metadata:
20+
name: clair-import
21+
namespace: openshift-pipelines
22+
23+
- name: Create Clair Import Task
24+
kubernetes.core.k8s:
25+
state: present
26+
definition:
27+
apiVersion: tekton.dev/v1
28+
kind: Task
29+
metadata:
30+
name: clair-import
31+
namespace: openshift-pipelines
32+
spec:
33+
results:
34+
- name: exit-code
35+
description: "Success of clair import (exit code)"
36+
- name: status-report
37+
description: "Report of clair import"
38+
steps:
39+
- name: clair-import
40+
image: "{{ oc_cli_image }}"
41+
script: |
42+
#!/bin/bash
43+
set -uo pipefail
44+
45+
clair_pod_name=$(oc get pods -n quay-enterprise -l quay-component=clair-app -o name | cut -d/ -f2)
46+
if oc exec -n quay-enterprise "$clair_pod_name" -- \
47+
/bin/sh -c "
48+
curl -L -o /tmp/updates.json.gz http://{{ quayHostname }}/clair/updates.json.gz
49+
/usr/bin/clairctl --config /clair/config.yaml import-updaters /tmp/updates.json.gz
50+
" > "$(results.status-report.path)" 2>&1; then
51+
rc=0
52+
else
53+
rc=$?
54+
fi
55+
echo "$rc" > "$(results.exit-code.path)"
56+
exit "$rc"
57+
58+
- name: Create Clair Import Pipeline
59+
kubernetes.core.k8s:
60+
state: present
61+
definition:
62+
apiVersion: tekton.dev/v1
63+
kind: Pipeline
64+
metadata:
65+
name: clair-import
66+
namespace: openshift-pipelines
67+
spec:
68+
tasks:
69+
- name: clair-import
70+
taskRef:
71+
name: clair-import
72+
results:
73+
- name: exit-code
74+
value: $(tasks.clair-import.results.exit-code)
75+
- name: status-report
76+
value: $(tasks.clair-import.results.status-report)
77+
timeout: "1h"

operators/openshift-pipelines-operator-rh/tasks.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
until: r_tekton_config_info is success
1515
retries: 120
1616
delay: 30
17+
18+
- name: Create Clair Import Pipeline
19+
ansible.builtin.include_tasks:
20+
file: clair_import_pipeline.yaml

operators/quay-operator/clair_disconnected.yaml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,37 @@
3737
src: "{{ workingDir }}/data/clair/updates.json.gz"
3838
dest: "/var/www/html/clair/updates.json.gz"
3939

40-
- name: Get Clair Pod object from quay-enterprise
41-
kubernetes.core.k8s_info:
42-
kind: Pod
43-
namespace: quay-enterprise
44-
label_selectors:
45-
- quay-component=clair-app
46-
register: clair_pod_list
40+
- name: Create Clair Import Role
41+
kubernetes.core.k8s:
42+
state: present
43+
definition:
44+
apiVersion: rbac.authorization.k8s.io/v1
45+
kind: Role
46+
metadata:
47+
name: clair-import
48+
namespace: quay-enterprise
49+
rules:
50+
- apiGroups: [""]
51+
resources: ["pods"]
52+
verbs: ["get", "list"]
53+
- apiGroups: [""]
54+
resources: ["pods/exec"]
55+
verbs: ["create"]
4756

48-
- name: Set Pod fact and verify existence
49-
ansible.builtin.set_fact:
50-
clair_pod: "{{ clair_pod_list.resources[0] }}"
51-
failed_when: clair_pod_list.resources | length == 0
52-
53-
- name: Execute Import inside the Clair Pod
54-
ansible.builtin.shell: |
55-
{{ workingDir }}/bin/oc exec -n quay-enterprise {{ clair_pod.metadata.name }} -- \
56-
/bin/sh -c "
57-
set -e
58-
curl -L -o /tmp/updates.json.gz http://{{ quayHostname }}/clair/updates.json.gz
59-
/usr/bin/clairctl --config /clair/config.yaml import-updaters /tmp/updates.json.gz
60-
"
61-
register: import_output
57+
- name: Create Clair Import RoleBinding
58+
kubernetes.core.k8s:
59+
state: present
60+
definition:
61+
apiVersion: rbac.authorization.k8s.io/v1
62+
kind: RoleBinding
63+
metadata:
64+
name: clair-import
65+
namespace: quay-enterprise
66+
subjects:
67+
- kind: ServiceAccount
68+
name: clair-import
69+
namespace: openshift-pipelines
70+
roleRef:
71+
kind: Role
72+
name: clair-import
73+
apiGroup: rbac.authorization.k8s.io

sync.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ echo -p "Quay disconnected .." -n1 -s
7676
ansible-playbook playbooks/06-day2.yaml -e@$global_vars -e@$certs_vars --tags quay-disconnected 2>&1 | tee -a ${log}
7777
echo -e "\e[38;5;10m Done...\033[0m"; date
7878

79+
echo -p "Clair disconnected .." -n1 -s
80+
ansible-playbook playbooks/06-day2.yaml -e@$global_vars -e@$certs_vars --tags clair-disconnected 2>&1 | tee -a ${log}
81+
echo -e "\e[38;5;10m Done...\033[0m"; date
82+
7983
echo -p "ACM ClusterImageSets .." -n1 -s
8084
ansible-playbook playbooks/06-day2.yaml -e@$global_vars -e@$certs_vars --tags acm-cis 2>&1 | tee -a ${log}
8185
echo -e "\e[38;5;10m Done...\033[0m"; date

0 commit comments

Comments
 (0)