Repository navigation
Read authorized keys from /var as well as ~/.ssh, 0.1.1 #3
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
Open
mobileoverlord
wants to merge
1
commit into
main
Choose a base branch
from
jschneck/authorized-keys-on-var
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
overlay/etc/ssh/sshd_config.d/50-avocado-authorized-keys.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Avocado: read keys from /var as well as ~/.ssh. | ||
| # | ||
| # The root filesystem is read-only, so a home directory on it (root's is | ||
| # /root) cannot hold ~/.ssh/authorized_keys. /var/lib/ssh/authorized_keys.d/ | ||
| # is writable and survives reboots and OS updates; put each user's keys in | ||
| # a file named for the user (e.g. .../authorized_keys.d/root), shipped with | ||
| # the runtime's var_files or written at provisioning. Per-user files keep one | ||
| # account's keys from opening another. StrictModes applies: the directory and | ||
| # files must be owned by root (or the user) and not group/world writable. | ||
| # | ||
| # sshd keeps the first value it sees and sshd_config Includes this directory | ||
| # first, so this takes precedence over sshd_config's own AuthorizedKeysFile. | ||
| AuthorizedKeysFile .ssh/authorized_keys /var/lib/ssh/authorized_keys.d/%u | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sshd will refuse keys shipped with runtime
var_fileson a Linux build host.avocado-cli copies runtime
var_fileswithcp -a(src/commands/runtime/build.rs:2439), then packs the var image withmkfs.btrfs -r(src/commands/runtime/var_image.rs:611). Both steps keep the uid, gid and mode of the host file. On a Linux host the key file belongs to the developer (for example uid 1000). On Ubuntu the default umask is 002, so the files are 0664 and the directories are 0775. StrictModes requires the key file and each parent directory up to/to be owned by root or the login user, with no group or world write.How it occurs: the user follows the CHANGELOG, adds
keys/roottovar_files, builds and provisions. Key login then fails. The only sign isAuthentication refused: bad ownership or modesin the journal. This extension also permits empty-password root login, so the user may not see the failure until they turn password auth off. The test in the PR wrote the key on the device as root, so it did not hit this path. I found this by reading the code and did not reproduce it on a device.Suggested fix: ship
overlay/usr/lib/tmpfiles.d/avocado-sshd-keys.conf:The
~keeps key files at 0644 and sets the directory to 0755. Thedline also creates the directory for users who write keys at provisioning. Addsystemd-tmpfiles --create /usr/lib/tmpfiles.d/avocado-sshd-keys.conftoon_mergeso the fix applies without a reboot.