Skip to content

Commit 29b93f6

Browse files
authored
Merge pull request #6194 from grondo/issue#6144
reject jobs submitted as user root in a multi-user instance
2 parents 10cdf3b + c36727e commit 29b93f6

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/modules/job-ingest/job-ingest.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#endif
1414
#include <time.h>
1515
#include <unistd.h>
16+
#include <sys/types.h>
1617
#include <jansson.h>
1718
#include <flux/core.h>
1819
#if HAVE_FLUX_SECURITY
@@ -81,9 +82,16 @@ static const double batch_timeout = 0.01;
8182
*/
8283
static int max_fluid_generator_id = 16384 - 16 - 1;
8384

85+
/* By default, root (userid=0) jobs are rejected at submission
86+
* unless the instance owner is also root. However, for testing
87+
* purposes it may be useful to allow root jobs:
88+
*/
89+
static bool allow_root_jobs = false;
90+
8491
struct job_ingest_ctx {
8592
flux_t *h;
8693
struct pipeline *pipeline;
94+
uid_t owner;
8795
#if HAVE_FLUX_SECURITY
8896
flux_security_t *sec;
8997
#else
@@ -574,6 +582,13 @@ static void submit_cb (flux_t *h, flux_msg_handler_t *mh,
574582
errmsg = error.text;
575583
goto error;
576584
}
585+
/* Do not allow root user to submit jobs in a multi-user instance.
586+
* The jobs will fail at runtime anyway.
587+
*/
588+
if (ctx->owner != 0 && !allow_root_jobs && job->cred.userid == 0) {
589+
errmsg = "submission of jobs as user root not supported";
590+
goto error;
591+
}
577592
if (pipeline_process_job (ctx->pipeline, job, &f, &error) < 0) {
578593
errmsg = error.text;
579594
goto error;
@@ -694,6 +709,9 @@ static int job_ingest_configure (struct job_ingest_ctx *ctx,
694709
else if (strstarts (argv[i], "max-fluid-generator-id=")) {
695710
max_fluid_id = argv[i] + 23;
696711
}
712+
else if (streq (argv[i], "allow-root-jobs")) {
713+
allow_root_jobs = true;
714+
}
697715
else {
698716
errprintf (error, "Invalid option: %s", argv[i]);
699717
errno = EINVAL;
@@ -797,6 +815,8 @@ int job_ingest_ctx_init (struct job_ingest_ctx *ctx,
797815
ctx->h = h;
798816
flux_error_t error;
799817

818+
ctx->owner = getuid ();
819+
800820
/* Default worker input buffer size is 10MB */
801821
ctx->buffer_size = "10M";
802822

t/t2201-job-cmd.t

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ test_expect_success HAVE_FLUX_SECURITY 'flux-job: submit ignores security-config
9595
signed.json >submit-signed.out 2>&1 &&
9696
grep "Ignoring security config" submit-signed.out
9797
'
98+
test_expect_success HAVE_FLUX_SECURITY 'flux-job: submit as root fails' '
99+
flux run --dry-run -n1 hostname | \
100+
flux python \
101+
${SHARNESS_TEST_SRCDIR}/scripts/sign-as.py 0 >signed0.json &&
102+
( export FLUX_HANDLE_USERID=0 &&
103+
test_must_fail \
104+
flux job submit --flags=signed signed0.json 2>signed0.err \
105+
) &&
106+
test_debug "cat signed0.err" &&
107+
grep "submission of jobs as user root not supported" signed0.err
108+
'
98109
test_expect_success 'flux-job: can submit jobspec on stdin with -' '
99110
flux job submit - <basic.json
100111
'

t/t2812-flux-job-last.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ submit_as_root()
6666

6767
# issue #5475
6868
# Execution may fail but submission should work - enough for this test
69+
test_expect_success FLUX_SECURITY 'reload job-ingest with allow-root-jobs' '
70+
flux module reload job-ingest allow-root-jobs
71+
'
6972
test_expect_success FLUX_SECURITY 'run a job as fake root' '
7073
submit_as_root true &&
7174
FLUX_HANDLE_USERID=0 flux job last

0 commit comments

Comments
 (0)