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

feat: add permission manager #1507

Merged
merged 14 commits into from
Jan 9, 2025
Merged

feat: add permission manager #1507

merged 14 commits into from
Jan 9, 2025

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Jan 6, 2025

Description

This PR builds on #1506.

This PR introduces a permission manager package dedicated to granting/revoking access and checking a user's permissions.
Some notable changes:

  • The jujuauth now uses a factory pattern since this is a stateful object that needs to be recreated for each websocket connection. After introducing the permission manager package this simplifies how much access the API layer needs to the underlying business layer structs.
  • Refactored some application offer grant/revoke tests. They were not using the standard yaml -> DB approach for creating test objects.

The rest of the changes are largely mechanical but unfortunately very long because we had access related logic in many different places.

The changes are easier to review commit-by-commit (or at least the first commit on its own then the rest separately).

Fixes JUJU-7252

Engineering checklist

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

@kian99 kian99 requested a review from a team as a code owner January 6, 2025 06:56
@kian99 kian99 force-pushed the permission-manager branch from 4bf6903 to b9343c4 Compare January 6, 2025 09:53
@kian99 kian99 changed the title feat: introduce permission manager feat: add permission manager Jan 6, 2025
@kian99 kian99 force-pushed the permission-manager branch from dabd03c to 18f62a8 Compare January 6, 2025 12:19
@kian99 kian99 mentioned this pull request Jan 7, 2025
3 tasks
@kian99 kian99 force-pushed the permission-manager branch from d515fbb to 64db740 Compare January 7, 2025 13:51
Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

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

a few comments

internal/jimm/jujuauth/factory.go Show resolved Hide resolved
internal/jimm/permissions/permissionmanager.go Outdated Show resolved Hide resolved
internal/jimm/permissions/export_test.go Outdated Show resolved Hide resolved
internal/jimm/permissions/suite_test.go Outdated Show resolved Hide resolved
internal/jimm/permissions/access.go Outdated Show resolved Hide resolved
internal/jimm/permissions/access_test.go Outdated Show resolved Hide resolved
}

// GetUserControllerAccess returns the user's level of access to the desired controller.
func (j *permissionManager) GetUserControllerAccess(ctx context.Context, user *openfga.User, controller names.ControllerTag) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: keep all the permissionManager method implementations in permissionmanager.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean just move all the methods in access.go to permissionmanager.go? What about relations.go which contains some more methods but these ones are generic OpenFGA ones.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, i think it would be much cleaner to have all methods of a type in a single file..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's re-organise in a separate PR then, there's a couple of ways of chopping it up.

internal/jimm/permissions/permissionmanager.go Outdated Show resolved Hide resolved
alesstimec and others added 2 commits January 8, 2025 13:27
Also updated constructor from NewPermissionManager to NewManager
Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

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

LGTM.. but ptal my comment about exposing types from lower levels (openfga. dbmodel)

@@ -76,7 +76,7 @@ func (j *JIMM) CheckRelation(ctx context.Context, user *openfga.User, tuple apip

// ListRelationshipTuples checks user permission and lists relationship tuples based of tuple struct with pagination.
// Listing filters can be relaxed: optionally exclude tuple.Relation or tuple.Object or specify only tuple.TargetObject.Kind.
func (j *JIMM) ListRelationshipTuples(ctx context.Context, user *openfga.User, tuple apiparams.RelationshipTuple, pageSize int32, continuationToken string) ([]openfga.Tuple, string, error) {
func (j *permissionManager) ListRelationshipTuples(ctx context.Context, user *openfga.User, tuple apiparams.RelationshipTuple, pageSize int32, continuationToken string) ([]openfga.Tuple, string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

remembering our discussion the other day about exposing dbmodel types in manager method, this is doing something similar, but exposing the underlying openfga.Tuple type. Eventually we might want to consider decoupling..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems fair.

}

// GetUserControllerAccess returns the user's level of access to the desired controller.
func (j *permissionManager) GetUserControllerAccess(ctx context.Context, user *openfga.User, controller names.ControllerTag) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, i think it would be much cleaner to have all methods of a type in a single file..

Copy link
Contributor

@SimoneDutto SimoneDutto left a comment

Choose a reason for hiding this comment

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

lgtm, with some questions

internal/jimm/jujuauth/factory.go Outdated Show resolved Hide resolved
internal/jimm/permissions/permissionmanager.go Outdated Show resolved Hide resolved
@kian99 kian99 requested a review from SimoneDutto January 9, 2025 08:23
@kian99 kian99 merged commit 212fb31 into canonical:v3 Jan 9, 2025
4 checks passed
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