Skip to content
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

Add rpm import in %post #4

Merged
merged 1 commit into from
Jan 16, 2025
Merged

Add rpm import in %post #4

merged 1 commit into from
Jan 16, 2025

Conversation

rocodes
Copy link
Contributor

@rocodes rocodes commented Dec 2, 2024

Add rpm key import in boostrap package post. There are 3 cases (clean install, upgrade package, uninstall); cover all of them.

  • In a clean install scenario, import the key to the rpm database.
  • In a package upgrade scenario (key bump), remove the old key and import the key again. (This will not be needed when rpm = 4.20 or rpm-sequoia >= 1.7.0 lands in dom0, but until then, maintain the logic).
  • In uninstall case, remove the key from the rpm database after the package is uninstalled.

See https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/ for guidelines on scriptlet ordering in upgrade, uninstall, etc.

Fixes freedomofpress/securedrop-workstation#423

Test plan

Clean install (no SDW)
Build this package with make build-rpm and install it in dom0.

  • Package installs successfully
  • repo file is present in /etc/yum.repos.d
  • rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n' | grep 'SecureDrop Release Signing Key' shows an entry corresponding to our release signing key in the rpm db (note: there's a 10 second delay because of trying to avoid rpm db transaction lock)
  • When keyring package is uninstalled, /etc/pki/rpm-gpg no longer contains our release signing key, and the key is removed from the rpm database (check with above command).

Upgrade testing: existing installs (existing SDW/4.2 setup, release key imported into rpm database and yum.repos file present in dom0)

  • Package installs successfully in dom0
  • When package is uninstalled, SecureDrop Release key no longer present in rpm database

Upgrade testing: keyring package upgrade
This test plan is meant to 'test' a keyring upgrade, meaning that the key is removed then reimported from the rpm database.
Reinstall the keyring package on top of itself via sudo dnf reinstall. While installing, watch the journal in a separate terminal.

  • Package installs successfully in dom0
  • no systemd failures visible in journal (2 services will be dispatched each with a timer, the first one to remove the existing key and the second one to reimport the new key)
  • After about 30 seconds, check RPM database and observe key (still) present.

Testing notes:
Removing files manually (manually deleting the key file or .repo file) then reinstalling the kerying package overtop of itself will not re-install the files or re-import the key. (This is standard rpm behaviour).

@adaFPF adaFPF marked this pull request as ready for review December 5, 2024 18:18
@adaFPF adaFPF marked this pull request as draft December 5, 2024 18:19
@adaFPF adaFPF marked this pull request as ready for review December 5, 2024 18:19
@adaFPF adaFPF marked this pull request as draft December 5, 2024 18:19
@rocodes rocodes force-pushed the add-rpm-import-postinst branch from 4884830 to 149e29f Compare December 6, 2024 21:26
@rocodes rocodes force-pushed the add-rpm-import-postinst branch 2 times, most recently from cfe85fb to 233379b Compare January 10, 2025 21:48
@rocodes rocodes marked this pull request as ready for review January 10, 2025 21:51
@rocodes rocodes requested a review from a team January 10, 2025 21:52
@rocodes rocodes force-pushed the add-rpm-import-postinst branch from 233379b to 9d4bc70 Compare January 13, 2025 14:28
@legoktm legoktm self-assigned this Jan 14, 2025
@legoktm
Copy link
Member

legoktm commented Jan 14, 2025

I wasn't able to get the clean install plan to work; but also I didn't have a clean install so I manually deleted the key from the rpm database, could that have caused any issues?

I built the RPM, installed it, verified the repo file was created, but installing the GPG key didn't work. Looking at my journalctl logs, I see:

Jan 14 09:04:10 dom0 systemd[1]: Started run-rd9d802708a17494eb9d008fbc21b167b.timer - /bin/rpm --import /etc/pki/rpm-gpg/RPM-GPG-securedrop-workstation.
Jan 14 09:04:41 dom0 systemd[1]: Started run-rd9d802708a17494eb9d008fbc21b167b.service - /bin/rpm --import /etc/pki/rpm-gpg/RPM-GPG-securedrop-workstation.
Jan 14 09:04:41 dom0 kernel: audit: type=1130 audit(1736863481.538:365): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=run-rd9d802708a17494eb9d008fbc21b167b comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jan 14 09:04:41 dom0 audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=run-rd9d802708a17494eb9d008fbc21b167b comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jan 14 09:04:41 dom0 rpm[4894]: error: /etc/pki/rpm-gpg/RPM-GPG-securedrop-workstation: import read failed(2).
Jan 14 09:04:41 dom0 systemd[1]: run-rd9d802708a17494eb9d008fbc21b167b.service: Main process exited, code=exited, status=1/FAILURE
Jan 14 09:04:41 dom0 systemd[1]: run-rd9d802708a17494eb9d008fbc21b167b.service: Failed with result 'exit-code'.
Jan 14 09:04:41 dom0 audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=run-rd9d802708a17494eb9d008fbc21b167b comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
Jan 14 09:04:41 dom0 systemd[1]: run-rd9d802708a17494eb9d008fbc21b167b.timer: Deactivated successfully.

Haven't looked up what "import read failed(2)" means yet.

Then I tried doing it manually from a dom0 terminal (sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-securedrop-workstation), and it worked fine

@legoktm
Copy link
Member

legoktm commented Jan 14, 2025

Also, when I uninstall the package (sudo dnf securedrop-workstation-keyring), I don't see it triggering any systemd-run unit and the key is still there.

@legoktm
Copy link
Member

legoktm commented Jan 14, 2025

Haven't looked up what "import read failed(2)" means yet.

Based on rpm-software-management/rpm#2683 I think it's just masking the underlying error.

@rocodes
Copy link
Contributor Author

rocodes commented Jan 14, 2025

hm, thanks / sorry about that - I'll take another look. I did step through all the test plans on my sdw machine last week.

@rocodes rocodes marked this pull request as draft January 14, 2025 18:59
@rocodes rocodes force-pushed the add-rpm-import-postinst branch 2 times, most recently from f920801 to f14f1fd Compare January 14, 2025 20:09
@rocodes rocodes marked this pull request as ready for review January 14, 2025 20:27
@rocodes rocodes force-pushed the add-rpm-import-postinst branch from f14f1fd to f39e184 Compare January 14, 2025 20:44
@rocodes rocodes force-pushed the add-rpm-import-postinst branch from f39e184 to f0b994f Compare January 15, 2025 16:57
@rocodes
Copy link
Contributor Author

rocodes commented Jan 15, 2025

ok, I think we're ready for re-review :)

When doing the 'upgrade' test (reinstalling the package on top of itself), wait about a minute after the package was installed for the first time (basically, watch the journal to be sure that the previous transaction lock held by importing the key has cleanly expired). Similarly, in the uninstall case, wait about 15-30 seconds to see the key removed from the rpm db.

@legoktm
Copy link
Member

legoktm commented Jan 16, 2025

Everything looks good so far, I'm just waiting on my SDW system to re-provision so I can test the last "Upgrade testing: existing installs" steps.

Copy link
Member

@legoktm legoktm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test plan checks out, nice work :)

@legoktm legoktm added this pull request to the merge queue Jan 16, 2025
Merged via the queue into main with commit 7a57fb5 Jan 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Explicitly manage our additions to the rpm keyring instead of appending
2 participants