-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1411 from weaviate/rbac_adapt_actions
Move *_collection actions to Collection
- Loading branch information
Showing
5 changed files
with
149 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,9 @@ services: | |
environment: | ||
ENABLE_MODULES: "generative-dummy,reranker-dummy" | ||
AUTHENTICATION_APIKEY_ENABLED: "true" | ||
AUTHENTICATION_APIKEY_ALLOWED_KEYS: "jane-secret-key,ian-secret-key,jp-secret-key" | ||
AUTHENTICATION_APIKEY_USERS: "[email protected],ian-smith,jp-hwang" | ||
AUTHENTICATION_APIKEY_ROLES: "viewer,editor,admin" | ||
AUTHENTICATION_APIKEY_ALLOWED_KEYS: "existing-key" | ||
AUTHENTICATION_APIKEY_USERS: "existing-user" | ||
AUTHENTICATION_APIKEY_ROLES: "admin" | ||
PERSISTENCE_DATA_PATH: "./data-weaviate-0" | ||
CLUSTER_IN_LOCALHOST: "true" | ||
CLUSTER_GOSSIP_BIND_PORT: "7100" | ||
|
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 |
---|---|---|
@@ -1,22 +1,71 @@ | ||
import pytest | ||
|
||
from integration.conftest import ClientFactory | ||
from weaviate.auth import Auth | ||
from weaviate.rbac.models import RBAC | ||
from weaviate.rbac.models import ( | ||
RBAC, | ||
Role, | ||
CollectionsPermission, | ||
RolesPermission, | ||
TenantsPermission, | ||
) | ||
|
||
|
||
RBAC_PORTS = (8092, 50063) | ||
RBAC_AUTH_CREDS = Auth.api_key("existing-key") | ||
|
||
|
||
def test_create_role(client_factory: ClientFactory) -> None: | ||
with client_factory( | ||
ports=(8092, 50063), auth_credentials=Auth.api_key("jp-secret-key") | ||
) as client: | ||
@pytest.mark.parametrize( | ||
"permissions,expected", | ||
[ | ||
( | ||
RBAC.permissions.collections(actions=RBAC.actions.collection.CREATE), | ||
Role( | ||
name="CreateAllCollections", | ||
cluster_actions=None, | ||
collections_permissions=[ | ||
CollectionsPermission(collection="*", action=RBAC.actions.collection.CREATE) | ||
], | ||
roles_permissions=None, | ||
tenants_permissions=None, | ||
), | ||
), | ||
( | ||
RBAC.permissions.roles(actions=RBAC.actions.roles.MANAGE), | ||
Role( | ||
name="ManageAllRoles", | ||
cluster_actions=None, | ||
collections_permissions=None, | ||
roles_permissions=[RolesPermission(role="*", action=RBAC.actions.roles.MANAGE)], | ||
tenants_permissions=None, | ||
), | ||
), | ||
( | ||
RBAC.permissions.tenants(collection="foo", actions=RBAC.actions.tenants.READ), | ||
Role( | ||
name="ReadAllTenantsInFoo", | ||
cluster_actions=None, | ||
collections_permissions=None, | ||
roles_permissions=None, | ||
tenants_permissions=[ | ||
TenantsPermission( | ||
collection="foo", tenant="*", action=RBAC.actions.tenants.READ | ||
) | ||
], | ||
), | ||
), | ||
], | ||
) | ||
def test_create_role(client_factory: ClientFactory, permissions, expected) -> None: | ||
with client_factory(ports=RBAC_PORTS, auth_credentials=RBAC_AUTH_CREDS) as client: | ||
if client._connection._weaviate_version.is_lower_than(1, 28, 0): | ||
pytest.skip("This test requires Weaviate 1.28.0 or higher") | ||
client.roles.create( | ||
name="CollectionCreator", | ||
permissions=RBAC.permissions.database(actions=RBAC.actions.database.CREATE_COLLECTIONS), | ||
) | ||
role = client.roles.by_name("CollectionCreator") | ||
assert role is not None | ||
assert role.name == "CollectionCreator" | ||
assert role.database_permissions is not None | ||
assert len(role.database_permissions) == 1 | ||
assert role.database_permissions[0] == RBAC.actions.database.CREATE_COLLECTIONS | ||
try: | ||
client.roles.create( | ||
name=expected.name, | ||
permissions=permissions, | ||
) | ||
role = client.roles.by_name(expected.name) | ||
assert role == expected | ||
finally: | ||
client.roles.delete(expected.name) |
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