Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvs: don't check namespace if user passes in at reference #1436

Merged
merged 4 commits into from
Apr 7, 2018
Merged
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
6 changes: 6 additions & 0 deletions src/modules/kvs/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct lookup {

char *namespace;
char *root_ref;
bool root_ref_set_by_user; /* if root_ref passed in by user */

char *path;

Expand Down Expand Up @@ -608,6 +609,7 @@ lookup_t *lookup_create (struct cache *cache,
saved_errno = ENOMEM;
goto cleanup;
}
lh->root_ref_set_by_user = true;
}

lh->h = h;
Expand Down Expand Up @@ -792,6 +794,10 @@ static int namespace_still_valid (lookup_t *lh)
{
struct kvsroot *root;

/* If user set root_ref, no need to do this check */
if (lh->root_ref_set_by_user)
return 0;

if (!(root = kvsroot_mgr_lookup_root_safe (lh->krm, lh->namespace))) {
lh->errnum = ENOTSUP;
return -1;
Expand Down
118 changes: 116 additions & 2 deletions src/modules/kvs/test/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,23 @@ void lookup_security (void) {
"lookup_create on val with rolemask user and invalid owner");
check_error (lh, EPERM, "lookup_create on val with rolemask user and invalid owner");

/* if root_ref is set, namespace checks won't occur */
ok ((lh = lookup_create (cache,
krm,
1,
KVS_PRIMARY_NAMESPACE,
root_ref,
"val",
FLUX_ROLE_USER,
6,
0,
NULL,
NULL)) != NULL,
"lookup_create on val with rolemask user and invalid owner w/ root_ref");
test = treeobj_create_val ("foo", 3);
check_value (lh, test, "lookup val with rolemask user and valid owner");
json_decref (test);

ok ((lh = lookup_create (cache,
krm,
1,
Expand Down Expand Up @@ -2940,6 +2957,7 @@ void lookup_stall_namespace_removed (void) {
json_t *root;
json_t *valref;
json_t *dirref;
json_t *test;
struct cache *cache;
kvsroot_mgr_t *krm;
lookup_t *lh;
Expand Down Expand Up @@ -3057,7 +3075,7 @@ void lookup_stall_namespace_removed (void) {
"lookup_create stalltest dirref.valref");
check_stall (lh, EAGAIN, 1, valref_ref, "dirref.valref stall #3");

cache_insert (cache, valref_ref, create_cache_entry_treeobj (valref));
cache_insert (cache, valref_ref, create_cache_entry_raw (strdup ("abcd"), 4));

ok (!kvsroot_mgr_remove_root (krm, KVS_PRIMARY_NAMESPACE),
"kvsroot_mgr_remove_root removed root successfully");
Expand Down Expand Up @@ -3155,7 +3173,7 @@ void lookup_stall_namespace_removed (void) {
"lookup_create stalltest dirref.valref");
check_stall (lh, EAGAIN, 1, valref_ref, "dirref.valref stall #3");

cache_insert (cache, valref_ref, create_cache_entry_treeobj (valref));
cache_insert (cache, valref_ref, create_cache_entry_raw (strdup ("abcd"), 4));

ok (!kvsroot_mgr_remove_root (krm, KVS_PRIMARY_NAMESPACE),
"kvsroot_mgr_remove_root removed root successfully");
Expand All @@ -3168,6 +3186,102 @@ void lookup_stall_namespace_removed (void) {

/* reset test */
kvsroot_mgr_remove_root (krm, KVS_PRIMARY_NAMESPACE);
cache_remove_entry (cache, root_ref);
cache_remove_entry (cache, dirref_ref);
cache_remove_entry (cache, valref_ref);
setup_kvsroot (krm, KVS_PRIMARY_NAMESPACE, cache, root_ref, 0);

/*
* Now, similar tests to above, but we pass in a root_ref. So the
* checks on namespaces before is now no longer necessary and we
* should eventually read the end value.
*/

ok ((lh = lookup_create (cache,
krm,
1,
KVS_PRIMARY_NAMESPACE,
root_ref,
"dirref.valref",
FLUX_ROLE_OWNER,
0,
0,
NULL,
NULL)) != NULL,
"lookup_create stalltest dirref.valref w/ root_ref");

/* Now remove namespace */

ok (!kvsroot_mgr_remove_root (krm, KVS_PRIMARY_NAMESPACE),
"kvsroot_mgr_remove_root removed root successfully");

/* Check for stalls, insert refs until should all succeed */

check_stall (lh, EAGAIN, 1, root_ref, "dirref.valref stall #1 w/ root_ref");

cache_insert (cache, root_ref, create_cache_entry_treeobj (root));

check_stall (lh, EAGAIN, 1, dirref_ref, "dirref.valref stall #2 w/ root_ref");

cache_insert (cache, dirref_ref, create_cache_entry_treeobj (dirref));

check_stall (lh, EAGAIN, 1, valref_ref, "dirref.valref stall #3 w/ root_ref");

cache_insert (cache, valref_ref, create_cache_entry_raw (strdup ("abcd"), 4));

test = treeobj_create_val ("abcd", 4);
check_value (lh, test, "lookup_create dirref.valref w/ root_ref");
json_decref (test);

/* reset test */
cache_remove_entry (cache, root_ref);
cache_remove_entry (cache, dirref_ref);
cache_remove_entry (cache, valref_ref);
setup_kvsroot (krm, KVS_PRIMARY_NAMESPACE, cache, root_ref, 0);

ok ((lh = lookup_create (cache,
krm,
1,
KVS_PRIMARY_NAMESPACE,
root_ref,
"dirref.valref",
FLUX_ROLE_USER,
0,
0,
NULL,
NULL)) != NULL,
"lookup_create stalltest dirref.valref w/ root_ref & role user ");

/* Now remove namespace and re-insert with different owner */

ok (!kvsroot_mgr_remove_root (krm, KVS_PRIMARY_NAMESPACE),
"kvsroot_mgr_remove_root removed root successfully");

setup_kvsroot (krm, KVS_PRIMARY_NAMESPACE, cache, root_ref, 2);

/* Check for stalls, insert refs until should all succeed */

check_stall (lh, EAGAIN, 1, root_ref, "dirref.valref stall #1 w/ root_ref & role user");

cache_insert (cache, root_ref, create_cache_entry_treeobj (root));

check_stall (lh, EAGAIN, 1, dirref_ref, "dirref.valref stall #2 w/ root_ref & role user");

cache_insert (cache, dirref_ref, create_cache_entry_treeobj (dirref));

check_stall (lh, EAGAIN, 1, valref_ref, "dirref.valref stall #3 w/ root_ref & role user");

cache_insert (cache, valref_ref, create_cache_entry_raw (strdup ("abcd"), 4));

test = treeobj_create_val ("abcd", 4);
check_value (lh, test, "lookup_create dirref.valref w/ root_ref & role user");
json_decref (test);

/* reset test */
kvsroot_mgr_remove_root (krm, KVS_PRIMARY_NAMESPACE);
cache_remove_entry (cache, root_ref);
cache_remove_entry (cache, dirref_ref);
cache_remove_entry (cache, valref_ref);
setup_kvsroot (krm, KVS_PRIMARY_NAMESPACE, cache, root_ref, 0);

cache_destroy (cache);
Expand Down
9 changes: 9 additions & 0 deletions t/t1005-kvs-security.t
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ test_expect_success 'kvs: get fails on other ranks (wrong user)' '
flux kvs --namespace=$NAMESPACETMP-USER get $DIR.test"
'

test_expect_success 'kvs: get works (wrong user, but with at reference)' '
set_userid 9999 &&
ref=`flux kvs --namespace=$NAMESPACETMP-USER get --treeobj .` &&
unset_userid &&
set_userid 9000 &&
flux kvs --namespace=$NAMESPACETMP-USER get --at ${ref} --json $DIR.test &&
unset_userid
'

test_expect_success NO_CHAIN_LINT 'kvs: watch works (user)' '
set_userid 9999 &&
flux kvs --namespace=$NAMESPACETMP-USER unlink -Rf $DIR &&
Expand Down