[SERVER-75897] Accept both int32/int64 values for int32/int64 QE equality fields in Query Analysis Created: 10/Apr/23  Updated: 02/Feb/24

Status: Backlog
Project: Core Server
Component/s: Field Level Encryption, Queryable Encryption
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Kevin Albertson Assignee: Reilly McBride
Resolution: Unresolved Votes: 0
Labels: qi-queryable-encryption
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-77264 Verify that integer types are interch... Closed
Assigned Teams:
Query Integration
Participants:

 Description   

Proposal

  • Always accept int32 values for an int64 field. Convert the int32 to int64.
  • Sometimes accept int64 values for an int32 field. Convert the int64 to int32 if the int64 is in range of an int32.

Background & Motivation

Query Analysis (mongocryptd / crypt_shared) returns an error if the value type being analyzed does not exactly match the bsonType from encryptedFields. Example:

// run this on mongocryptd:
db.runCommand({
    "insert": "test",
    "documents": [
        {
            "_id": 1,
            "value": NumberInt("123")
        }
    ],
    "$db": "test",
    "encryptionInformation": {
        "type": 1,
        "schema": {
            "test.test": {
                "escCollection": "enxcol_.test.esc",
                "ecocCollection": "enxcol_.test.ecoc",
                "fields": [
                    {
                        "keyId": UUID("b337ba84-68ec-4df5-b711-6e87bcfb9096"),
                        "path": "value",
                        "bsonType": "long",
                        "queries": {
                            "queryType": "equality",
                            "contention": 0
                        }
                    }
                ]
            }
        }
    }
})
// Results in: MongoServerError: Cannot encrypt element of type int because schema requires that type is one of: [ long ]

This gist includes an example to run against mongocryptd.

Some driver languages do not have a straightforward way to specify int32 and int64. This is noted in this slack conversation https://mongodb.slack.com/archives/C0406ECL478/p1681098681664019:

> Does PHP provide a way to specify the numeric type being encoded?
Not through any user-friendly API. For our internal needs, we reconstruct an Int64 object.



 Comments   
Comment by Davis Haupt (Inactive) [ 18/May/23 ]

Note that this is already implemented for the QE range preview, so I'm editing the ticket title to clarify that this modification is only necessary for equality indexes.

Comment by Davis Haupt (Inactive) [ 18/May/23 ]

This ticket is quick-win size. There are a few places where the code will have to be modified to let this type mismatch through, but it should not take more than a week to do.

Comment by Cynthia Braund (Inactive) [ 04/May/23 ]

I checked with the team as well and no concerns here, in fact it will be a more seamless experience.

Comment by Ted Tuckman [ 13/Apr/23 ]

kateryna.kamenieva@mongodb.com and cynthia.braund@mongodb.com can you weigh in on whether this is something we want to do?

CC davis.haupt@mongodb.com

Generated at Thu Feb 08 06:31:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.