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

Configurable DNS search domain #118

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[#114](https://github.com/scionproto-contrib/jpan/pull/114)
- Improved path duplication filtering.
[#117](https://github.com/scionproto-contrib/jpan/pull/117)
- Added environment variable / property for DNS search domain.
[#119](https://github.com/scionproto-contrib/jpan/pull/119)

### Changed
- Clean up TODO and deprecation info. [#100](https://github.com/scionproto-contrib/jpan/pull/100)
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,15 @@ attempt to get network information in the following order until it succeeds:
The reason that the daemon is checked last is that it has a default setting (`localhost:30255`)
while the other options are skipped if no property or environment variable is defined.

| Option | Java property | Environment variable | Default value |
|-------------------------------------|-------------------------------------|-------------------------------|-----------------|
| Daemon port, IP, or IP:port | `org.scion.daemon` | `SCION_DAEMON` | localhost:30255 |
| Bootstrap topology file path | `org.scion.bootstrap.topoFile` | `SCION_BOOTSTRAP_TOPO_FILE` | |
| Bootstrap server host | `org.scion.bootstrap.host` | `SCION_BOOTSTRAP_HOST` | |
| Bootstrap DNS NAPTR entry host name | `org.scion.bootstrap.naptr.name` | `SCION_BOOTSTRAP_NAPTR_NAME` | |
| Bootstrap DNS NAPTR entry host name | `org.scion.test.useOsSearchDomains` | `SCION_USE_OS_SEARCH_DOMAINS` | true |
| Option | Java property | Environment variable | Default value |
|----------------------------------------------|-----------------------------------------------------|--------------------------------|-----------------|
| Daemon port, IP, or IP:port | `org.scion.daemon` | `SCION_DAEMON` | localhost:30255 |
| Bootstrap topology file path | `org.scion.bootstrap.topoFile` | `SCION_BOOTSTRAP_TOPO_FILE` | |
| Bootstrap server host | `org.scion.bootstrap.host` | `SCION_BOOTSTRAP_HOST` | |
| Bootstrap DNS NAPTR entry host name | `org.scion.bootstrap.naptr.name` | `SCION_BOOTSTRAP_NAPTR_NAME` | |
| List of DNS search domains | `org.scion.dnsSearchDomains` | `SCION_DNS_SEARCH_DOMAINS` | |
| Use OS search domains, e.g. /etc/resolv.conf | `org.scion.test.useOsSearchDomains` | `SCION_USE_OS_SEARCH_DOMAINS` | true |


### DNS
JPAN will check the OS default DNS server to resolve SCION addresses.
Expand Down Expand Up @@ -377,6 +379,13 @@ file into you resources folder, or enable logging programmatically with
`System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");`
before using *any* JPAN code.

### No DNS search domain found. Please check your /etc/resolv.conf or similar. / No DNS record found for bootstrap server.

You may have to set the DNS search domain explicitly to a server with SCION NAPTR records. For example (works only if you are inside ETH):
```java
System.setProperty(Constants.PROPERTY_DNS_SEARCH_DOMAINS, "ethz.ch.");
```

### Local testbed (scionproto) does not contain any path

A common problem is that the certificates of the testbed have expired (default validity: 3 days).
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<scion.dnsjava.version>3.5.3</scion.dnsjava.version>
<scion.dnsjava.version>3.6.1</scion.dnsjava.version>
<scion.google-java-format.version>1.22.0</scion.google-java-format.version>
<scion.io-grpc.version>1.63.0</scion.io-grpc.version>
<scion.junit.version>5.10.1</scion.junit.version>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/scion/jpan/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public final class Constants {
public static final String ENV_USE_OS_SEARCH_DOMAINS = "SCION_USE_OS_SEARCH_DOMAINS";
public static final boolean DEFAULT_USE_OS_SEARCH_DOMAINS = true;

/** Provide list of DNS search domains. */
public static final String PROPERTY_DNS_SEARCH_DOMAINS = "org.scion.dnsSearchDomains";

public static final String ENV_DNS_SEARCH_DOMAINS = "SCION_DNS_SEARCH_DOMAINS";

/**
* Non-public property that allows specifying DNS TXT entries for debugging. Example with two
* entries: server1.com="scion=1-ff00:0:110,127.0.0.1";server2.ch="scion=1-ff00:0:112,::1"
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/scion/jpan/ScionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import static org.scion.jpan.Constants.ENV_BOOTSTRAP_NAPTR_NAME;
import static org.scion.jpan.Constants.ENV_BOOTSTRAP_TOPO_FILE;
import static org.scion.jpan.Constants.ENV_DAEMON;
import static org.scion.jpan.Constants.ENV_DNS_SEARCH_DOMAINS;
import static org.scion.jpan.Constants.ENV_USE_OS_SEARCH_DOMAINS;
import static org.scion.jpan.Constants.PROPERTY_BOOTSTRAP_HOST;
import static org.scion.jpan.Constants.PROPERTY_BOOTSTRAP_NAPTR_NAME;
import static org.scion.jpan.Constants.PROPERTY_BOOTSTRAP_TOPO_FILE;
import static org.scion.jpan.Constants.PROPERTY_DAEMON;
import static org.scion.jpan.Constants.PROPERTY_DNS_SEARCH_DOMAINS;
import static org.scion.jpan.Constants.PROPERTY_USE_OS_SEARCH_DOMAINS;

import io.grpc.*;
Expand Down Expand Up @@ -184,10 +186,13 @@ static ScionService defaultService() {
}

// try normal network
String searchDomain =
ScionUtil.getPropertyOrEnv(PROPERTY_DNS_SEARCH_DOMAINS, ENV_DNS_SEARCH_DOMAINS);
if (ScionUtil.getPropertyOrEnv(
PROPERTY_USE_OS_SEARCH_DOMAINS,
ENV_USE_OS_SEARCH_DOMAINS,
DEFAULT_USE_OS_SEARCH_DOMAINS)) {
PROPERTY_USE_OS_SEARCH_DOMAINS,
ENV_USE_OS_SEARCH_DOMAINS,
DEFAULT_USE_OS_SEARCH_DOMAINS)
|| searchDomain != null) {
String dnsResolver = DNSHelper.searchForDiscoveryService();
if (dnsResolver != null) {
defaultService = new ScionService(dnsResolver, Mode.BOOTSTRAP_SERVER_IP);
Expand Down
45 changes: 31 additions & 14 deletions src/main/java/org/scion/jpan/internal/DNSHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@

package org.scion.jpan.internal;

import static org.scion.jpan.Constants.ENV_DNS_SEARCH_DOMAINS;
import static org.scion.jpan.Constants.PROPERTY_DNS_SEARCH_DOMAINS;

import java.io.IOException;
import java.net.InetAddress;
import java.util.List;
import java.util.function.Function;
import org.scion.jpan.ScionRuntimeException;
import org.scion.jpan.ScionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xbill.DNS.AAAARecord;
import org.xbill.DNS.ARecord;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.NAPTRRecord;
import org.xbill.DNS.Name;
import org.xbill.DNS.Record;
import org.xbill.DNS.TXTRecord;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import org.xbill.DNS.*;

public class DNSHelper {

Expand Down Expand Up @@ -64,7 +60,7 @@
}

public static <R> R queryTXT(Name name, String key, Function<String, R> valueParser) {
Record[] records = new Lookup(name, Type.TXT).run();
org.xbill.DNS.Record[] records = new Lookup(name, Type.TXT).run();
if (records == null) {
return null;
}
Expand All @@ -86,7 +82,7 @@
}

public static InetAddress queryA(Name hostName) {
Record[] recordsA = new Lookup(hostName, Type.A).run();
org.xbill.DNS.Record[] recordsA = new Lookup(hostName, Type.A).run();
if (recordsA == null) {
throw new ScionRuntimeException("No DNS A entry found for host: " + hostName);
}
Expand All @@ -95,7 +91,7 @@
}

public static InetAddress queryAAAA(Name hostName) {
Record[] recordsA = new Lookup(hostName, Type.AAAA).run();
org.xbill.DNS.Record[] recordsA = new Lookup(hostName, Type.AAAA).run();

Check warning on line 94 in src/main/java/org/scion/jpan/internal/DNSHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/internal/DNSHelper.java#L94

Added line #L94 was not covered by tests
if (recordsA == null) {
throw new ScionRuntimeException("No DNS AAAA entry found for host: " + hostName);
}
Expand All @@ -104,9 +100,30 @@
}

public static String searchForDiscoveryService() {
String searchDomains =
ScionUtil.getPropertyOrEnv(PROPERTY_DNS_SEARCH_DOMAINS, ENV_DNS_SEARCH_DOMAINS);
if (searchDomains != null) {
for (String domain : searchDomains.split(";")) {
LOG.debug(
"Checking discovery service domain from environment variable/property: {}", domain);
try {
String a = getScionDiscoveryAddress(Name.fromString(domain));
if (a != null) {
return a;
}
} catch (TextParseException e) {
throw new ScionRuntimeException(e);
}

Check warning on line 116 in src/main/java/org/scion/jpan/internal/DNSHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/internal/DNSHelper.java#L114-L116

Added lines #L114 - L116 were not covered by tests
}
}

List<Name> domains = Lookup.getDefaultSearchPath();
if (domains.isEmpty()) {
LOG.warn("No DNS search domain found. Please check your /etc/resolv.conf or similar.");
LOG.warn(

Check warning on line 122 in src/main/java/org/scion/jpan/internal/DNSHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/internal/DNSHelper.java#L122

Added line #L122 was not covered by tests
"No DNS search domain found. Please check your /etc/resolv.conf or similar. You can also specify a domain via "
+ ENV_DNS_SEARCH_DOMAINS
+ " or "
+ PROPERTY_DNS_SEARCH_DOMAINS);
}
for (Name domain : domains) {
LOG.debug("Checking discovery service domain: {}", domain);
Expand All @@ -123,7 +140,7 @@
}

private static String getScionDiscoveryAddress(Name hostName) {
Record[] records = new Lookup(hostName, Type.NAPTR).run();
org.xbill.DNS.Record[] records = new Lookup(hostName, Type.NAPTR).run();
if (records == null) {
LOG.debug("Checking discovery service NAPTR: no records found");
return null;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/scion/jpan/internal/PathRawParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@
}

public int getSegmentCount() {
int nSegmentCount = 1;
nSegmentCount += segLen[1] > 0 ? 1 : 0;
nSegmentCount += segLen[2] > 0 ? 1 : 0;
int nSegmentCount = 0;

Check warning on line 136 in src/main/java/org/scion/jpan/internal/PathRawParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/internal/PathRawParser.java#L136

Added line #L136 was not covered by tests
for (int i = 0; i < segLen.length; i++) {
nSegmentCount += segLen[i] > 0 ? 1 : 0;
}
return nSegmentCount;
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/scion/jpan/api/ScionServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,24 @@ void testDomainSearchResolver() throws IOException {
MockNetwork.stopTiny();
}
}

@Test
void testDomainSearchResolver_PROPERTY() throws IOException {
MockNetwork.startTiny(MockNetwork.Mode.NAPTR);
try {
// Change to use custom search domain
System.setProperty(
Constants.PROPERTY_DNS_SEARCH_DOMAINS, MockBootstrapServer.TOPO_HOST + ".");
Lookup.setDefaultSearchPath("x.y.z."); // Invalid main path
// Lookup topology server
String address = MockNetwork.getTopoServer().getAddress().toString();
assertEquals(address.substring(1), DNSHelper.searchForDiscoveryService());
ScionService service = Scion.defaultService();
assertEquals(MockNetwork.getTopoServer().getLocalIsdAs(), service.getLocalIsdAs());
} finally {
Lookup.setDefaultSearchPath(Collections.emptyList());
MockNetwork.stopTiny();
System.clearProperty(Constants.PROPERTY_DNS_SEARCH_DOMAINS);
}
}
}
1 change: 1 addition & 0 deletions src/test/java/org/scion/jpan/testutil/JUnitSetUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void beforeEach(ExtensionContext context) {
System.clearProperty(Constants.PROPERTY_BOOTSTRAP_NAPTR_NAME);
System.clearProperty(Constants.PROPERTY_BOOTSTRAP_HOST);
System.clearProperty(Constants.PROPERTY_DAEMON);
System.clearProperty(Constants.PROPERTY_DNS_SEARCH_DOMAINS);
System.clearProperty(Constants.PROPERTY_HOSTS_FILES);
System.setProperty(Constants.PROPERTY_USE_OS_SEARCH_DOMAINS, "false");
if (failed) {
Expand Down