{"token_count": 5493}

# Configuring Workload Identity and Azure Federated Credentials

Teleport Workload Identity issues flexible short-lived identities in JWT format. Azure federated credentials allow you to use these JWTs to authenticate to Azure services.

You can authenticate as either a user-assigned managed identity or the service principal associated with a Microsoft Entra app registration. Both options use federated credentials and do not require a client secret or certificate.

This can be useful in cases where a machine needs to securely authenticate with Azure services without the use of a long-lived credential. This is because the machine can authenticate with Teleport without using any shared secrets by using one of our delegated join methods.

In this guide, you will configure Teleport Workload Identity and Azure to allow a workload to authenticate to the Azure Blob Storage and upload content to a container.

## How it works

This implementation differs from using the Teleport Application Service to protect Azure APIs in a few ways:

- Requests to Azure are not proxied through the Teleport Proxy Service, meaning reduced latency but also less visibility, as these requests will not be recorded in Teleport's audit log.
- Workload Identity works with any Azure client, including the command-line tool but also their SDKs.
- Using the Teleport Application Service to access Azure does not work with Machine & Workload Identity and therefore cannot be used when a machine needs to authenticate with Azure.

## Prerequisites

- A running Teleport cluster accessible at a hostname with a valid TLS certificate. If you want to get started with Teleport, [sign up](https://goteleport.com/signup) for a free trial or [set up a demo environment](https://goteleport.com/docs/ver/20.x/get-started/deploy-community.md).

- The `tctl` and `tsh` clients.

  Installing `tctl` and `tsh` clients

  1. Determine the version of your Teleport cluster. The `tctl` and `tsh` clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at `/v1/webapi/find` and use a JSON query tool to obtain your cluster version. Replace teleport.example.com:443 with the web address of your Teleport Proxy Service:

     **Mac/Linux**

     ```
     $ TELEPORT_DOMAIN=teleport.example.com:443
     $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')"
     ```

     **Windows - Powershell**

     ```
     $ $TELEPORT_DOMAIN = "teleport.example.com:443"
     $ $TELEPORT_VERSION = (Invoke-RestMethod -Uri "https://${TELEPORT_DOMAIN}/v1/webapi/find").server_version
     ```

  2. Follow the instructions for your platform to install `tctl` and `tsh` clients:

     **Mac**

     Download the signed macOS .pkg installer for Teleport, which includes the `tctl` and `tsh` clients:

     ```
     $ curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkg
     ```

     In Finder double-click the `pkg` file to begin installation.

     ---

     DANGER

     Using Homebrew to install Teleport is not supported. The Teleport package in Homebrew is not maintained by Teleport and we can't guarantee its reliability or security.

     ---

     **Windows - Powershell**

     ```
     $ curl.exe -O https://cdn.teleport.dev/teleport-v$TELEPORT_VERSION-windows-amd64-bin.zip
     Unzip the archive and move the `tctl` and `tsh` clients to your %PATH%
     NOTE: Do not place the `tctl` and `tsh` clients in the System32 directory, as this can cause issues when using WinSCP.
     Use %SystemRoot% (C:\Windows) or %USERPROFILE% (C:\Users\<username>) instead.
     ```

     **Linux**

     All of the Teleport binaries in Linux installations include the `tctl` and `tsh` clients. For more options (including RPM/DEB packages and downloads for i386/ARM/ARM64) see our [installation page](https://goteleport.com/docs/ver/20.x/installation/single-machine.md).

     ```
     $ curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
     $ tar -xzf teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
     $ cd teleport
     $ sudo ./install
     Teleport binaries have been copied to /usr/local/bin
     ```

  Connecting with TLS routing disabled

  This guide's commands assume your Teleport cluster uses TLS routing (`proxy_listener_mode: multiplex`), where the `tctl` and `tsh` clients reach every Teleport service through the Proxy Service's web address on port `443`. If you're not sure whether this applies to your cluster, check with whoever manages it.

  If your cluster uses separate listener ports instead, adjust ports as follows:

  - **`tsh` commands** (e.g., `tsh login --proxy=...`): continue using the Proxy Service web address on port `3080` (or `443` if behind a load balancer). Do not change these to port `3025`.

  - **Direct `tctl` or Auth Service API commands**: use port `3025` for the Auth Service gRPC listener:

    ```
    $ tctl status --auth-server=teleport.example.com:3025
    ```

* Check that you can connect to your Teleport cluster and verify that you can run `tctl` and `tsh` commands using your current credentials.

  1. Assign teleport.example.com to the domain name of the Teleport Proxy Service in your cluster and email\@example.com to your Teleport username.

  2. Authenticate to your Teleport cluster. This depends on whether your shell is interactive or not.

     **In an interactive shell:** Run the following command. By default, this triggers a multi-factor authentication prompt:

     ```
     $ tsh login --proxy=teleport.example.com --user=email@example.com
     $ tctl status
     Cluster  teleport.example.com
     Version  20.0.0-dev
     CA pin   sha256:abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678
     ```

     **On non-interactive environments:** If you are running `tsh` and `tctl` as an AI agent, in a CI/CD environment, or similar, make sure the `TELEPORT_IDENTITY_FILE` environment variable is assigned to a valid file path with credentials for your cluster. `tsh` and `tctl` read the file path from the environment variable and do not require a separate authentication step. If there is no identity file available, we recommend that you [set up Machine ID](https://goteleport.com/docs/ver/20.x/machine-workload-identity/getting-started.md) to provision one automatically.

     When executing `tctl` commands with an identity file, you must pass the `--auth-server` flag to provide the Teleport Auth Service address, which is not included in the identity file. If you provide the Proxy Service address, `tctl` connects to the Proxy Service, which forwards traffic to and from the Teleport Auth Service. Update 443 to `3025` if you are contacting the Auth Service directly with `tctl`:

     ```
     $ tctl status --auth-server=teleport.example.com:443
     ```

     For `tsh` commands that read an identity file, you must pass the `--proxy` flag, which points `tsh` to the address of the Teleport Proxy Service:

     ```
     $ tsh status --proxy=teleport.example.com
     ```

     Ensure client commands can access your identity file. Replace path/to/identity/file with the path to your identity file:

     ```
     $ export TELEPORT_IDENTITY_FILE="${TELEPORT_IDENTITY_FILE:-path/to/identity/file}"
     ```

     Add the `--auth-server` or `--proxy` flags to all subsequent `tctl` and `tsh` commands.

  If you can connect to the cluster and run the `tctl status` command, you can use your current credentials to run subsequent `tctl` commands from your workstation. If you host your own Teleport cluster, you can also run `tctl` commands on the computer that hosts the Teleport Auth Service for full permissions.

* `tbot` must already be installed and configured on the host where the workloads which need to access Teleport Workload Identity will run. For more information, see the [deployment guides](https://goteleport.com/docs/ver/20.x/machine-workload-identity/deployment.md).

* The Azure CLI on the same host where `tbot` and the workload runs. Follow the [Azure CLI installation instructions](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) for your platform, then confirm it works by running `az version`. This guide was tested against Azure CLI 2.90.0.

* An Azure resource group and subscription you wish to grant the workload access to.

* Permissions to create a user-assigned managed identity or app registration, configure its federated credentials, and assign Azure roles.

### Deciding on a SPIFFE ID structure

Within Teleport Workload Identity, all identities are represented using a SPIFFE ID. This is a URI that uniquely identifies the entity that the identity represents. The scheme is always `spiffe://`, and the host will be the name of your Teleport cluster. The structure of the path of this URI is up to you.

For the purposes of this guide, we will be granting access to Azure to the `spiffe://example.teleport.sh/svc/example-service` SPIFFE ID.

If you have already deployed Teleport Workload Identity, then you will already have a SPIFFE ID structure in place. If you have not, then you will need to decide on a structure for your SPIFFE IDs.

If you are only using Teleport Workload Identity with Azure Federated Credentials, you may structure your SPIFFE IDs so that they explicitly specify the Azure user-assigned managed identity or app registration service principal they are allowed to assume. However, it often makes more sense to name the workload or person that will use the SPIFFE ID. See the [best practices guide](https://goteleport.com/docs/ver/20.x/machine-workload-identity/workload-identity/best-practices.md) for further advice.

## Step 1/4. Configure Azure

To configure Azure to accept Workload Identity JWT SVIDs as authentication, you'll need to create either a user-assigned managed identity or an app registration to represent that workload within Azure, configure a federated credential, and then grant the user-assigned managed identity or app registration service principal the necessary permissions using a role assignment.

### Choose an Azure identity

To allow a workload identity to access Azure, you must first choose a type of identity to represent it in Microsoft Entra. This guide supports two options. Both can trust JWTs issued by Teleport through a federated credential, so neither requires a client secret or certificate.

- **User-assigned managed identity**: An identity you create in Azure and grant access to resources, such as the storage account in this example. Azure manages its credentials. Choose this when creating a new identity specifically for machine access. With federation, the workload can use this identity without assigning it to an Azure VM or other compute resource.
- **App registration**: A Microsoft Entra application definition. Registering the app also creates a service principal — the identity to which you grant access to Azure resources. Choose this if your organization already uses an app registration for the workload or needs to manage it as an Entra application.

### Register your workload

First, choose how the workload will be represented in Microsoft Entra.

**User-assigned managed identity**

1. Browse to the "Managed Identities" section of the Azure Portal.
2. Select "Create" to open the "Create User Assigned Managed Identity" form.
3. Select your resource group and subscription.
4. Enter a unique name for your identity that describes the workload it will represent. In our example, we will use "example-service".
5. Select "Review + create".
6. Browse to the "Properties" section of the created user-assigned managed identity and record its "Client ID" and "Tenant ID". These values will both be UUIDs.

**App registration**

1. In Microsoft Entra ID, browse to "App registrations" and select "New registration".
2. Enter a unique name that describes the workload the application will represent. In our example, we will use "example-service".
3. Select "Single tenant only – `your tenant`" and leave the redirect URI unset.
4. Select "Register".
5. From the app registration's "Overview" page, record its "Application (client) ID" and "Directory (tenant) ID". These values will both be UUIDs.

Microsoft Entra automatically creates a service principal for the app registration. Azure uses the service principal when authorizing the workload's access to resources.

### Create a federated credential

Next, configure a federated credential on the user-assigned managed identity or app registration. This configures Microsoft Entra to accept JWT SVIDs issued by your Teleport cluster.

**User-assigned managed identity**

Browse to your user-assigned managed identity in the Azure Portal, select "Federated credentials" from the "Settings" section, and then select "Add Credential".

**App registration**

Browse to your app registration in Microsoft Entra ID, select "Certificates & secrets", select the "Federated credentials" tab, and then select "Add credential".

Configure the federated credential as follows:

1. Select "Other issuer" for the "Federated credential scenario".
2. Enter the address of your Teleport Proxy service followed by `/workload-identity` for the "Issuer URL", for example `https://example.teleport.sh/workload-identity`.
3. Enter the SPIFFE ID you have decided on for the workload in the "Subject identifier" field. For example, `spiffe://example.teleport.sh/svc/example-service`. This will control which JWT SVIDs issued by Teleport Workload Identity will be accepted for the user-assigned managed identity or service principal associated with the app registration.
4. Ensure that the "Audience" is `api://AzureADTokenExchange`.
5. Enter a unique, identifiable name for the federated credential. For example, `example-teleport-sh-svc-example-service`.
6. Click "Add".

### Create a storage account and container

For the purposes of this guide, you'll create a storage account and container for your workload to authenticate to. You can skip this step if you already have resources you wish to grant the workload access to.

First, create a storage account:

1. Browse to the "Storage accounts" section of the Azure Portal and select the "Create" button to open the "Create a storage account" form.
2. Select your resource group and subscription.
3. Enter a unique, identifiable name for the storage account. Record this as you will need it later. In our examples we will use `examplestorageaccount`.
4. Select a region and select "Azure Blob Storage" for the "Primary Service" field.
5. Click "Create".

Now, you can create a storage container:

1. Browse to the "Storage accounts" section of the Azure Portal and select the storage account you created.
2. Browse to the "Containers" section beneath the "Data storage" section.
3. Select "Add container" to open the "New container" form.
4. Enter a unique, identifiable name for the container. Record this as you will need it later. In our examples we will use `examplecontainer`.

### Create a role assignment

Finally, grant the user-assigned managed identity or app registration service principal the necessary permissions for your workload to perform the actions it needs to within Azure.

When creating a role assignment in Azure, it can be scoped to different levels:

- Subscription (to grant access to any resource within the subscription)
- Resource Group (to grant access to any resource within the resource group)
- Resource (to grant access to a specific resource)

For the purposes of this guide, we will grant the user-assigned managed identity or app registration service principal the `Storage Blob Data Owner` role with the scope of the storage account you have created.

1. Browse to the "Storage accounts" section of the Azure Portal and select the storage account you created.
2. Browse to "Access control (IAM)" in the sidebar, then select "Add" and "Add role assignment".
3. Under "Role" select "Storage Blob Data Owner".

**User-assigned managed identity**

Under "Members", for "Assign access to" select "Managed identity" and then press "Select members". Select "User-assigned managed identity", then search for and select the user-assigned managed identity you created earlier.

**App registration**

Under "Members", for "Assign access to" select "User, group, or service principal" and then press "Select members". Search for the app registration's name and select the entry with object type "App". This assigns the role to its service principal.

Select "Review + assign" and save your changes.

## Step 2/4. Configure Teleport RBAC

Now we need to configure Teleport to allow a JWT to be issued containing the SPIFFE ID we have chosen.

First, you'll create a Workload Identity resource to define the identity and its characteristics. Create a new file called `workload-identity.yaml`:

```
kind: workload_identity
version: v1
metadata:
  name: example-workload-identity
  labels:
    example: getting-started
spec:
  spiffe:
    id: /svc/example-service

```

Replace:

- `example-workload-identity` with a descriptive name for the Workload Identity.
- `/svc/example-service` with the path part of the SPIFFE ID you have chosen.

Apply this to your cluster using `tctl`:

```
$ tctl create -f workload-identity.yaml
```

Next, you'll create a role which grants access to this Workload Identity. Create `role.yaml` with the following content:

```
kind: role
version: v6
metadata:
  name: example-workload-identity-issuer
spec:
  allow:
    workload_identity_labels:
      example: ["getting-started"]
    rules:
    - resources:
      - workload_identity
      verbs:
      - list
      - read

```

Replace:

- `example-workload-identity-issuer` with a descriptive name for the role.
- The labels selector if you have modified the labels of the Workload Identity.

Apply this role to your Teleport cluster using `tctl`:

```
$ tctl create -f role.yaml
```

---

TIP

You can also create and edit roles using the Web UI. Go to **Access -> Roles** and click **Create New Role** or pick an existing role to edit.

---

You now need to assign this role to the bot:

```
$ tctl bots update my-bot --add-roles example-workload-identity-issuer
```

## Step 3/4. Issue Workload Identity JWTs

You'll now configure `tbot` to issue and renew the short-lived JWT SVIDs for your workload. It'll write the JWT as a file on disk, where you can then configure Azure clients and SDKs to read it.

Take your already deployed `tbot` service and configure it to issue SPIFFE SVIDs by adding the following to the `tbot` configuration file:

```
services:
  - type: workload-identity-jwt
    destination:
      type: directory
      path: /opt/workload-identity
    selector:
      name: example-workload-identity
    audiences: ["api://AzureADTokenExchange"]

```

Replace:

- `/opt/workload-identity` with the directory where you want the JWT to be written.
- `example-workload-identity` with the name of the Workload Identity you have created.

Restart your `tbot` service to apply the new configuration. You should see a file created at `/opt/workload-identity/jwt_svid` containing the JWT.

## Step 4/4. Configure the Azure CLIs and SDKs

You can now use the issued JWT SVID to authenticate to Azure. How this is configured varies between the Azure CLI and Azure SDK.

### Configuring Azure CLI

To use the JWT SVID to authenticate with the Azure CLI, you perform log-in specifying the JWT and either the user-assigned managed identity's client and tenant IDs or the app registration's application client and directory tenant IDs. This performs an initial exchange of the JWT SVID for an Azure access token, which is then cached by the CLI until the access token expires.

Run the following, inserting the client and tenant ID you recorded in the first step:

```
$ az login \
  --federated-token "$(cat /opt/workload-identity/jwt_svid)" \
  --service-principal \
  --username azure-client-id \
  --tenant azure-tenant-id
```

Replace azure-client-id with the user-assigned managed identity's "Client ID" or the app registration's "Application (client) ID". Replace azure-tenant-id with the user-assigned managed identity's "Tenant ID" or the app registration's "Directory (tenant) ID".

You should see a message indicating that this has succeeded.

You can now test this has succeeded by uploading a file to the Azure Blob Storage container:

```
$ echo "testing 1,2,3..." > test.txt
# Upload a test file. Replace the name of the account and container with those
# you selected earlier.
$ az storage blob upload \
  --auth-mode login \
  --account-name examplestorageaccount \
  --container-name examplecontainer \
  --name test.txt \
  --file ./test.txt
# Check that the file has been uploaded. Replace the name of the account and
# container with those you selected earlier.
$ az storage blob list \
  --auth-mode login \
  --output table \
  --account-name examplestorageaccount \
  --container-name examplecontainer

```

### Configuring Azure SDKs

The Azure SDKs support a set of environment variables to configure them to use the federated credential for authentication with the issued JWT SVID:

- `AZURE_CLIENT_ID`: The user-assigned managed identity's client ID or the app registration's application client ID.
- `AZURE_TENANT_ID`: The user-assigned managed identity's tenant ID or the app registration's directory tenant ID.
- `AZURE_FEDERATED_TOKEN_FILE`: The path to the JWT SVID file, for example `/opt/workload-identity/jwt_svid`.

You can also explicitly configure the SDK to use the federated credential, this will vary language-to-language.

## Next steps

- [Azure Workload Identity Federation](https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation): The official Azure documentation for Workload Identity Federation.
- [Configure an app registration](https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation-create-trust): Configure a federated credential on a Microsoft Entra application.
- [Configure a user-assigned managed identity](https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation-create-trust-user-assigned-managed-identity): Configure a federated credential on a user-assigned managed identity.
- [Workload Identity Overview](https://goteleport.com/docs/ver/20.x/machine-workload-identity/workload-identity/introduction.md): Overview of Teleport Workload Identity.
- [JWT SVID Overview](https://goteleport.com/docs/ver/20.x/machine-workload-identity/workload-identity/jwt-svids.md): Overview of the JWT SVIDs issued by Teleport Workload Identity.
- [Best Practices](https://goteleport.com/docs/ver/20.x/machine-workload-identity/workload-identity/best-practices.md): Best practices for using Workload Identity in Production.
- Read the [configuration reference](https://goteleport.com/docs/ver/20.x/reference/machine-workload-identity/configuration.md) to explore all the available configuration options.
