Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 51fa47d

Browse files
committed
Merge branch '530-validate-passwords' into 'master'
feat: enforce strong DB password values Closes #530 See merge request postgres-ai/database-lab!813
2 parents 8fb3535 + 01e47a7 commit 51fa47d

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

‎engine/go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ require (
7474
github.com/stretchr/objx v0.5.0 // indirect
7575
github.com/tklauser/go-sysconf v0.3.11 // indirect
7676
github.com/tklauser/numcpus v0.6.1 // indirect
77+
github.com/wagslane/go-password-validator v0.3.0 // indirect
7778
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
7879
github.com/yusufpapurcu/wmi v1.2.3 // indirect
7980
golang.org/x/net v0.12.0 // indirect

‎engine/go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5
684684
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
685685
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
686686
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
687+
github.com/wagslane/go-password-validator v0.3.0 h1:vfxOPzGHkz5S146HDpavl0cw1DSVP061Ry2PX0/ON6I=
688+
github.com/wagslane/go-password-validator v0.3.0/go.mod h1:TI1XJ6T5fRdRnHqHt14pvy1tNVnrwe7m3/f1f2fDphQ=
687689
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
688690
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
689691
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

‎engine/internal/validator/validator.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
package validator
77

88
import (
9+
"fmt"
10+
911
"github.com/pkg/errors"
12+
passwordvalidator "github.com/wagslane/go-password-validator"
1013

1114
"gitlab.com/postgres-ai/database-lab/v3/pkg/client/dblabapi/types"
1215
)
1316

17+
const minEntropyBits = 60
18+
1419
// Service provides a validation service.
1520
type Service struct {
1621
}
@@ -29,5 +34,9 @@ func (v Service) ValidateCloneRequest(cloneRequest *types.CloneCreateRequest) er
2934
return errors.New("missing DB password")
3035
}
3136

37+
if err := passwordvalidator.Validate(cloneRequest.DB.Password, minEntropyBits); err != nil {
38+
return fmt.Errorf("password validation: %w", err)
39+
}
40+
3241
return nil
3342
}

‎engine/internal/validator/validator_test.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@ func TestValidationCloneRequest(t *testing.T) {
1818
&types.CloneCreateRequest{
1919
DB: &types.DatabaseRequest{
2020
Username: "username",
21-
Password: "password",
21+
Password: "secret_password",
2222
}})
2323

2424
assert.Nil(t, err)
2525
}
2626

27+
func TestWeakPassword(t *testing.T) {
28+
validator := Service{}
29+
err := validator.ValidateCloneRequest(
30+
&types.CloneCreateRequest{
31+
DB: &types.DatabaseRequest{
32+
Username: "username",
33+
Password: "password",
34+
}})
35+
36+
assert.ErrorContains(t, err, "insecure password")
37+
}
38+
2739
func TestValidationCloneRequestErrors(t *testing.T) {
2840
validator := Service{}
2941

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /