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

Make rpm_key aware of multiple keys in a keyfile #75251

Closed
wants to merge 4 commits into from

Conversation

mauved
Copy link

@mauved mauved commented Jul 14, 2021

SUMMARY

Fixes #50615.

Make rpm_key module use lists for key ids since a single key file can contain multiple keys.

I also made the fingerprint option accept lists of fingerprints since they correspond with key ids. All fingerprints in a keyfile should be present when the fingerprints option is set for task success.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

rpm_key

ADDITIONAL INFORMATION

Example:

- name: Add Google GPG keys to system
  rpm_key:
    key: https://dl.google.com/linux/linux_signing_key.pub
    fingerprint:
      # First key in keyfile
      - 4CCA 1EAF 950C EE4A B839 76DC A040 830F 7FAC 5991
      # Second key in keyfile
      - EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796

The rpm_key module only checked for the presence of the first key in a file when importing keys from files. This meant that in cases where a single file contained multiple keys it was possible for later keys to not be imported if the first key in a key file was already installed. It could also mean that multiple keys could be installed even when only expecting a single key in a file.

Sofia Nieves and others added 2 commits July 11, 2021 11:04
Google makes a RPM key file containing multiple public keys publicly
avaiable which is great for making sure ansible's rpm_key module can
handle multiple keys being present in a single file.
Multiple keys can be concatenated into a single file however. This aims
to make the module check for multiple key fingerprints beng present in a
single file. This also allows for a list of fingerprints to be passed to
module arguments for verification. If there's any mismatch, then the
module throws an error.
@ansibot ansibot added affects_2.12 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jul 14, 2021
@samdoran samdoran added the ci_verified Changes made in this PR are causing tests to fail. label Jul 14, 2021
- name: Issue 50615 - Verify key fingerprints. This should fail due to multiple key signatures
rpm_key:
# TODO: This needs to be rehosted on ansible CI infra
key: https://dl.google.com/linux/linux_signing_key.pub
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
key: https://dl.google.com/linux/linux_signing_key.pub
key: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/linux_signing_key.pub

- name: Issue 50615 - Add Google GPG keys to system
rpm_key:
# TODO: This needs to be rehosted on ansible CI infra
key: https://dl.google.com/linux/linux_signing_key.pub
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
key: https://dl.google.com/linux/linux_signing_key.pub
key: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/linux_signing_key.pub

@nitzmahone nitzmahone added P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Jul 15, 2021
Copy link
Member

@sivel sivel left a comment

Choose a reason for hiding this comment

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

This will also require a changelog in changelogs/fragments/

return True
for keyid in keyids:
if keyid in line.split(':')[4]:
matching_keys += 1
Copy link
Member

Choose a reason for hiding this comment

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

We're concerned about the potential edge cases where this may return a false positive. I think we'd be more comfortable, if we actually tracked the matching keys, and compared them against the actual content of keyids instead of asserting the lengths are equal.

Copy link
Author

Choose a reason for hiding this comment

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

Good point! I'll update this so it does an actual comparison.

- name: Issue 50615 - Verify key fingerprints. This should fail due to multiple key signatures
rpm_key:
# TODO: This needs to be rehosted on ansible CI infra
key: https://dl.google.com/linux/linux_signing_key.pub
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to get these uploaded to our S3 bucket. cc @samdoran

elif ret.startswith('0X'):
normalized_keyids.append(ret[2:])
else:
normalized_keyids.append(ret)
Copy link
Member

Choose a reason for hiding this comment

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

Can we maybe keep normalize_keyid and create a normalize_keyids that calls the singular version. That can make unit testing of this function in the future easier.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 23, 2021
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. core_review In order to be merged, this PR must follow the core review workflow. labels Aug 9, 2021
@samdoran samdoran added the ci_verified Changes made in this PR are causing tests to fail. label Aug 11, 2021
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 19, 2021
@mauved
Copy link
Author

mauved commented Oct 18, 2022

I let this go stale; I'll redo it and resubmit in a new PR.

@mauved mauved closed this Oct 18, 2022
@ansible ansible locked and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.12 bug This issue/PR relates to a bug. ci_verified Changes made in this PR are causing tests to fail. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. P3 Priority 3 - Approved, No Time Limitation stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rpm_key module: Importing key bundles
5 participants