-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
PUP-2289 Fix host type and provider. #3005
Conversation
please do not merge yet. i have to work on spec tests. |
CLA signed by all contributors. |
@lmello thanks! Ping when you have spec tests, but thanks very much for working on this!! |
@kylog done the tests. I will squash the commits. after that you can merge, if you like it. This fix the first bug reported on pup-2289, it will still be needed to fix the second bug that is on host provider (parsed or parsedfile). Would after we have both bugs fixed, would it be possible to generate one puppet 3.4 rpm package ? |
@kylog ready to go. Thanks! :-) |
I had fixed both bugs. :-) , there was one typo that was fixed, i had rebased the code into two commits, one that fix the resource type, and other that fix the resource provider. I had based the resource provider solution on mount resource type. |
@kylog any chance this could go in 3.7 ? |
@lmello unfortunately it's just a bit late for 3.7. We locked down the 3.7 list a couple weeks ago and we're hoping to release Tuesday (Sept 2). Thanks for the contribution though! And once 3.7 is out the door, we'll have more time to review open pull requests, etc, so we should get you feedback on this one before long. Thanks! |
@kylog Thanks for your explanation, sadly I discovered this bug, after the locking of 3.7 release :-/ . Completely understand the priorities, congratulations for the 3.7 release today! 👍 please let me know if you need anything from me to help this fix get merged. Best |
@kylog , I know the things are rushed because the puppetconf, but there is any chance this could go on a 3.7.2 release, if we have one ? I don't plan updating to puppet 4 this year, so having this fix on puppet 3.7 would be really awesome! :-) Thanks |
@@ -22,9 +22,13 @@ def valid_v6?(addr) | |||
|
|||
return false | |||
end | |||
def valid_newline?(addr) | |||
return false if addr =~ /\n/ or addr =~ /\r/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ||
instead of or
, and &&
instead of and
everywhere
Thanks for all the feedback. I will have time for making the changes on monday! :-) |
just for reference: |
@@ -17,10 +17,10 @@ | |||
|
|||
text_line :comment, :match => /^#/ | |||
text_line :blank, :match => /^\s*$/ | |||
|
|||
hosts_pattern = '^([0-9a-f:]\S+)\s+([^#\s+]\S+)\s*(.*?)?(?:\s*#\s*(.*))?$' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improved a little bit the regular expression, without making it to much complex :
this was needed because it was matching hostnames as ip address in the following bogus etc/hosts entry:
hostname hostalias #comment
also it was matching #comment as hostnames in the following bogus entry:
127.0.0.1 #comment
I like the original regex for it simplicity, and think we should not change this one to be specific and complex as the regex to validate ip address on host type.
end | ||
|
||
it "should not accept empty host_aliases" do | ||
proc { @class.new(:name => "foo", :host_aliases => ['alias1','']) }.should raise_error | ||
expect { @class.new(:name => "foo", :host_aliases => ['alias1','']) }.to raise_error(Puppet::ResourceError, /Host aliases cannot be an empty string/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
@kylog @hlindberg @ferventcoder Sorry for the long delay I had made all the requested changes and improved the spec tests. This helped finding a flaw in the implementation, that I had already fixed. I had to improve a little bit the regex for parsing etc/hosts lines, because it was matching wrong things as hostname (#comments) and ipaddress (Text for example, hostnames). This was tested with rspec and vagrant. could someone review the changes for merging ? best |
@@ -76,6 +84,7 @@ def inclusive? | |||
raise Puppet::Error, "Invalid host name" | |||
end | |||
end | |||
raise Puppet::Error, "Hostname cannot include newline" if (value =~ /\n/ || value =~ /\r/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also validate hostname to not include newline.
I had also squash all the changes into a single commit. |
@lmello one small thing in the commit message, we usually surround the ticket with parentheses like |
This commit fix the first bug reported on PUP-2289. This is done by implementing validation of newlines on ip, hostname, comments and host_aliases, making sure we don't have any \n or \r. The bug and fix is on host resource type. Bellow is the problem description: If the ip address or hostname or host_aliases use double quoting and have \n, Puppet Will: 1 - Write the wrong entry on /etc/hosts with the linebreak. This leads to a corrupted /etc/hosts, with some lines that could not be parsed by the host resource provider parsed. This leads to second bug on the second puppet run, where it will have error after failing to parse the file, but wipes out the /etc/hosts file, writing only the information on that file that is managed by puppet. How to reproduce it: 1- backup /etc/hosts cp /etc/hosts /etc/hosts.orig 2 - Create the script to reproduce the bug 01 cat <<EOF > /tmp/hostsbug.pp host {'hostsbug': ip => "10.10.12.1\n" } EOF The same apply if you have newline on hostname, hostaliases or comment. 3 - Run the script the first time to reproduce bug 01. puppet apply /tmp/hostsbug.pp 4 - Check /etc/hosts cat /etc/hosts Leonardo Rodrigues de Mello PUP-2289 Fix bug on host resource provider The host resource provider parsed file wipes all entries of etc/hosts file if it gets one entry that could not be parsed. This commits fix this problem, considering that incomplete lines are :text_lines. This is the same solution that was used for mount resource provider. I had checked that etc/hosts ignores invalid entries at least on linux, tested on rhel 5, 6, 7 and debian 5,6,7 and fedora 20. It would be great if someone could test it on other platforms. Thanks Leonardo Rodrigues de Mello Fixes as required on the pull request
@ferventcoder done! :-) |
This commit fix the first bug reported on PUP-2289.
This is done by implementing validation of newlines
on ip, hostname, comments and host_aliases, making
sure we don't have any \n or \r.
Bellow is the problem description:
If the ip address or hostname or host_aliases
use double quoting and have \n, Puppet Will:
1 - Write the wrong entry on /etc/hosts with the linebreak.
This leads to a corrupted /etc/hosts, with some lines
that could not be parsed by the host resource provider
parsed.
This leads to second bug on the second puppet run,
where it will have error after failing to parse the file,
but wipes out the /etc/hosts file, writing only the information
on that file that is managed by puppet.
How to reproduce it:
1- backup /etc/hosts
cp /etc/hosts /etc/hosts.orig
2 - Create the script to reproduce the bug 01
cat < /tmp/hostsbug.pp
host {'hostsbug': ip => "10.10.12.1\n" }
EOF
The same apply if you have newline on hostname, hostaliases or comment.
3 - Run the script the first time to reproduce bug 01.
puppet apply /tmp/hostsbug.pp
4 - Check /etc/hosts
cat /etc/hosts
Leonardo Rodrigues de Mello