Skip to content

Commit f98d938

Browse files
Add automatic DNS forwarder setup for IPA-AD trust
IPA trust tests fail with "Unable to read domain information" when IPA's DNS cannot resolve the AD domain. Added setup_dns_forwarder() to IPATrustADTopologyController that: Creates a DNS forward zone for the AD domain Resolves AD hostname to IP (required by ipa dnsforwardzone-add) Restarts named to apply the configuration Signed-off-by: Madhuri Upadhye <[email protected]>
1 parent e81edbf commit f98d938

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

sssd_test_framework/topology_controllers.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import socket
4+
35
from pytest_mh import BackupTopologyController
46
from pytest_mh.conn import ProcessResult
57

@@ -144,6 +146,9 @@ def topology_setup(self, client: ClientHost, ipa: IPAHost, trusted: ADHost | Sam
144146
self.logger.info(f"Topology '{self.name}' is already provisioned")
145147
return
146148

149+
# Configure DNS forwarder for AD domain on IPA server
150+
self.setup_dns_forwarder(ipa, trusted)
151+
147152
# Create trust
148153
self.logger.info(f"Establishing trust between {ipa.domain} and {trusted.domain}")
149154
ipa.kinit()
@@ -167,6 +172,52 @@ def topology_setup(self, client: ClientHost, ipa: IPAHost, trusted: ADHost | Sam
167172
# Backup so we can restore to this state after each test
168173
super().topology_setup()
169174

175+
def setup_dns_forwarder(self, ipa: IPAHost, trusted: ADHost | SambaHost) -> None:
176+
"""
177+
Configure DNS forwarder on IPA server for the trusted AD domain.
178+
179+
This ensures IPA can resolve the AD domain for trust establishment.
180+
"""
181+
self.logger.info(f"Configuring DNS forwarder for {trusted.domain} on {ipa.hostname}")
182+
ipa.kinit()
183+
184+
# Check if forwarder already exists
185+
result = ipa.conn.exec(
186+
["ipa", "dnsforwardzone-show", trusted.domain],
187+
raise_on_error=False,
188+
)
189+
190+
if result.rc == 0:
191+
self.logger.info(f"DNS forwarder for {trusted.domain} already exists, skipping")
192+
return
193+
194+
# Resolve AD server hostname to IP address (forwarder requires IP)
195+
# Use getattr to safely access the host attribute from the connection
196+
ad_hostname = getattr(trusted.conn, "host", trusted.hostname)
197+
try:
198+
ad_ip = socket.gethostbyname(ad_hostname)
199+
except socket.gaierror:
200+
self.logger.error(
201+
f"Could not resolve hostname '{ad_hostname}'. "
202+
"Please ensure it is resolvable from the test controller."
203+
)
204+
raise
205+
206+
# Add DNS forward zone pointing to the AD server IP
207+
ipa.conn.exec(
208+
[
209+
"ipa",
210+
"dnsforwardzone-add",
211+
trusted.domain,
212+
f"--forwarder={ad_ip}",
213+
"--forward-policy=only",
214+
]
215+
)
216+
217+
# Restart named to ensure it picks up the new forwarder zone
218+
ipa.conn.exec(["systemctl", "restart", "named"])
219+
self.logger.info(f"DNS forwarder for {trusted.domain} configured successfully")
220+
170221
# If this command is run on freshly started containers, it is possible the IPA is not yet
171222
# fully ready to create the trust. It takes a while for it to start working.
172223
@retry_command(max_retries=20, delay=5, match_stderr='CIFS server communication error: code "3221225581"')

0 commit comments

Comments
 (0)