Skip to content

Commit 42e6d49

Browse files
committed
add vex tarball downloader for IoP
1 parent 777e671 commit 42e6d49

7 files changed

Lines changed: 143 additions & 0 deletions

File tree

src/roles/iop_core/tasks/main.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
ansible.builtin.include_role:
5353
name: iop_cvemap_downloader
5454

55+
- name: Deploy IOP VEX Downloader
56+
ansible.builtin.include_role:
57+
name: iop_vex_downloader
58+
5559
- name: Deploy IOP VMAAS service
5660
ansible.builtin.include_role:
5761
name: iop_vmaas
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
iop_vex_downloader_base_url: "https://security.access.redhat.com/data/csaf/v2/vex/"
3+
iop_vex_downloader_latest_filename: "archive_latest.txt"
4+
iop_vex_downloader_output_dir: "/var/www/html/pub/iop/data/csaf/v2/vex/"
5+
iop_vex_downloader_output_filename: "vex-latest.tar.zst"
6+
iop_vex_downloader_timer_interval: "7d"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Path unit for vex-latest.tar.zst manual file watcher
3+
4+
[Path]
5+
PathChanged=/var/lib/foreman/vex-latest.tar.zst
6+
PathModified=/var/lib/foreman/vex-latest.tar.zst
7+
8+
[Install]
9+
WantedBy=multi-user.target
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Restart vex download timer
3+
ansible.builtin.systemd:
4+
name: iop-vex-download.timer
5+
state: restarted
6+
7+
- name: Restart vex download path
8+
ansible.builtin.systemd:
9+
name: iop-vex-download.path
10+
state: restarted
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
- name: Install vex download script
3+
ansible.builtin.template:
4+
src: iop-vex-downloader.sh.j2
5+
dest: /usr/local/bin/iop-vex-downloader.sh
6+
owner: root
7+
group: root
8+
mode: '0755'
9+
10+
- name: Create vex download service unit
11+
ansible.builtin.copy:
12+
dest: /etc/systemd/system/iop-vex-download.service
13+
content: |
14+
[Unit]
15+
Description=Manages vex-latest.tar.zst for IoP Vulnerability
16+
After=network-online.target iop-core-gateway.service
17+
Wants=network-online.target iop-core-gateway.service
18+
19+
[Service]
20+
Type=oneshot
21+
ExecStart=/usr/local/bin/iop-vex-downloader.sh \
22+
'{{ iop_vex_downloader_base_url }}' \
23+
'{{ iop_vex_downloader_latest_filename }}' \
24+
'{{ iop_vex_downloader_output_dir }}' \
25+
'{{ iop_vex_downloader_output_filename }}'
26+
User=root
27+
Group=root
28+
mode: '0644'
29+
30+
- name: Create vex download timer unit
31+
ansible.builtin.template:
32+
src: iop-vex-download.timer.j2
33+
dest: /etc/systemd/system/iop-vex-download.timer
34+
mode: '0644'
35+
notify: Restart vex download timer
36+
37+
- name: Create vex download path unit
38+
ansible.builtin.copy:
39+
src: iop-vex-download.path
40+
dest: /etc/systemd/system/iop-vex-download.path
41+
mode: '0644'
42+
notify: Restart vex download path
43+
44+
- name: Reload systemd daemon
45+
ansible.builtin.systemd:
46+
daemon_reload: true
47+
48+
- name: Flush handlers
49+
ansible.builtin.meta: flush_handlers
50+
51+
- name: Enable and start vex download timer
52+
ansible.builtin.systemd:
53+
name: iop-vex-download.timer
54+
enabled: true
55+
state: started
56+
57+
- name: Enable and start vex download path watcher
58+
ansible.builtin.systemd:
59+
name: iop-vex-download.path
60+
enabled: true
61+
state: started
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Timer for vex-latest.tar.zst download
3+
4+
[Timer]
5+
OnActiveSec=0
6+
OnUnitActiveSec={{ iop_vex_downloader_timer_interval }}
7+
8+
[Install]
9+
WantedBy=timers.target
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
URL="${1:-}"
6+
FILENAME_LATEST="${2:-}"
7+
OUTPUT_DIR="${3:-}"
8+
OUTPUT_FILENAME="${4:-}"
9+
10+
if [[ -z "$URL" || -z "$OUTPUT_DIR" || -z "$FILENAME_LATEST" || -z "$OUTPUT_FILENAME" ]]; then
11+
echo "Usage: $0 URL FILENAME_LATEST OUTPUT_DIR OUTPUT_FILENAME" >&2
12+
echo "Example: $0 https://security.access.redhat.com/data/csaf/v2/vex/ archive_latest.txt /root/download/ vex-latest.tar.zst" >&2
13+
exit 1
14+
fi
15+
16+
URL="${URL%/}/"
17+
OUTPUT_DIR="${OUTPUT_DIR%/}/"
18+
19+
ARCHIVE_DOWNLOAD_NAME_CONTENT=$(curl -sf $URL$FILENAME_LATEST)
20+
21+
if [ "$?" -ne 0 ]; then
22+
echo "Error: The tarball's name wasn't downloaded" >&2
23+
exit 1
24+
fi
25+
26+
mkdir -p "$OUTPUT_DIR"
27+
28+
curl -sf $URL$ARCHIVE_DOWNLOAD_NAME_CONTENT -o $OUTPUT_DIR$OUTPUT_FILENAME
29+
30+
RET=$?
31+
32+
if [ "$RET" -ne 0 ]; then
33+
echo "Error: Downloading of tarball failed. Curl failed with code $RET" >&2
34+
exit 2
35+
fi
36+
37+
curl -sf $URL$ARCHIVE_DOWNLOAD_NAME_CONTENT".asc" -o $OUTPUT_DIR$OUTPUT_FILENAME".asc"
38+
39+
RET=$?
40+
41+
if [ "$RET" -ne 0 ]; then
42+
echo "Error: Downloading of tarball's signature failed. Curl failed with code $RET" >&2
43+
exit 3
44+
fi

0 commit comments

Comments
 (0)