Skip to content

add pkcs11 support to Ansible ssh connection module - #32829

Merged
jborean93 merged 9 commits into
ansible:develfrom
thedavidwhiteside:feature/pkcs11
Jun 2, 2021
Merged

jborean93 merged 9 commits into
ansible:develfrom
thedavidwhiteside:feature/pkcs11

Conversation

@thedavidwhiteside

@thedavidwhiteside thedavidwhiteside commented Nov 12, 2017 •

Copy link
Copy Markdown
Contributor
SUMMARY

Ansible does not currently support PKCS#11 (PIV, CAC, smartcard) authentication. With a simple modification to the ssh connection plugin, you can easily add support for PKCS#11. Paramiko is in the process of adding PKCS11 support, after the support is added in the next stable release of Paramiko then its also possible to add PKCS11 support for the Ansible+Paramiko combination.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ssh connection plugin

ANSIBLE VERSION
ansible 2.11.0.dev0
  config file = None
  configured module search path = ['/Users/dwhitesi/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible_core-2.11.0.dev0-py3.9.egg/ansible
  ansible collection location = /Users/dwhitesi/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Feb 19 2021, 17:09:53) [Clang 12.0.0 (clang-1200.0.32.29)]
  jinja version = 3.0.0a1
  libyaml = True
USAGE
$ export ANSIBLE_PKCS11_PROVIDER=/usr/local/lib/opensc-pkcs11.so
$ ansible-playbook -u USERNAME -b -k -K PLAYBOOK.yml --connection=ssh
SSH password: << Enter your PKCS11 Pin for your smartcard
SUDO password[defaults to SSH password]: << Enter your user account password for sudo

I use https://github.com/OpenSC/OpenSC for the middleware, this is the pkcs11-provider library that you point Ansible to with the pkcs11_provider ini setting or ANSIBLE_PKCS11_PROVIDER env variable.

I tested with a smartcard, a very common device you might use with Ansible pkcs11 would be a Yubikey device (https://www.yubico.com/product/yubikey-neo).

  • David

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 cli/adhoc needs_triage Needs a first human triage before being processed. labels Nov 12, 2017
@ansibot

ansibot commented Nov 12, 2017

Copy link
Copy Markdown
Contributor

The test ansible-test sanity --test pep8 [?] failed with the following errors:

lib/ansible/cli/adhoc.py:108:22: E201 whitespace after '{'
lib/ansible/cli/console.py:416:27: E201 whitespace after '{'
lib/ansible/cli/playbook.py:102:26: E201 whitespace after '{'
lib/ansible/plugins/connection/ssh.py:390:161: E501 line too long (168 > 160 characters)
lib/ansible/plugins/connection/ssh.py:402:27: E128 continuation line under-indented for visual indent
lib/ansible/plugins/connection/ssh.py:403:27: E128 continuation line under-indented for visual indent

click here for bot help

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Nov 12, 2017
@ansibot

ansibot commented Nov 12, 2017

Copy link
Copy Markdown
Contributor

The test ansible-test sanity --test pep8 [?] failed with the following error:

lib/ansible/plugins/connection/ssh.py:395:26: E128 continuation line under-indented for visual indent

click here for bot help

@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. test This PR relates to tests. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Nov 12, 2017
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 13, 2017
@bcoca

bcoca commented Nov 13, 2017

Copy link
Copy Markdown
Member

so instead of hardocding them in many places, you can just add it instead just to the connection plugin that uses them, as ini/env/connection variables they will also be a lot more flexible.
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh
.py#L131

@thedavidwhiteside

Copy link
Copy Markdown
Contributor Author

The pkcs11_pin is sensitive and I wanted to follow the same process Ansible currently uses for passwords. I could just reuse the password variable for the pin and use ini/env/connection variables for the pkcs11_provider, and whenever you set the pkcs11_provider then it uses PKCS11 rather than password auth.

I see pkcs11 making its way to other connection plugins (paramiko_ssh), so thats why I initially took the approach of the variables being CLI options.

  • David

@bcoca

bcoca commented Nov 13, 2017

Copy link
Copy Markdown
Member

i think reusing password is fine and keeping the provider as separate parameter

@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 Nov 21, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed feature_pull_request stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Mar 2, 2018
@ansibot ansibot added core_review needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed merge_commit needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html 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. labels Mar 14, 2021
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Mar 22, 2021

@jborean93 jborean93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look great, just need to wait until we branch off the 2.11 changes so we can merge this into devel for the 2.12 release.

@ansibot ansibot added core_review and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Mar 24, 2021
@Akasurde

Copy link
Copy Markdown
Member

@jborean93 Since 2.11 is branched out. Do you want to merge this?

@thedavidwhiteside

thedavidwhiteside commented Jun 2, 2021 •

Copy link
Copy Markdown
Contributor Author

@jborean93, @bcoca, @nitzmahone is it time to merge?

@jborean93

Copy link
Copy Markdown
Contributor

My apologies should have looked at this earlier.

rebuild_merge

@ansibot ansibot added shipit and removed core_review stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 2, 2021
@jborean93

Copy link
Copy Markdown
Contributor

Bot is taking it's time, will just merge manually (it passed the rebuild test).

@jborean93
jborean93 merged commit 805799a into ansible:devel Jun 2, 2021
@Akasurde

Akasurde commented Jun 2, 2021 •

Copy link
Copy Markdown
Member

@thedavidwhiteside Thanks for the contribution and patients. @jborean93 @nitzmahone @bcoca Thanks for the review.

@ansible ansible locked and limited conversation to collaborators Jun 30, 2021
@thedavidwhiteside
thedavidwhiteside deleted the feature/pkcs11 branch July 21, 2023 05:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects_2.5 This issue/PR affects Ansible v2.5 feature This issue/PR relates to a feature request. test This PR relates to tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants