Skip to main content

Uplinks

An uplink is a link with an external registry that provides access to external packages.

Your teampnpm add reactverdaccio:4873MERGED METADATAUPLINKSnpmjsserver2baduplinknpmjsregistry.npmjs.org200 OK Β· 142msserver2mirror.local.netTIMEOUT 100msbaduplinklocalhost:55666ECONNREFUSEDGET reactGET reactGET reactGET reactreact.jsonreact.json1 Β· Verdaccio asks every uplink for the package2 Β· Slow or broken uplinks fail fast and are skipped3 Β· Healthy answers are merged and served onceClientpnpm installverdaccio:4873MERGED METADATAnpmjsnpmjs.org200 OKserver2mirror.localTIMEOUTbaduplinklocalhostREFUSEDGET reactGET reactGET reactGET reactreact.jsonreact.json1 Β· Verdaccio asks everyuplink for the package2 Β· Slow or broken uplinks failfast and are skipped3 Β· Healthy answers are mergedand served once

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:

PropertyTypeRequiredExampleSupportDescriptionDefault
urlstringYeshttps://registry.npmjs.org/allThe registry urlnpmjs
castringNo~./ssl/client.crt'allSSL path certificateNo default
timeoutstringNo100msallset new timeout for the request30s
maxagestringNo10mallhow long cached package metadata is used before asking the uplink again, see maxage2m
fail_timeoutstringNo10malldefines max time when a request becomes a failure5m
max_failsnumberNo2alllimit maximun failure request2
http_proxystringNohttp://proxy.server.orgalldefine HTTP proxy for registry accessNo default
https_proxystringNohttps://proxy.server.orgalldefine HTTPS proxy for registry accessNo default
no_proxystringNolocalhost,127.0.0.1allcomma-separated list of hosts that should not use proxyNo default
cachebooleanNo[true,false]>= 2.1cache all remote tarballs in storagetrue
authlistNosee below>= 2.5assigns the header 'Authorization' more infodisabled
headerslistNoauthorization: "Bearer SecretJWToken=="alllist of custom headers for the uplinkdisabled
strict_sslbooleanNo[true,false]>= 3.0If true, requires SSL certificates be valid.true
agent_optionsobjectNomaxSockets: 10>= 4.0.2options for the HTTP or HTTPS Agent responsible for managing uplink connection persistence and reuse more infoNo 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: token has priority over token_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.

  1. The first request for a package fetches its metadata from the uplink and stores it, together with the time of the fetch.
  2. While that copy is younger than maxage, requests are answered from the cache and the uplink is not contacted.
  3. Once it is older, the next request asks the uplink again and sends the ETag of the cached copy. If nothing changed, the uplink answers 304 with no body and the clock restarts; otherwise the new versions are merged into the cache.
  4. 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 maxage to appear. That includes its tarball: a client that asks for it directly, for example from a lockfile, gets a 404 until the metadata is refreshed.
  • maxage: 0 turns the cache off: every metadata request asks the uplink, usually for a cheap 304.
  • Tarballs are not affected. With cache: true a tarball is downloaded once and kept; it never expires.
  • It is not an offline switch. timeout, max_fails and fail_timeout decide 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: 30m
    internal:
    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 uplinkX-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 from 10.0.0.2, the uplink receives X-Forwarded-For: 203.0.113.7, 10.0.0.2.
  • The tarball request carries no X-Forwarded-For in 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 headers as 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 auth are 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 trustProxy setting 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:

UnitMeaningExampleResult
msmilliseconds500mshalf a second
sseconds30s30 seconds
mminutes2m2 minutes
hhours1h1 hour
ddays1d24 hours
wweeks2w14 days
Mmonths (30 days)1M30 days
yyears (365 days)1y365 days
noneseconds9090 seconds
  • Units are case sensitive: m is minutes and M is months.
  • Decimals are accepted: 1.5h is 90 minutes.
  • Several units can be combined, separated by spaces and from largest to smallest: 1h 30m, 1d 12h. 30m 1h and 1h 1h are rejected.
  • A value that cannot be parsed is rejected with an invalid interval error.
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 npm endpoints. Eg: verdaccio, npmjs registry, yarn registry, JFrog, Nexus and more.

  • Setting cache to false will help to save space in your hard drive. This will avoid store tarballs but 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, maxage and fail_timeout use the NGINX measurement units, see Time values.

  • When using the Helm Chart, you can use secretEnvVars to 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/registry
    cache: false
    auth:
    type: bearer
    token_env: CODEARTIFACT_AUTH_TOKEN
    strict_ssl: false
    headers:
    '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 return 404 no such file available. To recover, remove the cached package from your storage folder (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 as verdaccio-<package>. A refused off-uplink fetch (the 404 case above) is logged at warn (refused off-uplink tarball fetch), which you can alert on. Use log: { format: json } to ship these events to a log collector.