Skip to content

Commit df8f066

Browse files
committed
Add a new flag "allow_unknown_runas_id" to control matching of unknown IDs.
Previous, sudo would always allow unknown user or group IDs if the sudoers entry permitted it. This included the "ALL" alias. With this change, the admin must explicitly enable support for unknown IDs.
1 parent d7b4f88 commit df8f066

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed

doc/sudoers.man.in

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.nr BA @BAMAN@
2626
.nr LC @LCMAN@
2727
.nr PS @PSMAN@
28-
.TH "SUDOERS" "@mansectform@" "December 6, 2019" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
28+
.TH "SUDOERS" "@mansectform@" "December 8, 2019" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
2929
.nh
3030
.if n .ad l
3131
.SH "NAME"
@@ -2952,6 +2952,23 @@ This flag is
29522952
\fIoff\fR
29532953
by default.
29542954
.TP 18n
2955+
runas_allow_unknown_id
2956+
If enabled, allow matching of runas user and group IDs that are
2957+
not present in the password or group databases.
2958+
In addition to explicitly matching unknown user or group IDs in a
2959+
\fRRunas_List\fR,
2960+
this option also allows the
2961+
\fBALL\fR
2962+
alias to match unknown IDs.
2963+
This flag is
2964+
\fIoff\fR
2965+
by default.
2966+
.sp
2967+
This setting is only supported by version 1.8.30 or higher.
2968+
Older versions of
2969+
\fBsudo\fR
2970+
always allowed matching of unknown user and group IDs.
2971+
.TP 18n
29552972
runaspw
29562973
If set,
29572974
\fBsudo\fR

doc/sudoers.mdoc.in

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
.nr BA @BAMAN@
2525
.nr LC @LCMAN@
2626
.nr PS @PSMAN@
27-
.Dd December 6, 2019
27+
.Dd December 8, 2019
2828
.Dt SUDOERS @mansectform@
2929
.Os Sudo @PACKAGE_VERSION@
3030
.Sh NAME
@@ -2778,6 +2778,22 @@ when running a command or editing a file.
27782778
This flag is
27792779
.Em off
27802780
by default.
2781+
.It runas_allow_unknown_id
2782+
If enabled, allow matching of runas user and group IDs that are
2783+
not present in the password or group databases.
2784+
In addition to explicitly matching unknown user or group IDs in a
2785+
.Li Runas_List ,
2786+
this option also allows the
2787+
.Sy ALL
2788+
alias to match unknown IDs.
2789+
This flag is
2790+
.Em off
2791+
by default.
2792+
.Pp
2793+
This setting is only supported by version 1.8.30 or higher.
2794+
Older versions of
2795+
.Nm sudo
2796+
always allowed matching of unknown user and group IDs.
27812797
.It runaspw
27822798
If set,
27832799
.Nm sudo

plugins/sudoers/def_data.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ struct sudo_defs_types sudo_defs_table[] = {
525525
"log_server_peer_key", T_STR|T_BOOL|T_PATH,
526526
N_("Path to the sudoers private key file: %s"),
527527
NULL,
528+
}, {
529+
"runas_allow_unknown_id", T_FLAG,
530+
N_("Allow the use of unknown runas user and/or group ID"),
531+
NULL,
528532
}, {
529533
NULL, 0, NULL
530534
}

plugins/sudoers/def_data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@
242242
#define def_log_server_peer_cert (sudo_defs_table[I_LOG_SERVER_PEER_CERT].sd_un.str)
243243
#define I_LOG_SERVER_PEER_KEY 121
244244
#define def_log_server_peer_key (sudo_defs_table[I_LOG_SERVER_PEER_KEY].sd_un.str)
245+
#define I_RUNAS_ALLOW_UNKNOWN_ID 122
246+
#define def_runas_allow_unknown_id (sudo_defs_table[I_RUNAS_ALLOW_UNKNOWN_ID].sd_un.flag)
245247

246248
enum def_tuple {
247249
never,

plugins/sudoers/def_data.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,6 @@ log_server_peer_cert
381381
log_server_peer_key
382382
T_STR|T_BOOL|T_PATH
383383
"Path to the sudoers private key file: %s"
384+
runas_allow_unknown_id
385+
T_FLAG
386+
"Allow the use of unknown runas user and/or group ID"

plugins/sudoers/defaults.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ init_defaults(void)
537537
def_fdexec = digest_only;
538538
def_log_allowed = true;
539539
def_log_denied = true;
540+
def_runas_allow_unknown_id = false;
540541

541542
/* Syslog options need special care since they both strings and ints */
542543
#if (LOGGING & SLOG_SYSLOG)

plugins/sudoers/sudoers.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ static char *prev_user;
106106
static char *runas_user;
107107
static char *runas_group;
108108
static struct sudo_nss_list *snl;
109+
static bool unknown_runas_uid;
110+
static bool unknown_runas_gid;
109111

110112
#ifdef __linux__
111113
static struct rlimit nproclimit;
@@ -376,6 +378,22 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
376378
}
377379
}
378380

381+
/* Defer uid/gid checks until after defaults have been updated. */
382+
if (unknown_runas_uid && !def_runas_allow_unknown_id) {
383+
audit_failure(NewArgc, NewArgv, N_("unknown user: %s"),
384+
runas_pw->pw_name);
385+
sudo_warnx(U_("unknown user: %s"), runas_pw->pw_name);
386+
goto done;
387+
}
388+
if (runas_gr != NULL) {
389+
if (unknown_runas_gid && !def_runas_allow_unknown_id) {
390+
audit_failure(NewArgc, NewArgv, N_("unknown group: %s"),
391+
runas_gr->gr_name);
392+
sudo_warnx(U_("unknown group: %s"), runas_gr->gr_name);
393+
goto done;
394+
}
395+
}
396+
379397
/*
380398
* Look up the timestamp dir owner if one is specified.
381399
*/
@@ -1192,12 +1210,15 @@ set_runaspw(const char *user, bool quiet)
11921210
struct passwd *pw = NULL;
11931211
debug_decl(set_runaspw, SUDOERS_DEBUG_PLUGIN)
11941212

1213+
unknown_runas_uid = false;
11951214
if (*user == '#') {
11961215
const char *errstr;
11971216
uid_t uid = sudo_strtoid(user + 1, &errstr);
11981217
if (errstr == NULL) {
1199-
if ((pw = sudo_getpwuid(uid)) == NULL)
1218+
if ((pw = sudo_getpwuid(uid)) == NULL) {
1219+
unknown_runas_uid = true;
12001220
pw = sudo_fakepwnam(user, user_gid);
1221+
}
12011222
}
12021223
}
12031224
if (pw == NULL) {
@@ -1223,12 +1244,15 @@ set_runasgr(const char *group, bool quiet)
12231244
struct group *gr = NULL;
12241245
debug_decl(set_runasgr, SUDOERS_DEBUG_PLUGIN)
12251246

1247+
unknown_runas_gid = false;
12261248
if (*group == '#') {
12271249
const char *errstr;
12281250
gid_t gid = sudo_strtoid(group + 1, &errstr);
12291251
if (errstr == NULL) {
1230-
if ((gr = sudo_getgrgid(gid)) == NULL)
1252+
if ((gr = sudo_getgrgid(gid)) == NULL) {
1253+
unknown_runas_gid = true;
12311254
gr = sudo_fakegrnam(group);
1255+
}
12321256
}
12331257
}
12341258
if (gr == NULL) {

0 commit comments

Comments
 (0)