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

doc: add message security policy functions to man page #1285

Closed
wants to merge 3 commits into from

Conversation

garlick
Copy link
Member

@garlick garlick commented Nov 11, 2017

This was peeled off of #1277

Add missing man page coverage for flux_msg_handler_allow_rolemask() and deny_rolemask() with brief overview of message handler security and ref to RFC 12.

Restructure the rolemask filtering code to make it clear to casual reader that presence of the FLUX_ROLEMASK_OWNER bit in a message rolemask is a special case, rather than a role that can be controlled like any other. The code change affects readability but not function.

@garlick garlick changed the title [doc] add message security policy functions to man page doc: add message security policy functions to man page Nov 11, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 78.541% when pulling 42677b4 on garlick:rolemask_doc into 819d8c5 on flux-framework:master.

@codecov-io
Copy link

codecov-io commented Nov 11, 2017

Codecov Report

Merging #1285 into master will decrease coverage by 0.08%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1285      +/-   ##
==========================================
- Coverage   78.02%   77.94%   -0.09%     
==========================================
  Files         154      154              
  Lines       29104    29103       -1     
==========================================
- Hits        22709    22683      -26     
- Misses       6395     6420      +25
Impacted Files Coverage Δ
src/common/libflux/msg_handler.c 86.59% <100%> (-0.05%) ⬇️
src/modules/connector-local/local.c 76.11% <0%> (-1.31%) ⬇️
src/common/libflux/request.c 87.17% <0%> (-1.29%) ⬇️
src/common/libkvs/kvs.c 65.19% <0%> (-1.11%) ⬇️
src/broker/modservice.c 80.58% <0%> (-0.98%) ⬇️
src/modules/kvs/kvs.c 63.79% <0%> (-0.9%) ⬇️
src/common/libflux/rpc.c 93.38% <0%> (-0.83%) ⬇️
src/common/libflux/handle.c 83.66% <0%> (-0.5%) ⬇️
src/common/libflux/future.c 88.31% <0%> (-0.47%) ⬇️
src/common/libflux/message.c 81.25% <0%> (+0.11%) ⬆️
... and 3 more

@morrone
Copy link
Contributor

morrone commented Nov 12, 2017

I would like to suggest a different approach. I am not a fan of using "0" as a default value when another more clear option is possible. Zeros makes the code harder to read. Every time a zero is encountered as an option in a function call, anyone that hasn't already memorized the function prototype won't know what that zero means. The reader needs to jump out of the code they are reading and look up the prototype, and maybe even further documentation, and sometimes even just read the implementation of the function.

When the parameter is a mask, there is an easy way to avoid seeing zeros in the calls to the function. Usually the bits of the mask are either defined in an enum or through macros. There can then always be a name that can be specified rather than using zero as the default. zero should only be zero when the mask is litterally meant to be "match nothing". And even then, it would be better to use something like "FLUX_ROLE_NONE" rather than using zero.

When a reader sees a function call and one of the options is "FLUX_ROLE_NONE", the parameter's purpose is immediately obvious, whereas a zero would require a prototype lookup to understand its purpose.

I would recommend that we change the interfaces to always take FLUX_ROLE_USER, since that is always, in fact, required. If the caller doesn't include FLUX_ROLE_USER in their mask, that should simply be an error. This solves the problem of ambiguous zeros in the code, and also converts the FLUX_ROLE_USER behavior from being implicit to being explicit. Explicit always makes for more understandable code.

@garlick
Copy link
Member Author

garlick commented Nov 12, 2017

I'm not really buying that 0 is wrong for a bitmask value. Example: symbolic values available for chmod(2). I suppose it's nice if function calls have self-describing parameters, but the opposite is probably the norm.

I would recommend that we change the interfaces to always take FLUX_ROLE_USER, since that is always, in fact, required.

Assuming you mean FLUX_ROLE_OWNER? It seems like a "bring me a rock" API design - requiring the user to come up with something on every call that we already know.

@morrone
Copy link
Contributor

morrone commented Nov 13, 2017

(yes I mean FLUX_ROLE_OWNER)

You're still making them bring a rock: a zero. Which is literally rock shaped. :) I'm not clear on why a zero rock is better for readability and maintainability of the code than a descriptive rock.

@garlick
Copy link
Member Author

garlick commented Nov 13, 2017

Heh, good one. Well if it's a rock, at least I"m proposing it look like one.

I don't necessarily have a problem with what you're proposing, although I don't have a problem with what I've already worked out either. Since what you're proposing involves touching every advec call, changing the allow/deny functions to return an error instead of void, and patching sched, in addition to rewriting the man page verbage, it feels (to me) like a fair bit of work for little gain, and not high on my list of priorities.

How about we merge this as is since it's an incremental improvement over what we have now (which is no documentation). Then if you want to propose your improvements in another set of PR's, you can do that.

which add or remove roles from the message handler rolemask. The
FLUX_ROLE_OWNER bit position is ignored in the message handler rolemask.

The following roles are defined in RFC 12:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public interface in the code also defines FLUX_ROLE_NONE and FLUX_ROLE_ALL. I think those need to be documented as well.

@@ -30,6 +32,12 @@ SYNOPSIS

void flux_msg_handler_stop (flux_msg_handler_t *mh);

void flux_msg_handler_allow_rolemask (flux_msg_handler_t *w,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these functions really need a clear explanation of how they work. It is a little unual, I think, to have a function that or's the supplied mask rather than just setting the mask, and another that and's the inverse of the supplied mask. I think simple "set" and "get" mask functions would have been better. But since this is what we have, we should document what they do.

Copy link
Contributor

@morrone morrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if you are going this way, then this line from flux_msg_handler_deny_rolemask() should also be removed:

mh->rolemask |= FLUX_ROLE_OWNER;

@garlick
Copy link
Member Author

garlick commented Nov 13, 2017

Just rebased on current master and added a commit to address your suggestions for the man page.

I think that if you are going this way, then this line from flux_msg_handler_deny_rolemask() should also be removed:

mh->rolemask |= FLUX_ROLE_OWNER;

Hmm, that was already there, so not sure what you were looking at? I haven't changed that commit other than rebasing it just now.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 78.546% when pulling b02bc70 on garlick:rolemask_doc into 3c3890c on flux-framework:master.

Problem: message handler filtering based on rolemasks
is not discussed in flux_msg_handler_create(3).

Add man page stubs for flux_msg_handler_allow_rolemask()
and flux_msg_handler_deny_rolemask(), a SECURITY section,
and a reference to RFC 12.

Fixes flux-framework#1260
Add note about the 'rolemask' member of struct flux_msg_handler_spec,
referring back to the SECTION section in flux_msg_handler_create(3).
Add FLUX_ROLEMASK_NONE and FLUX_ROLEMASK_ALL and make
sure to be clear that allow/deny modify, not overwrite,
the existing rolemask.
@garlick
Copy link
Member Author

garlick commented Nov 24, 2017

This seems to be going nowhere so I'll withdraw the PR.

@garlick garlick closed this Nov 24, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 78.59% when pulling d00050a on garlick:rolemask_doc into a2b1063 on flux-framework:master.

@garlick garlick deleted the rolemask_doc branch February 25, 2020 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants