|
13 | 13 | #endif |
14 | 14 | #include <time.h> |
15 | 15 | #include <unistd.h> |
| 16 | +#include <sys/types.h> |
16 | 17 | #include <jansson.h> |
17 | 18 | #include <flux/core.h> |
18 | 19 | #if HAVE_FLUX_SECURITY |
@@ -81,9 +82,16 @@ static const double batch_timeout = 0.01; |
81 | 82 | */ |
82 | 83 | static int max_fluid_generator_id = 16384 - 16 - 1; |
83 | 84 |
|
| 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 | + |
84 | 91 | struct job_ingest_ctx { |
85 | 92 | flux_t *h; |
86 | 93 | struct pipeline *pipeline; |
| 94 | + uid_t owner; |
87 | 95 | #if HAVE_FLUX_SECURITY |
88 | 96 | flux_security_t *sec; |
89 | 97 | #else |
@@ -574,6 +582,13 @@ static void submit_cb (flux_t *h, flux_msg_handler_t *mh, |
574 | 582 | errmsg = error.text; |
575 | 583 | goto error; |
576 | 584 | } |
| 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 | + } |
577 | 592 | if (pipeline_process_job (ctx->pipeline, job, &f, &error) < 0) { |
578 | 593 | errmsg = error.text; |
579 | 594 | goto error; |
@@ -694,6 +709,9 @@ static int job_ingest_configure (struct job_ingest_ctx *ctx, |
694 | 709 | else if (strstarts (argv[i], "max-fluid-generator-id=")) { |
695 | 710 | max_fluid_id = argv[i] + 23; |
696 | 711 | } |
| 712 | + else if (streq (argv[i], "allow-root-jobs")) { |
| 713 | + allow_root_jobs = true; |
| 714 | + } |
697 | 715 | else { |
698 | 716 | errprintf (error, "Invalid option: %s", argv[i]); |
699 | 717 | errno = EINVAL; |
@@ -797,6 +815,8 @@ int job_ingest_ctx_init (struct job_ingest_ctx *ctx, |
797 | 815 | ctx->h = h; |
798 | 816 | flux_error_t error; |
799 | 817 |
|
| 818 | + ctx->owner = getuid (); |
| 819 | + |
800 | 820 | /* Default worker input buffer size is 10MB */ |
801 | 821 | ctx->buffer_size = "10M"; |
802 | 822 |
|
|
0 commit comments