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

Regenerate RSA key with size 4096 bits #376

Merged
merged 7 commits into from Jan 21, 2021
Merged

Regenerate RSA key with size 4096 bits #376

merged 7 commits into from Jan 21, 2021

Conversation

ssttehrani
Copy link
Contributor

According to NIST standards, achieving a security strength of 128 (2019 - 2030 & beyond) requires a factoring modulus with a length of at least 3072 bits, and since there is no major performance difference between RSA of size 2048 bits and RSA of size 4096 bits keys, it's better to ship SSH with RSA key of size 4096 bits.

@rndmh3ro
Copy link
Member

This is a good addition. However we should use the https://docs.ansible.com/ansible/latest/collections/community/crypto/openssh_keypair_module.html module for that?

@micheelengronne should we add this to the ssh baseline?

@ssttehrani
Copy link
Contributor Author

ssttehrani commented Jan 19, 2021

This is a good addition. However we should use the https://docs.ansible.com/ansible/latest/collections/community/crypto/openssh_keypair_module.html module for that?

@micheelengronne should we add this to the ssh baseline?

I replaced the shell module with the mentioned module as it provides a better and more reliable interface, but one problem occurred in the case of idempotency, since the openssh_keypair module needs to read the key to provide idempotency (refer to the screenshot attached), we need to set required ownership and group based on specific OS vars and this one is resolved with OS specific vars:
ssh_host_keys_owner
ssh_host_keys_group

thank you for your suggestion.

Screenshot from 2021-01-19 13-26-22

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
@ssttehrani
Copy link
Contributor Author

@rndmh3ro @micheelengronne
Any update?

@rndmh3ro
Copy link
Member

I'll have to take a look. Didn't have time yet

@ssttehrani
Copy link
Contributor Author

NP, thank you.

@micheelengronne
Copy link
Member

@rndmh3ro I think so. The ssh-baseline should reflect the current secure standards first.

path: "{{ ssh_host_keys_dir }}/ssh_host_rsa_key"
owner: "{{ ssh_host_keys_owner }}"
group: "{{ ssh_host_keys_group }}"
mode: "0600"
Copy link
Contributor

Choose a reason for hiding this comment

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

I found some references, that we need read access for group on RHEL systems on this file, making it 0640 .

see: https://bugzilla.redhat.com/show_bug.cgi?id=1372070

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I fixed it in the last commit.

@schurzi
Copy link
Contributor

schurzi commented Jan 20, 2021

PR for baseline is open dev-sec/ssh-baseline#188

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
@rndmh3ro rndmh3ro merged commit ef31838 into dev-sec:master Jan 21, 2021
@rndmh3ro
Copy link
Member

Great, thank you!
The tests pass, too.

@ssttehrani
Copy link
Contributor Author

Great, thank you!
The tests pass, too.

Thank you all.

@ssttehrani ssttehrani deleted the change_RSA_key_size branch January 21, 2021 18:36
divialth pushed a commit to divialth/ansible-collection-hardening that referenced this pull request Aug 3, 2022
* regenerate RSA key with size 4096 bits

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>

* fixed lint problem

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>

* fixed E301 lint error

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>

* added host keys related vars

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>

* used openssh_keypair module

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>

* changed RSA private key mode to 0640

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>

* specified condition to prevent wrong file mode on debian-based OS

Signed-off-by: Sina Tak Tehrani <ssttehrani@gmail.com>
nodiscc added a commit to nodiscc/xsrv that referenced this pull request Sep 4, 2022
…4096 bits keypair

- ref. dev-sec/ansible-collection-hardening#376
> According to NIST standards, achieving a security strength of 128 (2019 - 2030 & beyond) requires a factoring modulus with a length of at least 3072 bits, and since there is no major performance difference between RSA of size 2048 bits and RSA of size 4096 bits keys, it's better to ship SSH with RSA key of size 4096 bits.
- https://www.keylength.com/en/4/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants