Salt: Hosts File is incorrectly handled

Created on 3 Oct 2018  路  4Comments  路  Source: saltstack/salt

Description of Issue/Question

When modifying the hosts file using states.host the entire file is rewritten to use 1 IP entry and a number of aliases.

Example:

127.0.0.1 alias1
127.0.0.1 alias2
127.0.0.1 alias3

Gets rewritten into:

127.0.0.1 alias1 alias2 alias3

Problems start appearing with large numbers of host aliases pointing to the same IP, since the number of characters in a hosts file line is limited to 256 (can anyone find an RFC for this?) which essentially becomes 254 because of \n\r line endings under windows.

Besides, there is undocumented behaviour under Windows that limits the number of aliases in a hosts entry to 8 (1 host + 8 aliases). I was able to reproduce this under Windows Server 2016 with the following:

image

"alias" host entries stop being loaded into dns cache with alias10 (ipconfig /displaydns).

Same behaviour not present in Ubuntu Xenial, where I am able to ping alias10:

image

I am happy to submit a patch for modules.hosts where this is handled. However I would like to discuss the approach.

Regarding line character limit:

  1. Stop using aliases, and have one IP Hostname entry per line;
  2. Add aliases until the character limit is passed, at which point we break to the following line;

Regarding windows handling of aliases:

  1. Identify if we are running under windows (via os grain) and handle hosts file differently;
  2. Apply window's undocumented limits to all OSs and err on the safe side;

Setup

1 sls file with:

hosts_updater.set_windows_routes.{{redacted}}: 
  host.present:
    - ip: 127.0.0.1
    - names:
      - "{{redacted}}.redacted.info"

Steps to Reproduce Issue

Mentioned above

Versions Report

Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: 1.11.2
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 2.0.3
      gitpython: 2.1.7
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.5
      pycparser: 2.18
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 20 2017, 18:23:56)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 2.0.3
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
Bug Core P3 severity-medium stale team-core

Most helpful comment

Just to give some updates on this subject. Me and @jcrsilva are working on the fix on our current enterprise context, since we have the scale and the necessity for this fix we're implementing it and testing before the PR. As soon as we feel comfortable with it we will create a PR with the changes, we did some refactoring of the hosts module and state to make it a bit simpler.

All 4 comments

I don't have a strong preference, i think all of those options are fine, if you wanted to submit a PR, i think that adding comments on why this was changed would be really useful, so that it doesn't get changed back at some point.

also, when checking if it is windows or not, use __utils__['platforms.is_windows'] for 2018.3, and salt.utils.is_windows for 2017.

Thanks!
Daniel

Just to give some updates on this subject. Me and @jcrsilva are working on the fix on our current enterprise context, since we have the scale and the necessity for this fix we're implementing it and testing before the PR. As soon as we feel comfortable with it we will create a PR with the changes, we did some refactoring of the hosts module and state to make it a bit simpler.

Just to give some updates on this subject. Me and @jcrsilva are working on the fix on our current enterprise context, since we have the scale and the necessity for this fix we're implementing it and testing before the PR. As soon as we feel comfortable with it we will create a PR with the changes, we did some refactoring of the hosts module and state to make it a bit simpler.

@tacf and @jcrsilva let me know if I can help. I'm found that bug too, and suffering about that.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings