8000 Support checking for expired and untrusted keys by AlD · Pull Request #9950 · ansible-collections/community.general · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support checking for expired and untrusted keys #9950

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AlD
Copy link
@AlD AlD commented Mar 30, 2025

Adds state trusted.

Fixes #9949

SUMMARY

Adds functionality for pacman_key to check for key validity in terms of expiration and signature of the pacman machine key.

Introduces a new trusted state for the new functionality in order to preserve current behavior of present, although this should arguably be merged into present.

Moves gpg/pacman-key parsing into a trivial wrapper (GpgListResult) and adds two helpers that either return a single match or a collection of all matches for a certain gpg output item type.

Moves binary invocations with common flags into module methods.

Replaces --keyring with equivalent --homedir flag in order to allow for signature checks to work.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

pacman_key

ADDITIONAL INFORMATION

The existing test output already used an expired key, hence the GPG_SHOWKEY_OUTPUT{ → _EXPIRED} renaming of the variable holding the unchanged test data .

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit labels Mar 30, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Mar 30, 2025
Copy link
Collaborator
@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I've added some first comments.

Regarding the interface: I'm not sure whether a new state is the best way to do this. I think it would be better to be able to specify the update mode, because what you want to do is tell the module to update the key if the fingerprint matches, but other parameters do not.

Right now the module supports two update modes: "always" (force_update=true), and "compare fingerprint" (force_update=false). Having another mode "full idempotent" (checks ID and other parameters) is basically what you want, I think?

@AlD
Copy link
Author
AlD commented Mar 31, 2025

Thanks for the quick review, Felix.

Regarding the interface: I'm not sure whether a new state is the best way to do this. I think it would be better to be able to specify the update mode, because what you want to do is tell the module to update the key if the fingerprint matches, but other parameters do not.

I agree that a separate state is not very intuitive. IMHO this should just be the default behavior of the present state. I can't really think of a realistic scenario where a user would prefer using force_update to update an expired key.

In that vein I wouldn't even make this new functionality configurable, because even if a user prefers to keep an expired key, having an import attempt of the expired key on each run is likely not noticeable.

@ansibullbot

This comment was marked as outdated.

@ansibullbot

This comment was marked as outdated.

@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Mar 31, 2025
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-10 Automatically create a backport for the stable-10 branch labels Apr 1, 202 8000 5
@grawlinson
Copy link
Contributor

I'm happy with this PR. :)

Copy link
Collaborator
@russoz russoz left a comment

Choose a reason for hiding this comment

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

Small suggestion on handling the gpg command, other than that I do not have any strong opinion about solving this with an extra state or some other way, so I'll say it LGTM

Comment on lines +241 to +252
def gpg(self, args, keyring=None, **kwargs):
cmd = [self.gpg_binary]
if keyring:
cmd.append('--homedir={keyring}'.format(keyring=keyring))
cmd.extend(['--no-permission-warning', '--with-colons', '--quiet', '--batch', '--no-tty'])
return self.module.run_command(cmd + args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might want to consider using CmdRunner. See https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_cmdrunner.html for more details.

@@ -78,9 +78,9 @@
default: /etc/pacman.d/gnupg
state:
description:
- Ensures that the key is present (added) or absent (revoked).
- Ensures that the key is present (added), trusted (signed and not expired) or absent (revoked).
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does the PR ensure that the key is not expired? If the key provided to the module is already expired, I don't see how the module can change that.

Copy link
Author

Choose a reason for hiding this comment

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

It can't extend keys of course, you're right. It just won't return a success status if the key is expired.

Maybe "Ensures/checks" would be clearer? How long are these descriptions supposed to be?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The descriptions should be long enough that it's clear what the option actually does.

I would move the description for trusted into a new paragraph (instead of cramming everything into a single paragraph).

@@ -78,9 +78,9 @@
default: /etc/pacman.d/gnupg
state:
description:
- Ensures that the key is present (added) or absent (revoked).
- Ensures that the key is present (added), trusted (signed and not expired) or absent (revoked).
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should mention when trusted was added:

Suggested change
- Ensures that the key is present (added), trusted (signed and not expired) or absent (revoked).
- Ensures that the key is V(present) (added), V(trusted) (signed and not expired) or V(absent) (revoked).
- The state V(trusted) has been added in community.general 10.6.0.

Also formatting the state names as values is IMO a good idea.

Copy link
Author

Choose a reason for hiding this comment

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

If you're not opposed to folding the new functionality into the present state, I think that would be preferable. IMHO the currently implemented functionality of the present state does not solve a real life use case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this would be a breaking change, since this considerably changes the behavior of state=present. Since we don't accept breaking changes this isn't really acceptable.

(That's why I would solve this not with a new state, but with an option. That way we can deprecate its default, and eventually change it to the better behavior, and fix the issue that way.)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! Finally got around to making the change to make it an option now.

I squashed all commits now, but I could restore the individual commits as well of course. Just let me know what's easier to review. Not super familiar with GitHub review workflows.

@ansibullbot ansibullbot added stale_ci CI is older than 7 days, rerun before merging and removed stale_ci CI is older than 7 days, rerun before merging labels Apr 12, 2025
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Apr 23, 2025
@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-10 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pacman_key: Doesn't verify that keys are signed and not expired
5 participants
0