Skip to content

Commit 9231f5d

Browse files
Support reading mysql backend credentials from environment variables (#30136)
Signed-off-by: Miles <[email protected]> Co-authored-by: Violet Hynes <[email protected]>
1 parent 0b9ed13 commit 9231f5d

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

changelog/30136.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
storage/mysql: Added support for getting mysql backend username and password from the environment variables `VAULT_MYSQL_USERNAME` and `VAULT_MYSQL_PASSWORD`.
3+
```

physical/mysql/mysql.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"io/ioutil"
1414
"math"
1515
"net/url"
16+
"os"
1617
"sort"
1718
"strconv"
1819
"strings"
@@ -268,13 +269,22 @@ func NewMySQLClient(conf map[string]string, logger log.Logger) (*sql.DB, error)
268269
var err error
269270

270271
// Get the MySQL credentials to perform read/write operations.
271-
username, ok := conf["username"]
272-
if !ok || username == "" {
273-
return nil, fmt.Errorf("missing username")
272+
username := os.Getenv("VAULT_MYSQL_USERNAME")
273+
if username == "" {
274+
confUsername, ok := conf["username"]
275+
if !ok || confUsername == "" {
276+
return nil, fmt.Errorf("missing username")
277+
}
278+
username = confUsername
274279
}
275-
password, ok := conf["password"]
276-
if !ok || password == "" {
277-
return nil, fmt.Errorf("missing password")
280+
281+
password := os.Getenv("VAULT_MYSQL_PASSWORD")
282+
if password == "" {
283+
confPassword, ok := conf["password"]
284+
if !ok || confPassword == "" {
285+
return nil, fmt.Errorf("missing password")
286+
}
287+
password = confPassword
278288
}
279289

280290
// Get or set MySQL server address. Defaults to localhost and default port(3306)

website/content/docs/configuration/storage/mysql.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ storage "mysql" {
4343
- `tls_ca_file` `(string: "")` – Specifies the path to the CA certificate to
4444
connect using TLS.
4545

46-
- `plaintext_credentials_transmission` `(string: "")` - Provides authorization
46+
- `plaintext_connection_allowed` `(string: "")` - Provides authorization
4747
to send credentials over plaintext. Failure to provide a value AND a failure
4848
to provide a TLS CA certificate will warn that the credentials are being sent
4949
over plain text. In the future, failure to do acknowledge or use TLS will
@@ -64,10 +64,10 @@ storage "mysql" {
6464
Additionally, Vault requires the following authentication information.
6565

6666
- `username` `(string: <required>)` Specifies the MySQL username to connect to
67-
the database.
67+
the database. This value can also be set using the `VAULT_MYSQL_USERNAME` environment variable.
6868

6969
- `password` `(string: <required>)` Specifies the MySQL password to connect to
70-
the database.
70+
the database. This value can also be set using the `VAULT_MYSQL_PASSWORD` environment variable.
7171

7272
### High availability parameters
7373

0 commit comments

Comments
 (0)