2024-07-17 20:56:05 +00:00
|
|
|
import allure
|
|
|
|
import pytest
|
|
|
|
from frostfs_testlib import reporter
|
|
|
|
from frostfs_testlib.cli.frostfs_cli.cli import FrostfsCli
|
|
|
|
from frostfs_testlib.storage.dataclasses import ape
|
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
2024-09-02 16:22:59 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import TestFile
|
2024-07-17 20:56:05 +00:00
|
|
|
|
2024-10-29 10:32:07 +00:00
|
|
|
from ....helpers.bearer_token import create_bearer_token
|
|
|
|
from ....helpers.container_access import (
|
2024-07-17 20:56:05 +00:00
|
|
|
ALL_OBJECT_OPERATIONS,
|
|
|
|
assert_access_to_container,
|
|
|
|
assert_full_access_to_container,
|
|
|
|
assert_no_access_to_container,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-10-11 09:30:23 +00:00
|
|
|
@pytest.mark.nightly
|
2024-07-17 20:56:05 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.bearer
|
|
|
|
@pytest.mark.ape
|
|
|
|
class TestApeBearer(ClusterTestBase):
|
|
|
|
@allure.title("Operations with BearerToken (role={role}, obj_size={object_size})")
|
|
|
|
@pytest.mark.parametrize("role", [ape.Role.OWNER, ape.Role.OTHERS], indirect=True)
|
|
|
|
def test_bearer_token_operations(
|
|
|
|
self,
|
2024-09-02 16:22:59 +00:00
|
|
|
container: str,
|
|
|
|
objects: list[str],
|
2024-07-17 20:56:05 +00:00
|
|
|
frostfs_cli: FrostfsCli,
|
|
|
|
temp_directory: str,
|
|
|
|
test_wallet: WalletInfo,
|
|
|
|
role: ape.Role,
|
2024-09-02 16:22:59 +00:00
|
|
|
file_path: TestFile,
|
|
|
|
rpc_endpoint: str,
|
2024-07-17 20:56:05 +00:00
|
|
|
):
|
|
|
|
with reporter.step(f"Check {role} has full access to container without bearer token"):
|
2024-09-02 16:22:59 +00:00
|
|
|
assert_full_access_to_container(test_wallet, container, objects.pop(), file_path, self.shell, self.cluster)
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
with reporter.step(f"Deny all operations for everyone via APE"):
|
|
|
|
rule = ape.Rule(ape.Verb.DENY, ALL_OBJECT_OPERATIONS)
|
2024-09-02 16:22:59 +00:00
|
|
|
frostfs_cli.ape_manager.add(rpc_endpoint, rule.chain_id, target_name=container, target_type="container", rule=rule.as_string())
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
with reporter.step("Wait for one block"):
|
|
|
|
self.wait_for_blocks()
|
|
|
|
|
|
|
|
with reporter.step(f"Create bearer token with all operations allowed"):
|
|
|
|
bearer = create_bearer_token(
|
|
|
|
frostfs_cli,
|
|
|
|
temp_directory,
|
2024-09-02 16:22:59 +00:00
|
|
|
container,
|
2024-07-17 20:56:05 +00:00
|
|
|
rule=ape.Rule(ape.Verb.ALLOW, ALL_OBJECT_OPERATIONS),
|
2024-09-02 16:22:59 +00:00
|
|
|
endpoint=rpc_endpoint,
|
2024-07-17 20:56:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with reporter.step(f"Check {role} without token has no access to all operations with container"):
|
2024-09-02 16:22:59 +00:00
|
|
|
assert_no_access_to_container(test_wallet, container, objects.pop(), file_path, self.shell, self.cluster)
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
with reporter.step(f"Check {role} with token has access to all operations with container"):
|
2024-09-02 16:22:59 +00:00
|
|
|
assert_full_access_to_container(test_wallet, container, objects.pop(), file_path, self.shell, self.cluster, bearer)
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
with reporter.step(f"Remove deny rule from APE"):
|
2024-09-02 16:22:59 +00:00
|
|
|
frostfs_cli.ape_manager.remove(rpc_endpoint, rule.chain_id, target_name=container, target_type="container")
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
with reporter.step("Wait for one block"):
|
|
|
|
self.wait_for_blocks()
|
|
|
|
|
|
|
|
with reporter.step(f"Check {role} without token has access to all operations with container"):
|
2024-09-02 16:22:59 +00:00
|
|
|
assert_full_access_to_container(test_wallet, container, objects.pop(), file_path, self.shell, self.cluster)
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
@allure.title("BearerToken for compound operations (obj_size={object_size})")
|
|
|
|
def test_bearer_token_compound_operations(
|
|
|
|
self,
|
|
|
|
frostfs_cli: FrostfsCli,
|
|
|
|
temp_directory: str,
|
|
|
|
default_wallet: WalletInfo,
|
|
|
|
other_wallet: WalletInfo,
|
2024-11-16 11:33:56 +00:00
|
|
|
container: str,
|
2024-09-02 16:22:59 +00:00
|
|
|
objects: list[str],
|
|
|
|
rpc_endpoint: str,
|
|
|
|
file_path: TestFile,
|
2024-07-17 20:56:05 +00:00
|
|
|
):
|
|
|
|
"""
|
|
|
|
Bearer Token COMPLETLY overrides chains set for the specific target.
|
|
|
|
Thus, any restictions or permissions should be explicitly defined in BT.
|
|
|
|
"""
|
|
|
|
|
|
|
|
wallets_map = {
|
|
|
|
ape.Role.OWNER: default_wallet,
|
|
|
|
ape.Role.OTHERS: other_wallet,
|
|
|
|
}
|
|
|
|
|
|
|
|
access_map = {
|
|
|
|
ape.Role.OWNER: {
|
|
|
|
ape.ObjectOperations.PUT: True,
|
|
|
|
ape.ObjectOperations.GET: True,
|
|
|
|
ape.ObjectOperations.HEAD: True,
|
|
|
|
ape.ObjectOperations.GET_RANGE: True,
|
|
|
|
ape.ObjectOperations.GET_RANGE_HASH: True,
|
|
|
|
ape.ObjectOperations.SEARCH: True,
|
|
|
|
ape.ObjectOperations.DELETE: False,
|
|
|
|
},
|
|
|
|
ape.Role.OTHERS: {
|
|
|
|
ape.ObjectOperations.PUT: True,
|
|
|
|
ape.ObjectOperations.GET: True,
|
|
|
|
ape.ObjectOperations.HEAD: True,
|
|
|
|
ape.ObjectOperations.GET_RANGE: False,
|
|
|
|
ape.ObjectOperations.GET_RANGE_HASH: False,
|
|
|
|
ape.ObjectOperations.SEARCH: False,
|
|
|
|
ape.ObjectOperations.DELETE: True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_access_map = {
|
|
|
|
ape.Role.OWNER: {
|
|
|
|
ape.ObjectOperations.PUT: True,
|
2024-11-16 11:33:56 +00:00
|
|
|
ape.ObjectOperations.GET: False,
|
2024-07-17 20:56:05 +00:00
|
|
|
ape.ObjectOperations.HEAD: True,
|
|
|
|
ape.ObjectOperations.GET_RANGE: True,
|
2024-11-16 11:33:56 +00:00
|
|
|
ape.ObjectOperations.GET_RANGE_HASH: False,
|
|
|
|
ape.ObjectOperations.SEARCH: False,
|
2024-07-17 20:56:05 +00:00
|
|
|
ape.ObjectOperations.DELETE: True,
|
|
|
|
},
|
2024-11-16 11:33:56 +00:00
|
|
|
# Bearer Token COMPLETLY overrides chains set for the specific target.
|
|
|
|
# Thus, any restictions or permissions should be explicitly defined in BT.
|
2024-07-17 20:56:05 +00:00
|
|
|
ape.Role.OTHERS: {
|
2024-11-16 11:33:56 +00:00
|
|
|
ape.ObjectOperations.PUT: False,
|
2024-07-17 20:56:05 +00:00
|
|
|
ape.ObjectOperations.GET: False,
|
2024-11-16 11:33:56 +00:00
|
|
|
ape.ObjectOperations.HEAD: False,
|
2024-07-17 20:56:05 +00:00
|
|
|
ape.ObjectOperations.GET_RANGE: False,
|
|
|
|
ape.ObjectOperations.GET_RANGE_HASH: False,
|
2024-11-16 11:33:56 +00:00
|
|
|
ape.ObjectOperations.SEARCH: False,
|
|
|
|
ape.ObjectOperations.DELETE: False,
|
2024-07-17 20:56:05 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# Operations that we will deny for each role via APE
|
|
|
|
deny_map = {
|
|
|
|
ape.Role.OWNER: [ape.ObjectOperations.DELETE],
|
|
|
|
ape.Role.OTHERS: [
|
|
|
|
ape.ObjectOperations.SEARCH,
|
|
|
|
ape.ObjectOperations.GET_RANGE_HASH,
|
|
|
|
ape.ObjectOperations.GET_RANGE,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
# Operations that we will allow for each role with bearer token
|
|
|
|
bearer_map = {
|
|
|
|
ape.Role.OWNER: [
|
|
|
|
ape.ObjectOperations.PUT,
|
2024-11-16 11:33:56 +00:00
|
|
|
ape.ObjectOperations.HEAD,
|
2024-07-17 20:56:05 +00:00
|
|
|
ape.ObjectOperations.GET_RANGE,
|
2024-11-16 11:33:56 +00:00
|
|
|
# Delete also requires PUT (to make tobstone) and HEAD (to get simple objects header)
|
|
|
|
ape.ObjectOperations.DELETE,
|
2024-07-17 20:56:05 +00:00
|
|
|
],
|
|
|
|
ape.Role.OTHERS: [
|
|
|
|
ape.ObjectOperations.GET,
|
|
|
|
ape.ObjectOperations.GET_RANGE,
|
|
|
|
ape.ObjectOperations.GET_RANGE_HASH,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
conditions_map = {
|
|
|
|
ape.Role.OWNER: ape.Condition.by_role(ape.Role.OWNER),
|
|
|
|
ape.Role.OTHERS: ape.Condition.by_role(ape.Role.OTHERS),
|
|
|
|
}
|
|
|
|
|
|
|
|
verb_map = {ape.Role.OWNER: ape.Verb.ALLOW, ape.Role.OTHERS: ape.Verb.DENY}
|
|
|
|
|
|
|
|
for role, operations in deny_map.items():
|
|
|
|
with reporter.step(f"Add APE deny rule for {role}"):
|
|
|
|
rule = ape.Rule(ape.Verb.DENY, operations, conditions_map[role])
|
2024-09-02 16:22:59 +00:00
|
|
|
frostfs_cli.ape_manager.add(
|
|
|
|
rpc_endpoint, rule.chain_id, target_name=container, target_type="container", rule=rule.as_string()
|
|
|
|
)
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
with reporter.step("Wait for one block"):
|
|
|
|
self.wait_for_blocks()
|
|
|
|
|
|
|
|
for role, wallet in wallets_map.items():
|
|
|
|
with reporter.step(f"Assert access to container without bearer token for {role}"):
|
2024-09-02 16:22:59 +00:00
|
|
|
assert_access_to_container(access_map[role], wallet, container, objects.pop(), file_path, self.shell, self.cluster)
|
2024-07-17 20:56:05 +00:00
|
|
|
|
|
|
|
bearer_tokens = {}
|
|
|
|
for role in wallets_map.keys():
|
|
|
|
with reporter.step(f"Create bearer token for {role}"):
|
|
|
|
rule = ape.Rule(verb_map[role], bearer_map[role], conditions_map[role])
|
2024-09-02 16:22:59 +00:00
|
|
|
bt = create_bearer_token(frostfs_cli, temp_directory, container, rule, rpc_endpoint)
|
2024-07-17 20:56:05 +00:00
|
|
|
bearer_tokens[role] = bt
|
|
|
|
|
|
|
|
for role, wallet in wallets_map.items():
|
|
|
|
with reporter.step(f"Assert access to container with bearer token for {role}"):
|
|
|
|
assert_access_to_container(
|
2024-09-02 16:22:59 +00:00
|
|
|
bt_access_map[role], wallet, container, objects.pop(), file_path, self.shell, self.cluster, bearer_tokens[role]
|
2024-07-17 20:56:05 +00:00
|
|
|
)
|