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

WIP: Allow filtering of roles during permission fetching #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

afitzek
Copy link
Contributor

@afitzek afitzek commented Aug 10, 2017

This adds an optional external whitelist of roles available to a user.

We want to be able to restrict credentials (like a JWT), to only a given subset of the roles the user actually has and therefore only to the permissions associated with that given role.

Flowdock: https://www.flowdock.com/app/rulemotion/r-security/threads/6aoRkUtQ2XpwuPkwBu9rvnNrXb_

Change-Type: minor
Connects-To: #60

This is untested so far, I just tested it by changing the js directly in the api node_modules.

@afitzek afitzek requested a review from Page- August 10, 2017 11:41
@resin-jenkins
Copy link

Can one of the admins verify this patch?

Copy link
Collaborator

@Page- Page- left a comment

Choose a reason for hiding this comment

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

Could you add a description of the use case to the PR description please

@@ -180,7 +180,10 @@ exports.setup = (app, sbvrUtils) ->
throw err
.nodeify(callback)

exports.getUserPermissions = getUserPermissions = (userId, callback) ->
exports.getUserPermissions = getUserPermissions = (userId, roles, callback) ->
if typeof roles is 'function'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use _.isFunction please

@@ -206,6 +209,14 @@ exports.setup = (app, sbvrUtils) ->
uhr: expiry_date: null
, uhr: expiry_date: $gt: $now: null
]
if roles?
innerFilter = _.get(permsFilter, '$or.is_of__role.$any.$expr.rhp.role.$any.$expr')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather this is done as

roleFilter =
	r: is_of__user: $any:
		$alias: 'uhr'
		$expr:
			uhr: user: userId
			$or: [
				uhr: expiry_date: null
			,	uhr: expiry_date: $gt: $now: null
			]
if roles?
	roleFilter = $and: [
		roleFilter,
		r: name: $in: roles
	]

permsFilter = $or:
	is_of__user: $any:
		$alias: 'uhp'
		$expr:
			uhp: user: userId
			$or: [
				uhp: expiry_date: null
			,	uhp: expiry_date: $gt: $now: null
			]
	is_of__role: $any:
		$alias: 'rhp'
		$expr: rhp: role: $any:
			$alias: 'r'
			$expr: roleFilter

rather than using this hardcoded path which will be awkward to spot issues with and fix if the structure of the query changes in future (the logic should be the same, we just do the augmentation first and then it gets inserted straight into the correct spot of permsFilter when it's first created, rather than afterward)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice solution!

@Page-
Copy link
Collaborator

Page- commented Aug 11, 2017

add to whitelist

@afitzek afitzek changed the title Allow filtering of roles during permission fetching WIP: Allow filtering of roles during permission fetching Aug 11, 2017
This adds an optional external whitelist of roles available to a user.

Change-Type: minor
Connects-To: #60
Signed-off-by: Andreas Fitzek <[email protected]>
@afitzek afitzek force-pushed the 60-filter-roles-during-permission-fetching branch from 1b90cc5 to cc38fec Compare August 18, 2017 10:06
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.

3 participants