Skip to content

Commit 2022717

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 <mupadhye@redhat.com>
1 parent 9c026fb commit 2022717

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

sssd_test_framework/topology_controllers.py

Lines changed: 46 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

@@ -137,6 +139,9 @@ def topology_setup(self, client: ClientHost, ipa: IPAHost, trusted: ADHost | Sam
137139
self.logger.info(f"Topology '{self.name}' is already provisioned")
138140
return
139141

142+
# Configure DNS forwarder for AD domain on IPA server
143+
self.setup_dns_forwarder(ipa, trusted)
144+
140145
# Create trust
141146
self.logger.info(f"Establishing trust between {ipa.domain} and {trusted.domain}")
142147
ipa.kinit()
@@ -160,6 +165,47 @@ def topology_setup(self, client: ClientHost, ipa: IPAHost, trusted: ADHost | Sam
160165
# Backup so we can restore to this state after each test
161166
super().topology_setup()
162167

168+
def setup_dns_forwarder(self, ipa: IPAHost, trusted: ADHost | SambaHost) -> None:
169+
"""
170+
Configure DNS forwarder on IPA server for the trusted AD domain.
171+
172+
This ensures IPA can resolve the AD domain for trust establishment.
173+
"""
174+
self.logger.info(f"Configuring DNS forwarder for {trusted.domain} on {ipa.hostname}")
175+
ipa.kinit()
176+
177+
# Check if forwarder already exists
178+
result = ipa.conn.exec(
179+
["ipa", "dnsforwardzone-show", trusted.domain],
180+
raise_on_error=False,
181+
)
182+
183+
if result.rc == 0:
184+
self.logger.info(f"DNS forwarder for {trusted.domain} already exists, skipping")
185+
return
186+
187+
# Resolve AD server hostname to IP address (forwarder requires IP)
188+
try:
189+
ad_ip = socket.gethostbyname(trusted.conn.host)
190+
except socket.gaierror:
191+
# If resolution fails, try using the hostname directly
192+
ad_ip = trusted.conn.host
193+
194+
# Add DNS forward zone pointing to the AD server IP
195+
ipa.conn.exec(
196+
[
197+
"ipa",
198+
"dnsforwardzone-add",
199+
trusted.domain,
200+
f"--forwarder={ad_ip}",
201+
"--forward-policy=only",
202+
]
203+
)
204+
205+
# Restart named to ensure it picks up the new forwarder zone
206+
ipa.conn.exec(["systemctl", "restart", "named"])
207+
self.logger.info(f"DNS forwarder for {trusted.domain} configured successfully")
208+
163209
# If this command is run on freshly started containers, it is possible the IPA is not yet
164210
# fully ready to create the trust. It takes a while for it to start working.
165211
@retry_command(max_retries=20, delay=5, match_stderr='CIFS server communication error: code "3221225581"')

0 commit comments

Comments
 (0)