Skip to content

How to use Service Accounts via the IaaS-API

Service Accounts allow you to access the whole STACKIT API programmatically. The IaaS-API allows attaching service accounts to servers which makes them available inside the VM. Accessing serviceaccounts inside a VM is possible through the metadata API on the well-known url http://169.254.169.254/stackit/v1/service-accounts. A service account is referenced by its service account mail which is globally unique.

Service accounts can be created in the portal, the service account API or the STACKIT CLI.

Creating a Service Account with the STACKIT CLI

stackit service-account create --name <NAME>

Be sure to give the service account the correct permissions or roles for the intended tasks.

The IaaS-API allows to attach or detach Service Accounts on already running servers or adding service accounts on creation of a server.

stackit curl https://iaas.api.eu01.stackit.cloud/v1/projects/{projectId}/servers/{serverId}/service-accounts

After attaching the service account to a server it can immediately be used. The token of the service account is available through the server-local metadata API at http://169.254.169.254/stackit/v1/service-accounts.

Listing attached Service Accounts

curl http://169.254.169.254/stackit/v1/service-accounts

A token can be created and retrieved by calling the /token path.

Creating a Service Account Token

curl http://169.254.169.254/stackit/v1/service-accounts/<SERVICEACCOUNTMAIL>/token

Tokens have short lifetime and must be renewed regularly by retrieving a new token from this URL.

To follow this example install the STACKIT CLI.

  1. First we need to authenticate with the token
    Authenticate with the Token
stackit auth activate-service-account --service-account-token <TOKEN>
  1. Then we can use the client as usual as the service account permissions allow.