Skip to content

Commit

Permalink
Fixes inability to authenticate through the older cmdQuery mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Evengard committed Feb 12, 2024
1 parent 282c8e1 commit c66296b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/handler/cmd_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"strings"

"github.com/FerretDB/FerretDB/internal/clientconn/conninfo"
"github.com/FerretDB/FerretDB/internal/handler/common"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
Expand All @@ -28,19 +29,30 @@ import (

// CmdQuery implements deprecated OP_QUERY message handling.
func (h *Handler) CmdQuery(ctx context.Context, query *wire.OpQuery) (*wire.OpReply, error) {
cmd := query.Query().Command()
body := query.Query()
cmd := body.Command()
collection := query.FullCollectionName

// both are valid and are allowed to be run against any database as we don't support authorization yet
if (cmd == "ismaster" || cmd == "isMaster") && strings.HasSuffix(collection, ".$cmd") {
return common.IsMaster(ctx, query.Query(), h.TCPHost, h.ReplSetName)
return common.IsMaster(ctx, body, h.TCPHost, h.ReplSetName)
}

// TODO https://github.com/FerretDB/FerretDB/issues/3008

// database name typically is either "$external" or "admin"

if cmd == "saslStart" && strings.HasSuffix(collection, ".$cmd") {
mechanism, err := common.GetRequiredParam[string](body, "mechanism")
if err == nil && mechanism == "PLAIN" {
username, password, err := saslStartPlain(body)
if err != nil {
return nil, err
}

conninfo.Get(ctx).SetAuth(username, password)
}

var emptyPayload types.Binary
reply := wire.OpReply{
NumberReturned: 1,
Expand Down

0 comments on commit c66296b

Please sign in to comment.