|
| 1 | +--- |
| 2 | +title: npm-stage |
| 3 | +section: 1 |
| 4 | +description: Stage packages for publishing |
| 5 | +--- |
| 6 | + |
| 7 | +### Synopsis |
| 8 | + |
| 9 | +<!-- AUTOGENERATED USAGE DESCRIPTIONS --> |
| 10 | + |
| 11 | +### Description |
| 12 | + |
| 13 | +Staged publishing allows package maintainers to require proof-of-presence |
| 14 | +for all publishes. Proof-of-presence is where a human is involved, |
| 15 | +interjects, and provides authentication (2FA) during an action β in this |
| 16 | +case, publishing an npm package. |
| 17 | + |
| 18 | +Typically when maintainers use automated workflows to publish, |
| 19 | +proof-of-presence is lacking as there's no convenient way to interject the |
| 20 | +process and provide 2FA, as is the case for publishing with a granular |
| 21 | +access token with bypass and the trusted publishing flow. Staged publishing |
| 22 | +allows users to have their automated workflows stage a package without a 2FA |
| 23 | +prompt, deferring the act of 2FA, allowing the maintainer to approve the |
| 24 | +staged package and publish at a later point. |
| 25 | + |
| 26 | +The `npm stage publish` command packs the current working directory and |
| 27 | +places that version of the package into the registry in a state where it's |
| 28 | +not available for public access, allowing maintainers to approve the package |
| 29 | +at a later point in time. The act of staging does not prompt for 2FA and can be done with any token |
| 30 | +type, the act of approving will. |
| 31 | + |
| 32 | +Key behaviors: |
| 33 | + |
| 34 | +* Staged packages share the same semver version unique index as published |
| 35 | + packages β you cannot publish a version that already exists as a staged |
| 36 | + version for that package. |
| 37 | +* You can still publish packages normally while you have staged packages |
| 38 | + pending. |
| 39 | +* You can stage multiple versions of the same package. |
| 40 | +* `npm stage publish` has parity with `npm publish` and will respect |
| 41 | + `"private": true` in `package.json`, refusing to stage the package. |
| 42 | + |
| 43 | +### Prerequisites |
| 44 | + |
| 45 | +Before using `npm stage` commands, ensure the following requirements are met: |
| 46 | + |
| 47 | +* **Write permissions on the package:** You must have write access to the |
| 48 | + package you're configuring. |
| 49 | +* **Package must exist:** The package you're configuring must already exist |
| 50 | + on the npm registry. |
| 51 | +* **2FA enabled on your account:** Commands that require 2FA will prompt you |
| 52 | + to authenticate. If you don't already have 2FA enabled on your account, |
| 53 | + you must enable it before using these commands. |
| 54 | + |
| 55 | +### Subcommands |
| 56 | + |
| 57 | +* `npm stage publish [<package-spec>]` - Stage a package for publishing |
| 58 | +* `npm stage list [<package-spec>]` - List all staged package versions |
| 59 | +* `npm stage view <stage-id>` - View details of a specific staged package |
| 60 | +* `npm stage approve <stage-id>` - Approve a staged package for publishing |
| 61 | +* `npm stage reject <stage-id>` - Reject a staged package |
| 62 | +* `npm stage download <stage-id>` - Download the tarball for inspection |
| 63 | + |
| 64 | +### 2FA Requirements by Subcommand |
| 65 | + |
| 66 | +| Command | Requires 2FA | Notes | |
| 67 | +| --- | --- | --- | |
| 68 | +| `npm stage publish` | No | Designed for automated workflows; defers 2FA to approval | |
| 69 | +| `npm stage list` | No | View staged packages | |
| 70 | +| `npm stage view` | No | View staged package details | |
| 71 | +| `npm stage approve` | Yes | Prompts for 2FA to publish the staged package | |
| 72 | +| `npm stage reject` | Yes | Prompts for 2FA to permanently remove the staged package | |
| 73 | +| `npm stage download` | No | Downloads the tarball for local inspection | |
| 74 | + |
| 75 | +### Tag Behavior |
| 76 | + |
| 77 | +The `--tag` flag follows the same logic as `npm publish`. If no tag is |
| 78 | +provided, the `latest` tag is used by default. For pre-release versions |
| 79 | +(e.g., `1.0.0-beta.1`) and non-latest semver versions, the tag must be |
| 80 | +explicitly provided β otherwise the CLI will error, just as `npm publish` |
| 81 | +would. |
| 82 | + |
| 83 | +The tag is an immutable property of the staged package. Once a package is |
| 84 | +staged with a given tag, the tag cannot be changed. If you need to stage the |
| 85 | +same version with a different tag, you must first reject the existing staged |
| 86 | +package using `npm stage reject` and then re-stage it with the desired tag. |
| 87 | + |
| 88 | +### Token Behavior |
| 89 | + |
| 90 | +The key difference with staged publishing is that `npm stage publish` never |
| 91 | +requires a 2FA prompt, regardless of token type. This is what makes it |
| 92 | +suitable for automated workflows. The goal of `npm stage publish` is |
| 93 | +deferring proof-of-presence to a later point in time. |
| 94 | + |
| 95 | +| Token Type | `npm stage publish` | `npm publish` | |
| 96 | +| --- | --- | --- | |
| 97 | +| GAT with bypass | Can stage | Can publish (if allowed by package publishing access) | |
| 98 | +| GAT without bypass | Can stage | 2FA prompt (if allowed by package publishing access) | |
| 99 | +| Session token | Can stage | 2FA prompt | |
| 100 | +| Trust token (OIDC) | Can stage (if allowed) | Can publish (if allowed) | |
| 101 | + |
| 102 | +### Trust Relationship Permissions |
| 103 | + |
| 104 | +With staged publishing, trust relationships now support granular command |
| 105 | +permissions. Shortlived tokens issued through trust relationships can only be |
| 106 | +used with `npm stage publish` and `npm publish`. Shortlived tokens cannot run |
| 107 | +`npm stage` subcommands. |
| 108 | + |
| 109 | +`npm trust <provider>` supports `--allow-publish` and `--allow-stage-publish` |
| 110 | +to control which commands are available through each trust relationship. |
| 111 | + |
| 112 | +### Best Practices |
| 113 | + |
| 114 | +**Note:** The addition of staged publishing does not make your account or org |
| 115 | +more secure. Maintainers must still use the best practices listed below. |
| 116 | + |
| 117 | +1. **Delete Granular Access Tokens (GAT) with bypass 2FA enabled.** |
| 118 | + Now with staged publishing, we've eliminated the need for a GAT token |
| 119 | + that can bypass 2FA. We encourage you to delete all your tokens with |
| 120 | + bypass enabled and switch to using a trust relationship in your automated |
| 121 | + workflows, or create a GAT without bypass and use `npm stage publish`. |
| 122 | + |
| 123 | +2. **Disallow tokens from publishing at the package level.** |
| 124 | + All packages have their own access controls under "package access" |
| 125 | + allowing packages to be published with bypass tokens, which is no longer |
| 126 | + a necessity. We encourage you to select "Require two-factor |
| 127 | + authentication and disallow tokens (recommended)" for all your packages |
| 128 | + on the package access page. |
| 129 | + |
| 130 | +3. **Configure trust relationship permissions to prevent `npm publish`.** |
| 131 | + We encourage you to only enable `npm stage publish` on your trust |
| 132 | + relationships and disable `npm publish`. |
| 133 | + |
| 134 | +### Configuration |
| 135 | + |
| 136 | +<!-- AUTOGENERATED CONFIG DESCRIPTIONS --> |
| 137 | + |
| 138 | +### See Also |
| 139 | + |
| 140 | +* [npm publish](/commands/npm-publish) |
| 141 | +* [npm unpublish](/commands/npm-unpublish) |
| 142 | +* [npm trust](/commands/npm-trust) |
0 commit comments