-
Notifications
You must be signed in to change notification settings - Fork 24k
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
ansible_fqdn variable uses socket.getfqdn() which can provide weird results. #9972
Comments
I'm not sure this is really an issue is it? Ansible is calling Seems like you are using an IP which already has DNS, and IMO should update your workflow to make sure DNS configured properly prior to provisioning. I guess I view it as an OOO issue. |
Relying on external lookups for local facts like hostname ( fqdn ) is unreliable at best. Facts about a local machine should come from that machine, or at least be obvious ( in documentation and in naming ) that the fact uses external resources to determine its result. The issue here is that I'm actually using a TLD that already exists ( .computer ) for which I had no idea ( looks like it was created in Dec 2013 ) until I ran across this issue. This combined with the fact that even if it wasn't a valid TLD a shady DNS server upstream could still have a record for it ( Many ISPs will respond with an IP for a landing page on bad DNS lookups ). Therefore I cannot reliably use any hostname that I don't control the domain for in my own DNS servers if I don't want to risk This is a massive potential security hole that unless addressed with changes to the way ansible looks up this fact or at least an abundance of documentation and warnings about the potential hazards could make this a very hazardous fact to use. |
What about in environments where you have public/private/multiple interfaces? Depending on provisioning, you have multiple ips in the hosts file for the same name. Doing a PTR lookup then is a free for all at best. Is there any reason for ansible_fqdn to be anything other than |
Ah, I see. You simply named your system I can see your point, if you don't want to manage DNS for hosts you are booting. Just want the functionality @claco touches on. I personally like to manage DNS prior to systems I boot in route 53/dynect/self managed DNS, but I do see your point. |
you got it! I get what you're saying about you should set up DNS before booting system but this specific case was throwaway vagrant VMs, so not worth messing with DNS. I bet there are plenty of other use cases where setting up DNS is unnesesary overhead, and this behavior is unexpected and undocumented and potentially dangerous. |
Then what about using ansible_nodename rather than ansible_fqdn ? And ansible_fqdn kinda imply to use a resolver for that, cf hostname(1), so I do not think the current behavior should change. It could however be better documented, like all the facts. For now, we just have this http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts , which just say "here is a bunch of facts about the system", and people are expected to look at the output and know what they mean, constraints, and this kind of things, which is not very intuitive. |
Can You Help Us Out?Thanks for filing a ticket! I am the friendly GitHub Ansibot. It looks like you might not have filled out the issue description based on our standard issue template. You might not have known about that, and that's ok too, we'll tell you how to do it. We have a standard template because Ansible is a really busy project and it helps to have some standard information in each ticket, and GitHub doesn't yet provide a standard facility to do this like some other bug trackers. We hope you understand as this is really valuable to us!. Solving this is simple: please copy the contents of this template and paste it into the description of your ticket. That's it! If You Had A Question To Ask InsteadIf you happened to have a "how do I do this in Ansible" type of question, that's probably more of a user-list question than a bug report, and you should probably ask this question on the project mailing list instead. However, if you think you have a bug, the report is the way to go! We definitely want all the bugs filed :) Just trying to help! About Priority TagsSince you're here, we'll also share some useful information at this time. In general tickets will be assigned a priority between P1 (highest) and P5, and then worked in priority order. We may also have some follow up questions along the way, so keeping up with follow up comments via GitHub notifications is a good idea. Due to large interest in Ansible, humans may not comment on your ticket immediately. Mailing ListsIf you have concerns or questions, you're welcome to stop by the ansible-project or ansible-development mailing lists, as appropriate. Here are the links:
Thanks again for the interest in Ansible! |
* Since 22fc14a the `ansible_fqdn` resolves to "localhost". Related to: ansible/ansible#9972 * This patch does not fix hosts already provisioned with the version 22fc14a because it is expected that not many users already used it. * Moving the v6 entry above localhost solves the issue. Problem: /etc/hosts ``` ::1 localhost ip6-localhost ip6-loopback 0::1 host.testing test ``` returns "localhost" for `python -c "import socket; print socket.getfqdn()"` ``` 0::1 host.testing test ::1 localhost ip6-localhost ip6-loopback ``` returns "host.testing" for `python -c "import socket; print socket.getfqdn()"`
From man 1 hostname:
So, technically ansible does it right, and if you have incorrect ansible_fqdn either fix your DNS or /etc/hosts. |
I can confirm that putting a line like the following in
|
Hi! Thanks very much for your submission to Ansible. It sincerely means a lot to us. We're not sure this is a bug, and we don't mean for this to be confrontational. Let's explain what we're thinking:
As such, we're going to close this ticket. However, we're open to being corrected, should you wish to discuss. You can stop by one of our two mailing lists
Comments on closed tickets aren't something we monitor, so if you do disagree with this, a mailing list thread is probably appropriate. Thank you once again for this and your interest in Ansible! |
@paulczar Use the ansible-hostname role to set your hostname and ensure the proper line exists in |
I've been seeing some weird results show up in
ansible_fqdn
and finally tracked down why.ansible_fqdn uses socket.getfqdn() which appears to collect the system hostname and then loook it up in DNS. If DNS doesn't exist for the host, or worse, it exists out on the internets because now just about anything is allowed as a TLD you get someone elses result.
For example I have a VM who's hostname is set to
allinone.computer
I run
ansible -m test
against it and I get these values in the results -yurika dot WTF?!?!?!
So I do some digging, namely an strace against a python script that calls socket.fqdn() ( see here for the script and strace - https://gist.github.com/paulczar/ee2a9cf3871038fd8beb ).
Turns out socket.fqdn() calls
uname
from which it collects the nameallinone.computer
.It then calls out to resolve that via DNS, which since I don't have a DNS server with records for
.computer
it calls out to the TLD dns hints which happens to actually return a result because .computer is now a valid TLD.it gets back an IP address ( 77.78.104.3 ) and the it looks up the PTR record for that IP which gives it
thus ansible thinks my FQDN is
yurika.gransy.com
.There are many reasons for a person not to have DNS confgured ( or worse, to have had their dns poisoned, or broken for some reason) for the hostname that they're using, and in my opinion it could lead to some very undesirable behavior. if I had used
ansible_fqdn
as the destination for syslog then I'd be sending all of my logs out to some random host on the internets.The text was updated successfully, but these errors were encountered: