Skip to content

cc_ssh.py: fix private key group owner and permissions#1070

Merged
TheRealFalcon merged 1 commit into
canonical:mainfrom
esposem:sshd_host_permissions
Oct 19, 2021
Merged

cc_ssh.py: fix private key group owner and permissions#1070
TheRealFalcon merged 1 commit into
canonical:mainfrom
esposem:sshd_host_permissions

Conversation

@esposem
Copy link
Copy Markdown
Contributor

@esposem esposem commented Oct 15, 2021

Proposed Commit Message

When default host keys are created by sshd-keygen (/etc/ssh/ssh_host_*_key)
in RHEL/CentOS/Fedora, openssh it performs the following:

# create new keys
if ! $KEYGEN -q -t $KEYTYPE -f $KEY -C '' -N '' >&/dev/null; then
        exit 1
fi

# sanitize permissions
/usr/bin/chgrp ssh_keys $KEY
/usr/bin/chmod 640 $KEY
/usr/bin/chmod 644 $KEY.pub

Note that the group ssh_keys exists only in RHEL/CentOS/Fedora.

Now that we disable sshd-keygen to allow only cloud-init to create
them, we miss the "sanitize permissions" part, where we set the group
owner as ssh_keys and the private key mode to 640.

According to https://bugzilla.redhat.com/show_bug.cgi?id=2013644#c8, failing
to set group ownership and permissions like openssh does makes the RHEL openscap
tool generate an error.

Signed-off-by: Emanuele Giuseppe Esposito eesposit@redhat.com

RHBZ: 2013644

Test Steps

Check permissions after cloud-init has generated ssh host keys:

ll /etc/ssh/

-rw-------. 1 root root    545 Oct 14 13:03 ssh_host_ecdsa_key
-rw-r--r--. 1 root root    209 Oct 14 13:03 ssh_host_ecdsa_key.pub
-rw-------. 1 root root    452 Oct 14 13:03 ssh_host_ed25519_key
-rw-r--r--. 1 root root    129 Oct 14 13:03 ssh_host_ed25519_key.pub
-rw-------. 1 root root   2643 Oct 14 13:03 ssh_host_rsa_key
-rw-r--r--. 1 root root    601 Oct 14 13:03 ssh_host_rsa_key.pub

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

@esposem esposem force-pushed the sshd_host_permissions branch 3 times, most recently from 0719d8f to cbc79fb Compare October 15, 2021 12:41
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Thanks!

when default host keys are created by sshd-keygen (/etc/ssh/ssh_host_*_key),
openssh it performs the following:

# create new keys
if ! $KEYGEN -q -t $KEYTYPE -f $KEY -C '' -N '' >&/dev/null; then
        exit 1
fi

# sanitize permissions
/usr/bin/chgrp ssh_keys $KEY
/usr/bin/chmod 640 $KEY
/usr/bin/chmod 644 $KEY.pub

Now that we disable sshd-keygen to allow only cloud-init to create
them, we miss the "sanitize permissions" part, where we set the group
owner as ssh_keys and the private key mode to 640.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
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.

2 participants