|
| 1 | +import logging |
| 2 | +import os |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from helpers.cluster import ClickHouseCluster |
| 7 | +from helpers.mock_servers import start_mock_servers |
| 8 | + |
| 9 | +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 10 | + |
| 11 | + |
| 12 | +def run_sts_mock(started_cluster): |
| 13 | + script_dir = os.path.join(os.path.dirname(__file__), "mocks") |
| 14 | + start_mock_servers( |
| 15 | + started_cluster, |
| 16 | + script_dir, |
| 17 | + [ |
| 18 | + ("mock_sts.py", "resolver", "8081"), |
| 19 | + ], |
| 20 | + ) |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture(scope="module") |
| 24 | +def started_cluster(): |
| 25 | + cluster = ClickHouseCluster(__file__) |
| 26 | + try: |
| 27 | + cluster.add_instance( |
| 28 | + "node1", |
| 29 | + with_minio=True, |
| 30 | + ) |
| 31 | + |
| 32 | + logging.info("Starting cluster...") |
| 33 | + cluster.start() |
| 34 | + |
| 35 | + run_sts_mock(cluster) |
| 36 | + yield cluster |
| 37 | + |
| 38 | + finally: |
| 39 | + cluster.shutdown() |
| 40 | + |
| 41 | + |
| 42 | +def test_using_assumed_creds(started_cluster): |
| 43 | + instance = started_cluster.instances["node1"] |
| 44 | + |
| 45 | + # Create some file in non public-accessible minio |
| 46 | + instance.query( |
| 47 | + """ |
| 48 | + INSERT INTO FUNCTION s3 |
| 49 | + ( |
| 50 | + 'http://minio1:9001/root/test_assume.csv', 'minio', 'ClickHouse_Minio_P@ssw0rd', 'CSVWithNames' |
| 51 | + ) |
| 52 | + SELECT number as num, toString(number) as strnum FROM numbers(5); |
| 53 | + """ |
| 54 | + ) |
| 55 | + |
| 56 | + # Read them using credentials received from our fake STS |
| 57 | + r = instance.query( |
| 58 | + """ |
| 59 | + SELECT count() FROM s3 |
| 60 | + ('http://minio1:9001/root/test_assume.csv', |
| 61 | + SOME_FAKE_ID, SOME_FAKE_SECRET, 'CSVWithNames', |
| 62 | + extra_credentials( |
| 63 | + role_arn = 'arn:aws:iam::111111111111:role/BucketAccessRole-001', |
| 64 | + sts_endpoint_override = 'http://resolver:8081' |
| 65 | + ) |
| 66 | + ) |
| 67 | + """ |
| 68 | + ) |
| 69 | + |
| 70 | + assert r == "5\n" |
| 71 | + |
| 72 | + |
0 commit comments