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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: cli
description: Allow rotating the passphrase non-interactively
11 changes: 8 additions & 3 deletions pkg/secrets/passphrase/manager.go
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -225,7 +225,12 @@ func PromptForNewPassphrase(rotate bool) (string, secrets.Manager, error) {
firstMessage = "Enter your new passphrase to protect config/secrets"

if !isInteractive() {
return "", nil, fmt.Errorf("passphrase rotation requires an interactive terminal")
text, err := io.ReadAll(os.Stdin)
nicklasfrahm marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return "", nil, err
}
phrase = strings.TrimSpace(string(text))
break
}
}
// Here, the stack does not have an EncryptionSalt, so we will get a passphrase and create one
Expand Down Expand Up @@ -286,7 +291,7 @@ func readPassphrase(prompt string, useEnv bool) (phrase string, interactive bool
if err != nil {
return "", false, fmt.Errorf("unable to construct a path the PULUMI_CONFIG_PASSPHRASE_FILE: %w", err)
}
phraseDetails, err := ioutil.ReadFile(phraseFilePath)
phraseDetails, err := os.ReadFile(phraseFilePath)
if err != nil {
return "", false, fmt.Errorf("unable to read PULUMI_CONFIG_PASSPHRASE_FILE: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/secrets/passphrase/manager_test.go
@@ -1,7 +1,6 @@
package passphrase

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestPassphraseManagerCorrectPassfileReturnsSecretsManager(t *testing.T) {
resetEnv := resetPassphraseTestEnvVars()
defer resetEnv()

tmpFile, err := ioutil.TempFile("", "pulumi-secret-test")
tmpFile, err := os.CreateTemp("", "pulumi-secret-test")
assert.NoError(t, err)
defer os.Remove(tmpFile.Name())
_, err = tmpFile.WriteString("password")
Expand Down