Skip to content

feat(gpg-key): add gpg-key list and add - #488

Merged
q-horde merged 10 commits into
epic/481-keys-and-accessfrom
feature/482-gpg-key-list-add
Nov 16, 2026
Merged

q-horde merged 10 commits into
epic/481-keys-and-accessfrom
feature/482-gpg-key-list-add

Conversation

@q-horde

@q-horde q-horde commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the gpg-key command group with gpg-key list and gpg-key add, as in gh, on Gitea's /user/gpg_keys API, and marks gh ssh-key and gh repo deploy-key None in docs/parity.md (app.copia.io has SSH disabled). Slice 1 of 4 of the keys-and-access epic (plan revision 2).

Closes #482

Changes

  • gpg-key list (alias ls): every page of GET /user/gpg_keys, gh's columns EMAIL, KEY ID, PUBLIC KEY, ADDED, EXPIRES, --json/--jq/--template with the API's field names.
  • gpg-key add [<key-file>]: POST /user/gpg_keys with armored_public_key; duplicate key, not-armored and private key handled; Gitea's 404 for a key without a verified email gets a hint to verify that email; key content redacted from server messages.
  • No --signature (Lead decision on QUB-1230): app.copia.io does not register GET /user/gpg_key_token (Go's plain-text 404 page not found), so Gitea's signature route cannot be used. gh has no such flag either.
  • cmdutil.HTTPError keeps the API's message of a failed page (from closed PR feat(ssh-key): add ssh-key list and add #487).
  • Integration test TestGPGKeyList_Run lists the account's keys (plain and --json). It adds no key: Copia adds only a key with a verified email of the account, which the tests never read. add is covered by unit tests. The marker-repository key fixture of 64ada01 is reverted (e5ce2af), since nothing adds a key.
  • Docs: CHANGELOG, docs/parity.md (gpg-key section with the verified-email rule, ssh-key and deploy-key None, counts), docs/project-layout.md, sidebar, CLAUDE.md counts.

Security review QUB-1261 (round 2)

  • Finding 1 (medium): cmdutil.CheckArmor is an allowlist. Every line holding -----BEGIN must be the public key header, and a header naming PRIVATE or SECRET is refused as a private key (OpenSSH, PKCS#8, RSA, legacy PGP secret, a private block after a public one), all before any request (5a5038b).
  • Finding 2 (low): a server message that holds 16 bytes in a row of the key material, compared without white space, is left out; only the HTTP status is shown (5a5038b).
  • Finding 3 (low): cmdutil.ReadAPIMessage reads at most 64 KiB of an error body and cuts the message to 512 bytes; FetchPages and gpg-key add use it (fd3281e).

Automated checks

  • tests pass (horde-dev run go test ./...)
  • lint is clean (horde-dev run golangci-lint run ./..., also with --build-tags=integration)
  • horde-dev run go run script/gen-docs.go leaves no diff (manual pages are gitignored; the sidebar is updated by hand)
  • documentation updated in this PR

User test

  • copia-cli gpg-key list prints your GPG keys; gpg --armor --export <ID> | copia-cli gpg-key add - adds a key whose email is verified on your account; a key without such an email fails with the hint to verify it.

Notes for reviewer

The first integration run (actions run 43836533303) failed because GET /user/gpg_key_token answered 404 on Copia; that led to the decision above. The test job's govulncheck step fails on GO-2026-6859 (net/http, fixed in go1.27.4) on every branch; PR #496 bumps Go.

@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.40816% with 9 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
pkg/cmd/gpgkey/add/add.go 94.66% 4 Missing ⚠️
pkg/cmd/gpgkey/list/list.go 95.23% 4 Missing ⚠️
pkg/cmdutil/apimessage.go 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Gitea returns no user ID of a GPG key, so each test key is marked by a
private scratch repository it-run-<time>-gk<key ID>. A GPG key is deleted
only when such a marker names its ID: on the test's cleanup, or for a
marker older than two hours at the start of a later run, before the stale
repository sweep deletes the marker.
@q-horde
q-horde marked this pull request as ready for review November 16, 2026 09:04
@q-horde
q-horde marked this pull request as draft November 16, 2026 09:10
Copia does not register GET /user/gpg_key_token, so gpg-key add drops
--signature (Lead decision on QUB-1230) and no integration test adds a
GPG key. Without one, the key fixture, its marker repositories and its
sweep have nothing to guard.

This reverts commit 64ada01.
Copia does not register GET /user/gpg_key_token (it answers Go's plain
404 page not found), so a token signature cannot be made. gpg-key add
now sends the armored key only, like gh, and Gitea's 404 for a key
without a verified email shows a hint to verify that email instead of
Gitea's offer to sign the token.
The test adds no key: Copia adds only a key with a verified email of the
account, which the tests never read.
@q-horde
q-horde marked this pull request as ready for review November 16, 2026 09:29
ReadAPIMessage reads at most 64 KiB of an error body and cuts the
message to 512 bytes on a rune boundary, so a server cannot make
copia-cli read or print an error of any size. FetchPages uses it for
HTTPError.Message (security review QUB-1261, finding 3).
gpg-key add refused only PRIVATE KEY BLOCK, so an OpenSSH, PKCS#8, RSA
or legacy PGP secret key passed. cmdutil.CheckArmor is an allowlist:
every armor header must be the public key header, a header naming
PRIVATE or SECRET is refused as a private key. A server message that
holds 16 bytes in a row of the key material, compared without white
space, is left out of the error (security review QUB-1261, findings 1
and 2).
@q-horde

q-horde commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Closing and reopening to rerun CI against the updated epic base (Go 1.27.4 from #496 via #502).

@q-horde q-horde closed this Nov 16, 2026
@q-horde q-horde reopened this Nov 16, 2026
@q-horde
q-horde merged commit 6c7c503 into epic/481-keys-and-access Nov 16, 2026
9 of 10 checks passed
@q-horde
q-horde deleted the feature/482-gpg-key-list-add branch November 16, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant