Skip to content

Commit ae43242

Browse files
authored
CDRIVER-4489 refactor URI auth finalization by authentication mechanism (#1896)
* CDRIVER-3517 promote empty authSource to client error * CDRIVER-4128 promote invalid or unsupported CANONICALIZE_HOST_NAME values to client error * CDRIVER-5773 further remove support and testing of MONGODB-CR * CDRIVER-5776 avoid assertions for null fields * CDRIVER-5811 remove test skip for MONGODB-AWS username and password validation * CDRIVER-5812 remove workaround for incorrect MONGODB-AWS authSource * Modernize test code for URI and connection strings * Remove obsolete(?) comment concerning GSSAPISERVICENAME overwrites * Update wording for NEWS entries
1 parent f2ed9aa commit ae43242

File tree

9 files changed

+2177
-647
lines changed

9 files changed

+2177
-647
lines changed

NEWS

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ Instead, the names must be prefixed with the parent directory: `mongoc/mongoc.h`
3434
```
3535

3636

37+
Changes:
38+
39+
* URI authentication credentials validation (only applicable during creation of a new `mongoc_uri_t` object from a connection string):
40+
* `authMechanism` is now validated and returns a client error for invalid or unsupported values.
41+
* `authSource` is now validated and returns a client error for invalid or unsupported values for the specified `authMechanism`.
42+
* `authSource` is now correctly defaulted to `"$external"` for MONGODB-AWS (instead of the database name or `"admin"`).
43+
* The requirement that a password is provided is now enforced when the authentication mechanism is specified for:
44+
* PLAIN
45+
* SCRAM-SHA-1
46+
* SCRAM-SHA-256
47+
* The requirement that neither or both a username and password is provided (optionally with a `AWS_SESSION_TOKEN`) is now enforced for MONGODB-AWS.
48+
* `authMechanismProperties` is now prohibited (instead of ignored) when the authentication mechanism is specified for:
49+
* PLAIN
50+
* SCRAM-SHA-1
51+
* SCRAM-SHA-256
52+
* MONGODB-X509
53+
* `authMechanismProperties` is now validated and returns a client error for invalid or unsupported fields when the authentication mechanism is specified for:
54+
* GSSAPI: supported fields are SERVICE_NAME, CANONICALIZE_HOST_NAME, SERVICE_REALM, and SERVICE_HOST.
55+
* MONGODB-AWS: supported fields are AWS_SESSION_TOKEN.
56+
3757
libmongoc 1.30.2
3858
================
3959

src/libmongoc/src/mongoc/mongoc-sasl.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,18 @@ _mongoc_sasl_set_properties (mongoc_sasl_t *sasl, const mongoc_uri_t *uri)
110110
canonicalize = bson_iter_bool (&iter);
111111
}
112112

113+
/* newer "authMechanismProperties" URI syntax takes precedence */
113114
if (bson_iter_init_find_case (&iter, &properties, "CANONICALIZE_HOST_NAME") && BSON_ITER_HOLDS_UTF8 (&iter)) {
114-
/* newer "authMechanismProperties" URI syntax takes precedence */
115-
canonicalize = !strcasecmp (bson_iter_utf8 (&iter, NULL), "true");
115+
const char *const value = bson_iter_utf8 (&iter, NULL);
116+
117+
const bool is_true = strcasecmp (value, "true") == 0;
118+
119+
// CDRIVER-4128: only legacy boolean values are currently supported.
120+
if (!is_true && strcasecmp (value, "false") != 0) {
121+
MONGOC_WARNING ("Unsupported value for \"CANONICALIZE_HOST_NAME\": \"%s\"", value);
122+
} else {
123+
canonicalize = is_true;
124+
}
116125
}
117126

118127
sasl->canonicalize_host_name = canonicalize;

0 commit comments

Comments
 (0)