Skip to content

Commit f6b0bcb

Browse files
authored
Set up polaris permissions for credentials access + cleanup (#40)
* Cleanup - no need for setup-all.sh. All is done in create-tables.py now. If we want we can have separate scripts, but Python feels more suitable than bash, and already had catalog creation in there (bash had a bug and wasn't actually creating the catalog). * Add TABLE_READ_DATA priviliege to catalog admin, which is needed for fetching credentials and reading tables. Also TABLE_WRITE_DATA just in case.
1 parent 7eec9a7 commit f6b0bcb

File tree

4 files changed

+93
-122
lines changed

4 files changed

+93
-122
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
cargo build --release
5555
5656
- name: Start Iceberg catalog and S3 storage with Docker Compose
57-
run: docker compose -f ${{ github.workspace }}/docker/docker-compose.yml up -d minio setup_bucket polaris polaris-setup init table-creation
57+
run: docker compose -f ${{ github.workspace }}/docker/docker-compose.yml up -d minio setup_bucket polaris init table-creation
5858

5959
- name: Wait for table-creation container to complete
6060
run: |

docker/assets/polaris/setup-all.sh

Lines changed: 0 additions & 96 deletions
This file was deleted.

docker/docker-compose.yml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,37 +86,15 @@ services:
8686
working_dir: /app
8787
command: sh -c "pip install --no-cache-dir boto3 requests && python3 init-datasets.py"
8888

89-
polaris-setup:
90-
image: alpine/curl:latest
91-
container_name: polaris-setup
92-
depends_on:
93-
polaris:
94-
condition: service_healthy
95-
init:
96-
condition: service_completed_successfully
97-
networks:
98-
iceberg_net:
99-
environment:
100-
- CLIENT_ID=root
101-
- CLIENT_SECRET=s3cr3t
102-
volumes:
103-
- ./assets/polaris:/polaris
104-
entrypoint: /bin/sh
105-
command:
106-
- -c
107-
- >-
108-
echo 'Setting up Polaris catalog...' &&
109-
chmod +x /polaris/setup-all.sh &&
110-
/polaris/setup-all.sh POLARIS &&
111-
echo 'Polaris setup complete!'
112-
11389
table-creation:
11490
image: python:3.11-slim
11591
container_name: table-creation
11692
networks:
11793
iceberg_net:
11894
depends_on:
119-
polaris-setup:
95+
polaris:
96+
condition: service_healthy
97+
init:
12098
condition: service_completed_successfully
12199
volumes:
122100
- ./scripts/create-tables.py:/app/create-tables.py

docker/scripts/create-tables.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,90 @@ def ensure_catalog_exists(token):
171171
return False
172172

173173

174+
def grant_catalog_permissions(token):
175+
"""Grant TABLE_READ_DATA and TABLE_WRITE_DATA privileges to catalog_admin role."""
176+
print(f"\nGranting data access privileges to catalog_admin role...")
177+
178+
try:
179+
# Grant TABLE_READ_DATA
180+
read_grant = {
181+
"grant": {
182+
"type": "catalog",
183+
"privilege": "TABLE_READ_DATA"
184+
}
185+
}
186+
187+
print(" Granting TABLE_READ_DATA...")
188+
response = requests.put(
189+
f'{POLARIS_API}/catalogs/{CATALOG_NAME}/catalog-roles/catalog_admin/grants',
190+
headers={
191+
'Authorization': f'Bearer {token}',
192+
'Content-Type': 'application/json',
193+
'Polaris-Realm': 'POLARIS'
194+
},
195+
json=read_grant,
196+
timeout=10
197+
)
198+
199+
if response.status_code in [200, 201]:
200+
print(f" ✓ TABLE_READ_DATA privilege granted")
201+
else:
202+
print(f" Warning: TABLE_READ_DATA grant returned status {response.status_code}")
203+
print(f" Response: {response.text}")
204+
205+
# Grant TABLE_WRITE_DATA
206+
write_grant = {
207+
"grant": {
208+
"type": "catalog",
209+
"privilege": "TABLE_WRITE_DATA"
210+
}
211+
}
212+
213+
print(" Granting TABLE_WRITE_DATA...")
214+
response = requests.put(
215+
f'{POLARIS_API}/catalogs/{CATALOG_NAME}/catalog-roles/catalog_admin/grants',
216+
headers={
217+
'Authorization': f'Bearer {token}',
218+
'Content-Type': 'application/json',
219+
'Polaris-Realm': 'POLARIS'
220+
},
221+
json=write_grant,
222+
timeout=10
223+
)
224+
225+
if response.status_code in [200, 201]:
226+
print(f" ✓ TABLE_WRITE_DATA privilege granted")
227+
else:
228+
print(f" Warning: TABLE_WRITE_DATA grant returned status {response.status_code}")
229+
print(f" Response: {response.text}")
230+
231+
# Verify grants were applied
232+
print("\n Verifying grants...")
233+
response = requests.get(
234+
f'{POLARIS_API}/catalogs/{CATALOG_NAME}/catalog-roles/catalog_admin/grants',
235+
headers={
236+
'Authorization': f'Bearer {token}',
237+
'Polaris-Realm': 'POLARIS'
238+
},
239+
timeout=10
240+
)
241+
242+
if response.status_code == 200:
243+
grants = response.json().get('grants', [])
244+
print(" Current grants for catalog_admin:")
245+
for grant in grants:
246+
print(f" - {grant.get('type')}: {grant.get('privilege')}")
247+
else:
248+
print(f" Could not verify grants (status {response.status_code})")
249+
250+
return True
251+
252+
except Exception as e:
253+
print(f"ERROR: Failed to grant permissions: {e}")
254+
traceback.print_exc()
255+
return False
256+
257+
174258
def create_namespace(token, namespace, max_retries=5):
175259
"""Create a namespace if it doesn't exist.
176260
namespace should be a string, which can contain dots (e.g., 'tpch.sf01').
@@ -352,6 +436,11 @@ def main():
352436
print("ERROR: Failed to ensure catalog exists")
353437
sys.exit(1)
354438

439+
# Grant permissions to catalog_admin role
440+
if not grant_catalog_permissions(token):
441+
print("ERROR: Failed to grant catalog permissions")
442+
sys.exit(1)
443+
355444
# Create namespaces
356445
print("\n" + "=" * 60)
357446
print("Creating namespaces...")

0 commit comments

Comments
 (0)