Look up how to connect GitHub and Azure DevOps (ADO), and it doesn't take long before you're told to create a Personal Access Token (PAT). I know, because I told you the same thing.
In that post I covered why we run CI in GitHub Enterprise (GHE) and keep CD in ADO. One of the trade offs was auth: an ADO PAT stored in GHE to trigger the pipeline, and a GHE PAT stored in ADO to pull the release. The plan was to hang both off a service account so they weren't tied to one person.
It works, but it's two long lived tokens belonging to something pretending to be a person, and someone has to remember to rotate them. We've now removed both.
TL;DR
- GHE calls ADO using an Entra app registration, which gets a short lived token for each run
- That still uses a client secret, because federated credentials don't scale well here yet, especially on GHE.com
- ADO calls GHE using a GitHub App and an installation token with read only access to contents
- Both are written once, as a reusable workflow on one side and a pipeline template on the other
Why not stick with PATs?
A PAT belongs to a user. It carries that user's access (narrowed by whichever scopes you picked), it stops being useful when the account goes, and it sits there being valid until it expires or someone revokes it. A service account softens the "what happens when they leave" problem, but you've now got an account to own, secure and probably license.
What we want is for each system to have its own identity, with only the access that one job needs, handing out tokens that don't hang around.
The good news is that you don't have to start again. The official Azure/pipelines action, which I pointed you at last time, describes its token input as a PAT, but it also works with a Microsoft Entra access token. The action stays, what we hand it is the thing that changes.
GHE to ADO: an app registration instead of a person
ADO accepts Microsoft Entra tokens on its REST APIs, including tokens issued to a service principal. We created an app registration, and added it to our ADO organisation as a user with Basic access.
ADO doesn't use Entra API permissions to decide what that identity can do. It's controlled in ADO itself, in the same way as any other user.
The aim here is for the app to sit in its own ADO group, added only to the projects it needs, with just enough pipeline permissions to view and queue the pipelines it triggers.
GHE then uses the client ID and secret to request a token, and uses that to queue the pipeline. The token lasts around an hour.
Hang on, isn't that still a secret?
Yes. Client secrets aren't great. This one is long lived, it expires, and if it leaks then someone can get tokens with it until you revoke it.
It's still a better position than a PAT. The identity is an application, so there's no user or service account behind it. Its access is managed separately from any person's, and rotation happens on one app registration, where you can add the new secret before removing the old one.
So why not use federated credentials?
Ideally there would be no secret at all. With a Federated Identity Credential (FIC), Entra trusts the OIDC token that GitHub Actions issues for a run, and there's nothing to store.
The catch is the subject claim. A standard FIC needs an exact match, and by default the subject identifies the repo plus the branch, tag or environment the job is running against. That's fine for one application. Across an organisation it means a new credential for every repo and ref combination, with a limit of 20 per app registration. It doesn't scale.
Microsoft's answer is flexible federated identity credentials, which allow wildcards and can match on the reusable workflow being called. That's exactly what we'd want, but they're still in preview and the only GitHub issuer they support is token.actions.githubusercontent.com. If you're on GHE.com with data residency, your tokens come from token.actions.<subdomain>.ghe.com, so they're not an option.
What about customising the subject claim to leave the repo out? GitHub's docs show custom formats without a repo name, so I tried it. The catch is immutable subject claims. Every repo created after 15 July 2026 uses them regardless, as do repos renamed or transferred after that date, and GitHub keeps the owner and repo IDs in the subject even when you customise the format. It stays specific to each repo, so you're back to a credential per repo. For us, that makes the client secret the practical option for now.
Write it once: a composite action and a reusable workflow
The last thing I want is every repo carrying its own copy of the token request. As with our CI workflows, this lives centrally and is split into two layers.
A composite action handles the auth. A reusable workflow uses that action and then triggers the pipeline. Keeping them separate means anything else that needs to talk to ADO can use the auth step without the trigger.
The full code is in the GHE-ADO-Automation repo, so I'll stick to the interesting parts here. The uses paths point at my copy, change them to wherever you put yours.
The tenant ID (AZURE_TENANTID) and client ID (AZURE_DEVOPS_CLIENTID) are organisation variables, and the client secret (AZURE_DEVOPS_SECRET) is an organisation secret. Composite actions can't read the vars or secrets contexts, so the values are passed in as inputs.
# .github/actions/ado-auth/action.yml
name: Azure DevOps Authentication
description: Authenticate to Azure DevOps using an Entra service principal
inputs:
client-id:
description: Entra application client ID
required: true
tenant-id:
description: Entra tenant ID
required: true
client-secret:
description: Entra application client secret
required: true
outputs:
ado-token:
description: Azure DevOps access token
value: ${{ steps.token.outputs.ado-token }}
runs:
using: composite
steps:
- name: Get Azure DevOps access token
id: token
shell: bash
env:
CLIENT_ID: ${{ inputs.client-id }}
CLIENT_SECRET: ${{ inputs.client-secret }}
TENANT_ID: ${{ inputs.tenant-id }}
run: |
RESPONSE=$(curl --fail-with-body --silent \
--request POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=${CLIENT_ID}" \
--data-urlencode "client_secret=${CLIENT_SECRET}" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scope=https://app.vssps.visualstudio.com/.default" \
"https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token")
TOKEN=$(echo "$RESPONSE" | jq -r '.access_token')
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
echo "Failed to acquire Azure DevOps access token"
exit 1
fi
echo "::add-mask::$TOKEN"
echo "ado-token=$TOKEN" >> "$GITHUB_OUTPUT"
The scope is what gets you a token for Azure DevOps. The other line to keep is ::add-mask::, which stops the token appearing in logs.
The reusable workflow then does the useful part. It takes the project URL, pipeline name, artefact name, tag and version as inputs, with an optional name for an EF Core migrations bundle.
# .github/workflows/trigger-ado.yml (inputs trimmed)
jobs:
trigger-ado:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Get Azure DevOps access token
uses: MThomas564/GHE-ADO-Automation/.github/actions/ado-auth@v1
id: ado-auth
with:
client-id: ${{ vars.AZURE_DEVOPS_CLIENTID }}
client-secret: ${{ secrets.AZURE_DEVOPS_SECRET }}
tenant-id: ${{ vars.AZURE_TENANTID }}
- name: Build pipeline variables
id: variables
shell: bash
env:
ARTEFACT_NAME: ${{ inputs.artefact-name }}
TAG: ${{ inputs.tag }}
VERSION: ${{ inputs.version }}
MIGRATIONS_ARTEFACT_NAME: ${{ inputs.migrations-artefact-name }}
run: |
json=$(jq -cn \
--arg artefact "$ARTEFACT_NAME" \
--arg tag "$TAG" \
--arg version "$VERSION" \
--arg migrations "$MIGRATIONS_ARTEFACT_NAME" \
'{"artefact-name": $artefact, "tag": $tag, "version": $version}
+ (if $migrations != "" then {"migrations-artefact-name": $migrations} else {} end)')
echo "json=$json" >> "$GITHUB_OUTPUT"
- name: Trigger ADO
uses: Azure/pipelines@v1.2
with:
azure-devops-project-url: ${{ inputs.azure-devops-project-url }}
azure-pipeline-name: ${{ inputs.azure-pipeline-name }}
azure-devops-token: ${{ steps.ado-auth.outputs.ado-token }}
azure-pipeline-variables: ${{ steps.variables.outputs.json }}
The token is requested and used in the same job. That's deliberate, GitHub won't pass a masked value between jobs as an output. From there it goes into azure-devops-token, exactly where the PAT used to go, and the release details are passed to ADO as pipeline variables.
All an application repo needs is something like this.
jobs:
deploy:
needs: release
uses: MThomas564/GHE-ADO-Automation/.github/workflows/trigger-ado.yml@v1
with:
azure-devops-project-url: https://dev.azure.com/contoso/Payments
azure-pipeline-name: payments-api-deploy
artefact-name: payments-api.zip
tag: ${{ needs.release.outputs.tag }}
version: ${{ needs.release.outputs.version }}
secrets: inherit
We use secrets: inherit rather than passing the secret by name. If the secret is renamed or the workflow needs another one, the change happens in the shared workflow and none of the callers need touching. The trade off is that the shared workflow can read every secret available to the caller, not only this one, so be strict about who can change it and who can move the v1 tag.
One thing to be clear on, a reusable workflow is not a security boundary. Any workflow in a repo that can read the organisation secret could use it directly. If you can limit the secret to selected repos, do. In our case every repo in the organisation needs to deploy this way, so it's available to all of them. That's permissive, which makes what the app can do in ADO the thing to control. Keep its permissions narrow, and keep your approvals and checks on the ADO side, where the people who own deployment can manage them.
Organisation variables and secrets stop at the organisation, so each one using this needs its own set, with the same names for the shared workflow to find them.
ADO to GHE: a GitHub App
Going the other way, ADO needs to pull the immutable release from GHE. There's a built in Download GitHub Release task, but it doesn't support the right service connection type for GHE, particularly with data residency. At the time of writing there's an open issue for it.
So, as I mentioned last time, we use a custom script, and that script needs a credential passing in. That used to be a PAT, and getting rid of it is one of the main points of all this. A GitHub App is what replaces it.
Our app has one job, so it has read only access to contents, plus the read only metadata permission that GitHub makes mandatory. Contents is enough to download release assets. It can't push code, change settings or touch pull requests. We then install it into the organisation that owns the repos, with access to all repositories, which includes any created later. We're mid migration and expect most, if not all, of them to be deployed this way, so it saves us managing a list while things are moving. It's widely scoped, and we'd like to tighten that up as the migration completes.
Again, this is written once, as a stage template in a shared repo. A single PowerShell step signs a JSON Web Token (JWT) with the app's private key, uses it to find the installation, then swaps it for an installation access token, which expires after an hour. The same step then finds the release by its tag and downloads the assets, and the template publishes them as a pipeline artifact for the deployment stages.
This is the part that asks for the token, with the error handling trimmed out.
$repositoryName = $env:GHE_REPOSITORY.Split('/')[1]
$tokenRequest = @{
repositories = @($repositoryName)
permissions = @{ contents = 'read' }
} | ConvertTo-Json -Compress
$tokenResponse = Invoke-RestMethod -Method Post `
-Uri "$apiBase/app/installations/$($installation.id)/access_tokens" `
-Headers $appHeaders -ContentType 'application/json' -Body $tokenRequest
Note the repositories and permissions in the request body. The installation might cover lots of repos, but each token is cut down to the one this pipeline is deploying. The token never leaves that step, it isn't saved to a pipeline variable for something else to pick up.
The private key is the PEM file GitHub gives you. Its contents are copied straight into a secret variable in a variable group, with no conversion needed, and the script never writes the key to disk on the agent. We intend to move it to Key Vault as our migration moves us onto Managed DevOps Pools, but we aren't there yet. Doing it now would mean opening up the vault's networking more than we'd like, and for us that's currently a higher risk than the variable group.
Each ADO project that deploys this way needs a variable group in its library, which we've called ghe-automation, holding the app's GHE_APP_CLIENT_ID and GHE_APP_PRIVATE_KEY, with the key marked as secret. The catch is a copy of the key in every project, and each one needs updating when it's rotated.
A deployment pipeline then references the template, and its own stages depend on GitHubRelease.
trigger: none
pr: none
resources:
repositories:
- repository: adoTemplates
type: git
name: GHE-ADO-Automation
ref: refs/heads/main
variables:
- group: ghe-automation
stages:
- template: /ado/templates/fetch-ghe-release.yml@adoTemplates
parameters:
gheHost: '<subdomain>.ghe.com'
gheRepository: contoso/payments-api
A quick note on gheHost. GitHub's docs point you at api.<subdomain>.ghe.com for the API, but weirdly we haven't needed it. We pass the plain <subdomain>.ghe.com domain, the template adds /api/v3, and it works.
The host and repository are set in the pipeline YAML, and the template deliberately gives neither a default. What GHE passes across is the tag, version and artefact names, so queuing a run doesn't let you choose which repo the token is for. There's a full example with Dev, Test and Prod stages in the repo, where release candidates stop after Dev.
What you're still looking after
This doesn't get you to zero secrets. There's a client secret held in GHE and a private key available to ADO. The client secret will expire, so someone needs to own its rotation. The private key is the one to watch. Scoping each token doesn't limit the key itself, so whoever holds it can read every repo the app is installed on, and you should limit which pipelines can use it. It also won't rotate itself, because GitHub App keys don't expire and have to be revoked manually. GitHub recommends keeping it in a key vault and using the vault to do the signing, so the key never reaches the pipeline at all.
What's changed is what those secrets are. Neither belongs to a person, neither can be used directly against the thing you're trying to reach without first being exchanged for a token, and the access on each side belongs to the integration, so you can see it and cut it down. The logic that uses them is also written once, so when flexible federated credentials support GHE.com (and I hope they do), most of the work to drop the client secret is in the composite action and reusable workflow. Each calling repo will still need a small change to grant id-token: write.
If you've found a way to get this working on GHE.com without any secrets, I'd love to hear it. Feel free to reach out on LinkedIn.
Top comments (0)