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

Allow auto import only for specific key #421

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dwymark
Copy link

@dwymark dwymark commented Nov 13, 2021

Implemented a new command option "--gpg-auto-import-key-id" which allows users to only auto-import a GPG key with the provided key ID. This was done in response to a feature request in issue 401.

Implemented a new command option "--gpg-auto-import-key-id"
which allows users to only auto-import a GPG key with the
provided key ID.
src/Config.cc Outdated
@@ -570,6 +571,18 @@ std::vector<ZyppFlags::CommandGroup> Config::cliOptions()
// translators: --gpg-auto-import-keys
_("Automatically trust and import new repository signing keys.")
},
{ "gpg-auto-import-key-id", 0, ZyppFlags::RequiredArgument, std::move( ZyppFlags::StringType( &gpg_auto_import_key_id, "", "KEY_ID").
Copy link
Member

Choose a reason for hiding this comment

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

It's IMO debatable whether a new option is introduced or gpg-auto-import-keys is amended to take an optional argument. In any case a key or ,-separated list of keys should be accepted.

Copy link
Author

Choose a reason for hiding this comment

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

Great, I will make sure to accept comma separated keys as well.

I also like your suggestion of amending gpg-auto-import-keys rather than adding a new parameter. Do you want to open up that conversation to other stakeholders, or can we move forward with the single parameter implementation?

Copy link
Member

Choose a reason for hiding this comment

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

We can move on. Staying with gpg-auto-import-key and amending it to

  1. take an optional argument (comma separated list of IDs)
  2. allow multiple occurrences of gpg-auto-import-key

should be feasible for the argparser .

This enables the user to use --gpg-auto-import-key=A,B or --gpg-auto-import-key=A --gpg-auto-import-key=B as they like it.

It also allows to solve the issue of --gpg-auto-import-key ... --gpg-auto-import-key=A in a natural way. No errors about conflicting options are needed. The options build up a set of key IDs. An empty set accepts all keys as it currently does. Otherwise only the keys in the set are auto-accepted. Keys not in the set are treated as usual.

(@bzeller JFYI)

Copy link
Author

Choose a reason for hiding this comment

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

In order to make gpg-auto-import-keys optional, while still accepting comma separated lists of IDs as you suggest in your comment here, I had to make a small adjustment to the GenericContainerType definition in the argparser. If there was a better way to go about achieving this, let me know and I would be happy to make adjustments if necessary.

The change to GenericContainerType is in its own commit.

if (_gopts.gpg_auto_import_keys)
// if --gpg-auto-import-keys, --no-gpg-check, or --gpg-auto-import-key-id matches key, print info and don't ask.
if (_gopts.gpg_auto_import_keys
|| (!_gopts.gpg_auto_import_key_id.empty() && _gopts.gpg_auto_import_key_id == key_r.id()))
Copy link
Member

Choose a reason for hiding this comment

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

_gopts.gpg_auto_import_key_id == key_r.id() IMO is to strict.

The argument should be ID or FPR (recommended 16byte/40byte). As convenience a short-ID (8byte insecure) could be accepted. This would be key_r.providesKey( _gopts.gpg_auto_import_key_id ).

At least the manpage should state that the short-ID is considered to be insecure. Optionally the argparser could print a note/warning if a ! PublicKeyData::isSafeKeyId( _gopts.gpg_auto_import_key_id ) is passed.

Copy link
Author

Choose a reason for hiding this comment

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

Change made in commit 180266c

@mlandres mlandres self-requested a review November 15, 2021 14:30
@dwymark dwymark changed the title WIP: Allow auto import only for specific key Allow auto import only for specific key Nov 20, 2021
@dwymark dwymark marked this pull request as ready for review November 20, 2021 20:08
This helps to keep the code style consistent
with the rest of the code base.
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.

2 participants