NPM-TRUST(1)

NAME
npm-trust

Synopsis
<!-- AUTOGENERATED USAGE DESCRIPTIONS -->.SH Prerequisites

Before using npm trust commands, ensure the following requirements are met:

    •   npm version: npm@11.10.0 or above is required. Use npm install -g npm@^11.10.0 to update if needed.

    •   Write permissions on the package: You must have write access to the package you're configuring.

    •   2FA enabled on account: Two-factor authentication must be enabled at the account level. Even if it's not currently enabled, you must enable it to use trust commands.

    •   Supported authentication methods: Granular Access Tokens (GAT) with the bypass 2FA option are not supported. Legacy basic auth (username and password) credentials will not work for trust commands or endpoints.

    •   Package must exist: The package you're configuring must already exist on the npm registry.

Description

Configure trust relationships between npm packages and CI/CD providers using OpenID Connect (OIDC). This is the command-line equivalent of managing trusted publisher configurations on the npm website.

For a comprehensive overview of trusted publishing, see the npm trusted publishers documentation.

The [package] argument specifies the package name. If omitted, npm will use the name from the package.json in the current directory.

Each trust relationship has its own set of configuration options and flags based on the OIDC claims provided by that provider. OIDC claims come from the CI/CD provider and include information such as repository name, workflow file, or environment. Since each provider's claims differ, the available flags and configuration keys are not universal—npm matches the claims supported by each provider's OIDC configuration. For specific details on which claims and flags are supported for a given provider, use npm trust <provider> --help.

Permissions

When creating a trust relationship, you must specify at least one permission flag to indicate which operations the trusted publisher is allowed to perform:

    •   --allow-publish: Allows the trusted publisher to run npm publish for the package.

    •   --allow-stage-publish: Allows the trusted publisher to run npm stage for the package. The alias --allow-staged-publish is also accepted.

At least one of these flags is required when creating a trust configuration. You can specify both to grant both permissions.

Provider Options

The required options depend on the CI/CD provider you're configuring. Detailed information about each option is available in the managing trusted publisher configurations section of the npm documentation. If a provider is repository-based and the option is not provided, npm will use the repository.url field from your package.json, if available.

Currently, the registry only supports one configuration per package. If you attempt to create a new trust relationship when one already exists, it will result in an error. To replace an existing configuration:

    •   Use npm trust list [package] to view the ID of the existing trusted publisher

    •   Use npm trust revoke --id <id> [package] to remove the existing configuration

    •   Then create your new trust relationship

Bulk Usage

For maintainers managing a large number of packages, you can configure trusted publishing in bulk using bash scripting. Create a loop that iterates through package names and their corresponding configuration details, executing the npm trust <provider> command with the --yes flag for each package.

The first request will require two-factor authentication. During two-factor authentication, you'll see an option on the npm website to skip two-factor authentication for the next 5 minutes. Enabling this option will allow subsequent npm trust <provider> commands to proceed without two-factor authentication, streamlining the bulk configuration process.

We recommend adding a 2-second sleep between each call to avoid rate limiting. With this approach, you can configure approximately 80 packages within the 5-minute two-factor authentication skip window.

Configuration
<!-- AUTOGENERATED CONFIG DESCRIPTIONS -->.SH See Also

    •   npm publish

    •   npm token

    •   npm access

    •   npm config

    •   npm registry