Use private sources
Use this page when your packages live in private repositories or on an
enterprise host. Public packages on github.com need no setup. For anything
else, APM reuses credentials you already have (the GitHub CLI, the Azure CLI,
your git credential helper) or one environment variable.
Start with apm doctor
Section titled “Start with apm doctor”apm doctorapm auth github.comapm doctor checks git, network access and whether a token is present.
apm auth HOST names the credential APM will use for a GitHub or GitLab host
and walks you through creating one if there is none:
[+] github.com: using credential from GH_TOKEN.[i] Add --check to validate it against the API.How APM picks a credential
Section titled “How APM picks a credential”For a public github.com package, APM tries without credentials. On a 401,
403 or 404, and for every other host, it walks the chain for that kind of
host and uses the earliest credential it finds:
| Host | Credential order |
|---|---|
github.com, *.ghe.com, GitHub Enterprise Server | GITHUB_APM_PAT_<ORG>, GITHUB_APM_PAT, GITHUB_TOKEN, GH_TOKEN, gh auth token, git credential helper |
Azure DevOps Services (dev.azure.com, *.visualstudio.com) | ADO_APM_PAT, Azure CLI (az) sign-in, git credential helper |
| Azure DevOps Server | ADO_APM_PAT, git credential helper |
gitlab.com and registered GitLab hosts | GITLAB_APM_PAT, GITLAB_TOKEN, git credential helper |
| Any other host (Bitbucket, Gitea, your own server) | git credential helper |
github.com and every *.ghe.com host share one chain: GITHUB_APM_PAT
(and GITHUB_TOKEN, GH_TOKEN) is sent to github.com and to any
*.ghe.com host a dependency names. There is no per-host token today;
GITHUB_APM_PAT_<ORG> scopes a token to one organization name on any of
these hosts. A GitHub Enterprise Server host joins the chain only when the
GITHUB_HOST environment variable names it.
To keep these tokens on one host, set APM_STRICT_HOST_CREDENTIALS=1.
GITHUB_APM_PAT_<ORG>, GITHUB_APM_PAT, GITHUB_TOKEN and GH_TOKEN then
reach only the configured host (GITHUB_HOST, else github.com). For any
other github.com or *.ghe.com host, APM runs gh auth token and
git credential fill without those variables, and warns once naming the host.
Sign in for that host with gh auth login --hostname <host> or a credential
helper. Values 0, false, no, off or empty keep the default; any value
APM does not recognise turns strict mode on and prints a warning.
A token for one kind of host is never sent to another: a GITHUB_TOKEN set
in CI never reaches GitLab. APM sends credentials as an HTTPS header, never
in a URL, and does not store them. Every variable:
Environment variables.
GitHub and GitHub Enterprise
Section titled “GitHub and GitHub Enterprise”If gh repo clone contoso/review-skills works, apm install works: APM asks
the GitHub CLI for its token. For scripts and CI, set a token instead:
export GITHUB_APM_PAT=github_pat_...Create a fine-grained token with Contents: Read and Metadata: Read, owned by the organization that owns the repositories (a token owned by your user cannot read organization repositories). Authorize it for SSO if the organization requires it.
When packages come from several organizations, set one token each. The suffix is the organization name in upper case with hyphens as underscores:
export GITHUB_APM_PAT_CONTOSO=github_pat_...export GITHUB_APM_PAT_CONTOSO_LABS=github_pat_...GitHub Enterprise Cloud with data residency (*.ghe.com) has no public
repositories, so APM goes straight to credentials. Write the host in the
reference: apm install contoso.ghe.com/platform/review-skills.
GitHub Enterprise Server: make shorthand resolve to your server with
default_host: in apm.yml (committed) or GITHUB_HOST (per machine), and
write github.com/owner/repo for packages on GitHub:
default_host: github.contoso.comdependencies: apm: - platform/review-skills - github.com/microsoft/apm-sample-package#v1.0.0The same works from one command, for example for user scope. Keep
GITHUB_HOST set whenever you reinstall: APM writes the server’s entries as
shorthand and keeps the github.com/ prefix on the others:
export GITHUB_HOST=github.contoso.comexport GITHUB_APM_PAT_PLATFORM=ghp_... # token for the server's orgapm install --global \ github.contoso.com/platform/internal-skills/.agents/skills/jdk-installer#v2.1.0 \ github.com/contoso-oss/android-skills/performance/analyzer#mainEach package keeps its own host, subpath and ref in apm.yml and its host
and commit in apm.lock.yaml.
Enterprise Managed User tokens cannot read public github.com repositories;
public packages install without one.
Multi-account Git Credential Manager
Section titled “Multi-account Git Credential Manager”If you use several GitHub accounts, let Git Credential Manager pick one per organization. APM sends the repository path with each request:
git config --global credential.useHttpPath truegit config --global credential.https://github.com/contoso.username ana-contosoIf an account picker still appears, run apm install --verbose and compare
the path= APM logs with your config entry.
Azure DevOps
Section titled “Azure DevOps”Sign in with the Azure CLI, or set a personal access token with Code: Read:
az login --tenant <tenant-id>apm install dev.azure.com/contoso/platform/review-skillsexport ADO_APM_PAT=...References use org/project/repo; use the _git form for a subfolder and
encode spaces as %20:
apm install dev.azure.com/contoso/platform/_git/review-skills/skills/security#v2.0.0APM tries ADO_APM_PAT, then an Entra ID token from az, then your git
credential helper. A rejected PAT falls back to az with a warning to unset
the stale variable. When the credential came from Git Credential Manager, APM
reports success or a 401 back to it, so an expired credential is replaced.
Azure DevOps has no anonymous access; if every step fails, the error lists
what each one returned.
On-prem Azure DevOps Server
Section titled “On-prem Azure DevOps Server”Register the host so APM uses the Azure DevOps chain:
export ADO_HOST=ado.contoso.com # or APM_ADO_HOSTS=host1,host2export ADO_APM_PAT=...apm install ado.contoso.com/DefaultCollection/Platform/_git/review-skillsSet hostnames, with no scheme or port; put a non-default port in the dependency
URL. Azure DevOps Server does not use az. A server under a path prefix such
as /tfs/ is not supported.
GitLab (SaaS and self-managed)
Section titled “GitLab (SaaS and self-managed)”export GITLAB_APM_PAT=glpat-...Use a token with read_repository scope. gitlab.com is recognized
automatically. Register a self-managed host with GITLAB_HOST (one host) or
APM_GITLAB_HOSTS (comma-separated) so it gets GitLab tokens and API calls.
For a single dependency on an unrecognized host, type: gitlab on its
object-form entry selects GitLab’s API without sending it your tokens.
Other git hosts and SSH
Section titled “Other git hosts and SSH”For Bitbucket, Gitea or your own server, APM uses the same git credential
helper as your shell. If git clone https://git.contoso.com/team/repo.git
works, apm install works.
For an SSH dependency (git@host:org/repo.git), APM uses your ssh-agent and
~/.ssh/config without prompting, so load the key beforehand (ssh-add). Prefer
SSH for all shorthand with --ssh or apm config set prefer-ssh true; see
Transport selection.
Generic marketplace Git transport
Section titled “Generic marketplace Git transport”APM downloads marketplaces from generic git hosts without prompting:
| Remote | Credentials |
|---|---|
| HTTPS | Your git credential helper; platform token variables are removed |
| HTTP | None |
| SSH | Your key, no tokens, 30-second connect timeout |
| GitHub, GitLab, Azure DevOps | The host’s chain above |
Private hosted marketplace catalogs
Section titled “Private hosted marketplace catalogs”A hosted marketplace.json that requires a login uses its own variables,
never your git, registry or .netrc credentials:
| Variable | Sent as |
|---|---|
APM_MARKETPLACE_TOKEN_<NAME> | Authorization: Bearer <token> |
APM_MARKETPLACE_USER_<NAME> + APM_MARKETPLACE_PASS_<NAME> | Authorization: Basic <base64(user:pass)> |
<NAME> is the --name you registered, normalized like registry names
(corp-main -> CORP_MAIN). Bearer wins when both are set.
export APM_MARKETPLACE_TOKEN_CORP=your_tokenapm marketplace add https://catalog.example.com/team/marketplace.json --name corpThe credential stays within the registered URL’s origin, directory and query on every redirect and never authenticates package downloads. A 401, 403 or sign-in redirect fails with the variable to set. See Private hosted catalogs.
Git URL rewrite safety
Section titled “Git URL rewrite safety”APM honors your url.<base>.insteadOf rules when they stay on the same host,
such as HTTPS to SSH or a local mirror. It refuses rewrites that add
credentials, downgrade to http:// or git://, or change host. To find the
rule involved:
git config --show-origin --get-regexp '^url\..*\.insteadOf$'If Git cannot read its configuration, APM refuses too. The error shows Git’s first diagnostic line, with credentials redacted, and the config file Git names. To list every config file and its origin:
git config --show-origin --listCorporate CA and proxies
Section titled “Corporate CA and proxies”If your network inspects TLS, add your company’s CA to APM’s HTTPS trust. It keeps the operating system’s roots:
export APM_EXTRA_CA_BUNDLE=/path/to/corporate-ca.pemGit uses its own settings (git config http.sslCAInfo). Proxy and
certificate details: SSL / TLS issues.
To install through an Artifactory or other package proxy, see
Install through a proxy or offline.
TLS-inspecting proxy blocks the anonymous attempt
Section titled “TLS-inspecting proxy blocks the anonymous attempt”The initial, credential-free attempt to github.com can fail at TLS (for
example CRYPT_E_NO_REVOCATION_CHECK on Windows) while a plain git clone
works. Send your credential on that attempt instead:
apm install --auth-firstMake it permanent with APM_GITHUB_AUTH_FIRST=1 or
apm config set github-auth-first true. Other hosts are not affected.
Verify
Section titled “Verify”apm auth github.com --checkapm install --verbose--check validates the token against the host’s API. --verbose logs which
source each host used, for example token from ADO_APM_PAT.
When things go wrong
Section titled “When things go wrong”- 404 for a repository you can open in the browser. The token cannot see it: check the token’s owner, repository access and SSO authorization.
- Rate limited on
github.com. Set any validGITHUB_TOKEN. - Credential helper times out. Raise
APM_GIT_CREDENTIAL_TIMEOUT(seconds, default 60, maximum 180). - SSH hangs on a corporate network. Port 22 is blocked; use
--https. - More: Install failures.
Copyright (c) Microsoft Corporation. General documentation: CC-BY-4.0. Software, code examples and OpenAPM: Apache-2.0. See scope and exclusions.