Skip to content

Commit 7f0c6cc

Browse files
committed
day 2 sync of clair vulnerability data (import execution in tekton)
1 parent d629a0d commit 7f0c6cc

4 files changed

Lines changed: 109 additions & 21 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
- name: Get OpenShift CLI image from OpenShift release
3+
ansible.builtin.command: >
4+
{{ rootDir }}/bin/oc adm release info --registry-config={{ rootDir }}/config/pull-secret.json --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+
44+
clair_pod_name=$(oc get pods -n quay-enterprise -l quay-component=clair-app -o name | cut -d/ -f2)
45+
oc exec -n quay-enterprise $clair_pod_name -- \
46+
/bin/sh -c "
47+
curl -L -o /tmp/updates.json.gz http://{{ quayHostname }}/clair/updates.json.gz
48+
/usr/bin/clairctl --config /clair/config.yaml import-updaters /tmp/updates.json.gz
49+
" > $(results.status-report.path)
50+
echo $? > $(results.exit-code.path)
51+
52+
- name: Create Clair Import Pipeline
53+
kubernetes.core.k8s:
54+
state: present
55+
definition:
56+
apiVersion: tekton.dev/v1
57+
kind: Pipeline
58+
metadata:
59+
name: clair-import
60+
namespace: openshift-pipelines
61+
spec:
62+
tasks:
63+
- name: clair-import
64+
taskRef:
65+
name: clair-import
66+
results:
67+
- name: exit-code
68+
value: $(tasks.clair-import.results.exit-code)
69+
- name: status-report
70+
value: $(tasks.clair-import.results.status-report)
71+
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: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,34 @@
5959
src: "{{ workingDir }}/data/clair/updates.json.gz"
6060
dest: "/var/www/html/clair/updates.json.gz"
6161

62-
- name: Get Clair Pod object from quay-enterprise
63-
kubernetes.core.k8s_info:
64-
kind: Pod
65-
namespace: quay-enterprise
66-
label_selectors:
67-
- quay-component=clair-app
68-
register: clair_pod_list
69-
70-
- name: Set Pod fact and verify existence
71-
ansible.builtin.set_fact:
72-
clair_pod: "{{ clair_pod_list.resources[0] }}"
73-
failed_when: clair_pod_list.resources | length == 0
62+
- name: Create Clair Import Role
63+
kubernetes.core.k8s:
64+
state: present
65+
definition:
66+
apiVersion: rbac.authorization.k8s.io/v1
67+
kind: Role
68+
metadata:
69+
name: clair-import
70+
namespace: quay-enterprise
71+
rules:
72+
- apiGroups: [""]
73+
resources: ["pods"]
74+
verbs: ["get", "list", "exec"]
7475

75-
- name: Execute Import inside the Clair Pod
76-
ansible.builtin.shell: |
77-
{{ workingDir }}/bin/oc exec -n quay-enterprise {{ clair_pod.metadata.name }} -- \
78-
/bin/sh -c "
79-
set -e
80-
curl -L -o /tmp/updates.json.gz http://{{ quayHostname }}/clair/updates.json.gz
81-
/usr/bin/clairctl --config /clair/config.yaml import-updaters /tmp/updates.json.gz
82-
"
83-
register: import_output
76+
- name: Create Clair Import RoleBinding
77+
kubernetes.core.k8s:
78+
state: present
79+
definition:
80+
apiVersion: rbac.authorization.k8s.io/v1
81+
kind: RoleBinding
82+
metadata:
83+
name: clair-import
84+
namespace: quay-enterprise
85+
subjects:
86+
- kind: ServiceAccount
87+
name: clair-import
88+
namespace: openshift-pipelines
89+
roleRef:
90+
kind: Role
91+
name: clair-import
92+
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)