Closed pckroon closed 7 months ago
The main issue is that salt.module.dig.A
(and AAAA, but I'm ignoring ipv6 for now) doesn't allow passing more options (such as domain). See https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.dig.html#salt.modules.dig.A.
I worked around it for now by creating the following module (in /srv/salt/_modules/
) called dig_plus.py
:
import six
def A(host, nameserver=None, **dig_options):
dig = ['dig', '+short', six.text_type(host), 'A']
if nameserver is not None:
dig.append('@{}'.format(nameserver))
for name, value in dig_options.items():
if not name.startswith('_'):
#TODO: quote value?
dig.append('+{}={}'.format(name, value))
cmd = __salt__['cmd.run_all'](dig, python_shell=False)
if cmd['retcode'] != 0:
log.warning("dig returned exit code '%s'. Returning empty list as fallback",
cmd['retcode'])
return []
return [ip for ip in cmd['stdout'].split('\n') if __salt__['dig.check_ip'](ip)]
This is heavily based on the salt.modules.dig.A
code. All I added is the dig_options
. This way, you can do dig_plus.A(rohan, domain='example.com)'
.
Using this in openssh-formula/openssh/files/default/ssh_known_hosts
:
...
{%- for alias in aliases -%}
{%- for ip in salt['dig_plus.A'](alias, domain=use_hostnames) + salt['dig.AAAA'](alias) -%}
{%- do aliases_ips.setdefault(ip, []).append(alias) -%}
{%- endfor -%}
{%- endfor -%}
...
pillar.sls
openssh:
known_hosts:
hostnames: 'example.com'
...
Thanks for taking the time to post this issue!
This config works at least on my machines:
/etc/ssh/ssh_known_hosts:
host.domain.tld,1.2.3.4 ssh-ed25519 AAAAC...
/etc/resolv.conf:
search domain.tld
ssh root@host
just works without any known hosts issue.
The proposed change does not solve a problem. (Just my point of view. Maybe I miss something.) Additionally we'd introduce a higher chance of collision caused by identical host names in different domains.
Adding something like dig_plus would essentially mean writing a patch for Salt itself. This is out-of-scope for this formula.
I'll therefore close this issue. Feel free to re-open it in case you think I missed something important. :-)
Your setup
Formula commit hash / release tag
ba2f3c9fe323adc5047e15eefbfb997477534627
(current master)Versions reports (master & minion)
Pillar / config used
pillar.sls
Bug details
Describe the bug
Both
rohan.example.com
androhan
are aliases forrohan2018.example.com
(androhan2018
). However, in the known_hosts file generated onlyrohan2018.example.com
,rohan2018
, its IP, androhan.example.com
are listed. Notably,rohan
is missing.DNS is working in all directions:
nslookup rohan2018.example.com
returns IPnslookup rohan.example.com
returns IPnslookup rohan2018
returns IPnslookup rohan
returns IPnslookup <IP>
returnsrohan2018.example.com
nslookup rohan2018.example.com
returns IPnslookup rohan.example.com
returns IPnslookup rohan2018
returns IPnslookup rohan
returns IPnslookup <IP>
returnsrohan2018.example.com
Any help/advise is welcome :)
(It's also slightly tedious to have to list both
rohan
androhan.example.com
as aliases withhostnames: '*'
, but meh. That's a separate issue.)EDIT with update: removing
rohan.example.com
does'nt causerohan
to get added. So the issue seems not to be having multiple aliases for a host, but rather not using the DNS SEARCH for aliases