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

Allow rotating the password non-interactively #11094

Merged
merged 2 commits into from Oct 24, 2022
Merged

Conversation

nicklasfrahm
Copy link

Signed-off-by: Nicklas Frahm nilfr@vestas.com

Description

Fixes #11083. Also fixes some deprecation warnings within the passphrase package.

Checklist

  • I have tested this locally using:
    export PULUMI_CONFIG_PASSPHRASE=test
    pulumi stack init -s test
    echo "hello" | pulumi stack change-secrets-provider passphrase
    export PULUMI_CONFIG_PASSPHRASE=hello
    echo "test" | pulumi stack change-secrets-provider passphrase
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

Signed-off-by: Nicklas Frahm <nilfr@vestas.com>
@github-actions
Copy link

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Oct 20, 2022

Changelog

[uncommitted] (2022-10-21)

Features

  • [cli] Allow rotating the passphrase non-interactively

@RobbieMcKinstry
Copy link
Contributor

RobbieMcKinstry commented Oct 20, 2022

/run-acceptance-tests
Please view the results of the acceptance tests Here

Copy link
Contributor

@RobbieMcKinstry RobbieMcKinstry left a comment

Choose a reason for hiding this comment

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

LGTM! One small change requested, otherwise I'm good with it! :)

@RobbieMcKinstry
Copy link
Contributor

Also, I just want to say thanks, @nicklasfrahm. I appreciate you taking the time to fix this issue (especially so quickly after it was just opened)! 🎉

@github-actions
Copy link

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

@nicklasfrahm
Copy link
Author

@RobbieMcKinstry Could you give this another look?

@Frassle
Copy link
Member

Frassle commented Oct 24, 2022

bors merge

bors bot added a commit that referenced this pull request Oct 24, 2022
11094: Allow rotating the password non-interactively r=Frassle a=nicklasfrahm

Signed-off-by: Nicklas Frahm <nilfr@vestas.com>

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Fixes #11083. Also fixes some deprecation warnings within the `passphrase` package.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have tested this locally using:
  ```bash
  export PULUMI_CONFIG_PASSPHRASE=test
  pulumi stack init -s test
  echo "hello" | pulumi stack change-secrets-provider passphrase
  export PULUMI_CONFIG_PASSPHRASE=hello
  echo "test" | pulumi stack change-secrets-provider passphrase
  ```
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Nicklas Frahm <nilfr@vestas.com>
@bors
Copy link
Contributor

bors bot commented Oct 24, 2022

Build failed:

@Frassle
Copy link
Member

Frassle commented Oct 24, 2022

bors retry

bors bot added a commit that referenced this pull request Oct 24, 2022
11094: Allow rotating the password non-interactively r=Frassle a=nicklasfrahm

Signed-off-by: Nicklas Frahm <nilfr@vestas.com>

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Fixes #11083. Also fixes some deprecation warnings within the `passphrase` package.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have tested this locally using:
  ```bash
  export PULUMI_CONFIG_PASSPHRASE=test
  pulumi stack init -s test
  echo "hello" | pulumi stack change-secrets-provider passphrase
  export PULUMI_CONFIG_PASSPHRASE=hello
  echo "test" | pulumi stack change-secrets-provider passphrase
  ```
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Nicklas Frahm <nilfr@vestas.com>
@bors
Copy link
Contributor

bors bot commented Oct 24, 2022

Build failed:

@Frassle
Copy link
Member

Frassle commented Oct 24, 2022

bors retry

@bors
Copy link
Contributor

bors bot commented Oct 24, 2022

Build succeeded:

@bors bors bot merged commit 4870ecd into pulumi:master Oct 24, 2022
@same-id
Copy link
Contributor

same-id commented Nov 29, 2023

I don't think this solution is good enough.
Consider this:

First run:

pulumi stack init -s test

No problem, stack created

Second run:

export PULUMI_CONFIG_PASSPHRASE=test
pulumi stack change-secrets-provider passphrase

No problem, secret newly created

Third run:

export PULUMI_CONFIG_PASSPHRASE=test
pulumi stack change-secrets-provider passphrase

passphrase had been set to the empty string.

The rotation must be more explicit.

I suggest:

Introducing PULUMI_CONFIG_ROTATE_PASSPHRASE, PULUMI_CONFIG_ROTATE_PASSPHRASE_FILE, PULUMI_CONFIG_ROTATE_PASSPHRASE_STDIN
If none provided will previously and explicitely fail with:
passphrase rotation requires an interactive terminal, or through the use of PULUMI_CONFIG_ROTATE_PASSPHRASE_STDIN=TRUE to read from stdin, PULUMI_CONFIG_ROTATE_PASSPHRASE to specify the new passphrase or PULUMI_CONFIG_ROTATE_PASSPHRASE_FILE to specify the new passphrase using a file.

@nicklasfrahm
Copy link
Author

nicklasfrahm commented Nov 29, 2023

What if we failed it, if the passphrase is empty? I also feel like it would be nice to do some of this via flags rather than ENV vars. What do you think?

Something like, --allow-empty-passphrase?

@Frassle
Copy link
Member

Frassle commented Nov 29, 2023

I'd really like to disallow empty passphrase in general but last time we did that users complained that it broke their workflows, very https://xkcd.com/1172/ feeling to that.

But we could probably disallow empty passphrases on stdin, I don't even think we need to have an opt-out to allow empty passphrases.

@nicklasfrahm
Copy link
Author

nicklasfrahm commented Nov 29, 2023

I generally prefer strongly discouraging these things and allowing opt-outs for the 1% of cases that are not the user's but the environment's fault. Phase of moon, etc.

@same-id
Copy link
Contributor

same-id commented Nov 29, 2023

For context, I reached here through a miraculous turn of events that took me forever to debug

//nolint:paralleltest // mutates environment variables
func TestChangeSecretsProviderToPassphraseNonInteractively(t *testing.T) {
	e := ptesting.NewEnvironment(t)
	e.Passphrase = "correct horse battery staple"
	defer func() {
		if !t.Failed() {
			e.DeleteEnvironment()
		}
	}()

	const stackName = "imulup"

	integration.CreateBasicPulumiRepo(e)

	e.ImportDirectory("integration/stack_outputs/nodejs")

	e.SetBackend(e.LocalURL())
	e.RunCommand(
		"pulumi", "stack", "init", stackName,
	)

	e.RunCommand("pulumi", "stack", "change-secrets-provider", "passphrase")

	e.RunCommand("pulumi", "up", "--non-interactive", "--yes", "--skip-preview")
}

This fails on pulumi up with:

STDERR: error: getting stack configuration: get stack secrets manager: incorrect passphrase

Why?

I think this code is incorrect:

        // If we're setting the secrets provider to the same provider then do a rotation.
	rotateProvider := secretsProvider == currentProjectStack.SecretsProvider ||
		// passphrase doesn't get saved to stack state, so if we're changing to passphrase see if
		// the current secrets provider is empty
		((secretsProvider == "passphrase") && (currentProjectStack.SecretsProvider == ""))

Specifically:

(secretsProvider == "passphrase") && (currentProjectStack.SecretsProvider == ""))

Since it marks this is a rotation then secret provider actually being set in the first ever change-secrets-provider is actually from stdin (empty string) and not correct horse battery staple from env var.
But then up runs with correct horse battery staple?

@same-id
Copy link
Contributor

same-id commented Nov 29, 2023

With my suggestion, if passphrase rotation is set, It would have failed in
pulumi stack change-secrets-provider passphrase with

error: Existing passphrase rotation requires either an interactive terminal, to rotate non-interactively set PULUMI_CONFIG_ROTATE_PASSPHRASE_STDIN=TRUE to read from stdin, PULUMI_CONFIG_ROTATE_PASSPHRASE to specify the new passphrase or PULUMI_CONFIG_ROTATE_PASSPHRASE_FILE to specify the new passphrase from a file.

or at least

error: Existing passphrase rotation requires either an interactive session or provide the --stdin flag to the change-secrets-provider command.

Now I see that pulumi stack change-secrets-provider passphrase fails with "Existing passphrase rotation" which allows my to catch the actual bug.

Also pulumi stack change-secrets-provider passphrase --stdin is more explicit and you can see from miles away that it will not use the envvar but will prefer stdin.

WDYT?

@nicklasfrahm
Copy link
Author

I like the option with the flag, because it is a lot less typing than all those environment variables, so it does have a certain simplicity to it.

@Frassle
Copy link
Member

Frassle commented Nov 29, 2023

Adding a flag now would be a breaking change, its much more palatable to go with erroring on empty here, still a break change but a more manageable and understandable one.

@same-id
Copy link
Contributor

same-id commented Nov 29, 2023

I think that it's still has to be explicit when read from stdin.

echo hi | pulumi stack change-secrets-provider passphrase <- may not really use "hi" as passphrase
...
echo bye | pulumi stack change-secrets-provider passphrase

First one maybe not even read the passphrase from stdin - depends if it was a rotation or not.

@same-id
Copy link
Contributor

same-id commented Nov 29, 2023

Spinned up a PR to show how it will look like:

#14698

Regardless, I do agree empty passphrases are useless, might as well not encrypt at all

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.

Allow STDIN to change passphrase
6 participants