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

VAULT-13614 Support SCRAM-SHA-256 encrypted passwords for PostgreSQL #19616

Merged
merged 56 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
da0d8ae
scram password hash support
raymonstah Mar 8, 2023
e8db5e5
provide "password_encryption" config
raymonstah Mar 17, 2023
49bc306
fmt
raymonstah Mar 17, 2023
72e8096
changelog
raymonstah Mar 17, 2023
5a54a44
add test docs
raymonstah Mar 17, 2023
e032a37
ldaputil: adds comment on available text/template functions (#19469)
austingebauer Mar 7, 2023
f2b2b0b
UI: OIDC callback bug. (#18521)
davidspek Mar 7, 2023
b55c3b2
Delete test-link-rewrites.yml (#19467)
ashleemboyer Mar 7, 2023
c27026d
Change headings to h2 (#19402)
maxiscoding28 Mar 7, 2023
88988e1
UI/vault 12818/oracle banner sll (#19019)
Monkeychip Mar 8, 2023
8185d68
UI: fix delete for SSH engine config (#19448)
hellobontempo Mar 8, 2023
72c5ce8
bug: correct sdk handling of the zero int64 value (#18729)
valli0x Mar 9, 2023
e8f8084
VAULT-14215 Fix panic for non-TLS listeners during SIGHUP (#19483)
VioletHynes Mar 9, 2023
25e359f
Fix failing TestHCPLinkConnected Test (#19474)
Mar 9, 2023
139fad6
Remove the note about Vault not supporting number Okta verify push nu…
yhyakuna Mar 10, 2023
e4957d6
Add info about gcp service account key encoding (#19496)
robmonte Mar 10, 2023
0e8ecd0
Un-hiding link to 1.13 upgrade guide (#19505)
mladlow Mar 10, 2023
0fb9b15
sdk: Fix fmt + add FieldType test (#19493)
tomhjp Mar 10, 2023
3e4bc9f
Add support for importing RSA-PSS keys into Transit (#19519)
cipherboy Mar 13, 2023
edef778
Remove .mdx extension from link (#19514)
ashleemboyer Mar 13, 2023
068c146
change mul and div functions (#19495)
rculpepper Mar 13, 2023
915c245
add comment to explain use of math/rand package in lifetime_watcher (…
Mar 14, 2023
e210cae
Fix a possible data race with rollback manager and plugin reload (#19…
fairclothjm Mar 14, 2023
aaf2824
Remove oracle banner (#19532)
Monkeychip Mar 14, 2023
f0e9dea
Ignore special HTTP fields in response validation tests (#19530)
averche Mar 14, 2023
7983f92
VAULT-12798 Correct removal behaviour when JWT is symlink (#18863)
VioletHynes Mar 14, 2023
0102e61
PKI Responses Part 4 (#18612)
AnPucel Mar 14, 2023
5d4f9b8
Glimmer Navigate Input component (#19517)
Monkeychip Mar 15, 2023
28590b8
Add Oracle Cloud auth to the Vault Agent (#19260)
F21 Mar 15, 2023
559627c
Update auto-auth docs to remove tilde for home (#19548)
VioletHynes Mar 15, 2023
fd60cdc
Add the Tokenization/Rotation persistence issue as a Known Issue (#19…
sgmiller Mar 15, 2023
9aa7fee
adding copyright header (#19555)
hghaf099 Mar 15, 2023
405f598
database/elasticsearch: upgrades plugin to v0.13.1 (#19545)
austingebauer Mar 15, 2023
4c8d062
ci: pin terraform until planning bug is resolved (#19560)
ryancragun Mar 15, 2023
a579239
Add upgrade note for Removed builtins in 1.13 (#19531)
mpalmi Mar 15, 2023
ebf5b63
comment out HCP_SCADA_ADDRESS environment variable (#19583)
Mar 16, 2023
8ddea0b
Fix remount for mounts with spaces in the name (#19585)
VioletHynes Mar 16, 2023
08231ce
[QT-523] Remove copyright/license header from raft config used in the…
Mar 16, 2023
97b68f5
VAULT-14204 Update parameter policy documentation (#19586)
miagilepner Mar 17, 2023
3d4ba60
update link policy fetch URL (#19371)
ccapurso Mar 17, 2023
882b172
UI: Glimmerize BoxRadio and AlertPopup (#19571)
kiannaquach Mar 17, 2023
76c7871
UI: Glimmerize - Colocate template and remove component file (#19569)
kiannaquach Mar 17, 2023
addc7c0
vault-12244 (#19591)
hghaf099 Mar 17, 2023
1071315
UI: Glimmerize InfoTable, PageHeader, UpgradePage, NamespaceReminder,…
kiannaquach Mar 17, 2023
6039a6c
Update KV-V2 docs to explicitly call out the secret mount path as a p…
VioletHynes Mar 17, 2023
0ad6835
UI: Glimmerize Chevron, EmptyState, FieldGroupShow, InfoTooltip, Icon…
kiannaquach Mar 17, 2023
ef51b7b
Add known issue about OCSP GET redirection responses (#19523)
stevendpclark Mar 17, 2023
cb65677
Merge branch 'main' into raymond/scram-support
raymonstah Mar 17, 2023
3ca59d1
add scram package to test_packages
raymonstah Mar 17, 2023
99e2d6e
add scram package to test_packages
raymonstah Mar 20, 2023
e0f926e
sort imports
raymonstah Mar 20, 2023
b998c23
add SCRAM library to copywrite ignore
raymonstah Mar 20, 2023
efe94fd
rename from Encrypt to Hash
raymonstah Mar 20, 2023
ef287a2
rename password_encryption to password_authentication
raymonstah Mar 20, 2023
ceaba05
rename password_encryption to password_authentication (part 2)
raymonstah Mar 20, 2023
aac9e01
rename encrypted to hash in docs
raymonstah Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/generate-test-package-lists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ test_packages[13]+=" $base/command/server"
test_packages[13]+=" $base/physical/aerospike"
test_packages[13]+=" $base/physical/cockroachdb"
test_packages[13]+=" $base/plugins/database/postgresql"
test_packages[13]+=" $base/plugins/database/postgresql/scram"
if [ "${ENTERPRISE:+x}" == "x" ] ; then
test_packages[13]+=" $base/vault/external_tests/filteredpathsext"
fi
Expand Down
3 changes: 3 additions & 0 deletions changelog/19616.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
raymonstah marked this conversation as resolved.
Show resolved Hide resolved
secrets/postgresql: Add configuration to scram-sha-256 encrypt passwords on Vault before sending them to PostgreSQL
```
76 changes: 63 additions & 13 deletions plugins/database/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"regexp"
"strings"

"github.com/hashicorp/vault/plugins/database/postgresql/scram"
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why we copied to code instead of importing github.com/supercaracal/scram-sha-256?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately when I last checked, it wasn't an option since all of the source code was in a main package and un-exported.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aight, surprised there are no packages that would do what we need but it's simple enough and open sourced so I think copying is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, wondering if it would be worthwhile to have the Crypto team take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, tagged @hashicorp/vault-crypto

Copy link
Contributor

Choose a reason for hiding this comment

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

woops somehow forgot we have our own resident Crypto expert! Thanks for jumping in @swenson !


raymonstah marked this conversation as resolved.
Show resolved Hide resolved
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-secure-stdlib/strutil"
"github.com/hashicorp/vault/sdk/database/dbplugin/v5"
Expand All @@ -35,6 +37,26 @@ ALTER ROLE "{{username}}" WITH PASSWORD '{{password}}';
defaultUserNameTemplate = `{{ printf "v-%s-%s-%s-%s" (.DisplayName | truncate 8) (.RoleName | truncate 8) (random 20) (unix_time) | truncate 63 }}`
)

type PasswordEncryption string
raymonstah marked this conversation as resolved.
Show resolved Hide resolved

var (
PasswordEncryptionSCRAMSHA256 PasswordEncryption = "scram-sha-256"
PasswordEncryptionPlainText PasswordEncryption = "plaintext"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would PasswordEncryptionNone PasswordEncryption = "none" be a more appropriate name?
Plaintext encryption sounds a bit funky to me, curious to hear from others.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for PasswordEncryptionNone


var passwordEncryptions = map[PasswordEncryption]struct{}{
PasswordEncryptionSCRAMSHA256: {},
PasswordEncryptionPlainText: {},
}

func parsePasswordEncryption(s string) (PasswordEncryption, error) {
if _, ok := passwordEncryptions[PasswordEncryption(s)]; !ok {
return "", fmt.Errorf("'%s' is not a valid password encryption type", s)
}

return PasswordEncryption(s), nil
}
raymonstah marked this conversation as resolved.
Show resolved Hide resolved

var (
_ dbplugin.Database = (*PostgreSQL)(nil)
_ logical.PluginVersioner = (*PostgreSQL)(nil)
Expand Down Expand Up @@ -69,6 +91,7 @@ func new() *PostgreSQL {

db := &PostgreSQL{
SQLConnectionProducer: connProducer,
PasswordEncryption: PasswordEncryptionPlainText,
}

return db
Expand All @@ -77,7 +100,8 @@ func new() *PostgreSQL {
type PostgreSQL struct {
*connutil.SQLConnectionProducer

usernameProducer template.StringTemplate
usernameProducer template.StringTemplate
PasswordEncryption PasswordEncryption
}

func (p *PostgreSQL) Initialize(ctx context.Context, req dbplugin.InitializeRequest) (dbplugin.InitializeResponse, error) {
Expand Down Expand Up @@ -105,6 +129,20 @@ func (p *PostgreSQL) Initialize(ctx context.Context, req dbplugin.InitializeRequ
return dbplugin.InitializeResponse{}, fmt.Errorf("invalid username template: %w", err)
}

passwordEncryptionRaw, err := strutil.GetString(req.Config, "password_encryption")
if err != nil {
return dbplugin.InitializeResponse{}, err
raymonstah marked this conversation as resolved.
Show resolved Hide resolved
}

if passwordEncryptionRaw != "" {
pwEncryption, err := parsePasswordEncryption(passwordEncryptionRaw)
if err != nil {
return dbplugin.InitializeResponse{}, err
}

p.PasswordEncryption = pwEncryption
}

resp := dbplugin.InitializeResponse{
Config: newConf,
}
Expand Down Expand Up @@ -188,6 +226,15 @@ func (p *PostgreSQL) changeUserPassword(ctx context.Context, username string, ch
"username": username,
"password": password,
}

if p.PasswordEncryption == PasswordEncryptionSCRAMSHA256 {
hashedPassword, err := scram.Encrypt(password)
if err != nil {
return fmt.Errorf("unable to scram-sha256 password: %w", err)
}
m["password"] = hashedPassword
}
maxcoulombe marked this conversation as resolved.
Show resolved Hide resolved

if err := dbtxn.ExecuteTxQueryDirect(ctx, tx, m, query); err != nil {
return fmt.Errorf("failed to execute query: %w", err)
}
Expand Down Expand Up @@ -272,15 +319,24 @@ func (p *PostgreSQL) NewUser(ctx context.Context, req dbplugin.NewUserRequest) (
}
defer tx.Rollback()

m := map[string]string{
"name": username,
"username": username,
"password": req.Password,
"expiration": expirationStr,
}

if p.PasswordEncryption == PasswordEncryptionSCRAMSHA256 {
hashedPassword, err := scram.Encrypt(req.Password)
if err != nil {
return dbplugin.NewUserResponse{}, fmt.Errorf("unable to scram-sha256 password: %w", err)
}
m["password"] = hashedPassword
}

for _, stmt := range req.Statements.Commands {
if containsMultilineStatement(stmt) {
// Execute it as-is.
m := map[string]string{
"name": username,
"username": username,
"password": req.Password,
"expiration": expirationStr,
}
if err := dbtxn.ExecuteTxQueryDirect(ctx, tx, m, stmt); err != nil {
return dbplugin.NewUserResponse{}, fmt.Errorf("failed to execute query: %w", err)
}
Expand All @@ -293,12 +349,6 @@ func (p *PostgreSQL) NewUser(ctx context.Context, req dbplugin.NewUserRequest) (
continue
}

m := map[string]string{
"name": username,
"username": username,
"password": req.Password,
"expiration": expirationStr,
}
if err := dbtxn.ExecuteTxQueryDirect(ctx, tx, m, query); err != nil {
return dbplugin.NewUserResponse{}, fmt.Errorf("failed to execute query: %w", err)
}
Expand Down
51 changes: 51 additions & 0 deletions plugins/database/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/hashicorp/vault/helper/testhelpers/docker"
"github.com/hashicorp/vault/helper/testhelpers/postgresql"
"github.com/hashicorp/vault/sdk/database/dbplugin/v5"
Expand Down Expand Up @@ -93,6 +95,55 @@ func TestPostgreSQL_Initialize_ConnURLWithDSNFormat(t *testing.T) {
}
}

// TestPostgreSQL_SCRAM_Passwords tests that password_encryption works when set to scram-sha-256.
// When sending an encrypted password, the raw password should still successfully authenticate the user.
func TestPostgreSQL_SCRAM_Passwords(t *testing.T) {
cleanup, connURL := postgresql.PrepareTestContainer(t, "13.4-buster")
defer cleanup()

dsnConnURL, err := dbutil.ParseURL(connURL)
if err != nil {
t.Fatal(err)
}

connectionDetails := map[string]interface{}{
"connection_url": dsnConnURL,
"password_encryption": string(PasswordEncryptionSCRAMSHA256),
}

req := dbplugin.InitializeRequest{
Config: connectionDetails,
VerifyConnection: true,
}

db := new()
resp := dbtesting.AssertInitialize(t, db, req)
assert.Equal(t, string(PasswordEncryptionSCRAMSHA256), resp.Config["password_encryption"])

if !db.Initialized {
t.Fatal("Database should be initialized")
}

ctx := context.Background()
newUserRequest := dbplugin.NewUserRequest{
Statements: dbplugin.Statements{
Commands: []string{
`
CREATE ROLE "{{name}}" WITH
LOGIN
PASSWORD '{{password}}'
VALID UNTIL '{{expiration}}';
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "{{name}}";`,
},
},
Password: "somesecurepassword",
Expiration: time.Now().Add(1 * time.Minute),
}
newUserResponse, err := db.NewUser(ctx, newUserRequest)

assertCredsExist(t, db.ConnectionURL, newUserResponse.Username, newUserRequest.Password)
}
raymonstah marked this conversation as resolved.
Show resolved Hide resolved

func TestPostgreSQL_NewUser(t *testing.T) {
type testCase struct {
req dbplugin.NewUserRequest
Expand Down
21 changes: 21 additions & 0 deletions plugins/database/postgresql/scram/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Taishi Kasuga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
86 changes: 86 additions & 0 deletions plugins/database/postgresql/scram/scram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package scram
raymonstah marked this conversation as resolved.
Show resolved Hide resolved

//
// @see https://github.com/postgres/postgres/blob/c30f54ad732ca5c8762bb68bbe0f51de9137dd72/src/interfaces/libpq/fe-auth.c#L1167-L1285
// @see https://github.com/postgres/postgres/blob/e6bdfd9700ebfc7df811c97c2fc46d7e94e329a2/src/interfaces/libpq/fe-auth-scram.c#L868-L905
// @see https://github.com/postgres/postgres/blob/c30f54ad732ca5c8762bb68bbe0f51de9137dd72/src/port/pg_strong_random.c#L66-L96
// @see https://github.com/postgres/postgres/blob/e6bdfd9700ebfc7df811c97c2fc46d7e94e329a2/src/common/scram-common.c#L160-L274
// @see https://github.com/postgres/postgres/blob/e6bdfd9700ebfc7df811c97c2fc46d7e94e329a2/src/common/scram-common.c#L27-L85

// Implementation from https://github.com/supercaracal/scram-sha-256/blob/d3c05cd927770a11c6e12de3e3a99c3446a1f78d/main.go
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"fmt"
"io"

"golang.org/x/crypto/pbkdf2"
)

const (
// @see https://github.com/postgres/postgres/blob/e6bdfd9700ebfc7df811c97c2fc46d7e94e329a2/src/include/common/scram-common.h#L36-L41
saltSize = 16

// @see https://github.com/postgres/postgres/blob/c30f54ad732ca5c8762bb68bbe0f51de9137dd72/src/include/common/sha2.h#L22
digestLen = 32

// @see https://github.com/postgres/postgres/blob/e6bdfd9700ebfc7df811c97c2fc46d7e94e329a2/src/include/common/scram-common.h#L43-L47
iterationCnt = 4096
)

var (
clientRawKey = []byte("Client Key")
serverRawKey = []byte("Server Key")
)

func genSalt(size int) ([]byte, error) {
salt := make([]byte, size)
if _, err := io.ReadFull(rand.Reader, salt); err != nil {
return nil, err
}
return salt, nil
}

func encodeB64(src []byte) (dst []byte) {
dst = make([]byte, base64.StdEncoding.EncodedLen(len(src)))
base64.StdEncoding.Encode(dst, src)
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why not just return []byte(base64.StdEncoding.EncodeToString(dst, src))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, most of the source code in this file is copied over from here.

Not opposed to changing it, including handling the errors you mentioned below.

return
}

func getHMACSum(key, msg []byte) []byte {
h := hmac.New(sha256.New, key)
_, _ = h.Write(msg)
Copy link
Contributor

@cipherboy cipherboy Mar 20, 2023

Choose a reason for hiding this comment

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

HMAC and SHA-256 may error with BoringCrypto fwiw.

I believe this mostly occurs with large inputs, which this shouldn't really have in general, but still worth noting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to know. The docs for the functions in the Go standard library say they will "never" return an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the Go standard library doesn't really document the BoringCrypto behavior from what I've seen, especially since its not officially supported.

return h.Sum(nil)
}

func getSHA256Sum(key []byte) []byte {
h := sha256.New()
_, _ = h.Write(key)
return h.Sum(nil)
}

func encryptPassword(rawPassword, salt []byte, iter, keyLen int) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't encryption.

Suggested change
func encryptPassword(rawPassword, salt []byte, iter, keyLen int) string {
func hashPassword(rawPassword, salt []byte, iter, keyLen int) string {

Copy link
Contributor

Choose a reason for hiding this comment

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

Not to bikeshed, I'm fine with hash, but I had some un-submitted comments potentially suggesting crypt here as a name. IIRC, this format that's returned here is the Unix crypt format (man crypt), which is used for password hashing.

digestKey := pbkdf2.Key(rawPassword, salt, iter, keyLen, sha256.New)
clientKey := getHMACSum(digestKey, clientRawKey)
storedKey := getSHA256Sum(clientKey)
serverKey := getHMACSum(digestKey, serverRawKey)

return fmt.Sprintf("SCRAM-SHA-256$%d:%s$%s:%s",
iter,
string(encodeB64(salt)),
string(encodeB64(storedKey)),
string(encodeB64(serverKey)),
)
}

func Encrypt(password string) (string, error) {
raymonstah marked this conversation as resolved.
Show resolved Hide resolved
salt, err := genSalt(saltSize)
if err != nil {
return "", err
}

hashedPassword := encryptPassword([]byte(password), salt, iterationCnt, digestLen)
return hashedPassword, nil
}
27 changes: 27 additions & 0 deletions plugins/database/postgresql/scram/scram_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package scram

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

// TestScram tests that the Encrypt method. The encrypted password string should have a SCRAM-SHA-256 prefix.
func TestScram(t *testing.T) {
tcs := map[string]struct {
Password string
}{
"empty-password": {Password: ""},
"simple-password": {Password: "password"},
}

for name, tc := range tcs {
t.Run(name, func(t *testing.T) {
got, err := Encrypt(tc.Password)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(got, "SCRAM-SHA-256$4096:"))
assert.Len(t, got, 133)
})
}
}
5 changes: 5 additions & 0 deletions website/content/api-docs/secret/databases/postgresql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ has a number of parameters to further configure a connection.
and password fields. See the [databases secrets engine docs](/vault/docs/secrets/databases#disable-character-escaping)
for more information. Defaults to `false`.

- `password_encryption` `(string: "plaintext")` - When set to "scram-sha-256", passwords will be encrypted by Vault and stored as-is by PostgreSQL.
raymonstah marked this conversation as resolved.
Show resolved Hide resolved
Using "scram-sha-256" requires a minimum version of PostgreSQL 10. Available options are "scram-sha-256" and "plaintext". The default is "plaintext".
When set to "plaintext", passwords will be sent to PostgresSQL in plaintext format and may appear in PostgreSQL logs as-is.
raymonstah marked this conversation as resolved.
Show resolved Hide resolved


<details>
<summary><b>Default Username Template</b></summary>

Expand Down
3 changes: 2 additions & 1 deletion website/content/docs/secrets/databases/postgresql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ options, including SSL options, can be found in the [pgx][pgxlib] and
allowed_roles="my-role" \
connection_url="postgresql://{{username}}:{{password}}@localhost:5432/database-name" \
username="vaultuser" \
password="vaultpass"
password="vaultpass" \
password_encryption="scram-sha-256"
```

1. Configure a role that maps a name in Vault to an SQL statement to execute to
Expand Down