Uplinks
An uplink is a link with an external registry that provides access to external packages.
Usageβ
uplinks:
npmjs:
url: https://registry.npmjs.org/
server2:
url: http://mirror.local.net/
timeout: 100ms
server3:
url: http://mirror2.local.net:9000/
baduplink:
url: http://localhost:55666/
Here's an example of seamlessly integrating npmjs and GitHub registries using Verdaccio: How to use Verdaccio with GitHub registry
Configurationβ
You can define mutiple uplinks and each of them must have an unique name (key). They can have the following properties:
| Property | Type | Required | Example | Support | Description | Default |
|---|---|---|---|---|---|---|
| url | string | Yes | https://registry.npmjs.org/ | all | The registry url | npmjs |
| ca | string | No | ~./ssl/client.crt' | all | SSL path certificate | No default |
| timeout | string | No | 100ms | all | set new timeout for the request | 30s |
| maxage | string | No | 10m | all | how long cached package metadata is used before asking the uplink again, see maxage | 2m |
| fail_timeout | string | No | 10m | all | defines max time when a request becomes a failure | 5m |
| max_fails | number | No | 2 | all | limit maximun failure request | 2 |
| http_proxy | string | No | http://proxy.server.org | all | define HTTP proxy for registry access | No default |
| https_proxy | string | No | https://proxy.server.org | all | define HTTPS proxy for registry access | No default |
| no_proxy | string | No | localhost,127.0.0.1 | all | comma-separated list of hosts that should not use proxy | No default |
| cache | boolean | No | [true,false] | >= 2.1 | cache all remote tarballs in storage | true |
| auth | list | No | see below | >= 2.5 | assigns the header 'Authorization' more info | disabled |
| headers | list | No | authorization: "Bearer SecretJWToken==" | all | list of custom headers for the uplink | disabled |
| strict_ssl | boolean | No | [true,false] | >= 3.0 | If true, requires SSL certificates be valid. | true |
| agent_options | object | No | maxSockets: 10 | >= 4.0.2 | options for the HTTP or HTTPS Agent responsible for managing uplink connection persistence and reuse more info | No default |
Auth propertyβ
The auth property allows you to use an auth token with an uplink. Using the default environment variable:
uplinks:
private:
url: https://private-registry.domain.com/registry
auth:
type: bearer
token_env: true # by defaults points to the environment variable `NPM_TOKEN`
or via a specified custom environment variable:
uplinks:
private:
url: https://private-registry.domain.com/registry
auth:
type: bearer
token_env: FOO_TOKEN # override the default `NPM_TOKEN` by a custom one
token_env: FOO_TOKEN internally will use process.env['FOO_TOKEN']
or by directly specifying a token oh the configuration file (not recommended by security corcerns):
uplinks:
private:
url: https://private-registry.domain.com/registry
auth:
type: bearer
token: 'token'
Note:
tokenhas priority overtoken_env
How maxage worksβ
maxage is how long Verdaccio trusts the metadata of a package (its list of versions and dist-tags) cached from an uplink before asking that uplink again. It is set per uplink and counted per package.
- The first request for a package fetches its metadata from the uplink and stores it, together with the time of the fetch.
- While that copy is younger than
maxage, requests are answered from the cache and the uplink is not contacted. - Once it is older, the next request asks the uplink again and sends the
ETagof the cached copy. If nothing changed, the uplink answers304with no body and the clock restarts; otherwise the new versions are merged into the cache. - If the uplink cannot be reached at that point, the cached metadata is served anyway.
What follows from that:
- A version published upstream can take up to
maxageto appear. That includes its tarball: a client that asks for it directly, for example from a lockfile, gets a404until the metadata is refreshed. maxage: 0turns the cache off: every metadata request asks the uplink, usually for a cheap304.- Tarballs are not affected. With
cache: truea tarball is downloaded once and kept; it never expires. - It is not an offline switch.
timeout,max_failsandfail_timeoutdecide when Verdaccio stops trying an uplink that does not answer. - The time of the fetch is stored with the package, so restarting Verdaccio does not refresh anything.
- The check made before a publish always asks the uplink and ignores
maxage.
Choosing a valueβ
-
Keep the default (
2m) for the public registry in most setups. Installs stay fast and new versions show up within a couple of minutes. -
Raise it (
10m,1h) when many clients or CI jobs install all day and you want fewer requests to the uplink, or the uplink rate-limits you. The cost is that new upstream versions take that long to appear. -
Lower it, or use
0, for an uplink you publish to yourself, such as another private registry, when a version must be installable right after it is published. Every metadata request then waits for that uplink. -
Set it per uplink instead of looking for one value that fits all of them:
uplinks:npmjs:url: https://registry.npmjs.org/maxage: 30minternal:url: https://registry.internal.example/maxage: 0
Client address sent to uplinksβ
When a client asks for a package that Verdaccio does not have, Verdaccio asks the uplink
on the client's behalf. The uplink therefore sees the address of your Verdaccio server,
not the address of the client. To tell the uplink which client the request is for,
Verdaccio adds an X-Forwarded-For header to some of the requests it sends.
Installing a package takes two kinds of request, and they are treated differently:
| Request to the uplink | X-Forwarded-For sent by Verdaccio |
|---|---|
Metadata (GET /lodash) | the chain the client request arrived with, then the client address |
Tarball (GET /lodash/-/lodash-4.17.21.tgz) | not sent |
For example, a client at 198.51.100.4 runs npm install lodash against Verdaccio:
- With a direct connection, the metadata request reaches the uplink with
X-Forwarded-For: 198.51.100.4. - If the client reaches Verdaccio through a reverse proxy that already added
X-Forwarded-For: 203.0.113.7, and the proxy connects from10.0.0.2, the uplink receivesX-Forwarded-For: 203.0.113.7, 10.0.0.2. - The tarball request carries no
X-Forwarded-Forin either case.
The administrator of the uplink can use the header to see in the logs which client asked for which package, or to apply limits per client instead of treating everything as coming from Verdaccio.
Setting your own valueβ
A value set in the headers property of the uplink replaces the one
Verdaccio would generate, on metadata and tarball requests alike. The header name can be
written in any capitalisation.
uplinks:
private:
url: https://private-registry.domain.com/registry
headers:
x-forwarded-for: 192.0.2.10
Use this when the uplink should always see one fixed address, for instance to keep the addresses of your clients inside your network.
With http_proxy or https_proxyβ
When the uplink is reached through http_proxy or https_proxy, Verdaccio does not
generate the header, because a misconfigured proxy may reject such requests. A value set
in headers is still sent.
What to keep in mindβ
- The client address leaves your Verdaccio. Every metadata request to an uplink tells
that uplink the address of the client. If that is not acceptable, set a fixed value in
headersas shown above. - Redirects. If the uplink answers a metadata request with a redirect to another
host, Verdaccio follows it and that host receives the header too. Credentials set in
authare not sent to the other host. - The incoming chain is not verified. The part of the chain that the client sent is
forwarded as received, so a client can write anything in it. Only the last address,
which Verdaccio adds from the real connection, is reliable. The
trustProxysetting does not change what is forwarded to uplinks.
Time valuesβ
timeout, maxage and fail_timeout take a number followed by a unit, in the style of the NGINX measurement units:
| Unit | Meaning | Example | Result |
|---|---|---|---|
ms | milliseconds | 500ms | half a second |
s | seconds | 30s | 30 seconds |
m | minutes | 2m | 2 minutes |
h | hours | 1h | 1 hour |
d | days | 1d | 24 hours |
w | weeks | 2w | 14 days |
M | months (30 days) | 1M | 30 days |
y | years (365 days) | 1y | 365 days |
| none | seconds | 90 | 90 seconds |
- Units are case sensitive:
mis minutes andMis months. - Decimals are accepted:
1.5his 90 minutes. - Several units can be combined, separated by spaces and from largest to smallest:
1h 30m,1d 12h.30m 1hand1h 1hare rejected. - A value that cannot be parsed is rejected with an
invalid intervalerror.
uplinks:
npmjs:
url: https://registry.npmjs.org/
timeout: 30s
maxage: 10m
fail_timeout: 1h 30m
You Must knowβ
-
Uplinks must be registries compatible with the
npmendpoints. Eg: verdaccio, npmjs registry, yarn registry, JFrog, Nexus and more. -
Setting
cacheto false will help to save space in your hard drive. This will avoid storetarballsbut it will keep metadata in folders. -
Multiple uplinks might slow down the lookup of your packages. For each request an npm client makes, verdaccio makes 1 call to each configured uplink.
-
timeout,maxageandfail_timeoutuse the NGINX measurement units, see Time values. -
When using the Helm Chart, you can use
secretEnvVarsto inject sensitive environment variables, which can be used to configure private uplink auth. -
While trying to configure AWS CodeArtifact to be used as an uplink, it is necessary to define the
accept: */*in headers. -
An example of uplink configuration for AWS CodeArtifact is given below
uplinks:aws-codeArtifact:url: https://private-registry.domain.com/registrycache: falseauth:type: bearertoken_env: CODEARTIFACT_AUTH_TOKENstrict_ssl: falseheaders:'Accept': '*/*''Accept-Encoding': 'gzip, deflate, br''Cache-Control': 'no-cache' -
For security reasons, Verdaccio only downloads a tarball from a URL that a configured uplink actually serves. This matters for registries that host their tarballs on a separate host than the uplink URL (CDN-backed registries such as GitHub Packages or AWS CodeArtifact): if a package was cached by an older Verdaccio that did not record its internal tarball bookkeeping (
_distfiles), and that tarball is no longer stored locally, requesting it can return404 no such file available. To recover, remove the cached package from yourstoragefolder (storage/<package>) so Verdaccio re-syncs it from the uplink and rebuilds the bookkeeping. Packages whose tarballs are still on disk, or whose tarballs are served from the uplink's own host, are not affected. -
Tarball fetches to uplinks are observable through the logger. With
log: { level: http }, every outgoing tarball download is logged with its target url and the uplink it was fetched from; a tarball hosted outside any configured uplink (a CDN-backed registry) is fetched through an autogenerated proxy that appears in the logs asverdaccio-<package>. A refused off-uplink fetch (the404case above) is logged atwarn(refused off-uplink tarball fetch), which you can alert on. Uselog: { format: json }to ship these events to a log collector.