-
Notifications
You must be signed in to change notification settings - Fork 1.5k
JAVA-6235: Configurable DNS domain validation for SRV records #2054
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
Open
apmasell
wants to merge
12
commits into
mongodb:main
Choose a base branch
from
apmasell:JAVA-6235
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
421f084
Add configurable DNS domain validation for SRV records
rozza 14542d5
fixup: check TLD list
apmasell ed6a147
fixup
apmasell 28ef6b9
style
apmasell 061d7e9
fixup:idn
apmasell 8a4afe9
fixup:idn
apmasell ad44f13
fixup:idn
apmasell 46628ce
fixup:idn
apmasell 21d5248
fixup:idn
apmasell c034d01
fixup:idn
apmasell 366566c
fixup:idn
apmasell b950893
build(deps): bump testing/resources/specifications
dependabot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |||||
|
|
||||||
| import static com.mongodb.assertions.Assertions.isTrueArgument; | ||||||
| import static com.mongodb.assertions.Assertions.notNull; | ||||||
| import static com.mongodb.internal.connection.DomainNameUtils.normalizeSrvAllowedHostsSuffix; | ||||||
| import static com.mongodb.internal.connection.ServerAddressHelper.createServerAddress; | ||||||
| import static java.util.Collections.singletonList; | ||||||
| import static java.util.Collections.unmodifiableList; | ||||||
|
|
@@ -50,6 +51,7 @@ public final class ClusterSettings { | |||||
| private final String srvHost; | ||||||
| private final Integer srvMaxHosts; | ||||||
| private final String srvServiceName; | ||||||
| private final String srvAllowedHostsSuffix; | ||||||
| private final List<ServerAddress> hosts; | ||||||
| private final ClusterConnectionMode mode; | ||||||
| private final ClusterType requiredClusterType; | ||||||
|
|
@@ -88,6 +90,7 @@ public static final class Builder { | |||||
| private String srvHost; | ||||||
| private Integer srvMaxHosts; | ||||||
| private String srvServiceName = "mongodb"; | ||||||
| private String srvAllowedHostsSuffix; | ||||||
| private List<ServerAddress> hosts = DEFAULT_HOSTS; | ||||||
| private ClusterConnectionMode mode; | ||||||
| private ClusterType requiredClusterType = ClusterType.UNKNOWN; | ||||||
|
|
@@ -114,6 +117,7 @@ public Builder applySettings(final ClusterSettings clusterSettings) { | |||||
| srvHost = clusterSettings.srvHost; | ||||||
| srvServiceName = clusterSettings.srvServiceName; | ||||||
| srvMaxHosts = clusterSettings.srvMaxHosts; | ||||||
| srvAllowedHostsSuffix = clusterSettings.srvAllowedHostsSuffix; | ||||||
| hosts = clusterSettings.hosts; | ||||||
| mode = clusterSettings.mode; | ||||||
| requiredReplicaSetName = clusterSettings.requiredReplicaSetName; | ||||||
|
|
@@ -185,6 +189,26 @@ public Builder srvServiceName(final String srvServiceName) { | |||||
| return this; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Sets the SRV allowed hosts suffix used to validate hosts returned via SRV lookup. | ||||||
| * | ||||||
| * <p>If set, its value is used as the domain for SRV host name validation, replacing the domain inferred from | ||||||
| * the SRV host name. The value is normalized: a leading {@code "."} is prepended if absent, so | ||||||
| * {@link #getSrvAllowedHostsSuffix()} always returns a value beginning with {@code "."}. This setting is only | ||||||
| * used with SRV. Specifying an overly broad suffix (for example a bare TLD) weakens SRV host name validation and | ||||||
| * is the responsibility of the caller.</p> | ||||||
| * | ||||||
| * @param srvAllowedHostsSuffix the SRV allowed hosts suffix; may not be null or empty | ||||||
| * @return this | ||||||
| * @since 5.9 | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * @see #getSrvAllowedHostsSuffix() | ||||||
| */ | ||||||
| public Builder srvAllowedHostsSuffix(final String srvAllowedHostsSuffix) { | ||||||
| notNull("srvAllowedHostsSuffix", srvAllowedHostsSuffix); | ||||||
| this.srvAllowedHostsSuffix = normalizeSrvAllowedHostsSuffix(srvAllowedHostsSuffix); | ||||||
| return this; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Sets the hosts for the cluster. Any duplicate server addresses are removed from the list. | ||||||
| * | ||||||
|
|
@@ -328,6 +352,7 @@ public Builder applyConnectionString(final ConnectionString connectionString) { | |||||
| mode(ClusterConnectionMode.LOAD_BALANCED); | ||||||
| if (connectionString.isSrvProtocol()) { | ||||||
| srvHost(connectionString.getHosts().get(0)); | ||||||
| applySrvConnectionStringOptions(connectionString); | ||||||
| } else { | ||||||
| hosts(singletonList(createServerAddress(connectionString.getHosts().get(0)))); | ||||||
| } | ||||||
|
|
@@ -338,10 +363,7 @@ public Builder applyConnectionString(final ConnectionString connectionString) { | |||||
| if (srvMaxHosts != null) { | ||||||
| srvMaxHosts(srvMaxHosts); | ||||||
| } | ||||||
| String srvServiceName = connectionString.getSrvServiceName(); | ||||||
| if (srvServiceName != null) { | ||||||
| srvServiceName(srvServiceName); | ||||||
| } | ||||||
| applySrvConnectionStringOptions(connectionString); | ||||||
| } else if (directConnection != null) { | ||||||
| mode(directConnection ? ClusterConnectionMode.SINGLE : ClusterConnectionMode.MULTIPLE); | ||||||
| List<String> hosts = directConnection ? singletonList(connectionString.getHosts().get(0)) : connectionString.getHosts(); | ||||||
|
|
@@ -367,6 +389,19 @@ public Builder applyConnectionString(final ConnectionString connectionString) { | |||||
| return this; | ||||||
| } | ||||||
|
|
||||||
| // Applies the SRV options shared by the load-balanced and multi-server SRV paths. srvMaxHosts is intentionally | ||||||
| // not applied here, as it is only valid for the multi-server path. | ||||||
| private void applySrvConnectionStringOptions(final ConnectionString connectionString) { | ||||||
| String srvServiceName = connectionString.getSrvServiceName(); | ||||||
| if (srvServiceName != null) { | ||||||
| srvServiceName(srvServiceName); | ||||||
| } | ||||||
| String srvAllowedHostsSuffix = connectionString.getSrvAllowedHostsSuffix(); | ||||||
| if (srvAllowedHostsSuffix != null) { | ||||||
| srvAllowedHostsSuffix(srvAllowedHostsSuffix); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Build the settings from the builder. | ||||||
| * | ||||||
|
|
@@ -421,6 +456,21 @@ public String getSrvServiceName() { | |||||
| return srvServiceName; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Gets the SRV allowed hosts suffix used to validate hosts returned via SRV lookup. | ||||||
| * | ||||||
| * <p>If present, its value is used as the domain for SRV host name validation, replacing the domain inferred from | ||||||
| * the SRV host name. The value is normalized to always begin with {@code "."}.</p> | ||||||
| * | ||||||
| * @return the normalized SRV allowed hosts suffix, always beginning with {@code "."}. Defaults to null. | ||||||
| * @since 5.9 | ||||||
| * @see Builder#srvAllowedHostsSuffix(String) | ||||||
| */ | ||||||
| @Nullable | ||||||
| public String getSrvAllowedHostsSuffix() { | ||||||
| return srvAllowedHostsSuffix; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Gets the seed list of hosts for the cluster. | ||||||
| * | ||||||
|
|
@@ -554,6 +604,7 @@ public boolean equals(final Object o) { | |||||
| && Objects.equals(srvHost, that.srvHost) | ||||||
| && Objects.equals(srvMaxHosts, that.srvMaxHosts) | ||||||
| && srvServiceName.equals(that.srvServiceName) | ||||||
| && Objects.equals(srvAllowedHostsSuffix, that.srvAllowedHostsSuffix) | ||||||
| && hosts.equals(that.hosts) | ||||||
| && mode == that.mode | ||||||
| && requiredClusterType == that.requiredClusterType | ||||||
|
|
@@ -564,8 +615,8 @@ public boolean equals(final Object o) { | |||||
|
|
||||||
| @Override | ||||||
| public int hashCode() { | ||||||
| return Objects.hash(srvHost, srvMaxHosts, srvServiceName, hosts, mode, requiredClusterType, requiredReplicaSetName, serverSelector, | ||||||
| localThresholdMS, serverSelectionTimeoutMS, clusterListeners); | ||||||
| return Objects.hash(srvHost, srvMaxHosts, srvServiceName, srvAllowedHostsSuffix, hosts, mode, requiredClusterType, | ||||||
| requiredReplicaSetName, serverSelector, localThresholdMS, serverSelectionTimeoutMS, clusterListeners); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -575,6 +626,7 @@ public String toString() { | |||||
| + (srvHost == null ? "" : ", srvHost=" + srvHost) | ||||||
| + (srvServiceName == null ? "" : ", srvServiceName=" + srvServiceName) | ||||||
| + (srvMaxHosts == null ? "" : ", srvMaxHosts=" + srvMaxHosts) | ||||||
| + (srvAllowedHostsSuffix == null ? "" : ", srvAllowedHostsSuffix=" + srvAllowedHostsSuffix) | ||||||
| + ", mode=" + mode | ||||||
| + ", requiredClusterType=" + requiredClusterType | ||||||
| + ", requiredReplicaSetName='" + requiredReplicaSetName + '\'' | ||||||
|
|
@@ -624,6 +676,7 @@ private ClusterSettings(final Builder builder) { | |||||
| srvHost = builder.srvHost; | ||||||
| srvMaxHosts = builder.srvMaxHosts; | ||||||
| srvServiceName = builder.srvServiceName; | ||||||
| srvAllowedHostsSuffix = builder.srvAllowedHostsSuffix; | ||||||
| hosts = builder.hosts; | ||||||
| requiredReplicaSetName = builder.requiredReplicaSetName; | ||||||
| if (builder.mode != null) { | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature will probably be released in
5.13(next minor)