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

Migrate public keys from GPG to database-backed storage #6946

Merged
merged 2 commits into from Oct 4, 2023

Conversation

legoktm
Copy link
Member

@legoktm legoktm commented Sep 21, 2023

Status

Ready for review, depends on #6892 and #6948.

Description of Changes

  • Add --gpg to loaddata.py to create GPG-backed sources (primarily for testing/dev purposes)
  • Migrate public keys from GPG to database-backed storage (the main commit in this PR)

Commit messages have more detail on each.

Fixes #6800.

Testing

  • Start the dev server (make dev) and open a shell into the container, e.g. podman exec --user=root -it $(podman ps --filter name=securedrop --format '{{.ID}}') bash
  • Run alembic stamp 811334d7105f (ID of the migration before this one)
  • Run ./loaddata.py --gpg to add some GPG sources
  • Run select filesystem_id, pgp_fingerprint from sources; in SQLite to verify there are some sources without a fingerprint set in the database
  • Run alembic upgrade head, completes successfully. Then run the database query again to see that all fingerprints have been populated.
  • Obligatory CI passes & visual review

Deployment

Any special considerations for deployment?

This is a non-destructive migration. There is some risk the migration fails, which would halt package upgrade, but the main point where we expect that to happen (gpg.export_key()) is wrapped in a try/except.

Checklist

  • Linting (make lint) and tests (make test) pass in the development container
  • I have written a test plan and validated it for this PR
  • These changes do not require documentation

@legoktm legoktm force-pushed the sequoia-migrate-public branch 3 times, most recently from fe26e56 to 92fc742 Compare September 28, 2023 18:47
@legoktm legoktm marked this pull request as ready for review September 28, 2023 18:49
@legoktm legoktm requested a review from a team as a code owner September 28, 2023 18:49
@legoktm
Copy link
Member Author

legoktm commented Sep 28, 2023

This is ready for review now, but same caveat that it depends on #6892 and #6948.

@cfm cfm self-assigned this Sep 29, 2023
@cfm cfm self-requested a review September 29, 2023 01:36
Copy link
Member

@cfm cfm left a comment

Choose a reason for hiding this comment

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

This looks great, @legoktm. I've taken the liberty of being a little aggressive in my testing just to make sure we're hitting the code-paths you intend. :-)

I've left a couple of questions inline, but otherwise I'll be happy to approve and merge this once it's rebased from develop after #6892.

  • Start the dev server (make dev) and open a shell into the container, e.g. podman exec --user=root -it $(podman ps --filter name=securedrop --format '{{.ID}}') bash
  • Run alembic stamp 811334d7105f (ID of the migration before this one)
  • Run ./loaddata.py --gpg to add some GPG sources
  • Run select filesystem_id, pgp_fingerprint from sources; in SQLite to verify there are some sources without a fingerprint set in the database
  • My addition: Choose one of the new sources and smoke-test a round trip: source submits; journalist replies
  • Run alembic upgrade head, completes successfully. Then run the database query again to see that all fingerprints have been populated.
  • My addition, aggressive: gpg --homedir /var/lib/securedrop/keys --list-secret-keys, then gpg --homedir /var/lib/securedrop/keys --delete-secret-key each one
  • My addition: Choose the same source as before and smoke-test a round trip: source submits; journalist replies
  • Obligatory CI passes & visual review

@legoktm
Copy link
Member Author

legoktm commented Oct 3, 2023

Rebased and integrated is_valid_public_key() checks.

@cfm
Copy link
Member

cfm commented Oct 3, 2023

Thanks for the discussion, @legoktm. I'm happy with this, and I'll merge as soon as #6948 is in and this is rebased with it.

New sources are created using Sequoia by default, but we need GPG-backed
sources to test the migration process. This function is mostly copied
from tests.utils.create_legacy_gpg_key.
Add an alembic migration that iterates over the GPG keyring, identifies
source keys, exports them from GPG and saves them into the database.

The main failure risks are the interactions with GPG. We already run
`gpg.list_keys()` on startup, so it's unlikely that's broken (and if it
is, we have bigger problems). So the main concern is exporting the key
might fail. The export operation is wrapped in a try/except and we
validate the exported key we get from GPG.

Notably, this does not increase our footprint of pretty_bad_protcol
usage as the two functions being used are already in use elsewhere in
SecureDrop.

Some higher-level design information is at
<#6946 (comment)>.

Fixes #6800.
@legoktm
Copy link
Member Author

legoktm commented Oct 4, 2023

Rebased + signed.

Copy link
Member

@cfm cfm left a comment

Choose a reason for hiding this comment

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

Thanks, @legoktm! We've resolved all our discussions from #6946 (review), so I'll merge as soon as CI passes.

@cfm cfm merged commit fd11009 into develop Oct 4, 2023
9 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.

One-time migration of sources' public keys and fingerprints from gpg to database-backed storage
2 participants