Skip to content

Commit 94bf05d

Browse files
authored
Merge pull request #5185 from grondo/submit-update
flux-job: submit: strip unnecessary whitespace from pre-signed jobspec
2 parents 6ecabe9 + a652478 commit 94bf05d

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/cmd/flux-job.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "src/common/libutil/monotime.h"
4848
#include "src/common/libutil/fsd.h"
4949
#include "src/common/libutil/fdutils.h"
50+
#include "src/common/libutil/strstrip.h"
5051
#include "src/common/libidset/idset.h"
5152
#include "src/common/libeventlog/eventlog.h"
5253
#include "src/common/libioencode/ioencode.h"
@@ -1525,7 +1526,7 @@ int cmd_submit (optparse_t *p, int argc, char **argv)
15251526
#if HAVE_FLUX_SECURITY
15261527
flux_security_t *sec = NULL;
15271528
const char *sec_config;
1528-
const char *sign_type;
1529+
const char *sign_type = NULL;
15291530
#endif
15301531
int flags = 0;
15311532
void *jobspec;
@@ -1563,27 +1564,38 @@ int cmd_submit (optparse_t *p, int argc, char **argv)
15631564
* context so jobspec can be pre-signed before submission.
15641565
*/
15651566
if (optparse_hasopt (p, "security-config")
1566-
|| optparse_hasopt (p, "sign-type")) {
1567-
sec_config = optparse_get_str (p, "security-config", NULL);
1568-
if (!(sec = flux_security_create (0)))
1569-
log_err_exit ("security");
1570-
if (flux_security_configure (sec, sec_config) < 0)
1571-
log_err_exit ("security config %s", flux_security_last_error (sec));
1572-
sign_type = optparse_get_str (p, "sign-type", NULL);
1567+
|| optparse_hasopt (p, "sign-type")) {
1568+
if (flags & FLUX_JOB_PRE_SIGNED)
1569+
log_msg ("Ignoring security config with --flags=pre-signed");
1570+
else {
1571+
sec_config = optparse_get_str (p, "security-config", NULL);
1572+
if (!(sec = flux_security_create (0)))
1573+
log_err_exit ("security");
1574+
if (flux_security_configure (sec, sec_config) < 0)
1575+
log_err_exit ("security config %s",
1576+
flux_security_last_error (sec));
1577+
sign_type = optparse_get_str (p, "sign-type", NULL);
1578+
}
15731579
}
15741580
#endif
15751581
if (!(h = flux_open (NULL, 0)))
15761582
log_err_exit ("flux_open");
1577-
jobspecsz = read_jobspec (input, &jobspec);
1578-
assert (((char *)jobspec)[jobspecsz] == '\0');
1579-
if (jobspecsz == 0)
1583+
if ((jobspecsz = read_jobspec (input, &jobspec)) == 0)
15801584
log_msg_exit ("required jobspec is empty");
1585+
1586+
/* If jobspec was pre-signed, then assign J to to jobspec after
1587+
* stripping surrounding whitespace.
1588+
*/
1589+
if (flags & FLUX_JOB_PRE_SIGNED)
1590+
J = strstrip (jobspec);
1591+
15811592
urgency = optparse_get_int (p, "urgency", FLUX_JOB_URGENCY_DEFAULT);
15821593

15831594
#if HAVE_FLUX_SECURITY
15841595
if (sec) {
15851596
if (!(J = flux_sign_wrap (sec, jobspec, jobspecsz, sign_type, 0)))
1586-
log_err_exit ("flux_sign_wrap: %s", flux_security_last_error (sec));
1597+
log_err_exit ("flux_sign_wrap: %s",
1598+
flux_security_last_error (sec));
15871599
flags |= FLUX_JOB_PRE_SIGNED;
15881600
}
15891601
#endif

t/t2201-job-cmd.t

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ test_expect_success HAVE_FLUX_SECURITY 'flux-job: submit with bad sign type fail
8787
--sign-type=notvalid \
8888
basic.json
8989
'
90-
90+
test_expect_success HAVE_FLUX_SECURITY 'flux-job: submit ignores security-config with --flags=signed' '
91+
flux run --dry-run -n1 hostnane | \
92+
flux python \
93+
${SHARNESS_TEST_SRCDIR}/scripts/sign-as.py $(id -u) >signed.json &&
94+
flux job submit --security-config=/nonexist --flags=signed \
95+
signed.json >submit-signed.out 2>&1 &&
96+
grep "Ignoring security config" submit-signed.out
97+
'
9198
test_expect_success 'flux-job: can submit jobspec on stdin with -' '
9299
flux job submit - <basic.json
93100
'

t/t2404-job-exec-multiuser.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test_expect_success 'job-exec: large jobspec does not get truncated' '
6565
actual=imp-$(flux job id $id).input &&
6666
test_debug "echo expecting J of size $(wc -c < job.signed)B" &&
6767
test_debug "echo input to IMP was $(wc -c < $actual)B" &&
68-
jq -j .J ${actual} > J.input &&
68+
jq -r .J ${actual} > J.input &&
6969
test_cmp job.signed J.input
7070
)
7171
'

0 commit comments

Comments
 (0)