Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pam_ssh_agent_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, const char **argv)
/*
* user is the name of the target-user, and so must be used for validating the authorized_keys file
*/
parse_authorized_key_file(user, authorized_keys_file_input);
parse_authorized_key_file(user, ruser, authorized_keys_file_input);
} else {
pamsshagentauth_verbose("Using default file=/etc/security/authorized_keys");
authorized_keys_file = pamsshagentauth_xstrdup("/etc/security/authorized_keys");
Expand Down
6 changes: 6 additions & 0 deletions pam_ssh_agent_auth.pod
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Automatically enables allow_user_owned_authorized_keys_file

=item %u -- Username

=item %r -- Remote Username

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would add an explanation here that the file must still belong to root/the target user and cannot be writable to the RUSER (Ownership is checked by auth_secure_path, so misuse cannot lead directly to a bypass; but it won't work).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated:

@@ -81,6 +81,10 @@ Automatically enables allow_user_owned_authorized_keys_file

 =item %r -- Remote Username

+Allows programs like su that set RUSER to the origin user and USER to the destination user, to name the key according to the user calling the program.
+
+The key file must belong to root or the target user. It must not be writable by the RUSER.
+
 =item %f -- FQDN

 =back

@AlD AlD Aug 21, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The key file must belong to root or the target user. It must not be writable by the RUSER.

This logic is backwards. There may be cases where it's acceptable for this file to be writable by RUSER. There are no cases where the originating user should be able to write to this file. See also #17.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No, you're actually right. According to sudoers/auth/pam.c RUSER is actually the 'from' user, just as you wrote.

Set PAM_RUSER to the invoking user (the "from" user).

My confusion, and apparently that of the person who originally reported #17, comes from the fact that ruser and user somehow end up being identical when invoked via sudo. Not sure where that bug comes from, but a safeguard against this in pam_ssh_agent_auth could make sense.

Allows programs like su that set RUSER to the origin user and USER to the destination user, to name the key according to the user calling the program.

The key file must belong to root or the target user. It must not be writable by the RUSER.

=item %f -- FQDN

=back
Expand Down
4 changes: 2 additions & 2 deletions pam_user_authorized_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern uint8_t allow_user_owned_authorized_keys_file;
uid_t authorized_keys_file_allowed_owner_uid;

void
parse_authorized_key_file(const char *user,
parse_authorized_key_file(const char *user, const char *ruser,
const char *authorized_keys_file_input)
{
char fqdn[HOST_NAME_MAX] = "";
Expand Down Expand Up @@ -152,7 +152,7 @@ parse_authorized_key_file(const char *user,
authorized_keys_file =
pamsshagentauth_percent_expand(auth_keys_file_buf, "h",
getpwnam(user)->pw_dir, "H", hostname,
"f", fqdn, "u", user, NULL);
"f", fqdn, "u", user, "r", ruser, NULL);
}

int
Expand Down
2 changes: 1 addition & 1 deletion pam_user_authorized_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@

#include "identity.h"
int pam_user_key_allowed(const char *, Key *);
void parse_authorized_key_file(const char *, const char *);
void parse_authorized_key_file(const char *, const char *, const char *);

#endif