Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Try to fix dns resolving

Fang-Pen Lin5627a696cb42
diff --git a/backend/bdd/features/environment.py b/backend/bdd/features/environment.py
index 52fda3ecab..8ed1410e01 100644
--- a/backend/bdd/features/environment.py
+++ b/backend/bdd/features/environment.py
@@ -23,6 +23,9 @@ CERT_CA_ID = os.environ.get("CERT_CA_ID")
CERT_TEMPLATE_ID = os.environ.get("CERT_TEMPLATE_ID")
AUTH_TOKEN = os.environ.get("INFISICAL_TOKEN")
BOOTSTRAP_INFISICAL = int(os.environ.get("BOOTSTRAP_INFISICAL", 0))
+TECHNITIUM_URL = os.environ.get("TECHNITIUM_URL", "http://localhost:5380")
+TECHNITIUM_USER = os.environ.get("TECHNITIUM_USER", "admin")
+TECHNITIUM_PASSWORD = os.environ.get("TECHNITIUM_PASSWORD", "infisical")
# Called mostly from a CI to setup the new Infisical instance to get it ready for BDD tests
@@ -188,6 +191,9 @@ def before_all(context: Context):
base_vars = {
"BASE_URL": BASE_URL,
"PEBBLE_URL": PEBBLE_URL,
+ "TECHNITIUM_URL": TECHNITIUM_URL,
+ "TECHNITIUM_USER": TECHNITIUM_USER,
+ "TECHNITIUM_PASSWORD": TECHNITIUM_PASSWORD,
}
if BOOTSTRAP_INFISICAL:
details = bootstrap_infisical(context)
@@ -206,6 +212,7 @@ def before_all(context: Context):
}
context._initial_vars = vars
context.http_client = httpx.Client(base_url=BASE_URL)
+ context.technitium_http_client = httpx.Client(base_url=TECHNITIUM_URL)
def before_scenario(context: Context, scenario: typing.Any):
diff --git a/backend/bdd/features/pki/acme/challenge.feature b/backend/bdd/features/pki/acme/challenge.feature
index 6f79e0841a..0d673c567c 100644
--- a/backend/bdd/features/pki/acme/challenge.feature
+++ b/backend/bdd/features/pki/acme/challenge.feature
@@ -30,19 +30,19 @@ Feature: Challenge
Then I add names to certificate signing request csr
"""
{
- "COMMON_NAME": "localhost"
+ "COMMON_NAME": "example.com"
}
"""
And I create a RSA private key pair as cert_key
And I sign the certificate signing request csr with private key cert_key and output it as csr_pem in PEM format
And I submit the certificate signing request PEM csr_pem certificate order to the ACME server as order
- And I select challenge with type dns-01 for domain localhost from order in order as challenge
- And I add challenge response DNS records for challenge at localhost
+ And I select challenge with type dns-01 for domain example.com from order in order as challenge
+ Then I add domain example.com challenge response DNS records for challenge
And I tell ACME server that challenge is ready to be verified
And I poll and finalize the ACME order order as finalized_order
And the value finalized_order.body with jq ".status" should be equal to "valid"
And I parse the full-chain certificate from order finalized_order as cert
- And the value cert with jq ".subject.common_name" should be equal to "localhost"
+ And the value cert with jq ".subject.common_name" should be equal to "example.com"
Scenario: Validate challenge with retry
Given I have an ACME cert profile as "acme_profile"
diff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.py
index 1ce839638f..a847cbadba 100644
--- a/backend/bdd/features/steps/pki_acme.py
+++ b/backend/bdd/features/steps/pki_acme.py
@@ -266,9 +266,7 @@ def step_impl(context: Context, ca_id: str, template_id: str, profile_var: str):
)
-@given(
- 'I create an ACME profile with config as "{profile_var}"'
-)
+@given('I create an ACME profile with config as "{profile_var}"')
def step_impl(context: Context, profile_var: str):
profile_slug = faker.slug()
jwt_token = context.vars["AUTH_TOKEN"]
@@ -1030,6 +1028,58 @@ def step_impl(context: Context, var_path: str, hostname: str):
serve_challenges(context=context, challenges=[challenge])
+@then("I add domain {domain} challenge response DNS records for {var_path}")
+def step_impl(context: Context, domain: str, var_path: str):
+ client = context.technitium_http_client
+ challenge = eval_var(context, var_path, as_json=False)
+
+ zone = domain
+ domain = f"{challenge.chall.LABEL}.{domain}"
+ value = challenge.chall.validation(context.acme_client.net.key)
+
+ resp = client.post(
+ "/api/user/login",
+ data={
+ "user": context.vars["TECHNITIUM_USER"],
+ "pass": context.vars["TECHNITIUM_PASSWORD"],
+ },
+ )
+ resp.raise_for_status()
+
+ token = resp.json()["token"]
+ resp = client.post(
+ "/api/zones/create",
+ params=dict(
+ token=token,
+ zone=zone,
+ type="Primary",
+ ),
+ )
+ resp.raise_for_status()
+ error_msg = resp.json().get("errorMessage")
+ if error_msg is not None and not error_msg.startswith("Zone already exists:"):
+ raise RuntimeError(f"Unexpected error while creating zone {zone}: {error_msg}")
+
+ resp = client.post(
+ "/api/zones/records/add",
+ params=dict(
+ token=token,
+ zone=zone,
+ domain=domain,
+ type="TXT",
+ text=value,
+ ),
+ )
+ resp.raise_for_status()
+ error_msg = resp.json().get("errorMessage")
+ if error_msg is not None and not error_msg.startswith(
+ "Cannot add record: record already exists"
+ ):
+ raise RuntimeError(
+ f"Unexpected error while creating TXT record {domain} for zone {zone}: {error_msg}"
+ )
+
+
@then("I tell ACME server that {var_path} is ready to be verified")
def step_impl(context: Context, var_path: str):
challenge = eval_var(context, var_path, as_json=False)
diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
index b24db33da1..a7bcde7de3 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
@@ -121,12 +121,12 @@ export const pkiAcmeChallengeServiceFactory = ({
const recordName = `_acme-challenge.${challenge.auth.identifierValue}`;
const records = await resolver.resolveTxt(recordName);
- const recordValue = records.map((chunks) => chunks.join("")).join("");
+ const recordValues = records.map((chunks) => chunks.join(""));
const thumbprint = challenge.auth.account.publicKeyThumbprint;
const expectedChallengeResponseBody = `${challenge.auth.token}.${thumbprint}`;
- if (recordValue !== expectedChallengeResponseBody) {
+ if (!recordValues.some((recordValue) => recordValue.trim() === expectedChallengeResponseBody)) {
throw new AcmeIncorrectResponseError({ message: "ACME DNS-01 challenge response is not correct" });
}
};
@@ -172,6 +172,9 @@ export const pkiAcmeChallengeServiceFactory = ({
throw new AcmeServerInternalError({ message: "Unknown error validating ACME challenge response" });
}
if (exp instanceof Error) {
+ if ((exp as unknown as { code?: string })?.code === "ENOTFOUND") {
+ throw new AcmeDnsFailureError({ message: "Hostname could not be resolved (DNS failure)" });
+ }
logger.error(exp, "Error validating ACME challenge response");
throw exp;
}