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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRIVERS-2922: Allow valid SRV hostnames with fewer than 3 parts #1628

Merged
merged 28 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f27364c
feat(DRIVERS-2922): loosen options parser restrictions
aditi-khare-mongoDB Aug 8, 2024
2385382
add test criteria
aditi-khare-mongoDB Aug 14, 2024
1873743
grammar fix
aditi-khare-mongoDB Aug 14, 2024
fbacddb
wording fix
aditi-khare-mongoDB Aug 15, 2024
b052a3a
temp commit - changing terminology
aditi-khare-mongoDB Aug 20, 2024
73f7dac
change terminology
aditi-khare-mongoDB Aug 20, 2024
726d576
update changelog
aditi-khare-mongoDB Aug 20, 2024
81f43da
add in prose test ref
aditi-khare-mongoDB Aug 20, 2024
d363089
add parent matching requirements
aditi-khare-mongoDB Aug 23, 2024
9144879
update changelod
aditi-khare-mongoDB Aug 23, 2024
da90490
added in new prose test requirements + fixed formatting
aditi-khare-mongoDB Sep 3, 2024
ff800b4
requested changes
aditi-khare-mongoDB Sep 3, 2024
b26afc2
requested changes 2
aditi-khare-mongoDB Sep 4, 2024
a029753
uniform formatting + fix typo
aditi-khare-mongoDB Sep 5, 2024
43785b2
team review requested changes
aditi-khare-mongoDB Sep 6, 2024
be32cbb
team review requested changes
aditi-khare-mongoDB Sep 6, 2024
cf83c95
team review requested changes 2
aditi-khare-mongoDB Sep 13, 2024
6d953e3
update deprecation comment
aditi-khare-mongoDB Sep 13, 2024
9db03a7
typo
aditi-khare-mongoDB Sep 13, 2024
c2d075c
Merge branch 'master' into drivers-2922/uri-validation
aditi-khare-mongoDB Sep 16, 2024
f4175e9
clarify subdomain
aditi-khare-mongoDB Sep 20, 2024
54a5555
add in Shanes test
aditi-khare-mongoDB Sep 23, 2024
0a90e7c
update changelog date
aditi-khare-mongoDB Sep 24, 2024
e1f6d67
add in specific cases
aditi-khare-mongoDB Sep 24, 2024
fbc8b29
fix test cases
aditi-khare-mongoDB Sep 24, 2024
d658107
fix tests
aditi-khare-mongoDB Sep 24, 2024
c4bb2b4
fix tests
aditi-khare-mongoDB Sep 24, 2024
63f99bb
grammar fix
aditi-khare-mongoDB Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ step before it considers the connection string and SDAM specifications. In this
host names is replaced with a single host name. The format is:

```
mongodb+srv://{hostname}.{domainname}/{options}
mongodb+srv://{subdomain}.{domainname}/{options}
```

`{options}` refers to the optional elements from the [Connection String](../connection-string/connection-string-spec.md)
Expand Down Expand Up @@ -81,20 +81,26 @@ parse error and MUST NOT do DNS resolution or contact hosts.
It is an error to specify more than one host name in a connection string with the `mongodb+srv` protocol, and the driver
MUST raise a parse error and MUST NOT do DNS resolution or contact hosts.

A driver MUST verify that in addition to the `{hostname}`, the `{domainname}` consists of at least two parts: the domain
name, and a TLD. Drivers MUST raise an error and MUST NOT contact the DNS server to obtain SRV (or TXT records) if the
full URI does not consist of at least three parts.
Prior to DNS resolution. `{hostname}` format can follow any of the following formats:

- `{subdomain}`.`{second-level domain}`.`{top-level domain}` (ex: `{blogs.mongodb.com}`)
- `{second-level domain}`.`{top-level domain}` (ex: `{mongodb.localhost}`)
- `{top-level domain}` (ex: `{localhost}`)

For the purposes of this document, `{domainname}` refers to all parts of the hostname, excluding the `{subdomain}`.

Node:
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved

If `mongodb+srv` is used, a driver MUST implicitly also enable TLS. Clients can turn this off by passing `tls=false` in
either the Connection String, or options passed in as parameters in code to the MongoClient constructor (or equivalent
API for each driver), but not through a TXT record (discussed in a later section).

#### Querying DNS

In this preprocessing step, the driver will query the DNS server for SRV records on `{hostname}.{domainname}`, prefixed
with the SRV service name and protocol. The SRV service name is provided in the `srvServiceName` URI option and defaults
to `mongodb`. The protocol is always `tcp`. After prefixing, the URI should look like:
`_{srvServiceName}._tcp.{hostname}.{domainname}`. This DNS query is expected to respond with one or more SRV records.
aditi-khare-mongoDB marked this conversation as resolved.
Show resolved Hide resolved
In this preprocessing step, the driver will query the DNS server for SRV records on the hostname, prefixed with the SRV
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
service name and protocol. The SRV service name is provided in the `srvServiceName` URI option and defaults to
`mongodb`. The protocol is always `tcp`. After prefixing, the URI should look like: `_{srvServiceName}._tcp.{hostname}`.
This DNS query is expected to respond with one or more SRV records.

The priority and weight fields in returned SRV records MUST be ignored.

Expand All @@ -118,12 +124,12 @@ randomization.

### Default Connection String Options

As a second preprocessing step, a Client MUST also query the DNS server for TXT records on `{hostname}.{domainname}`. If
aditi-khare-mongoDB marked this conversation as resolved.
Show resolved Hide resolved
available, a TXT record provides default connection string options. The maximum length of a TXT record string is 255
characters, but there can be multiple strings per TXT record. A Client MUST support multiple TXT record strings and
concatenate them as if they were one single string in the order they are defined in each TXT record. The order of
multiple character strings in each TXT record is guaranteed. A Client MUST NOT allow multiple TXT records for the same
host name and MUST raise an error when multiple TXT records are encountered.
As a second preprocessing step, a Client MUST also query the DNS server for TXT records on `{hostname}`. If available, a
TXT record provides default connection string options. The maximum length of a TXT record string is 255 characters, but
there can be multiple strings per TXT record. A Client MUST support multiple TXT record strings and concatenate them as
if they were one single string in the order they are defined in each TXT record. The order of multiple character strings
in each TXT record is guaranteed. A Client MUST NOT allow multiple TXT records for the same host name and MUST raise an
error when multiple TXT records are encountered.

Information returned within a TXT record is a simple URI string, just like the `{options}` in a connection string.

Expand All @@ -148,10 +154,10 @@ the Connection String spec.

### CNAME not supported

The use of DNS CNAME records is not supported. Clients MUST NOT check for a CNAME record on `{hostname}.{domainname}`. A
system's DNS resolver could transparently handle CNAME, but because of how clients validate records returned from SRV
queries, use of CNAME could break validation. Seedlist discovery therefore does not recommend or support the use of
CNAME records in concert with SRV or TXT records.
The use of DNS CNAME records is not supported. Clients MUST NOT check for a CNAME record on `{hostname}`. A system's DNS
resolver could transparently handle CNAME, but because of how clients validate records returned from SRV queries, use of
CNAME could break validation. Seedlist discovery therefore does not recommend or support the use of CNAME records in
concert with SRV or TXT records.

## Example

Expand Down Expand Up @@ -200,6 +206,12 @@ mongodb://mongodb1.mongodb.com:27317,mongodb2.mongodb.com:27107/?ssl=true&replic

## Test Plan

### Prose Tests

See README.md in the accompanying [test directory](tests).

### Spec Tests

See README.md in the accompanying [test directory](tests).

Additionally, see the `mongodb+srv` test `invalid-uris.yml` in the
Expand Down Expand Up @@ -254,6 +266,9 @@ In the future we could consider using the priority and weight fields of the SRV

## ChangeLog

- 2024-08-20: Removed requirement for URI to have three '.' separated parts. Replace usage of 'TLD' with 'top-level
domain'. `{hostname}` now refers to the entire hostname, not just the `{subdomain}`.

- 2024-03-06: Migrated from reStructuredText to Markdown.

- 2022-10-05: Revise spec front matter and reformat changelog.
Expand Down
7 changes: 7 additions & 0 deletions source/initial-dns-seedlist-discovery/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
This directory contains platform-independent tests that drivers can use to prove their conformance to the Initial DNS
Seedlist Discovery spec.

### Prose Tests
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved

When given a valid SRV with

1. Only one domain level (ex: `{localhost}`)
2. Only two domain levels (ex: `{mongo.local}`) Parse the connection string without throwing a parse related error.
aditi-khare-mongoDB marked this conversation as resolved.
Show resolved Hide resolved

## Test Setup

The tests in the `replica-set` directory MUST be executed against a three-node replica set on localhost ports 27017,
Expand Down
Loading