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

Validate user credendials before trying to bootstrap. #209

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

bergsjoh
Copy link
Contributor

Silently validate user credentials before throwing a an exception and print userfriendly errors msgs.

bootstrap.py Outdated
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
if sock.connect_ex((host, 8443)) == 0:
Copy link
Member

Choose a reason for hiding this comment

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

the if and else parts have identical code, so how about:

for port in [8443, 443]:
    if sock.connect_ex((host, port)) == 0:
        sock.close()
        return str(port)
return None

bootstrap.py Outdated
so we need to disable SSL verification since it's now enabled
per default in RHEL7.4+.
"""
port = guess_api_port(options.foreman_fqdn)
Copy link
Member

Choose a reason for hiding this comment

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

instead of doing this here as a special case, why not using API_PORT = guess_api_port() in https://github.com/bergsjoh/katello-client-bootstrap/blob/d1a85da6d7cc9fc4c78bf56c1e325912a7cbca46/bootstrap.py#L851?

and then that should probably be moved after the argument parsing, as otherwise foreman_fqdn won't be defined yet.

bootstrap.py Outdated
sys.exit(2)


def guess_api_port(host):
Copy link
Member

Choose a reason for hiding this comment

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

the function returns an int, this will break the string concatenation above.

@evgeni
Copy link
Member

evgeni commented Aug 26, 2017

This looks good to me now. I did not run the code yet, though.

Could you please rebase on the latest master changes?

@evgeni evgeni added this to the 1.5.0 milestone Aug 26, 2017
@bergsjoh
Copy link
Contributor Author

Rebased.

Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

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

one small change request, but otherwise looks fine.

@@ -1013,6 +1061,8 @@ def exec_service(service, command, failonerror=True):
# > Clean the environment from LD_... variables
clean_environment()

validate_login()
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment like # > Validate credentials, this will ease the generation of the flow as described in https://github.com/Katello/katello-client-bootstrap/blob/master/CONTRIBUTING.md#developer-and-contributor-notes

@evgeni
Copy link
Member

evgeni commented Aug 29, 2017

after discussion with @bergsjoh on IRC: this does not work as intended, as Katello/Satellite also has 8443 open (Candlepin). Going to have to hit /katello/api/ping or similar.

@evgeni evgeni modified the milestones: 1.5.0, 1.6.0 Jan 22, 2018
@beav
Copy link

beav commented Jun 15, 2018

@bergsjoh @evgeni is this still being worked on? It hasn't been updated in awhile.

@bergsjoh
Copy link
Contributor Author

Whoops, almost a year. Sorry I got busy about the time we realized that the first approach didn't work. Haven't looked into the alternate of using ping or so still. If you want to finish it up, feel free @beav.

@sideangleside sideangleside removed this from the 1.6.0 milestone Aug 7, 2018
@sideangleside
Copy link
Member

@beav @bergsjoh I'll rebase, improve and finish this PR unless anyone has any aversions.

@sideangleside sideangleside self-assigned this Aug 7, 2018
@sideangleside sideangleside added this to the 1.7.0 milestone Aug 7, 2018
@bergsjoh
Copy link
Contributor Author

bergsjoh commented Aug 8, 2018

Please go ahead @sideangleside. Thx.

@evgeni
Copy link
Member

evgeni commented Aug 10, 2018

@sideangleside when I last talked with @bergsjoh about this, we ended up in a dark corner: the credential verification has to happen before we install the katello-ca-consumer RPM, so we don't know the port yet. both Katello and Content Proxy have 443 and 8443 open, but only one of them is serving the right API.

So you'd need to do a guess_port(), which connects to both ports and tries an (unathenticated) ping, and then use the port that answered correctly in the rest of the code.

Good luck :)

@evgeni evgeni modified the milestones: 1.7.0, 1.8.0 Jan 24, 2019
@@ -804,6 +836,20 @@ def exec_service(service, command, failonerror=True):
exec_failok("/sbin/service %s %s" % (service, command))


def guess_api_port(host):
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'd go with the following version:

def guess_api_port(hostname):
    """Helper function to get the API port by probing"""
    for port in [443, 8443]:
        url = 'https://' + hostname + ':' + str(port) + '/katello/api/status'
        try:
            call_api(url, no_verify_ssl=True, silent=True, safe=True)
            return str(port)
        except:  # noqa: E722, pylint:disable=bare-except
            pass
    return "443"

the /katello/api/status endpoint doesn't require authentication and returns a JSON.

We just need to make call_api not to call sys.exit(1) if safe=True

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.

4 participants