Skip to content

Secure Service Users Authentication

Last updated on

The following tutorial shows how to create an IAM Service Account and a Dremio Service User and configure the Dremio Service User to use the identity of the STACKIT Service Account.

  • You have a STACKIT Dremio Instance
  • You have STACKIT CLI installed
  • You have EDITOR permissions in IAM on the STACKIT Project.
  • You have a Dremio Service User
  • You have permissions to edit Service Users in the Dremio Instance.

Creating a STACKIT Service Account Key Pair

Section titled “Creating a STACKIT Service Account Key Pair”

Following these steps you will have:

  • a STACKIT Service Account with a unique email address, such as dremio-tutorial-r33abmi8@sa.stackit.cloud
  • a STACKIT Service Account Key Pair JSON file, saved at $HOME/Downloads/tutorial-sa-key.json

The email address and the key file will be used in the next stage with Dremio to configure the Service User External Credentials and execute the JWT Token Exchange for authentication.

  1. Open your project in the STACKIT Portal

    Screenshot of STACKIT Portal

  2. Navigate to IAM Service Accounts from the menu on the left and click the Create service account button.

    Screenshot of STACKIT IAM Create Service Account

  3. Give it a name and click Create. This will have generated a unique email address for your service account, consisting of the assigned name and a random suffix.

    Screenshot of STACKIT IAM Service Accounts

  4. Click on the entry for the newly created service account to go to its Overview page. Then click on the Service account keys entry in the menu on the left.

    Screenshot of STACKIT IAM Service Account Keys

  5. Create a new service account key by clicking on Create service account key. Select Create new key pair, set an expiration date and click Create

    Screenshot of STACKIT IAM Create Key Pair

  6. Once you are presented with a newly generated key, click on the Download drop-down menu and select Download JSON. Save it under a name such as tutorial-sa-key.json.

    Screenshot of Dremio IdP Configure

Creating an External Credential for a Dremio Service User

Section titled “Creating an External Credential for a Dremio Service User”

Now that we have a STACKIT Service account, we proceed by creating External Credentials on a Dremio Service User to use use Service Account key.

  1. In your Dremio Instance, navigate to Settings -> User Management -> Service Users. Follow the tutorial on creating a Service User if you don’t already have one.

    When creating a Dremio Service User with the intent to associate with a STACKIT Service Account, we recomment to use the generated email address of the Service Account as the Service User’s name.

  2. Click on the Username of the Service User and select the Credentials tab. From there click Add and select Configure an external credential.

    Screenshot of Dremio Service User Credentials

  3. Fill in the form as follows, and click Configure.

    • Label: any label of your choice
    • Audience: api.stackit.cloud
    • User claim: email
    • External ID: the email of the STACKIT service account created in the previous steps (e.g. dremio-tutorial-r33abmi8@sa.stackit.cloud)
    • Issuer UDL: https://accounts.stackit.cloud
    • JWKS URL (optional for the stackit IdP, as it uses the standard URL path): https://accounts.stackit.cloud/.well-known/jwks.json

    Screenshot of Dremio Service User External Credentials Config

  4. In the overview of the external credential you will find and Exchange Request URL, with a Copy button next to it. You will need this to authorize the Token Exchange outlined in the following section

    Screenshot of Dremio Created External Credential

Executing a JWT Token Exchange between a STACKIT Service Account and a Dremio Service User

Section titled “Executing a JWT Token Exchange between a STACKIT Service Account and a Dremio Service User”

This section demonstrates how a workload can authenticate to Dremio by using a STACKIT Service Account. This is done by executing a JWT token exchange between the STACKIT Service Account and the Dremio Service User.

#!/bin/bash
# ==========================================
# 1. Configuration
# ==========================================
DREMIO_URL="https://<dremio-id>.dremio.eu01.onstackit.cloud"
EXCHANGE_REQUEST="//oauth.dremio.app/clients/<client-id>/credentials/<credential-id>"
SA_KEY_PATH="tutorial-sa-key.json"
# ==========================================
# 2. Get the STACKIT Service Account Token
# ==========================================
echo "Activating STACKIT Service Account..."
stackit auth activate-service-account --service-account-key-path="$SA_KEY_PATH"
SA_TOKEN=$(stackit auth get-access-token)
if [ -z "$SA_TOKEN" ]; then
echo "Failed to retrieve STACKIT Service Account token."
exit 1
fi
# ==========================================
# 3. Exchange for Dremio Token
# ==========================================
RESPONSE_BODY_FILE=$(mktemp)
# Use -w to capture the status code into a variable, and -o to save the body
HTTP_STATUS=$(curl -s -w "%{http_code}" -o "$RESPONSE_BODY_FILE" -X POST "$DREMIO_URL/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "subject_token=$SA_TOKEN" \
--data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
--data-urlencode "scope=dremio.all" \
--data-urlencode "audience=${EXCHANGE_REQUEST}")
# Read the body and clean up the temp file
DREMIO_RESPONSE=$(cat "$RESPONSE_BODY_FILE")
rm "$RESPONSE_BODY_FILE"
# Check if the HTTP status code is not 200 (OK)
if [ "$HTTP_STATUS" -ne 200 ]; then
echo "Token exchange failed!"
echo "HTTP Status Code: $HTTP_STATUS"
echo "Response Body: $DREMIO_RESPONSE"
exit 1
fi
DREMIO_TOKEN=$(echo "$DREMIO_RESPONSE" | jq -r .access_token)
if [ "$DREMIO_TOKEN" == "null" ] || [ -z "$DREMIO_TOKEN" ]; then
echo "Token exchange failed. Response:"
echo "$DREMIO_RESPONSE"
exit 1
fi
# ==========================================
# 4. Test Dremio API
# ==========================================
echo "Fetching Dremio Catalog..."
curl -s -X GET "$DREMIO_URL/api/v3/catalog" \
-H "Authorization: Bearer $DREMIO_TOKEN" \
-H "Content-Type: application/json" | jq .