Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 2FA for npm via --otp #2076

Closed
wants to merge 1 commit into from
Closed

Conversation

rbuckton
Copy link
Contributor

@rbuckton rbuckton commented May 7, 2019

Description

This adds an --otp CLI argument to lerna publish to support publishing to NPM registries that require two-factor authentication.

Motivation and Context

It is currently possible to publish using 2FA without the --otp argument, however this requires setting an environment variable prior to calling lerna publish, and the process of setting an environment variable differs in different shells (i.e. bash, cmd, PowerShell, etc.). Providing this via an option simplifies the process and documents the capability.

How Has This Been Tested?

I've added tests to verify the --otp option is passed to npmPublish as a configuration option and have also verified that the --otp option works by publishing a monorepo to NPM using an account that requires 2FA to publish.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. (NOTE: There are tests that currently fail without this change when run on Windows).

Fixes #1091

@rbuckton
Copy link
Contributor Author

rbuckton commented May 8, 2019

@evocateur, do you have time to take a look?

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me that this solves the issue, except possibly in the case where one has already run lerna version seperately and has a very fast (or no) build for each package. I took a stab at things awhile back, but it's incomplete: https://github.com/lerna/lerna/compare/one-time-password-to-rule-them-all

lerna publish --otp 123456
```

> Please keep in mind that one-time passwords often expire within a few minutes of their generation. Please ensure adequate time for the publish process to complete.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually expire within 30 seconds, so it's not clear that this solution would be guaranteed to work in all cases (imagine per-package builds that take 2 seconds each in a repo with 30 packages to publish...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is true, until lerna has true OTP support, the only alternative is to set the NPM_CONFIG_OTP environment variable (which differs per system) and has the same downsides.

@rbuckton
Copy link
Contributor Author

Per-package OTP isn't terribly complicated with otplease in your branch, the problem is having to repeatedly enter the same OTP until a new one is needed. One way might be to maintain an in-memory cache of OTPs per registry and have otplease update that cache prior to a retry. I can tinker with something and put up a separate PR for that.

@rbuckton
Copy link
Contributor Author

Closing in favor of #2084

@rbuckton rbuckton closed this May 12, 2019
evocateur added a commit that referenced this pull request May 13, 2019
This allows a potential prompt to be skipped as long as the OTP has not expired before it is used.

Credit: @rbuckton
Fixes #2076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support 2FA --otp=123456
2 participants