Skip to content

Commit 6455538

Browse files
Use env var in spark container (#1522)
* added Signed-off-by: owenowenisme <mses010108@gmail.com> * fix Signed-off-by: owenowenisme <mses010108@gmail.com> * add export Signed-off-by: owenowenisme <mses010108@gmail.com> * update docs using .env Signed-off-by: owenowenisme <mses010108@gmail.com> * update docs Signed-off-by: owenowenisme <mses010108@gmail.com> * change back from using .env to export Signed-off-by: owenowenisme <mses010108@gmail.com> * Apply suggestions from code review Co-authored-by: Adnan Hemani <adnan.h@berkeley.edu> --------- Signed-off-by: owenowenisme <mses010108@gmail.com> Co-authored-by: Adnan Hemani <adnan.h@berkeley.edu>
1 parent e6d0523 commit 6455538

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

getting-started/assets/polaris/create-catalog.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ set -e
2222
apk add --no-cache jq
2323

2424
token=$(curl -s http://polaris:8181/api/catalog/v1/oauth/tokens \
25-
--user root:s3cr3t \
25+
--user ${CLIENT_ID}:${CLIENT_SECRET} \
2626
-d grant_type=client_credentials \
2727
-d scope=PRINCIPAL_ROLE:ALL | sed -n 's/.*"access_token":"\([^"]*\)".*/\1/p')
2828

getting-started/assets/trino-config/catalog/iceberg.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ connector.name=iceberg
2121
iceberg.catalog.type=rest
2222
iceberg.rest-catalog.uri=http://polaris:8181/api/catalog
2323
iceberg.rest-catalog.security=OAUTH2
24-
iceberg.rest-catalog.oauth2.credential=root:s3cr3t
24+
iceberg.rest-catalog.oauth2.credential=${ENV:CLIENT_ID}:${ENV:CLIENT_SECRET}
2525
iceberg.rest-catalog.oauth2.scope=PRINCIPAL_ROLE:ALL
2626
iceberg.rest-catalog.warehouse=quickstart_catalog
2727
# Required to support local filesystem: https://trino.io/docs/current/object-storage.html#configuration

getting-started/eclipselink/docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ services:
3636
polaris.persistence.eclipselink.configuration-file: /deployments/config/eclipselink/persistence.xml
3737
polaris.realm-context.realms: POLARIS
3838
quarkus.otel.sdk.disabled: "true"
39+
POLARIS_BOOTSTRAP_CREDENTIALS: POLARIS,${CLIENT_ID},${CLIENT_SECRET}
3940
volumes:
4041
- ../assets/eclipselink/:/deployments/config/eclipselink
4142
healthcheck:
@@ -54,6 +55,8 @@ services:
5455
- STORAGE_LOCATION=${STORAGE_LOCATION}
5556
- AWS_ROLE_ARN=${AWS_ROLE_ARN}
5657
- AZURE_TENANT_ID=${AZURE_TENANT_ID}
58+
- CLIENT_ID=${CLIENT_ID}
59+
- CLIENT_SECRET=${CLIENT_SECRET}
5760
volumes:
5861
- ../assets/polaris/:/polaris
5962
entrypoint: '/bin/sh -c "chmod +x /polaris/create-catalog.sh && /polaris/create-catalog.sh"'
@@ -79,7 +82,7 @@ services:
7982
--conf, "spark.sql.catalog.quickstart_catalog.type=rest",
8083
--conf, "spark.sql.catalog.quickstart_catalog.warehouse=quickstart_catalog",
8184
--conf, "spark.sql.catalog.quickstart_catalog.uri=http://polaris:8181/api/catalog",
82-
--conf, "spark.sql.catalog.quickstart_catalog.credential=root:s3cr3t",
85+
--conf, "spark.sql.catalog.quickstart_catalog.credential=${USER_CLIENT_ID}:${USER_CLIENT_SECRET}",
8386
--conf, "spark.sql.catalog.quickstart_catalog.scope=PRINCIPAL_ROLE:ALL",
8487
--conf, "spark.sql.defaultCatalog=quickstart_catalog",
8588
--conf, "spark.sql.catalogImplementation=in-memory",
@@ -91,6 +94,9 @@ services:
9194
depends_on:
9295
polaris-setup:
9396
condition: service_completed_successfully
97+
environment:
98+
- CLIENT_ID=${CLIENT_ID}
99+
- CLIENT_SECRET=${CLIENT_SECRET}
94100
stdin_open: true
95101
tty: true
96102
ports:

site/content/in-dev/unreleased/getting-started/using-polaris.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ Title: Using Polaris
2121
type: docs
2222
weight: 400
2323
---
24-
24+
## Setup
25+
Define your `CLIENT_ID` & `CLIENT_SECRET` and export them for future use.
26+
```shell
27+
export CLIENT_ID=YOUR_CLIENT_ID
28+
export CLIENT_SECRET=YOUR_CLIENT_SECRET
29+
```
2530
## Defining a Catalog
2631

2732
In Polaris, the [catalog]({{% relref "../entities#catalog" %}}) is the top-level entity that objects like [tables]({{% relref "../entities#table" %}}) and [views]({{% relref "../entities#view" %}}) are organized under. With a Polaris service running, you can create a catalog like so:
@@ -79,11 +84,13 @@ With a catalog created, we can create a [principal]({{% relref "../entities#prin
7984

8085
Be sure to provide the necessary credentials, hostname, and port as before.
8186

82-
When the `principals create` command completes successfully, it will return the credentials for this new principal. Be sure to note these down for later. For example:
87+
When the `principals create` command completes successfully, it will return the credentials for this new principal. Export them for future use. For example:
8388

84-
```
89+
```shell
8590
./polaris ... principals create example
8691
{"clientId": "XXXX", "clientSecret": "YYYY"}
92+
export USER_CLIENT_ID=XXXX
93+
export USER_CLIENT_SECRET=YYYY
8794
```
8895

8996
Now, we grant the principal the [principal role]({{% relref "../entities#principal-role" %}}) we created, and grant the [catalog role]({{% relref "../entities#catalog-role" %}}) the principal role we created. For more information on these entities, please refer to the linked documentation.
@@ -154,27 +161,21 @@ bin/spark-sql \
154161
--conf spark.sql.catalog.quickstart_catalog=org.apache.iceberg.spark.SparkCatalog \
155162
--conf spark.sql.catalog.quickstart_catalog.catalog-impl=org.apache.iceberg.rest.RESTCatalog \
156163
--conf spark.sql.catalog.quickstart_catalog.uri=http://localhost:8181/api/catalog \
157-
--conf spark.sql.catalog.quickstart_catalog.credential='XXXX:YYYY' \
164+
--conf spark.sql.catalog.quickstart_catalog.credential='${USER_CLIENT_ID}:${USER_CLIENT_SECRET}' \
158165
--conf spark.sql.catalog.quickstart_catalog.scope='PRINCIPAL_ROLE:ALL' \
159166
--conf spark.sql.catalog.quickstart_catalog.token-refresh-enabled=true \
160167
--conf spark.sql.catalog.quickstart_catalog.client.region=us-west-2
161168
```
162169

163170

164-
Replace `XXXX` and `YYYY` with the client ID and client secret generated when you created the `quickstart_user` principal.
165-
166171
Similar to the CLI commands above, this configures Spark to use the Polaris running at `localhost:8181`. If your Polaris server is running elsewhere, but sure to update the configuration appropriately.
167172

168173
Finally, note that we include the `hadoop-aws` package here. If your table is using a different filesystem, be sure to include the appropriate dependency.
169174

170175
#### Using Spark SQL from a Docker container
171176

172-
Replace the credentials used in the Docker container using the following code:
173-
177+
Refresh the Docker container with the user's credentials:
174178
```shell
175-
USER_CLIENT_ID="XXXX"
176-
USER_CLIENT_SECRET="YYYY"
177-
sed -i "s/^\(.*spark\.sql\.catalog\.quickstart_catalog\.credential=\).*/\1${USER_CLIENT_ID}:${USER_CLIENT_SECRET}\",/" getting-started/eclipselink/docker-compose.yml
178179
docker compose -f getting-started/eclipselink/docker-compose.yml up -d
179180
```
180181

@@ -233,12 +234,9 @@ org.apache.iceberg.exceptions.ForbiddenException: Forbidden: Principal 'quicksta
233234

234235
### Connecting with Trino
235236

236-
Replace the credentials used in the Docker container using the following code:
237+
Refresh the Docker container with the user's credentials:
237238

238239
```shell
239-
USER_CLIENT_ID="XXXX"
240-
USER_CLIENT_SECRET="YYYY"
241-
sed -i "s/^\(iceberg\.rest-catalog\.oauth2\.credential=\).*/\1${USER_CLIENT_ID}:${USER_CLIENT_SECRET}/" getting-started/eclipselink/trino-config/catalog/iceberg.properties
242240
docker compose -f getting-started/eclipselink/docker-compose.yml down trino
243241
docker compose -f getting-started/eclipselink/docker-compose.yml up -d
244242
```

0 commit comments

Comments
 (0)