Skip to content

Commit 8cbfd3f

Browse files
committed
add test for assume role (with fake STS)
1 parent ae9123a commit 8cbfd3f

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

tests/integration/test_s3_assume_role/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
3+
from bottle import response, route, run
4+
5+
6+
MOCK_XML_RESPONSE = """<AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
7+
<AssumeRoleResult>
8+
<Credentials>
9+
<AccessKeyId>minio</AccessKeyId>
10+
<SecretAccessKey>ClickHouse_Minio_P@ssw0rd</SecretAccessKey>
11+
<Expiration>2055-12-31T23:59:59Z</Expiration>
12+
</Credentials>
13+
</AssumeRoleResult>
14+
</AssumeRoleResponse>"""
15+
16+
# <SessionToken>MOCK_SESSION_TOKEN</SessionToken> is not being returned -- it is not required by minio
17+
# When "real" STS returns it -- it is also used to read from s3
18+
19+
@route("/", method="POST")
20+
def return_creds():
21+
response.status = 200
22+
response.content_type = "application/xml"
23+
return MOCK_XML_RESPONSE
24+
25+
26+
@route("/", method="GET")
27+
def ping():
28+
return "OK"
29+
30+
31+
run(host="0.0.0.0", port=int(sys.argv[1]))
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)