Skip to content

Commit a405191

Browse files
committed
Plaintext passwords in auth config block are now prohibited
1 parent 06b2d3d commit a405191

5 files changed

Lines changed: 23 additions & 27 deletions

File tree

ROAD_TO_WS4SQL.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@ The version in this branch is a work in progress to add features and (unfortunat
66

77
## Changes
88

9+
### Breaking changes
10+
11+
- When running the app, the config files must be specified on the command line, the file paths cannot be used anymore (there). This is described in the "Migration" section below. The file path is in the config file.
12+
- The only exception is a "simple case" to serve a file path without any config. This can be done with the new `--quick-db` parameter.
13+
- Hashed passwords in auth config must now be hashed with BCrypt, not SHA256.
14+
- Plain text passwords are not permitted anymore, in auth config.
15+
16+
### Major features
17+
918
- SQLite is embedded via [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) and CGO. Should be way faster.
1019
- Support for DuckDB (see below).
11-
- [**BREAKING CHANGE**] When running the app, the config files must be specified on the command line, the file paths cannot be used anymore (there). This is described in the "Migration" section below. The file path is in the config file.
12-
- The only exception is a "simple case" to serve a file path without any config. This can be done with the new `--quick-db` parameter.
13-
- [**BREAKING CHANGE**] Hashed passwords in auth config must now be hashed with BCrypt, not SHA256.
14-
- Fail fast if the request is empty, don't even attempt to authenticate.
1520
- Target platforms (because of CGO) are now 4 (`win/amd64`, `macos/arm64`, `linux/amd64`, `linux/arm64`).
1621
- For Docker, `linux/amd64` and `linux/arm64`.
1722
- Docker images are now based on `distroless/static-debian12`.
1823
- Docker images are now hosted on Github's Container Registry.
1924

25+
### Minor changes
26+
27+
- Fail fast if the request is empty, don't even attempt to authenticate.
28+
2029
## Migration
2130

2231
- For any `--db` and `--mem-db` switch that was used, an explicit YAML config file must be created. The format is the same, but there is a new section at the beginning:
@@ -31,7 +40,8 @@ database:
3140
readOnly: false # Same as before, but moved here.
3241
```
3342
34-
- For any hashed password previously specified in an `auth` block, the hash must be BCrypt, not SHA256.
43+
- For any hashed password (`HashedPassword = ...`) previously specified in an `auth` block, the hash must be BCrypt, not SHA256.
44+
- For any plain text password (`Password = ...`), convert in `HashedPassword`, also using BCrypt.
3545

3646
## Specific to DuckDB
3747

src/authentication.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ func parseAuth(db *structs.Db) {
119119
if cred.User == "" {
120120
mllog.Fatal("no user for credential")
121121
}
122-
if (cred.HashedPassword == "") == (cred.Password == "") {
123-
mllog.Fatal("one and only one of 'password' and 'hashedPassword' must be specified")
124-
}
125-
// Populates the cleartext password cache, so that there is only one
126-
// point where the password is stored in clear text.
127-
// If the password is specified as a BCrypt hash, it will be cached
128-
// when the BCrypt "puzzle" is solved for the first time.
129-
if cred.Password != "" {
130-
cred.ClearTextPassword.Store([]byte(cred.Password))
131-
}
132122
}
133123
mllog.StdOutf(" + Authentication enabled, with %d credentials", len(auth.ByCredentials))
134124
}

src/authentication_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func TestSetupAuthCreds(t *testing.T) {
5555
Mode: "INLINE",
5656
ByCredentials: []structs.CredentialsCfg{
5757
{
58-
User: "pietro",
59-
Password: "hey",
58+
User: "pietro",
59+
HashedPassword: "$2b$12$Xo7tQh0BDzDAiPghc7AU1Ocx2MnGls46Ot55y4MQNtPRhK0nemyWq", // "hey"
6060
},
6161
{
6262
User: "paolo",
@@ -348,8 +348,8 @@ func TestBASetupAuthCreds(t *testing.T) {
348348
Mode: "HTTP",
349349
ByCredentials: []structs.CredentialsCfg{
350350
{
351-
User: "pietro",
352-
Password: "hey",
351+
User: "pietro",
352+
HashedPassword: "$2b$12$Xo7tQh0BDzDAiPghc7AU1Ocx2MnGls46Ot55y4MQNtPRhK0nemyWq", // "hey"
353353
},
354354
{
355355
User: "paolo",
@@ -580,8 +580,8 @@ func TestCustomCodeSetup(t *testing.T) {
580580
CustomErrorCode: &errCode,
581581
ByCredentials: []structs.CredentialsCfg{
582582
{
583-
User: "pietro",
584-
Password: "hey",
583+
User: "pietro",
584+
HashedPassword: "$2b$12$Xo7tQh0BDzDAiPghc7AU1Ocx2MnGls46Ot55y4MQNtPRhK0nemyWq", // "hey"
585585
},
586586
{
587587
User: "paolo",

src/cli_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ func TestConfigs(t *testing.T) {
9191
assert(t, cfgdb.Auth.ByQuery == "", "the db has ByQuery with a value")
9292
assert(t, len(cfgdb.Auth.ByCredentials) == 2, "the db has not the correct number of credentials")
9393
assert(t, cfgdb.Auth.ByCredentials[0].User == "myUser1", "the db has not the correct first user")
94-
assert(t, cfgdb.Auth.ByCredentials[0].Password == "myHotPassword", "the db has not the correct first password")
9594
assert(t, cfgdb.Auth.ByCredentials[0].HashedPassword == "", "the db has not the correct first hashed password")
9695
assert(t, cfgdb.Auth.ByCredentials[1].User == "myUser2", "the db has not the correct second user")
97-
assert(t, cfgdb.Auth.ByCredentials[1].Password == "", "the db has not the correct second password")
9896
assert(t, len(cfgdb.Auth.ByCredentials[1].HashedPassword) == 64, "the db has not the correct second hashed password")
9997
assert(t, *cfgdb.DatabaseDef.DisableWALMode, "the db has not the correct WAL mode")
10098
assert(t, cfgdb.DatabaseDef.ReadOnly, "the db has not the correct ReadOnly value")

src/structs/configFile.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ type ScheduledTask struct {
3838

3939
type CredentialsCfg struct {
4040
User string `yaml:"user"`
41-
Password string `yaml:"password"`
4241
HashedPassword string `yaml:"hashedPassword"`
43-
// This is a cache: it's the Password if specified in cleartext, or
44-
// gets populated with the cleartext password when the hashed one is
45-
// checked.
42+
// This is a cache: it gets populated with the cleartext
43+
// password when the hashed one is checked.
4644
ClearTextPassword atomic.Value
4745
}
4846

0 commit comments

Comments
 (0)