forked from goauthentik/authentik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rbac: rework API for terraform, add blueprint support (goauthentik#10698
) * rbac: rework API slightly to improve terraform compatibility Signed-off-by: Jens Langhammer <[email protected]> * sigh https://www.django-rest-framework.org/api-guide/filtering/#filtering-and-object-lookups Signed-off-by: Jens Langhammer <[email protected]> * add permission support for users global permissions Signed-off-by: Jens Langhammer <[email protected]> * add role support to blueprints Signed-off-by: Jens Langhammer <[email protected]> * fix yaml tags Signed-off-by: Jens Langhammer <[email protected]> * add generated read-only role Signed-off-by: Jens Langhammer <[email protected]> * fix web Signed-off-by: Jens Langhammer <[email protected]> * make permissions optional Signed-off-by: Jens Langhammer <[email protected]> * add docs Signed-off-by: Jens Langhammer <[email protected]> * add object permission support to blueprints Signed-off-by: Jens Langhammer <[email protected]> * fix tests kinda Signed-off-by: Jens Langhammer <[email protected]> * add more tests and fix bugs Signed-off-by: Jens Langhammer <[email protected]> --------- Signed-off-by: Jens Langhammer <[email protected]>
- Loading branch information
Showing
31 changed files
with
4,130 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: 1 | ||
entries: | ||
- model: authentik_core.user | ||
id: user | ||
identifiers: | ||
username: "%(id)s" | ||
attrs: | ||
name: "%(id)s" | ||
- model: authentik_rbac.role | ||
id: role | ||
identifiers: | ||
name: "%(id)s" | ||
- model: authentik_flows.flow | ||
identifiers: | ||
slug: "%(id)s" | ||
attrs: | ||
designation: authentication | ||
name: foo | ||
title: foo | ||
permissions: | ||
- permission: view_flow | ||
user: !KeyOf user | ||
- permission: view_flow | ||
role: !KeyOf role |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 1 | ||
entries: | ||
- model: authentik_rbac.role | ||
identifiers: | ||
name: "%(id)s" | ||
attrs: | ||
permissions: | ||
- authentik_blueprints.view_blueprintinstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 1 | ||
entries: | ||
- model: authentik_core.user | ||
identifiers: | ||
username: "%(id)s" | ||
attrs: | ||
name: "%(id)s" | ||
permissions: | ||
- authentik_blueprints.view_blueprintinstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Test blueprints v1""" | ||
|
||
from django.test import TransactionTestCase | ||
from guardian.shortcuts import get_perms | ||
|
||
from authentik.blueprints.v1.importer import Importer | ||
from authentik.core.models import User | ||
from authentik.flows.models import Flow | ||
from authentik.lib.generators import generate_id | ||
from authentik.lib.tests.utils import load_fixture | ||
from authentik.rbac.models import Role | ||
|
||
|
||
class TestBlueprintsV1RBAC(TransactionTestCase): | ||
"""Test Blueprints rbac attribute""" | ||
|
||
def test_user_permission(self): | ||
"""Test permissions""" | ||
uid = generate_id() | ||
import_yaml = load_fixture("fixtures/rbac_user.yaml", id=uid) | ||
|
||
importer = Importer.from_string(import_yaml) | ||
self.assertTrue(importer.validate()[0]) | ||
self.assertTrue(importer.apply()) | ||
user = User.objects.filter(username=uid).first() | ||
self.assertIsNotNone(user) | ||
self.assertTrue(user.has_perms(["authentik_blueprints.view_blueprintinstance"])) | ||
|
||
def test_role_permission(self): | ||
"""Test permissions""" | ||
uid = generate_id() | ||
import_yaml = load_fixture("fixtures/rbac_role.yaml", id=uid) | ||
|
||
importer = Importer.from_string(import_yaml) | ||
self.assertTrue(importer.validate()[0]) | ||
self.assertTrue(importer.apply()) | ||
role = Role.objects.filter(name=uid).first() | ||
self.assertIsNotNone(role) | ||
self.assertEqual( | ||
list(role.group.permissions.all().values_list("codename", flat=True)), | ||
["view_blueprintinstance"], | ||
) | ||
|
||
def test_object_permission(self): | ||
"""Test permissions""" | ||
uid = generate_id() | ||
import_yaml = load_fixture("fixtures/rbac_object.yaml", id=uid) | ||
|
||
importer = Importer.from_string(import_yaml) | ||
self.assertTrue(importer.validate()[0]) | ||
self.assertTrue(importer.apply()) | ||
flow = Flow.objects.filter(slug=uid).first() | ||
user = User.objects.filter(username=uid).first() | ||
role = Role.objects.filter(name=uid).first() | ||
self.assertIsNotNone(flow) | ||
self.assertEqual(get_perms(user, flow), ["view_flow"]) | ||
self.assertEqual(get_perms(role.group, flow), ["view_flow"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.