Reputation: 4868
I have some Circle workflows that automatically publish npm packages. Is there any way to integrate two factor authentication into that flow?
I imagine that all of the test/build steps would run and then hold before actually publishing and wait for a one time code to be input. Is this possible?
Upvotes: 4
Views: 765
Reputation: 3062
It is possible if you want to use a little more services. Using a self-hosted Hashicorp Vault, you can enable TOTP and store your secret key given by npm CLI when you enable 2FA for auth-and-writes
.
When you got that, you can call your Vault server to provide you the OTP needed to publish and give it to the npm publish
command with --otp
option.
For more details, you can read this article, How to deploy npm package with 2FA enabled on write. This article gives an example with Travis, but it should apply to CircleCI without any major changes. The big difference should be how to encrypt your secrets (npm token, Vault token, etc) within your configuration.
Upvotes: 0
Reputation: 33
I have just make a test about how to publish with 2FA on npmjs and the steps to publish correctly are the following:
I don't know if it is the best process, but that works for me with recently tokens invalidation.
EDIT: I let here my example repo, but package have been unpublished from npmjs to not make noise: https://github.com/sergiohgz/test-publish-2fa-circleci
Upvotes: 1