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

feat: manage ssh certificates #252

Merged
merged 19 commits into from
Sep 11, 2023
Merged

Conversation

EmyLIEUTAUD
Copy link
Contributor

Enhancement:

  • Deploy User CA on the system
  • Configure principals (optional)

Reason:
This allows you to configure and manage the SSH server to authenticate via certificates.
Improves SSH authentication security: certificates have a validity period, unlike SSH keys.

More information on SSH certificates is available here: Managing SSH Access at Scale with HashiCorp Vault.

Result:
All tests passed.
The related documentation is available and an example can be found in examples/example-use-certificates.yml.

Issue Tracker Tickets (Jira or BZ if any): -

@mattwillsher mattwillsher changed the title Manage SSH Certificates feat: Manage SSH Certificates Aug 31, 2023
Comment on lines 8 to 12
- name: Copy Trusted user CA Keys
ansible.builtin.template:
src: "trusted-user-ca-keys.pem.j2"
dest: "{{ sshd['TrustedUserCAKeys'] }}"
mode: '0600'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it confusing that you are making a file with .pem extension which lists SSH keys in non-PEM format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the extension given as an example in the HashiCorp tutorial. In any case, the extension doesn't matter. Do you know a format that would be suitable without being confusing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally the SSH public keys have the .pub extension so I would probably go with that one.

tests/tests_set_common.yml Outdated Show resolved Hide resolved
Comment on lines 47 to 48
# If not null, list of trusted CA keys
sshd_trusted_user_ca_keys_list: []
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment does not math the default value here. Probably mention empty instead of null in the comment?

@EmyLIEUTAUD EmyLIEUTAUD changed the title feat: Manage SSH Certificates feat: manage ssh certificates Sep 6, 2023
Copy link
Member

@mattwillsher mattwillsher left a comment

Choose a reason for hiding this comment

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

One spelling correction but otherwise lgtm

tasks/certificates.yml Outdated Show resolved Hide resolved
examples/example-use-certificates.yml Outdated Show resolved Hide resolved
tasks/certificates.yml Outdated Show resolved Hide resolved
src: "auth_principals.j2"
dest: "{{ sshd['AuthorizedPrincipalsFile'] | dirname }}/{{ item.key }}"
mode: '0644'
loop: "{{ q('dict', sshd_principals) }}"
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
loop: "{{ q('dict', sshd_principals) }}"
loop: "{{ ('dict', sshd_principals) }}"

Is it a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was an old syntax we used, but it's no longer documented. I've modified it to make the code easier to understand.


- name: Check AuthorizedPrincipalsFile exists
ansible.builtin.assert:
that:
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
that:
that: authorizedprincipalsfile_stat.stat.exists

- name: Check AuthorizedPrincipalsFile exists
ansible.builtin.assert:
that:
- authorizedprincipalsfile_stat.stat.exists
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
- authorizedprincipalsfile_stat.stat.exists


- name: Check TrustedUserCAKeys file exists
ansible.builtin.assert:
that:
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
that:
that: trustedusercakeys_file_stat.stat.exists

- name: Check TrustedUserCAKeys file exists
ansible.builtin.assert:
that:
- trustedusercakeys_file_stat.stat.exists
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
- trustedusercakeys_file_stat.stat.exists

@spetrosi
Copy link
Contributor

spetrosi commented Sep 6, 2023

lgtm

tasks/certificates.yml Outdated Show resolved Hide resolved
Copy link
Collaborator

@Jakuje Jakuje left a comment

Choose a reason for hiding this comment

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

hope last nits to the wording of README. Then I would love to have the fixup commits slightly squashed as the commit series is getting long ...

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
build(deps): bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

spelling correction

use random ssh key

fix ansible lint

fix test syntax

update dictionary loop syntax

update README and add variables to configure directories and files
@@ -8,7 +8,7 @@ repos:
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/ansible/ansible-lint.git
rev: v6.5.2
rev: v6.17.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

please, keep the dependencies changes in at least separate commit (ideally separate PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Version restored here: 610a356.

README.md Outdated Show resolved Hide resolved
tests/tests_set_common.yml Outdated Show resolved Hide resolved
add teststo certificates and restore ansible-lint version

fix tests for certificates

build(deps): bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Copy link
Member

@mattwillsher mattwillsher left a comment

Choose a reason for hiding this comment

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

Minor ordering in docs but looks good to me otherwise.

I don't understand why the checkout action is showing the version change - have you rebased from main recently? It might resolve that

README.md Outdated Show resolved Hide resolved
fix README

change trusted user ca keys directory default mode
Copy link
Collaborator

@Jakuje Jakuje left a comment

Choose a reason for hiding this comment

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

code wise it looks good. I would prefer the fixups commits squashed, but if others are ok with the commit series. I do not want to block the changes

@mattwillsher mattwillsher merged commit 0bc6d8f into willshersystems:main Sep 11, 2023
16 checks passed
@mattwillsher
Copy link
Member

Thanks for all the work on this @EmyLIEUTAUD

I'll get a new release out that includes this code in the few days.

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.

None yet

5 participants