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

Enforce new authentication #4075

Merged
merged 52 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
fbaf68a
get authentication mechanism from db
chilagrow Feb 14, 2024
f5c6049
add test for conneting without plain username password
chilagrow Feb 14, 2024
88b6316
add authentication to sasl start
chilagrow Feb 15, 2024
bcfd350
add authentication to all handlers except command query
chilagrow Feb 15, 2024
3699034
move files
chilagrow Feb 15, 2024
8e65773
Merge branch 'main' into enforce-new-auth
chilagrow Feb 15, 2024
70f0183
until first user is created new authentication always succeeds
chilagrow Feb 15, 2024
470ca14
is master does not need authentication
chilagrow Feb 15, 2024
40be66d
handle database without any pool yet
chilagrow Feb 16, 2024
2e98e84
merge conflict
chilagrow Feb 16, 2024
fd048c6
do not authenticate on some handlers
chilagrow Feb 16, 2024
4a6b841
authentication for sha256 is done by conversation step, so handler ch…
chilagrow Feb 16, 2024
90de3fa
Plain credential hashes password
chilagrow Feb 16, 2024
b4b4c57
add test for scram sha256 user for empty database
chilagrow Feb 16, 2024
5dc7ae5
fix create update and drop user tests
chilagrow Feb 16, 2024
c3583d1
update error and panic
chilagrow Feb 16, 2024
8d72103
create pool upon registry creation
chilagrow Feb 19, 2024
f694f4e
do not authenticate on handler if bypass backend auth is not set
chilagrow Feb 19, 2024
b08beea
user tests use credentials for test runner
chilagrow Feb 19, 2024
4286628
lint
chilagrow Feb 19, 2024
287b728
Revert "user tests use credentials for test runner"
chilagrow Feb 19, 2024
950e567
authentication checks user instead of db.user
chilagrow Feb 19, 2024
a9be0e2
backend fallback
chilagrow Feb 19, 2024
a4b5699
cleanup
chilagrow Feb 19, 2024
daba28a
missing import
chilagrow Feb 19, 2024
5a8014e
revert
chilagrow Feb 19, 2024
eda4ed1
tidy up
chilagrow Feb 19, 2024
add453e
add test for plain mechanism backend user
chilagrow Feb 19, 2024
0d786cb
simplify test user
chilagrow Feb 19, 2024
5bdcfc4
update comments
chilagrow Feb 19, 2024
f74532c
remove unused var
chilagrow Feb 19, 2024
5c4b117
Merge branch 'main' into enforce-new-auth
chilagrow Feb 19, 2024
d407f5f
sqlite does not have backend auth
chilagrow Feb 19, 2024
0ab1f56
use opt out way
chilagrow Feb 20, 2024
306c10b
add todo links
chilagrow Feb 20, 2024
55a52b9
merge
chilagrow Feb 20, 2024
0128186
rename reorder
chilagrow Feb 20, 2024
a0df39f
add todo
chilagrow Feb 20, 2024
24c393c
address feedback
chilagrow Feb 21, 2024
e3edaae
Merge branch 'main' into enforce-new-auth
chilagrow Feb 21, 2024
73ec82a
create user during the setup
chilagrow Feb 21, 2024
ae2d02b
Merge branch 'main' into enforce-new-auth
chilagrow Feb 22, 2024
07c749a
fix test
chilagrow Feb 22, 2024
3f95100
update comment add explaination add more mechanisms
chilagrow Feb 22, 2024
c4c1224
PLAIN and SHA handles authenticated users the same way
chilagrow Feb 22, 2024
53d76ae
Merge branch 'main' into enforce-new-auth
chilagrow Feb 26, 2024
d5d2499
do not use pwd as abbrev
chilagrow Feb 26, 2024
7bcc892
update comment
chilagrow Feb 26, 2024
dbd27a8
do not allow SCRAM if new authentication is not enabled
chilagrow Feb 27, 2024
e45cc60
Merge branch 'main' into enforce-new-auth
AlekSi Feb 27, 2024
339b52d
Merge branch 'main' into enforce-new-auth
AlekSi Feb 28, 2024
fb4dd9e
Merge branch 'main' into enforce-new-auth
AlekSi Feb 28, 2024
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
Prev Previous commit
Next Next commit
address feedback
  • Loading branch information
chilagrow committed Feb 21, 2024
commit 24c393cb18542cd90c2b3f09fc62a6c1f28d6229
4 changes: 2 additions & 2 deletions integration/users/create_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ func createTestRunnerUser(tb *testing.T, ctx context.Context, db *mongo.Database
return
}

username, pwd, mechanism := "username", "password", "PLAIN"
username, password, mechanism := "username", "password", "PLAIN"

err := db.Client().Database("admin").RunCommand(ctx, bson.D{
{"createUser", username},
{"roles", bson.A{}},
{"pwd", pwd},
{"pwd", password},
{"mechanisms", bson.A{mechanism}},
}).Err()
require.NoErrorf(tb, err, "cannot create user")
Expand Down
1 change: 1 addition & 0 deletions internal/handler/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (h *Handler) authenticate(ctx context.Context) error {
// until local exception is implemented.
// TODO https://github.com/FerretDB/FerretDB/issues/4100
conninfo.Get(ctx).UnsetBypassBackendAuth()
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
h.L.DPanic("backend is used for authentication - no user in admin.system.users collection")

return nil
}
Expand Down
72 changes: 36 additions & 36 deletions internal/handler/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

// command represents a handler for single command.
type command struct {
// Unsafe indicates that the command does not require authentication.
Unsafe bool
// anonymous indicates that the command does not require authentication.
anonymous bool

// Handler processes this command.
//
Expand All @@ -44,14 +44,14 @@ func (h *Handler) initCommands() {
Help: "Returns aggregated data.",
},
"buildInfo": {
Handler: h.MsgBuildInfo,
Unsafe: true,
Help: "Returns a summary of the build information.",
Handler: h.MsgBuildInfo,
anonymous: true,
Help: "Returns a summary of the build information.",
},
"buildinfo": { // old lowercase variant
Handler: h.MsgBuildInfo,
Unsafe: true,
Help: "", // hidden
Handler: h.MsgBuildInfo,
anonymous: true,
Help: "", // hidden
},
"collMod": {
Handler: h.MsgCollMod,
Expand All @@ -66,8 +66,8 @@ func (h *Handler) initCommands() {
Help: "Reduces the disk space collection takes and refreshes its statistics.",
},
"connectionStatus": {
Handler: h.MsgConnectionStatus,
Unsafe: true,
Handler: h.MsgConnectionStatus,
anonymous: true,
Help: "Returns information about the current connection, " +
"specifically the state of authenticated users and their available permissions.",
},
Expand Down Expand Up @@ -160,9 +160,9 @@ func (h *Handler) initCommands() {
Help: "Returns the value of the parameter.",
},
"hello": {
Handler: h.MsgHello,
Unsafe: true,
Help: "Returns the role of the FerretDB instance.",
Handler: h.MsgHello,
anonymous: true,
Help: "Returns the role of the FerretDB instance.",
},
"hostInfo": {
Handler: h.MsgHostInfo,
Expand All @@ -173,14 +173,14 @@ func (h *Handler) initCommands() {
Help: "Inserts documents into the database.",
},
"isMaster": {
Handler: h.MsgIsMaster,
Unsafe: true,
Help: "Returns the role of the FerretDB instance.",
Handler: h.MsgIsMaster,
anonymous: true,
Help: "Returns the role of the FerretDB instance.",
},
"ismaster": { // old lowercase variant
Handler: h.MsgIsMaster,
Unsafe: true,
Help: "", // hidden
Handler: h.MsgIsMaster,
anonymous: true,
Help: "", // hidden
},
"killCursors": {
Handler: h.MsgKillCursors,
Expand All @@ -207,23 +207,23 @@ func (h *Handler) initCommands() {
Help: "Logs out from the current session.",
},
"ping": {
Handler: h.MsgPing,
Unsafe: true,
Help: "Returns a pong response.",
Handler: h.MsgPing,
anonymous: true,
Help: "Returns a pong response.",
},
"renameCollection": {
Handler: h.MsgRenameCollection,
Help: "Changes the name of an existing collection.",
},
"saslStart": {
Handler: h.MsgSASLStart,
Unsafe: true,
Help: "", // hidden
Handler: h.MsgSASLStart,
anonymous: true,
Help: "", // hidden
},
"saslContinue": {
Handler: h.MsgSASLContinue,
Unsafe: true,
Help: "", // hidden
Handler: h.MsgSASLContinue,
anonymous: true,
Help: "", // hidden
},
"serverStatus": {
Handler: h.MsgServerStatus,
Expand All @@ -242,9 +242,9 @@ func (h *Handler) initCommands() {
Help: "Validates collection.",
},
"whatsmyuri": {
Handler: h.MsgWhatsMyURI,
Unsafe: true,
Help: "Returns peer information.",
Handler: h.MsgWhatsMyURI,
anonymous: true,
Help: "Returns peer information.",
},
// please keep sorted alphabetically
}
Expand Down Expand Up @@ -276,9 +276,9 @@ func (h *Handler) initCommands() {

for name, cmd := range h.commands {
h.commands[name] = command{
Handler: h.authenticateWrapper(cmd),
Unsafe: cmd.Unsafe,
Help: cmd.Help,
Handler: h.authenticateWrapper(cmd),
anonymous: cmd.anonymous,
Help: cmd.Help,
}
}
}
Expand All @@ -289,10 +289,10 @@ func (h *Handler) Commands() map[string]command {
}

// authenticateWrapper wraps the command handler with the authentication check.
// If Unsafe is true, the command handler is executed without authentication.
// If anonymous is true, the command handler is executed without authentication.
func (h *Handler) authenticateWrapper(cmd command) func(context.Context, *wire.OpMsg) (*wire.OpMsg, error) {
return func(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
if cmd.Unsafe {
if cmd.anonymous {
return cmd.Handler(ctx, msg)
}

Expand Down