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

CSS-9389 Implement the EntitlementsService interface #1277

Merged

Conversation

SimoneDutto
Copy link
Contributor

Description

Add entitlements Api.
Atm it is done via a static variables declaration.

Fixes JIRA/GitHub issue number

Engineering checklist

Check only items that apply

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

Test instructions

Notes for code reviewers

@SimoneDutto SimoneDutto requested a review from a team as a code owner July 22, 2024 12:01
Copy link

⚠️ This PR contains unsigned commits. To get your PR merged, please sign those commits (git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch (git push --force-with-lease).

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.

Learn how to use 1Password to sign your commits.

Watch the demo

@SimoneDutto SimoneDutto force-pushed the add-entitlements-api branch from 7cac0d2 to 02c5b4c Compare July 22, 2024 12:12
Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

lgtm

internal/rebac_admin/entitlements.go Outdated Show resolved Hide resolved
internal/rebac_admin/entitlements.go Show resolved Hide resolved
internal/rebac_admin/entitlements.go Show resolved Hide resolved
internal/rebac_admin/static_entitlements.go Outdated Show resolved Hide resolved
internal/rebac_admin/static_entitlements.go Outdated Show resolved Hide resolved
@SimoneDutto SimoneDutto force-pushed the add-entitlements-api branch from 02c5b4c to c297be2 Compare July 22, 2024 12:22
@SimoneDutto SimoneDutto changed the title add entitlements api to rebac endpoint CSS-9389 Implement the EntitlementsService interface Jul 22, 2024
@SimoneDutto SimoneDutto force-pushed the add-entitlements-api branch from 59d1790 to a85d537 Compare July 22, 2024 12:39
internal/rebac_admin/static_entitlements.go Outdated Show resolved Hide resolved
openfga/auth_model.go Outdated Show resolved Hide resolved
service_test.go Outdated
@@ -293,6 +293,32 @@ func TestRebacAdminApi(t *testing.T) {
c.Assert(response.StatusCode, qt.Equals, 200)
}

func TestRebacEntitlementsApi(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be adding this test in here, otherwise we might start to test all our HTTP endpoints in here which is probably not what we want.
@ale8k @babakks @alesstimec What do you guys think about this?
In other packages like internal/jimmjwx/ we create a JIMM service by calling jimm.NewService. Should service layer tests exist here (in service_test.go) or in the package internal/rebac_admin?

Copy link
Member

Choose a reason for hiding this comment

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

@SimoneDutto Yeah, please remove this test.

@kian99 I agree. We already have a test for ReBAC Admin API in service_test.go but that's just for the sake of composition and to make sure we're correctly enabling the API.

Other endpoints should be tested inside the rebac_admin package. Also, I think we shouldn't test against the HTTP endpoints (i.e., calling /entitlements directly) because that's the responsibility of the rebac-admin-ui-handlers library (and we should know as little as possible about the HTTP API endpoints in JIMM). So, we can safely assume the library works as expected.

Generally, in the rebac_admin package tests we should just call the methods (like EntitlementsService.RawEntitlements) directly and assert the returned value against an expected value. However, in our static implementation of EntitlementsService interface, I don't see a point of having tests only to assert against a the same static values.

Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

Thanks for this. Just a few comments.

{EntitlementType: "writer", EntityName: "user", EntityType: "model"},
{EntitlementType: "writer", EntityName: "user:*", EntityType: "model"},
{EntitlementType: "writer", EntityName: "group#member", EntityType: "model"},
{EntitlementType: "controller", EntityName: "controller", EntityType: "model"},
Copy link
Member

@babakks babakks Jul 22, 2024

Choose a reason for hiding this comment

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

This should be removed. Generally, let's remove all entitlements that has a receiver other than user, user:*, or group#member.

{EntitlementType: "can_addmodel", EntityName: "user", EntityType: "cloud"},
{EntitlementType: "can_addmodel", EntityName: "user:*", EntityType: "cloud"},
{EntitlementType: "can_addmodel", EntityName: "group#member", EntityType: "cloud"},
{EntitlementType: "controller", EntityName: "controller", EntityType: "cloud"},
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed.

{EntitlementType: "reader", EntityName: "user", EntityType: "applicationoffer"},
{EntitlementType: "reader", EntityName: "user:*", EntityType: "applicationoffer"},
{EntitlementType: "reader", EntityName: "group#member", EntityType: "applicationoffer"},
{EntitlementType: "model", EntityName: "model", EntityType: "applicationoffer"},
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed.

service_test.go Outdated
@@ -293,6 +293,32 @@ func TestRebacAdminApi(t *testing.T) {
c.Assert(response.StatusCode, qt.Equals, 200)
}

func TestRebacEntitlementsApi(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

@SimoneDutto Yeah, please remove this test.

@kian99 I agree. We already have a test for ReBAC Admin API in service_test.go but that's just for the sake of composition and to make sure we're correctly enabling the API.

Other endpoints should be tested inside the rebac_admin package. Also, I think we shouldn't test against the HTTP endpoints (i.e., calling /entitlements directly) because that's the responsibility of the rebac-admin-ui-handlers library (and we should know as little as possible about the HTTP API endpoints in JIMM). So, we can safely assume the library works as expected.

Generally, in the rebac_admin package tests we should just call the methods (like EntitlementsService.RawEntitlements) directly and assert the returned value against an expected value. However, in our static implementation of EntitlementsService interface, I don't see a point of having tests only to assert against a the same static values.


import "github.com/canonical/rebac-admin-ui-handlers/v1/resources"

// For rebac v1 this list is kept manually.
Copy link
Member

Choose a reason for hiding this comment

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

To make things simpler I'd move this static slice to the entitlements.go file.

@SimoneDutto SimoneDutto merged commit ddd14ae into canonical:feature-rebac-admin Jul 22, 2024
4 checks passed
@SimoneDutto SimoneDutto deleted the add-entitlements-api branch July 22, 2024 14:08
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