Skip to content
Browse documentation

Workload identity

Azure managed identities

Give an Azure App Service or Function App short-lived read access to one Bulgur environment.

Before you start

Azure Managed Identity is supported on Azure App Service and Azure Functions in Microsoft public cloud. A real system-assigned App Service identity passed CLI run, CLI pull, and Node SDK reads against hosted https://api.bulgur.dev, including target-boundary and policy-revocation checks.

Azure support requires Bulgur CLI or Node SDK 1.4.0 or newer and a matching server version. The Azure App Service CLI/SDK flow passed against hosted Bulgur Cloud. CLI/SDK 1.3.0 did not include Azure support. Azure DevOps, AKS, VMs, and sovereign clouds are outside this provider's scope.

Set up the Entra API audience

Create a dedicated single-tenant Microsoft Entra app registration to represent Bulgur's API audience. In the registration's Overview, copy its Application (client) ID. Set its Application ID URI to api://<API-application-client-ID> under Expose an API.

Configure the registration to issue v2 access tokens and include the idtyp optional claim in access tokens. The resource request uses api://<client-ID>; the aud claim in the resulting v2 token is the bare client ID GUID. The API registration ID is not the managed identity's principal ID or client ID.

json
{
  "api": { "requestedAccessTokenVersion": 2 },
  "optionalClaims": {
    "accessToken": [{ "name": "idtyp", "essential": false }]
  }
}

Bulgur accepts app-only access tokens. This Bulgur policy does not require an app-role assignment. Do not create a client secret for this flow.

Enable an App Service or Function App identity

  • In your App Service or Function App, open Identity and enable System assigned. Save the change. Use a dedicated identity for each workload with a different Bulgur policy.
  • Copy the identity's Object (principal) ID from the Identity page. This is the service principal object ID Bulgur checks. Do not copy the identity's client ID into the principal ID field.
  • For a user-assigned identity, attach it to the app and copy its client ID. The client ID is only a runtime selector; the policy still uses that identity's principal ID.

Any app that can use a managed identity can authenticate as that identity. Limit identity assignment and use a separate identity when workloads need separate access.

Create the Bulgur policy

In organization settings, open Workload identities and create an Azure Managed Identity policy. Enter three separate IDs: the Microsoft Entra tenant ID, the managed identity principal/object ID, and the dedicated API registration's client ID as audience.

Choose one Bulgur project and one non-Shared environment. The workload can read that environment and its inherited Shared values, but cannot directly read Shared or another environment.

Dashboard fieldCopy this value
Tenant IDDirectory (tenant) ID from Microsoft Entra overview.
Managed identity principal IDObject (principal) ID from the app's managed identity page.
API audience client IDApplication (client) ID from the dedicated API app registration.

Install the CLI and SDK

Use Bulgur CLI or Node SDK 1.4.0 or newer with a server version that supports Azure Managed Identity. CLI/SDK 1.3.0 did not include Azure support.

sh
npm install bulgur@^1.4.0

CLI binaries target macOS and Linux.

Run a command with the CLI

Set the Bulgur identity ID and the API registration client ID in the App Service or Function App settings. Azure supplies IDENTITY_ENDPOINT and IDENTITY_HEADER; do not create or edit those settings yourself. Omit BULGUR_AZURE_CLIENT_ID for a system-assigned identity. Set it to the user-assigned identity's client ID only when selecting that identity.

sh
export BULGUR_AUTH=azure-oidc
export BULGUR_IDENTITY_ID=<bulgur-identity-id>
export BULGUR_AZURE_AUDIENCE=<api-registration-client-id>
# Optional, for a user-assigned managed identity:
# export BULGUR_AZURE_CLIENT_ID=<managed-identity-client-id>
npx bulgur run -- node server.js

The client requests resource api://<BULGUR_AZURE_AUDIENCE>. The v2 token audience claim is the bare GUID. Use a process manager or app startup command to run the built CLI; don't put actual credentials in source control.

Read values from the Node SDK

Use the Node SDK on Node.js 18 or newer with a Bulgur 1.4.0 or newer package and server version that supports Azure Managed Identity. It has no Azure package dependency. loadValues returns a request-local object and does not change process.env.

js
const { loadValues } = require("bulgur");

async function main() {
  const values = await loadValues({
    auth: "azure-oidc",
    identityId: process.env.BULGUR_IDENTITY_ID,
    azureAudience: process.env.BULGUR_AZURE_AUDIENCE,
    // Optional for a user-assigned identity:
    azureClientId: process.env.BULGUR_AZURE_CLIENT_ID,
  });
  return values;
}

main().catch(() => {
  console.error("Could not load Bulgur values");
  process.exitCode = 1;
});

If authentication fails

  • For an unauthorized exchange, compare the Bulgur policy tenant ID with the app's tenant, the principal ID with the identity Object (principal) ID, and the audience with the API app's client ID. These values are different IDs.
  • Check that the API app uses v2 access tokens and includes the idtyp optional claim. User/delegated tokens are not accepted; the managed identity token must be app-only.
  • Run on App Service or Functions where Azure provides the identity endpoint variables. Do not copy those runtime variables from another app or use a local developer credential as fallback.
  • The client accepts loopback localhost or 127.0.0.1 with /MSI/token and an optional trailing slash, or a canonical IPv4 address in 169.254.0.0/16 other than the VM IMDS address 169.254.169.254, on port 8081 and exact lowercase path /msi/token. It does not use DNS, proxies, or redirects.

Token lifetime and revocation

Azure source tokens can be reused while valid. The verifier accepts an exp - iat span up to 24 hours 5 minutes plus 30 seconds of clock tolerance because Azure backdates iat and nbf by five minutes. Bulgur sessions last at most five minutes and never beyond source-token expiry.

Disabling, editing, or deleting the Bulgur policy revokes its Bulgur sessions. It does not revoke the Entra source token. If access is no longer needed, disable or delete the Bulgur policy and remove the managed identity from the app.