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

Resolve string handling for "https://" or "http://" in update_rhsm_conf #17222

Merged
merged 6 commits into from
Apr 3, 2018
Merged

Resolve string handling for "https://" or "http://" in update_rhsm_conf #17222

merged 6 commits into from
Apr 3, 2018

Conversation

robbmanes
Copy link
Contributor

Previously, if a proxy URI was entered into the registration page leading with
"https://" or "http://", it would be incorrectly entered into the rhsm.conf.
This patch prevents this by ensuring it is a valid URI, and correctly parsing
the string regardless if it has only a host in the URI or if it leads with the
protocol.

@robbmanes
Copy link
Contributor Author

robbmanes commented Mar 28, 2018

From BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1561448

The issue arises if, in the editing window where you type the URL of the proxy (Configuration=> Settings=> Region=> Redhat Updates=> Edit), you specify the proxy prefixed with "https://" or "http://". This will incorrectly assume everything after the colon is a port number.

This is likely a text parsing issue, reading the colon as the port indicator and subsequently breaking up the line like so:

proxy_hostname = https
proxy_port = //rmanes-server.someserver.com

Workaround is to either:

  • Specify the proxy without prepending "https://" or "http://"
  • Edit the /etc/rhsm/rhsm.conf and change the proxy_hostname and proxy_port fields to the correct proxy location.

The above patch didn't seem to need any new specs, and I call into question my own if/else statement, but couldn't make a smaller unless work for me.

@bdunne bdunne self-assigned this Mar 28, 2018
@robbmanes
Copy link
Contributor Author

robbmanes commented Mar 28, 2018

I stupidly didn't test with raw IP's - correcting and squashing shortly.

Build fails when we try something like:

irb(main):001:0> Addressable::URI.parse('192.0.2.0:3128')
Addressable::URI::InvalidURIError: Invalid scheme format: 192.0.2.0

So need to revamp the test before we handle a URI - open to suggestions as well.

robbmanes and others added 6 commits April 2, 2018 14:56
Previously, if a proxy URI was entered into the registration page leading with
"https://" or "http://", it would be incorrectly entered into the rhsm.conf.
This patch prevents this by ensuring it is a valid URI, and correctly parsing
the string regardless if it has only a host in the URI or if it leads with the
protocol.

https://bugzilla.redhat.com/show_bug.cgi?id=1561448
- Allow for http(s) or other schemes
- Allow for hostname, IPv4 or IPv6 addresses

https://bugzilla.redhat.com/show_bug.cgi?id=1561448
@bdunne
Copy link
Member

bdunne commented Apr 2, 2018

@carbonin Can I get another set of 👀 on this since I'm also a committer here?

@bdunne bdunne requested a review from carbonin April 2, 2018 18:59
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

👍

@miq-bot
Copy link
Member

miq-bot commented Apr 2, 2018

Checked commits https://github.com/robbmanes/manageiq/compare/ab7f65233e51e43c983c88f726efcd3d7a39f40d~...963a3f3a6c2a5d2b5f1059b06c75756323f22a13 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. ⭐

@@ -83,8 +83,9 @@ def self.update_rhsm_conf(options = {})

return unless option_values[:proxy_address]

write_rhsm_config(:proxy_hostname => option_values[:proxy_address].split(':')[0],
:proxy_port => option_values[:proxy_address].split(':')[1],
proxy_uri = URI.parse(option_values[:proxy_address].include?("://") ? option_values[:proxy_address] : "http://#{option_values[:proxy_address]}")
Copy link
Member

@carbonin carbonin Apr 2, 2018

Choose a reason for hiding this comment

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

I feel like this just punts the issue down the road. Is there no field validation for this? Couldn't we just say "This thing needs to be a valid URI" and give a flash message otherwise?

For example if someone were to forget a / and enter "http:/example.com:123" you would end up in this situation right?

irb(main):007:0> uri = URI.parse("http://http:/example.com:123")
=> #<URI::HTTP http://http/example.com:123>
irb(main):008:0> uri.host
=> "http"
irb(main):009:0> uri.port
=> 80

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree - I tried using Addressable::URI objects initially before I did string checking but am not sure there is error checking by the caller of this method, and testing with that manner threw other ugly exceptions further down the stack that similar didn't appear in the UI or any easy-to-interpret log, so I instead just altered the string validation.

I can look at it deeper after this week, I am onsite with a customer now unfortunately, or we can close this PR in favor of a method that does better error handling.

Copy link
Member

Choose a reason for hiding this comment

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

¯\(ツ)/¯ I think I'm okay with this as is for now. @carbonin and I were just discussing that we may want to open a RFE to the UI to add validation to this field. At least this adds the ability to accept URLs

@bdunne bdunne added the blocker label Apr 3, 2018
Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

Agree with @bdunne. This is nothing but an improvement so LGTM.

@carbonin carbonin self-assigned this Apr 3, 2018
@carbonin carbonin merged commit b44f6b1 into ManageIQ:master Apr 3, 2018
@carbonin carbonin added this to the Sprint 83 Ending Apr 9, 2018 milestone Apr 3, 2018
@simaishi
Copy link
Contributor

@robbmanes @carbonin Can this be gaprindashvili/yes ?

simaishi pushed a commit that referenced this pull request Apr 12, 2018
Resolve string handling for "https://" or "http://" in update_rhsm_conf
(cherry picked from commit b44f6b1)

https://bugzilla.redhat.com/show_bug.cgi?id=1566562
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 6501817774fc8c83bda0047cc90ac39991090d85
Author: Nick Carboni <ncarboni@redhat.com>
Date:   Tue Apr 3 10:25:46 2018 -0400

    Merge pull request #17222 from robbmanes/properly_validate_proxy_urls
    
    Resolve string handling for "https://" or "http://" in update_rhsm_conf
    (cherry picked from commit b44f6b17977f8f8e317360ecde03ea92e35b32ba)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1566562

@simaishi
Copy link
Contributor

@robbmanes @bdunne Can this be fine/yes? This is a blocker for the next Fine build.

simaishi pushed a commit that referenced this pull request Apr 27, 2018
Resolve string handling for "https://" or "http://" in update_rhsm_conf
(cherry picked from commit b44f6b1)

https://bugzilla.redhat.com/show_bug.cgi?id=1572621
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit f25f8108571e619800d56e8c4bffdf8cc144778d
Author: Nick Carboni <ncarboni@redhat.com>
Date:   Tue Apr 3 10:25:46 2018 -0400

    Merge pull request #17222 from robbmanes/properly_validate_proxy_urls
    
    Resolve string handling for "https://" or "http://" in update_rhsm_conf
    (cherry picked from commit b44f6b17977f8f8e317360ecde03ea92e35b32ba)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1572621

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
…oxy_urls

Resolve string handling for "https://" or "http://" in update_rhsm_conf
(cherry picked from commit b44f6b1)

https://bugzilla.redhat.com/show_bug.cgi?id=1572621
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants