[SERVER-59846] Structured Logging in Mongo Shell Generates Invalid JSON Created: 09/Sep/21  Updated: 24/Sep/21  Resolved: 24/Sep/21

Status: Closed
Project: Core Server
Component/s: Logging, Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Peter Garafano (Inactive) Assignee: Gabriel Marks
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sprint: Security 2021-10-04
Participants:

 Description   

The Mongo Shell (not mongosh) produces structured log entries using --verbose that contain invalid JSON:

{
    "t": {
        "$date": "2021-09-09T09:46:35.891Z"
    },
    "s": "D1",
    "c": "-",
    "id": 23074,
    "ctx": "main",
    "msg": "User assertion",
    "attr": {
        "error": "DNSHostNotFound: Failed to look up service "xxxx-0.xxx.mongodb.net": Success",
        "file": "src/mongo/util/dns_query_posix-impl.h",
        "line": 324
    }
}

Note that the error is in the attr.error field where the quotes around the hostname are not escaped. The issue appears to be here.



 Comments   
Comment by Gabriel Marks [ 24/Sep/21 ]

Most likely not an issue coming from the server side of things – possibly an issue of how the log was processed after being output.

Comment by Gabriel Marks [ 20/Sep/21 ]

I'm getting: 

 

{"t":{"$date":"2021-09-20T21:36:02.263Z"},"s":"D1", "c":"ASSERT",   "id":23074,   "ctx":"-","msg":"User assertion","attr":{"error":"DNSHostNotFound: Failed to look up service \"_mongodb._tcp.cluster0.xxxx.mongodb.net\": Success","file":"src/mongo/util/dns_query_posix-impl.h","line":349}}

which looks correctly escaped to me.

 

Comment by Peter Garafano (Inactive) [ 20/Sep/21 ]

Hi Gabriel,

In this case, simply connecting to an Atlas Cluster using the Mongo Shell

mongo "mongodb+srv://cluster0.xxxx.mongodb.net/myFirstDatabase" --username xxxx --verbose

The key here is, the required TXT record describing the authSource and replicaSet, needs to be missing/inaccessible.

Comment by Gabriel Marks [ 20/Sep/21 ]

Hi Peter, would it be possible for you to provide a list of commands leading up to this log entry being produced? Thanks so much!

Generated at Thu Feb 08 05:48:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.