Skip to main content

Service Principal

A service principal is a non-human identity in a Microsoft Entra ID tenant that applications, pipelines, and scripts use to authenticate to Azure. It receives its own RBAC permissions, separate from any employee account.

Service Principal

A service principal is the tenant-local instance of an app registration. The app registration defines the application globally, and the service principal is what actually gets role assignments on subscriptions and resource groups. Using one for automation avoids tying a pipeline to a person's account, which breaks on password resets, MFA prompts, and offboarding.

How Does a Service Principal Authenticate?

It can use a client secret, a certificate, or a federated credential. Federated credentials (workload identity federation) let GitHub Actions or Azure DevOps exchange a short-lived OIDC token for Azure access, so no secret is stored at all.

sequenceDiagram participant G as GitHub Actions participant E as Entra ID participant A as Azure G->>E: Present OIDC token E-->>G: Short-lived Azure token G->>A: Deploy with scoped role

How Do You Create One With Limited Scope?

Bash
az ad sp create-for-rbac --name cicd-orders-sp \
--role Contributor \
--scopes /subscriptions/<sub-id>/resourceGroups/mumbai-orders-prod-rg

Why It Matters in Production

A fintech like CRED can scope its pipeline's service principal to only the resource groups it deploys to, so a leaked credential cannot reach unrelated production data.

Security

Prefer managed identities when the workload runs in Azure, and workload identity federation for external CI systems. Both remove the secret you would otherwise have to protect.

Common Mistake

Giving a pipeline a long-lived secret stored as a plain variable. Secrets get logged or forgotten, then expire and break deployments at a bad moment.

Frequently Asked Questions

What is the difference between an app registration and a service principal?

The app registration is the global definition of the application, and the service principal is its local identity in a tenant. Role assignments attach to the service principal.

Service principal or managed identity?

Use a managed identity for resources running in Azure, since Azure handles its credentials. Use a service principal for external systems such as CI pipelines, ideally with federated credentials.

How do I rotate a service principal secret?

Create a new secret or certificate, update every consumer, then remove the old one. Secrets have an expiry, so track it to avoid surprise outages.

Found a mistake, an outdated step or a broken link?