Skip to content
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

Update http_proxy validation to support IPs too #9

Closed
wants to merge 5 commits into from

Conversation

MrSecure
Copy link

Update validation of http_proxy & http_proxy_port to be a bit more strict, as well as to allow IPv4 and IPv6 address as the http_proxy.

  • http_proxy_port is checked to ensure it's in the appropriate range
  • http_proxy is now checked using stdlib's id_domain_name, is_ipv4_address, and is_ipv6_address functions
  • If http_proxy is an IPv6 address, it is enclosed in brackets so that the $proxy_uri will be usable.

Copy link
Member

@edestecd edestecd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the issues I mentioned and I will merge.

if is_ipv4_address($http_proxy) or is_domain_name($http_proxy) {
$proxy_is_valid = true
} elsif is_ipv6_address($http_proxy) { # IPv6 needs to be enclosed in []
$http_proxy = enclose_ipv6($http_proxy)
Copy link
Member

@edestecd edestecd Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puppet does not allow you to reassign a variable. You will need to use another variable like $_http_proxy and then use that below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 1b57abd

if $http_proxy_port { validate_re($http_proxy_port, '^\d+$') }
# Validates that $http_proxy is a valid, usable domain name or IP address
if $http_proxy and size($http_proxy) > 3 { # '.' is an RFC-valid domain name, but not usable in this context
if is_ipv4_address($http_proxy) or is_domain_name($http_proxy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions were not introduced untill stdlib version 4.12.0.
You will need to require a minimum of that version here: https://github.com/MiamiOH/puppet-httpproxy/blob/master/metadata.json#L12

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in commit e8317c7

# Invalid proxy specified - could also 'undef' the value an continue??
$proxy_is_valid = 'No, the proxy is not valid'
}
validate_bool($proxy_is_valid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not really validating a boolean here. I feel like this is kind of a bad way to do this.
I think a better approach would be to just use the fail function in the else with a nice message about why the input is not valid (Its not a valid domain or ip.)
Something like this: https://github.com/MiamiOH/puppet-pam_access/blob/master/manifests/params.pp#L18

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for the function to do that! Thank you. I'll get rid of that ugly hack.

if is_ipv4_address($http_proxy) or is_domain_name($http_proxy) {
$_http_proxy = $http_proxy
} elsif is_ipv6_address($http_proxy) { # IPv6 needs to be enclosed in []
$_http_proxy = enclose_ipv6($http_proxy)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of other files reference this var too:
I almost missed these...

"%_httpproxy ${httpproxy::http_proxy}",

'host' => $httpproxy::http_proxy,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed those, but both looked like the underlying tooling handled host & port independently. For rpm, this is the case. I'll fix it up for APT, since the underlying puppet module concatenates the host and port into a string in the erb template.

Copy link
Author

@MrSecure MrSecure Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed APT handling in 2b8ae10

And THANK YOU for taking the time to review and help me improve the PR!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your reasoning for why the rpm class does not need the same thing?
If you don't change it in the rpm class then your ipv6 fix will not be applied to the rpm config file...

Can you help me understand why you think that one is not necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rpm case, rpm.pp creates a file which contains a line for %_httpport and a line for %_httpproxy, and RPM/YUM builds the full proxy RUL on the fly, handling enclosing the IPv6 address in brackets if needed.

For apt configurations, the parameters are passed into the '::apt' class's proxy hash (package/apt.pp#L9) . In the apt module, they're used to build a single string which requires that the IPv6 address be wrapped in brackets (init.pp#L76 and proxy.erb#L1). In all likelihood, it's probably more accurate to say that the apt module has a bug - it does not properly handle IPv6 addresses when using them in the template; this would qualify as a work-around for that bug.

Despite the appearance to the contrary, the puppetlabs/apt module uses
the 'host' and 'port' to form a proxy URL string.  Because of this, we
need to use the _http_proxy variable, in case the value holds an IPv6
address which needs to be proprely enclosed.

Signed-off-by: Mr. Secure <ben.github@mrsecure.org>
@MrSecure
Copy link
Author

MrSecure commented Dec 8, 2016

Created upstream PR for IPv6 handling - puppetlabs/puppetlabs-apt#645

@edestecd
Copy link
Member

edestecd commented Apr 9, 2018

Fixed in #10

@edestecd edestecd closed this Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants