-
Notifications
You must be signed in to change notification settings - Fork 674
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
NOISSUE - Check For Subject During Policy Addition #1826
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1826 +/- ##
==========================================
- Coverage 67.44% 67.40% -0.04%
==========================================
Files 118 118
Lines 9470 9483 +13
==========================================
+ Hits 6387 6392 +5
- Misses 2404 2408 +4
- Partials 679 683 +4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve conflicts and remove duplicate APIs (ShareClient = AddPolicy). Don't forget to update API docs accordingly.
8606ca8
to
87d82b5
Compare
That is done at https://github.com/mainflux/mainflux/pull/1825 |
things/policies/service.go
Outdated
@@ -101,7 +107,7 @@ func (svc service) Authorize(ctx context.Context, ar AccessRequest) (Policy, err | |||
// 1. The client is admin | |||
// | |||
// 2. The client has `g_add` action on the object or is the owner of the object. | |||
func (svc service) AddPolicy(ctx context.Context, token string, p Policy) (Policy, error) { | |||
func (svc service) AddPolicy(ctx context.Context, token, client string, p Policy) (Policy, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the client
param bool flag external
. At the moment, external indicates anything that's not a Thing, and later we'll add verification if it's a user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to document this param, it's very important.
473df09
to
c02a4fd
Compare
things/policies/service.go
Outdated
|
||
return errors.ErrAuthorization | ||
default: | ||
return errors.New("invalid client") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract the error to a new exported var.
users/policies/policies.go
Outdated
var PolicyTypes = []string{"g_add", "g_delete", "g_update", "g_list", "c_delete", "c_update", "c_list", "m_write", "m_read"} | ||
// | ||
// Sharing policies | ||
// 11. c_share - share a client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborate: Allowed to add members of the group to the other groups.
LGTM |
292e3b7
to
97363bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, LGTM
9abfa50
to
fba79ab
Compare
things/policies/service.go
Outdated
ReadAction = "m_read" | ||
WriteAction = "m_write" | ||
addPolicyAction = "g_add" | ||
sharePolicyAction = "c_share" | ||
ClientEntityType = "client" | ||
GroupEntityType = "group" | ||
ThingEntityType = "thing" | ||
thingsObjectKey = "things" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate logically.
things/clients/service.go
Outdated
@@ -16,15 +16,21 @@ import ( | |||
) | |||
|
|||
const ( | |||
MyKey = "mine" | |||
thingsObjectKey = "things" | |||
MyKey = "mine" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to export this (except for tests)? If not, please don't export.
things/clients/service.go
Outdated
) | ||
|
||
var AdminRelationKey = []string{updateRelationKey, listRelationKey, deleteRelationKey} | ||
var AdminRelationKey = []string{updateRelationKey, listRelationKey, deleteRelationKey, shareRelationKey} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment exported vars. Also, rename to AdminRelationKeys
.
e90ae3e
to
ca5b8b5
Compare
things/policies/service.go
Outdated
switch external { | ||
case false: | ||
ar := AccessRequest{Subject: userID, Object: p.Subject, Action: sharePolicyAction} | ||
if _, err := svc.policies.EvaluateThingAccess(ctx, ar); err != nil { | ||
return err | ||
} | ||
case true: | ||
if err := svc.usersAuthorize(ctx, userID, p.Subject, sharePolicyAction, ClientEntityType); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch external { | |
case false: | |
ar := AccessRequest{Subject: userID, Object: p.Subject, Action: sharePolicyAction} | |
if _, err := svc.policies.EvaluateThingAccess(ctx, ar); err != nil { | |
return err | |
} | |
case true: | |
if err := svc.usersAuthorize(ctx, userID, p.Subject, sharePolicyAction, ClientEntityType); err != nil { | |
return err | |
} | |
} | |
return nil | |
switch { | |
case external: | |
ar := AccessRequest{Subject: userID, Object: p.Subject, Action: sharePolicyAction} | |
if _, err := svc.policies.EvaluateThingAccess(ctx, ar); err != nil { | |
return err | |
} | |
default: | |
if err := svc.usersAuthorize(ctx, userID, p.Subject, sharePolicyAction, ClientEntityType); err != nil { | |
return err | |
} | |
} | |
return nil |
This looks a little bit more elegant. Or use simple if
instead.
users/clients/service.go
Outdated
@@ -17,12 +17,15 @@ import ( | |||
) | |||
|
|||
const ( | |||
MyKey = "mine" | |||
clientsObjectKey = "clients" | |||
MyKey = "mine" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous Things remarks.
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
f70caa1
to
8458de1
Compare
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
8458de1
to
102b2c8
Compare
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Check For Subject During Adding Policies Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Make Object to be Group ID Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Change from string to bool Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Update Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * When it is Admin Don't Check Subject Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Minor Refractoring Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Group Constants Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Test if User Doesn't Have Policy Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Combine Share Things Cases Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove Unnecessary Case Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Check For Non NIL error Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove 3 Cases From Bool Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Listing Actions Incase of Sharing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Capitalize comments Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Move AdminRelationKeys to Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Tests After Rebase Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Rename myKey Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Simplify checkSubject Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
* Check For Subject During Adding Policies Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Make Object to be Group ID Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Change from string to bool Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Update Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * When it is Admin Don't Check Subject Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Minor Refractoring Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Group Constants Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Test if User Doesn't Have Policy Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Combine Share Things Cases Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove Unnecessary Case Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Check For Non NIL error Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove 3 Cases From Bool Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Listing Actions Incase of Sharing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Capitalize comments Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Move AdminRelationKeys to Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Tests After Rebase Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Rename myKey Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Simplify checkSubject Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo blackd0t@protonmail.com
What does this do?
On
things
services check if the subject is athing
or auser
.c_share
action on the thingc_share
action on the userWhich issue(s) does this PR fix/relate to?
No issue
List any changes that modify/break current functionality
object
column in thepolicies
table references theid
column of thegroups
table.subject
in addition to checking forobject
Have you included tests for your changes?
Yes
Did you document any new/modified functionality?
No
Notes
To be merged after https://github.com/mainflux/mainflux/pull/1825