Identities, permissions and secrets in automation
Service principals and managed identities, GitHub tokens and apps, service connections and PATs, roles and access levels, Key Vault, OIDC and secure files.
In this lesson you'll learn
- Choosing service principals or managed identities
- GitHub Apps, GITHUB_TOKEN, PATs, service connections
- Permissions and access levels in GitHub and Azure DevOps
- Secrets, secretless sign-in, secure files and stopping leaks
1. Identities for automation
Why not just use my own account?
A pipeline that signs in as a person breaks when they leave, has all their rights, and leaves an audit trail that blames them. Automation needs its own identity with only the rights it needs.
- Managed identity: Azure creates and rotates the credential for a resource. System-assigned lives and dies with one resource; user-assigned is a separate resource you can attach to several. Use one whenever the code runs on Azure (a VM, a self-hosted agent on Azure, an app).
- Service principal: an app registration's identity. Use it when the caller runs outside Azure (GitHub-hosted runners, Microsoft-hosted agents), ideally with workload identity federation instead of a secret.
2. Tokens and connections
- GITHUB_TOKEN: created for each workflow run, scoped to the repository, expires when the job ends. Set the least
permissions:in the workflow (for examplecontents: read,id-token: writefor OIDC). - GitHub Apps: fine-grained permissions per repository, short-lived installation tokens, act as themselves, not as a person: best for integrations and automation across repositories.
- Personal access tokens: act as a person. Prefer fine-grained PATs with an expiry and only the repositories and scopes needed; avoid them for long-running automation.
- Azure DevOps service connections: how pipelines reach Azure and other services; prefer workload identity federation. Azure DevOps PATs should be scoped (for example Agent Pools: Read and manage only) with a short expiry.
3. Permissions and access levels
- GitHub: organisation owners and members, teams, repository roles (Read, Triage, Write, Maintain, Admin), custom roles, and outside collaborators for people outside the organisation who need access to specific repositories.
- Azure DevOps: security groups at organisation level (Project Collection Administrators) and project level (Project Administrators, Contributors, Readers, Build Administrators), with permissions on repositories, pipelines, environments and service connections.
- Access levels (licensing) in Azure DevOps: Stakeholder (free: work items and boards, no code), Basic (code, pipelines, boards; first five users free) and Basic + Test Plans.
- Organise work in projects (a boundary for repositories, pipelines and permissions) and teams (their own backlog, board and area paths).
4. Secrets
- Azure Key Vault holds secrets, keys and certificates. Pipelines read them with the AzureKeyVault task or a Key Vault-linked variable group; GitHub workflows sign in with OIDC and read them with the CLI.
- Secretless authentication: workload identity federation (OpenID Connect) lets GitHub Actions and Azure Pipelines sign in to Azure with short-lived tokens, so there's no client secret to store or rotate.
- Secure files in the Azure Pipelines Library hold certificates, provisioning profiles and key files; the DownloadSecureFile task fetches them into a temporary folder that's cleaned up after the job.
- Preventing leaks: secret variables are masked in logs, but don't echo them, write them to files that become artifacts, pass them on command lines that get logged, or expose them to pull requests from forks (both platforms withhold secrets from fork pull requests by default).
Example
Larkfield Group replaced 40 client secrets in service connections with workload identity federation in an afternoon. The remaining signing certificate lives as a secure file, and the one integration that touches every repository is now a GitHub App instead of an engineer's PAT.
Exam traps to remember
- Code running on Azure: managed identity. Code running elsewhere: service principal with federation.
- Stakeholder access is free and can't see code.
- Outside collaborators are GitHub's way to give non-members repository access.
Test yourself: 3 check questions and exam-style practice questions on this topic are in the AZ-400 DevOps Engineer app.
Practise in the app