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

ec2_key - fix security vulnerability #1704

Merged
merged 11 commits into from
Aug 31, 2023

Conversation

abikouo
Copy link
Contributor

@abikouo abikouo commented Aug 16, 2023

Depends-On: ansible/ansible-zuul-jobs#1816

SUMMARY

"When creating a new keypair the ec2_key module prints out the private key directly to the standard output. This makes it unusable in any kind of public workflow.
The only reasonable implementation to address this will be to write the private key to a file. This is what other modules (such as community.crypto.openssh_keypair) that work with ssh keys do.
This fix consists in :

  • update module return private_key to store path to a file containing private key instead of private key directly
  • add new module paramter path to define the path where the private key will be stored when creating a new key pair.
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_key

Co-authored-by: @jillr

@abikouo abikouo changed the title ec2_key - fix security vulnerability issues ec2_key - fix security vulnerability issue Aug 16, 2023
@abikouo abikouo changed the title ec2_key - fix security vulnerability issue ec2_key - fix security vulnerability Aug 16, 2023
@abikouo abikouo added backport-4 PR should be backported to the stable-4 branch backport-5 PR should be backported to the stable-5 branch backport-6 PR should be backported to the stable-6 branch labels Aug 16, 2023
@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

@alinabuzachis
Copy link
Contributor

@abikouo This cannot be backported because it adds new features where version_added is 7.0.0 and a new module with the same version_added.

@abikouo
Copy link
Contributor Author

abikouo commented Aug 16, 2023

@abikouo This cannot be backported because it adds new features where version_added is 7.0.0 and a new module with the same version_added.

@alinabuzachis I added the label for the backport PR to be created once this is merged (to see the impacts). Indeed the backport will be performed manually

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/ee99f849c8dc4829945230739ab0b1a7

✔️ ansible-galaxy-importer SUCCESS in 3m 42s
✔️ build-ansible-collection SUCCESS in 13m 02s
✔️ ansible-test-splitter SUCCESS in 5m 23s
integration-amazon.aws-1 RETRY_LIMIT in 5m 21s
Skipped 43 jobs

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug community_review integration tests/integration module module new_module New module new_plugin New plugin plugins plugin (any type) tests tests labels Aug 16, 2023
@alinabuzachis
Copy link
Contributor

alinabuzachis commented Aug 16, 2023

@abikouo Oh, I saw the changelog now. If it is a breaking_change we cannot backport as far as I know.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/1db35422ee30429e954012dd716bd704

✔️ ansible-galaxy-importer SUCCESS in 4m 10s
✔️ build-ansible-collection SUCCESS in 13m 18s
✔️ ansible-test-splitter SUCCESS in 5m 03s
integration-amazon.aws-1 RETRY_LIMIT in 3m 48s
Skipped 43 jobs

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

I don't like this approach.

To avoid the value turning up in the logs you can already use no_log and register, if anything this is a vulnerability in playbooks using the default behaviour, rather than the module:

- ec2_key: {...}
  no_log: True
  register: ec2_key_result

Defaulting to writing out a key is going to result in confusion because it will write it out on the 'host' side rather than the 'controller' side. However, if you then want to connect to an instance using this key you'll usually need it on the 'controller' side.

What I would suggest instead:

  • Document that no_log should generally be used (unfortunately Ansible doesn't have support for 'secret' return values yet for this to be handled in the same way that it is for input values)
  • Add file_name as a new optional parameter. When used it'll write out the key to that file, here we can also document that this is written out 'host' side rather than 'controller' side. This becomes a new feature, which we can backport to stable-5 and stable-6

In theory we could then change the default behaviour in main to default to writing to a file, but I still don't think this is necessary.

@abikouo
Copy link
Contributor Author

abikouo commented Aug 17, 2023

recheck

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/a456d6651af14392ab636ea2a6444e2e

✔️ ansible-galaxy-importer SUCCESS in 5m 21s
✔️ build-ansible-collection SUCCESS in 13m 55s
✔️ ansible-test-splitter SUCCESS in 5m 39s
integration-amazon.aws-1 FAILURE in 8m 22s
Skipped 43 jobs

@jillr
Copy link
Collaborator

jillr commented Aug 17, 2023

To avoid the value turning up in the logs you can already use no_log and register, if anything this is a vulnerability in playbooks using the default behaviour, rather than the module:

I actually didn't realize register would still work with no_log, TIL. We'll definitely talk this over!

@felixfontein
Copy link
Contributor

Telling users to use no_log: true is best practices for such cases. When we finally have data tagging, that can be used for a better solution (mark that specific return value as secret/no_log/whatever it will be called) that doesn't require to remove the complete log output from the module.

@abikouo
Copy link
Contributor Author

abikouo commented Aug 22, 2023

I don't like this approach.

To avoid the value turning up in the logs you can already use no_log and register, if anything this is a vulnerability in playbooks using the default behaviour, rather than the module:

- ec2_key: {...}
  no_log: True
  register: ec2_key_result

Defaulting to writing out a key is going to result in confusion because it will write it out on the 'host' side rather than the 'controller' side. However, if you then want to connect to an instance using this key you'll usually need it on the 'controller' side.

What I would suggest instead:

  • Document that no_log should generally be used (unfortunately Ansible doesn't have support for 'secret' return values yet for this to be handled in the same way that it is for input values)
  • Add file_name as a new optional parameter. When used it'll write out the key to that file, here we can also document that this is written out 'host' side rather than 'controller' side. This becomes a new feature, which we can backport to stable-5 and stable-6

In theory we could then change the default behaviour in main to default to writing to a file, but I still don't think this is necessary.

@tremble thanks for the feedback!!
I am going to document that no_log and register should be the preferred way of using this module, a new optional parameter (path renamed to file_name) will be added also

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/f6341d65a62f44ccaebe611095034724

✔️ ansible-galaxy-importer SUCCESS in 5m 12s
✔️ build-ansible-collection SUCCESS in 13m 35s
✔️ ansible-test-splitter SUCCESS in 5m 28s
integration-amazon.aws-1 FAILURE in 13m 20s
Skipped 43 jobs

@softwarefactory-project-zuul
Copy link
Contributor

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/ansible-collections/amazon.aws for 1704,cd0b977ed57c1c1bfc1ede2acd5d1fc8402971db

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/9f1320f166f14980b296a7cca873476e

✔️ ansible-galaxy-importer SUCCESS in 4m 48s
✔️ build-ansible-collection SUCCESS in 12m 18s
✔️ ansible-test-splitter SUCCESS in 5m 04s
✔️ integration-amazon.aws-1 SUCCESS in 7m 12s
Skipped 43 jobs

@GomathiselviS GomathiselviS added the mergeit Merge the PR (SoftwareFactory) label Aug 31, 2023
@softwarefactory-project-zuul
Copy link
Contributor

Build failed (gate pipeline). For information on how to proceed, see
http://docs.openstack.org/infra/manual/developers.html#automated-testing

https://ansible.softwarefactory-project.io/zuul/buildset/d51c5d28b56145479a01b5e1291dc80a

✔️ ansible-galaxy-importer SUCCESS in 4m 30s
✔️ build-ansible-collection SUCCESS in 12m 35s
✔️ ansible-test-splitter SUCCESS in 4m 44s
✔️ integration-amazon.aws-1 SUCCESS in 7m 57s
integration-community.aws-1 TIMED_OUT in 1h 00m 54s
✔️ integration-community.aws-2 SUCCESS in 24m 33s
✔️ integration-community.aws-3 SUCCESS in 5m 18s
✔️ integration-community.aws-4 SUCCESS in 48m 14s
✔️ integration-community.aws-5 SUCCESS in 22m 27s
integration-community.aws-6 RETRY_LIMIT in 1m 42s
✔️ integration-community.aws-7 SUCCESS in 25m 14s
✔️ integration-community.aws-8 SUCCESS in 31m 06s
integration-community.aws-9 RETRY_LIMIT in 6m 58s
✔️ integration-community.aws-10 SUCCESS in 34m 07s
✔️ integration-community.aws-11 SUCCESS in 34m 41s
✔️ integration-community.aws-12 SUCCESS in 16m 09s
✔️ integration-community.aws-13 SUCCESS in 41m 40s
✔️ integration-community.aws-14 SUCCESS in 41m 34s
✔️ integration-community.aws-15 SUCCESS in 18m 10s
✔️ integration-community.aws-16 SUCCESS in 25m 03s
✔️ integration-community.aws-17 SUCCESS in 28m 41s
✔️ integration-community.aws-18 SUCCESS in 15m 21s
✔️ integration-community.aws-19 SUCCESS in 18m 06s
✔️ integration-community.aws-20 SUCCESS in 12m 54s
Skipped 23 jobs

@gravesm
Copy link
Member

gravesm commented Aug 31, 2023

recheck

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/5ec09a2f202f41b5ad2281ab23887d0b

✔️ ansible-galaxy-importer SUCCESS in 5m 04s
✔️ build-ansible-collection SUCCESS in 13m 01s
✔️ ansible-test-splitter SUCCESS in 5m 08s
✔️ integration-amazon.aws-1 SUCCESS in 7m 54s
✔️ integration-community.aws-1 SUCCESS in 37m 55s
✔️ integration-community.aws-2 SUCCESS in 26m 38s
✔️ integration-community.aws-3 SUCCESS in 5m 24s
✔️ integration-community.aws-4 SUCCESS in 47m 14s
✔️ integration-community.aws-5 SUCCESS in 6m 05s
✔️ integration-community.aws-6 SUCCESS in 24m 04s
✔️ integration-community.aws-7 SUCCESS in 23m 06s
✔️ integration-community.aws-8 SUCCESS in 39m 12s
✔️ integration-community.aws-9 SUCCESS in 24m 41s
✔️ integration-community.aws-10 SUCCESS in 32m 31s
✔️ integration-community.aws-11 SUCCESS in 42m 50s
✔️ integration-community.aws-12 SUCCESS in 15m 43s
✔️ integration-community.aws-13 SUCCESS in 41m 50s
✔️ integration-community.aws-14 SUCCESS in 35m 26s
✔️ integration-community.aws-15 SUCCESS in 18m 09s
✔️ integration-community.aws-16 SUCCESS in 24m 50s
✔️ integration-community.aws-17 SUCCESS in 28m 35s
integration-community.aws-18 RETRY_LIMIT in 1m 41s
✔️ integration-community.aws-19 SUCCESS in 18m 47s
✔️ integration-community.aws-20 SUCCESS in 13m 25s
Skipped 23 jobs

krisek pushed a commit to krisek/amazon.aws that referenced this pull request Aug 31, 2023
Add ec2_key_info module

SUMMARY


Separated the info module from PR ansible-collections#1704
ISSUE TYPE


New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
Reviewed-by: Helen Bailey <hebailey@redhat.com>
Reviewed-by: GomathiselviS
Reviewed-by: Mike Graves <mgraves@redhat.com>
@gravesm gravesm merged commit 1a077fb into ansible-collections:main Aug 31, 2023
63 of 65 checks passed
@patchback
Copy link

patchback bot commented Aug 31, 2023

Backport to stable-6: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 1a077fb on top of patchback/backports/stable-6/1a077fb3a15241db8964dc086d3b15370bbd1e4a/pr-1704

Backporting merged PR #1704 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/amazon.aws.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-6/1a077fb3a15241db8964dc086d3b15370bbd1e4a/pr-1704 upstream/stable-6
  4. Now, cherry-pick PR ec2_key - fix security vulnerability #1704 contents into that branch:
    $ git cherry-pick -x 1a077fb3a15241db8964dc086d3b15370bbd1e4a
    If it'll yell at you with something like fatal: Commit 1a077fb3a15241db8964dc086d3b15370bbd1e4a is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 1a077fb3a15241db8964dc086d3b15370bbd1e4a
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR ec2_key - fix security vulnerability #1704 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-6/1a077fb3a15241db8964dc086d3b15370bbd1e4a/pr-1704
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

softwarefactory-project-zuul bot pushed a commit that referenced this pull request Sep 1, 2023
[PR #1715/937471be backport][stable-6] Add ec2_key_info module

This is a backport of PR #1715 as merged into main (937471b).
SUMMARY


Separated the info module from PR #1704
ISSUE TYPE


New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Sep 1, 2023
* WIP: begin swapping out private key data for key file

Start sketching out unit tests

* ec2_key - update module return private_key and add new parameter path defining path to a file to store private key when creating new key pair

* fix changelog file

* fix additional sanity issues

* ec2_key - Remove breaking_change feature, add new parameter to save private key in

* Code review updates

* Refactoring

* Remove key_info

* Doc fixes

* Uncomment call to ec2_key_info in tests

* Add key_info runtume.yml

---------

Co-authored-by: Jill Rouleau <jill.rouleau@bespokess.com>
Co-authored-by: GomathiselviS <gomathiselvi@gmail.com>
(cherry picked from commit 1a077fb)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Sep 1, 2023
[manual backport stable-6] ec2_key - fix security vulnerability (#1704)

WIP: begin swapping out private key data for key file

Start sketching out unit tests


ec2_key - update module return private_key and add new parameter path defining path to a file to store private key when creating new key pair


fix changelog file


fix additional sanity issues


ec2_key - Remove breaking_change feature, add new parameter to save private key in


Code review updates


Refactoring


Remove key_info


Doc fixes


Uncomment call to ec2_key_info in tests


Add key_info runtume.yml



Co-authored-by: Jill Rouleau jill.rouleau@bespokess.com
Co-authored-by: GomathiselviS gomathiselvi@gmail.com
(cherry picked from commit 1a077fb)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: GomathiselviS
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 18, 2023
v8.4.0

Major Changes
-------------

fortinet.fortios

- Improve the document for adding notes and examples in Q&A for modules using Integer number as the mkey.

Minor Changes
-------------

amazon.aws

- cloudformation - Add support for ``disable_rollback`` to update stack operation (ansible-collections/amazon.aws#1681).
- ec2_key - add support for new parameter ``file_name`` to save private key in when new key is created by AWS. When this option is provided the generated private key will be removed from the module return (ansible-collections/amazon.aws#1704).

ansible.netcommon

- Add a new cliconf plugin ``default`` that can be used when no cliconf plugin is found for a given network_os. This plugin only supports ``get()``. (ansible-collections/ansible.netcommon#569)
- httpapi - Add additional option ``ca_path``, ``client_cert``, ``client_key``, and ``http_agent`` that are available in open_url but not to httpapi. (ansible-collections/ansible.netcommon#528)
- telnet - add crlf option to send CRLF instead of just LF (ansible-collections/ansible.netcommon#440).

ansible.utils

- Add ipcut filter plugin.(ansible-collections/ansible.utils#251)
- Add ipv6form filter plugin.(ansible-collections/ansible.utils#230)

arista.eos

- Add support for overridden operation in bgp_global resource module.
@bastien-roucaries
Copy link

This is CVE-2023-4237

@felixfontein
Copy link
Contributor

That CVE seems to be mis-filed on GitHub, since the issue does not affect the ansible-core PyPI package, but the amazon.aws collection (and the ansible PyPI package, which includes that collection).

@bastien-roucaries
Copy link

@felixfontein Care to reassign ?

@felixfontein
Copy link
Contributor

I'd rather leave that to the collection maintainers since they know which versions of the collection are affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-6 PR should be backported to the stable-6 branch bug This issue/PR relates to a bug community_review integration tests/integration mergeit Merge the PR (SoftwareFactory) module module needs_maintainer plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants