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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix speculativeAuthenticate panic on empty database #4178

Merged
merged 2 commits into from Mar 13, 2024

Conversation

chilagrow
Copy link
Contributor

@chilagrow chilagrow commented Mar 13, 2024

Description

This panic is only visible on mechanism called MONGODB-X509. But it's nice to fix panic if you come across one 馃

Run FerretDB with --test-enable-new-auth flag.

diff --git a/Taskfile.yml b/Taskfile.yml
index c50d557f3..8cef1ba5c 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -364,6 +364,7 @@ tasks:
         --handler=pg
         --postgresql-url='postgres://username@127.0.0.1:5432/ferretdb?search_path='
         --test-records-dir=tmp/records
+        --test-enable-new-auth

Run mongosh without database, use below mechanism, it won't panic for PLAIN or SCRAM.

$ docker compose exec mongodb mongosh --verbose --shell 'mongodb://host.docker.internal:27017/?authMechanism=MONGODB-X509'
Current Mongosh Log ID: 65f163a2de277b1c0f3c9181                                                      
Connecting to:          mongodb://host.docker.internal:27017/?authMechanism=MONGODB-X509&directConnection=true&appName=mongosh+2.1.4                                                                        
MongoNetworkError: connection 1 to 192.168.65.2:27017 closed                                                     

See panic, it appears because Op query seems to error on command error or lazyerror.

2024-03-13T17:23:46.441+0900    ERROR   // 127.0.0.1:43834 -> 127.0.0.1:27017   clientconn/conn.go:525  Handler error for unhandled response opcode      {"error": "BadValue (2): required parameter \"db\" is miss
ing", "opcode": "OP_REPLY"}                                                                                                                                                                                        
github.com/FerretDB/FerretDB/internal/clientconn.(*conn).route                                                                                                                                                     
        /home/chi/go/src/github.com/chilagrow/FerretDB/internal/clientconn/conn.go:525                   
github.com/FerretDB/FerretDB/internal/clientconn.(*conn).run
        /home/chi/go/src/github.com/chilagrow/FerretDB/internal/clientconn/conn.go:316
github.com/FerretDB/FerretDB/internal/clientconn.acceptLoop.func1
        /home/chi/go/src/github.com/chilagrow/FerretDB/internal/clientconn/listener.go:305               
2024-03-13T17:23:46.441+0900    ERROR   // 127.0.0.1:43834 -> 127.0.0.1:27017   clientconn/conn.go:615  Response header: length:     0, id:    0, response_to:    0, opcode: OP_REPLY
github.com/FerretDB/FerretDB/internal/clientconn.(*conn).logResponse                                     
        /home/chi/go/src/github.com/chilagrow/FerretDB/internal/clientconn/conn.go:615                   
github.com/FerretDB/FerretDB/internal/clientconn.(*conn).run                                                                                                                                                       
        /home/chi/go/src/github.com/chilagrow/FerretDB/internal/clientconn/conn.go:317                   
github.com/FerretDB/FerretDB/internal/clientconn.acceptLoop.func1                                        
        /home/chi/go/src/github.com/chilagrow/FerretDB/internal/clientconn/listener.go:305               
2024-03-13T17:23:46.441+0900    ERROR   // 127.0.0.1:43834 -> 127.0.0.1:27017   clientconn/conn.go:616  Response message:
%!s(<nil>)                   

Since if SpeculativeAuthenticate does not succeed, it calls saslStart. If db is not set, return Op query without SpeculativeAuthenticate field, the error is returned from saslStart.

Closes #4100.

Readiness checklist

  • I added/updated unit tests (and they pass).
  • I added/updated integration/compatibility tests (and they pass).
  • I added/updated comments and checked rendering.
  • I made spot refactorings.
  • I updated user documentation.
  • I ran task all, and it passed.
  • I ensured that PR title is good enough for the changelog.
  • (for maintainers only) I set Reviewers (@FerretDB/core), Milestone (Next), Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 73.81%. Comparing base (ea9c5bd) to head (e0bc05e).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4178      +/-   ##
==========================================
- Coverage   74.52%   73.81%   -0.72%     
==========================================
  Files         339      339              
  Lines       22785    22786       +1     
==========================================
- Hits        16981    16819     -162     
- Misses       4498     4683     +185     
+ Partials     1306     1284      -22     
Files Coverage 螖
internal/handler/cmd_query.go 45.94% <0.00%> (-1.28%) 猬囷笍

... and 19 files with indirect coverage changes

Flag Coverage 螖
filter-true 67.21% <0.00%> (-0.87%) 猬囷笍
hana-1 ?
integration 67.21% <0.00%> (-0.87%) 猬囷笍
mongodb-1 4.89% <0.00%> (-0.01%) 猬囷笍
postgresql-1 46.60% <0.00%> (-0.02%) 猬囷笍
postgresql-2 49.40% <0.00%> (-0.06%) 猬囷笍
postgresql-3 49.31% <0.00%> (-0.04%) 猬囷笍
sqlite-1 45.75% <0.00%> (-0.03%) 猬囷笍
sqlite-2 ?
sqlite-3 48.51% <0.00%> (-0.01%) 猬囷笍
unit 32.54% <0.00%> (-0.01%) 猬囷笍

Flags with carried forward coverage won't be shown. Click here to find out more.

@chilagrow chilagrow changed the title fix panic on unset db Fix op query panic on empty database Mar 13, 2024
@chilagrow chilagrow changed the title Fix op query panic on empty database Fix speculativeAuthenticate panic on empty database Mar 13, 2024
@chilagrow chilagrow added the code/chore Code maintenance improvements label Mar 13, 2024
@chilagrow chilagrow added this to the Next milestone Mar 13, 2024
@chilagrow
Copy link
Contributor Author

With this fix an error is returned.

$ docker compose exec mongodb mongosh --verbose --shell 'mongodb://host.docker.internal:27017/?authMechanism=MONGODB-X509'                         [100/9304]
Current Mongosh Log ID: 65f16407349a0891c9b05ba3                                                                                                                                                            
Connecting to:          mongodb://host.docker.internal:27017/?authMechanism=MONGODB-X509&directConnection=true&appName=mongosh+2.1.4                                                                        
MongoServerError: no such command: 'authenticate'     

@chilagrow chilagrow marked this pull request as ready for review March 13, 2024 10:46
@chilagrow chilagrow requested a review from a team as a code owner March 13, 2024 10:46
@chilagrow chilagrow enabled auto-merge (squash) March 13, 2024 10:47
@AlekSi AlekSi changed the title Fix speculativeAuthenticate panic on empty database Fix speculativeAuthenticate panic on empty database Mar 13, 2024
Copy link
Member

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@chilagrow chilagrow merged commit 8483f04 into FerretDB:main Mar 13, 2024
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/chore Code maintenance improvements
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Implement localhost exception
3 participants