-
Notifications
You must be signed in to change notification settings - Fork 40
add vex tarball downloader for IoP #638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pfreyburg
wants to merge
10
commits into
theforeman:master
Choose a base branch
from
pfreyburg:RHINENG-25683-add-vex-tarball-downloader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
42e6d49
add vex tarball downloader for IoP
pfreyburg eac8b8e
iop vex: add offline mode
pfreyburg a79056f
add tests for vex
pfreyburg 77f2a14
IoP vex: edit script
pfreyburg e1bd040
IoP vex script: use full curl options
pfreyburg 0c57510
IoP vex: fix test path
pfreyburg 3f87058
IoP vex: fix script name in tests
pfreyburg 82c426c
IoP vex: add trap for deleting tmp files
pfreyburg 03c7816
IoP vex: rm stored checksum
pfreyburg 4447cb6
IoP vex downloader: fix shellcheck
pfreyburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| iop_vex_downloader_base_url: "https://security.access.redhat.com/data/csaf/v2/vex/" | ||
| iop_vex_downloader_output_dir: "/var/www/html/pub/iop/data/csaf/v2/vex/" | ||
| iop_vex_downloader_timer_interval: "7d" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [Unit] | ||
| Description=Path unit for vex-latest.tar.zst manual file watcher | ||
|
|
||
| [Path] | ||
| PathChanged=/var/lib/foreman/vex-latest.tar.zst | ||
| PathModified=/var/lib/foreman/vex-latest.tar.zst | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| - name: Restart vex download timer | ||
| ansible.builtin.systemd: | ||
| name: iop-vex-download.timer | ||
| state: restarted | ||
|
|
||
| - name: Restart vex download path | ||
| ansible.builtin.systemd: | ||
| name: iop-vex-download.path | ||
| state: restarted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| - name: Install vex download script | ||
| ansible.builtin.template: | ||
| src: iop-vex-downloader.sh.j2 | ||
| dest: /usr/local/bin/iop-vex-downloader.sh | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
|
|
||
| - name: Create vex download service unit | ||
| ansible.builtin.copy: | ||
| dest: /etc/systemd/system/iop-vex-download.service | ||
| content: | | ||
| [Unit] | ||
| Description=Manages vex-latest.tar.zst for IoP Vulnerability | ||
| After=network-online.target iop-core-gateway.service | ||
| Wants=network-online.target iop-core-gateway.service | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/local/bin/iop-vex-downloader.sh \ | ||
| '{{ iop_vex_downloader_base_url }}' \ | ||
| '{{ iop_vex_downloader_output_dir }}' | ||
| User=root | ||
| Group=root | ||
| mode: '0644' | ||
|
|
||
| - name: Create vex download timer unit | ||
| ansible.builtin.template: | ||
| src: iop-vex-download.timer.j2 | ||
| dest: /etc/systemd/system/iop-vex-download.timer | ||
| mode: '0644' | ||
| notify: Restart vex download timer | ||
|
|
||
| - name: Create vex download path unit | ||
| ansible.builtin.copy: | ||
| src: iop-vex-download.path | ||
| dest: /etc/systemd/system/iop-vex-download.path | ||
| mode: '0644' | ||
| notify: Restart vex download path | ||
|
|
||
| - name: Reload systemd daemon | ||
| ansible.builtin.systemd: | ||
| daemon_reload: true | ||
|
|
||
| - name: Flush handlers | ||
| ansible.builtin.meta: flush_handlers | ||
|
|
||
| - name: Enable and start vex download timer | ||
| ansible.builtin.systemd: | ||
| name: iop-vex-download.timer | ||
| enabled: true | ||
| state: started | ||
|
|
||
| - name: Enable and start vex download path watcher | ||
| ansible.builtin.systemd: | ||
| name: iop-vex-download.path | ||
| enabled: true | ||
| state: started |
9 changes: 9 additions & 0 deletions
9
src/roles/iop_vex_downloader/templates/iop-vex-download.timer.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [Unit] | ||
| Description=Timer for vex-latest.tar.zst download | ||
|
|
||
| [Timer] | ||
| OnActiveSec=0 | ||
| OnUnitActiveSec={{ iop_vex_downloader_timer_interval }} | ||
|
|
||
| [Install] | ||
| WantedBy=timers.target |
91 changes: 91 additions & 0 deletions
91
src/roles/iop_vex_downloader/templates/iop-vex-downloader.sh.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #!/bin/bash | ||
|
|
||
| # set -euo pipefail | ||
|
|
||
| FILENAME_LATEST="archive_latest.txt" | ||
| OUTPUT_FILENAME="vex-latest.tar.zst" | ||
|
|
||
| URL="${1:-}" | ||
|
pfreyburg marked this conversation as resolved.
|
||
| OUTPUT_DIR="${2:-}" | ||
|
|
||
|
|
||
| if [[ -z "${URL}" || -z "${OUTPUT_DIR}" ]]; then | ||
| echo "Usage: ${0} URL OUTPUT_DIR" >&2 | ||
| echo "Example: ${0} https://security.access.redhat.com/data/csaf/v2/vex/ /root/download/" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| URL="${URL%/}/" | ||
| OUTPUT_DIR="${OUTPUT_DIR%/}/" | ||
|
|
||
| mkdir -p "${OUTPUT_DIR}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| MANUAL_FILE="/var/lib/foreman/vex-latest.tar.zst" | ||
| CHECKSUM_FILE="${OUTPUT_FILENAME}.checksum" | ||
|
pfreyburg marked this conversation as resolved.
Outdated
|
||
|
|
||
| if [[ -f "$MANUAL_FILE" ]]; then | ||
| echo "Offline mode: Using manual file from $MANUAL_FILE" | ||
|
|
||
| CURRENT_CHECKSUM=$(sha256sum "$MANUAL_FILE" | cut -d' ' -f1) | ||
| STORED_CHECKSUM="" | ||
|
|
||
| if [[ -f "$CHECKSUM_FILE" ]]; then | ||
| STORED_CHECKSUM=$(cat "$CHECKSUM_FILENAME") | ||
| fi | ||
|
|
||
| if [[ "$CURRENT_CHECKSUM" != "$STORED_CHECKSUM" ]]; then | ||
| echo "Copying updated manual file" | ||
| cp -Z "$MANUAL_FILE" "${OUTPUT_DIR}${OUTPUT_FILENAME}" && echo "$CURRENT_CHECKSUM" > "$CHECKSUM_FILE" | ||
| chmod 644 "${OUTPUT_DIR}${OUTPUT_FILENAME}" | ||
| else | ||
| echo "Manual file unchanged, skipping" | ||
| fi | ||
| else | ||
| echo "Online mode: Checking for updates from $URL" | ||
| ARCHIVE_DOWNLOAD_NAME_CONTENT=$(curl --silent \ | ||
| --fail \ | ||
| --location \ | ||
| "${URL}${FILENAME_LATEST}") | ||
|
|
||
| TEMP_FILE_ARCH=$(mktemp -t "iop-vex-download.XXXXXX") | ||
| TEMP_FILE_ASC=$(mktemp -t "iop-vex-download.asc.XXXXXX") | ||
|
pfreyburg marked this conversation as resolved.
Outdated
|
||
|
|
||
| trap "rm -f ${TEMP_FILE_ARCH} ${TEMP_FILE_ASC}" EXIT | ||
|
|
||
| if [ "${?}" -ne 0 ]; then | ||
| echo "Error: The tarball's name wasn't downloaded" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| curl --silent \ | ||
| --fail \ | ||
| --location \ | ||
| "${URL}${ARCHIVE_DOWNLOAD_NAME_CONTENT}" \ | ||
| --output ${TEMP_FILE_ARCH} | ||
|
|
||
| RET=${?} | ||
|
|
||
| if [ "${RET}" -ne 0 ]; then | ||
| echo "Error: Downloading of tarball failed. Curl failed with code ${RET}" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| curl --silent \ | ||
| --fail \ | ||
| --location \ | ||
| "${URL}${ARCHIVE_DOWNLOAD_NAME_CONTENT}.asc" \ | ||
| --output ${TEMP_FILE_ASC} | ||
|
|
||
| RET=${?} | ||
|
|
||
| if [ "${RET}" -ne 0 ]; then | ||
| echo "Error: Downloading of tarball's signature failed. Curl failed with code ${RET}" >&2 | ||
| exit 3 | ||
| fi | ||
|
|
||
| mv -Z ${TEMP_FILE_ARCH} "${OUTPUT_DIR}${OUTPUT_FILENAME}" | ||
| mv -Z ${TEMP_FILE_ASC} "${OUTPUT_DIR}${OUTPUT_FILENAME}.asc" | ||
|
|
||
| chmod 644 "${OUTPUT_DIR}${OUTPUT_FILENAME}" | ||
| chmod 644 "${OUTPUT_DIR}${OUTPUT_FILENAME}.asc" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import pytest | ||
|
|
||
| pytestmark = pytest.mark.feature("iop") | ||
|
|
||
|
|
||
| def test_vex_download_script(server): | ||
| script = server.file("/usr/local/bin/iop-vex-downloader.sh") | ||
| assert script.exists | ||
| assert script.is_file | ||
| assert script.mode == 0o755 | ||
|
|
||
|
|
||
| def test_vex_download_service_unit(server): | ||
| unit = server.file("/etc/systemd/system/iop-vex-download.service") | ||
| assert unit.exists | ||
| assert unit.is_file | ||
|
|
||
| content = unit.content_string | ||
| assert "Type=oneshot" in content | ||
| assert "iop-vex-downloader.sh" in content | ||
| assert "iop-core-gateway.service" in content | ||
|
|
||
|
|
||
| def test_vex_download_timer_unit(server): | ||
| unit = server.file("/etc/systemd/system/iop-vex-download.timer") | ||
| assert unit.exists | ||
| assert unit.is_file | ||
|
|
||
| content = unit.content_string | ||
| assert "OnActiveSec=0" in content | ||
| assert "OnUnitActiveSec=7d" in content | ||
| assert "WantedBy=timers.target" in content | ||
|
|
||
|
|
||
| def test_vex_download_timer_enabled(server): | ||
| timer = server.service("iop-vex-download.timer") | ||
| assert timer.is_enabled | ||
| assert timer.is_running | ||
|
|
||
|
|
||
| def test_vex_download_path_unit(server): | ||
| unit = server.file("/etc/systemd/system/iop-vex-download.path") | ||
| assert unit.exists | ||
| assert unit.is_file | ||
|
|
||
| content = unit.content_string | ||
| assert "PathChanged=/var/lib/foreman/vex-latest.tar.zst" in content | ||
| assert "PathModified=/var/lib/foreman/vex-latest.tar.zst" in content | ||
| assert "WantedBy=multi-user.target" in content | ||
|
|
||
|
|
||
| def test_vex_download_path_enabled(server): | ||
| path = server.service("iop-vex-download.path") | ||
| assert path.is_enabled | ||
| assert path.is_running |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the script would implement the archive change checking, we could increase this default value to 1 day. 7 days might not be ideal for either scenarios, online and offline.