2022-08-25 10:57:55 +00:00
|
|
|
import allure
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
|
|
|
from frostfs_testlib.steps.acl import create_eacl, form_bearertoken_file, set_eacl, wait_for_cache_expired
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.acl import EACLAccess, EACLOperation, EACLRole, EACLRule
|
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
|
|
|
|
2023-02-27 16:54:27 +00:00
|
|
|
from pytest_tests.helpers.container_access import (
|
2022-09-05 12:12:56 +00:00
|
|
|
check_custom_access_to_container,
|
|
|
|
check_full_access_to_container,
|
|
|
|
check_no_access_to_container,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
from pytest_tests.testsuites.acl.conftest import Wallets
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.acl
|
|
|
|
@pytest.mark.acl_bearer
|
2022-12-05 22:31:45 +00:00
|
|
|
class TestACLBearer(ClusterTestBase):
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Operations with BearerToken (role={role.value}, obj_size={object_size})")
|
2022-09-05 12:12:56 +00:00
|
|
|
@pytest.mark.parametrize("role", [EACLRole.USER, EACLRole.OTHERS])
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_bearer_token_operations(
|
|
|
|
self,
|
|
|
|
wallets: Wallets,
|
|
|
|
eacl_container_with_objects: tuple[str, list[str], str],
|
|
|
|
role: EACLRole,
|
|
|
|
):
|
2022-08-25 10:57:55 +00:00
|
|
|
cid, objects_oids, file_path = eacl_container_with_objects
|
|
|
|
user_wallet = wallets.get_wallet()
|
|
|
|
deny_wallet = wallets.get_wallet(role)
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint = self.cluster.default_rpc_endpoint
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Check {role.value} has full access to container without bearer token"):
|
2022-09-05 12:12:56 +00:00
|
|
|
check_full_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
deny_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Set deny all operations for {role.value} via eACL"):
|
|
|
|
eacl = [EACLRule(access=EACLAccess.DENY, role=role, operation=op) for op in EACLOperation]
|
2022-12-05 22:31:45 +00:00
|
|
|
eacl_file = create_eacl(cid, eacl, shell=self.shell)
|
2024-03-11 16:34:54 +00:00
|
|
|
set_eacl(user_wallet, cid, eacl_file, shell=self.shell, endpoint=endpoint)
|
2022-08-25 10:57:55 +00:00
|
|
|
wait_for_cache_expired()
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Create bearer token for {role.value} with all operations allowed"):
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer = form_bearertoken_file(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
2023-11-29 13:34:59 +00:00
|
|
|
[EACLRule(operation=op, access=EACLAccess.ALLOW, role=role) for op in EACLOperation],
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Check {role.value} without token has no access to all operations with container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
check_no_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
deny_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Check {role.value} with token has access to all operations with container"):
|
2022-09-05 12:12:56 +00:00
|
|
|
check_full_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
deny_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Set allow all operations for {role.value} via eACL"):
|
|
|
|
eacl = [EACLRule(access=EACLAccess.ALLOW, role=role, operation=op) for op in EACLOperation]
|
2022-12-05 22:31:45 +00:00
|
|
|
eacl_file = create_eacl(cid, eacl, shell=self.shell)
|
2024-03-11 16:34:54 +00:00
|
|
|
set_eacl(user_wallet, cid, eacl_file, shell=self.shell, endpoint=endpoint)
|
2022-08-25 10:57:55 +00:00
|
|
|
wait_for_cache_expired()
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Check {role.value} without token has access to all operations with container"):
|
2022-09-05 12:12:56 +00:00
|
|
|
check_full_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
deny_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("BearerToken for compound operations (obj_size={object_size})")
|
2024-03-11 16:34:54 +00:00
|
|
|
def test_bearer_token_compound_operations(self, wallets: Wallets, eacl_container_with_objects):
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint = self.cluster.default_rpc_endpoint
|
2022-08-25 10:57:55 +00:00
|
|
|
cid, objects_oids, file_path = eacl_container_with_objects
|
|
|
|
user_wallet = wallets.get_wallet()
|
|
|
|
other_wallet = wallets.get_wallet(role=EACLRole.OTHERS)
|
|
|
|
|
|
|
|
# Operations that we will deny for each role via eACL
|
|
|
|
deny_map = {
|
|
|
|
EACLRole.USER: [EACLOperation.DELETE],
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.OTHERS: [
|
|
|
|
EACLOperation.SEARCH,
|
|
|
|
EACLOperation.GET_RANGE_HASH,
|
|
|
|
EACLOperation.GET_RANGE,
|
|
|
|
],
|
2022-08-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Operations that we will allow for each role with bearer token
|
|
|
|
bearer_map = {
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.USER: [
|
|
|
|
EACLOperation.DELETE,
|
|
|
|
EACLOperation.PUT,
|
|
|
|
EACLOperation.GET_RANGE,
|
|
|
|
],
|
|
|
|
EACLRole.OTHERS: [
|
|
|
|
EACLOperation.GET,
|
|
|
|
EACLOperation.GET_RANGE,
|
|
|
|
EACLOperation.GET_RANGE_HASH,
|
|
|
|
],
|
2022-08-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deny_map_with_bearer = {
|
2023-11-29 13:34:59 +00:00
|
|
|
EACLRole.USER: [op for op in deny_map[EACLRole.USER] if op not in bearer_map[EACLRole.USER]],
|
|
|
|
EACLRole.OTHERS: [op for op in deny_map[EACLRole.OTHERS] if op not in bearer_map[EACLRole.OTHERS]],
|
2022-08-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eacl_deny = []
|
|
|
|
for role, operations in deny_map.items():
|
2023-11-29 13:34:59 +00:00
|
|
|
eacl_deny += [EACLRule(access=EACLAccess.DENY, role=role, operation=op) for op in operations]
|
2022-10-13 18:53:44 +00:00
|
|
|
set_eacl(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-10-13 18:53:44 +00:00
|
|
|
cid,
|
2022-12-05 22:31:45 +00:00
|
|
|
eacl_table_path=create_eacl(cid, eacl_deny, shell=self.shell),
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=endpoint,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
wait_for_cache_expired()
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check rule consistency without bearer"):
|
2022-09-05 12:12:56 +00:00
|
|
|
check_custom_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map[EACLRole.USER],
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
check_custom_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
other_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map[EACLRole.OTHERS],
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check rule consistency using bearer token"):
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer_user = form_bearertoken_file(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
[
|
|
|
|
EACLRule(operation=op, access=EACLAccess.ALLOW, role=EACLRole.USER)
|
|
|
|
for op in bearer_map[EACLRole.USER]
|
|
|
|
],
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer_other = form_bearertoken_file(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
[
|
2022-09-28 12:07:16 +00:00
|
|
|
EACLRule(operation=op, access=EACLAccess.ALLOW, role=EACLRole.OTHERS)
|
2022-09-05 12:12:56 +00:00
|
|
|
for op in bearer_map[EACLRole.OTHERS]
|
|
|
|
],
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check_custom_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map_with_bearer[EACLRole.USER],
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer_user,
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
check_custom_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
other_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map_with_bearer[EACLRole.OTHERS],
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer_other,
|
2022-12-05 22:31:45 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|