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

Add independent registry auth support #5128

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

michaelgugino
Copy link
Contributor

@michaelgugino michaelgugino commented Aug 18, 2017

Added the ability to support authentication for independent / 3rd party
registries. This commit will allow users to provide a oreg_auth_user and
oreg_auth_password to dynmically generate a docker config.json file.

The docker config.json file can be used by openshift to authenticate to
independent / 3rd party registries. oreg_host must supply endpoint connection
info in the form of 'hostname.com:port', with (optional) port 443 default.

To update the config.json on a later run, the user can specify
oreg_auth_credentials_replace=False to update the credentials.

These settings must be used in tandem with oreg_url

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1316341

@michaelgugino michaelgugino requested a review from sdodson August 18, 2017 02:54
@michaelgugino
Copy link
Contributor Author

I have tested the logic of the new statements to ensure the auth file is placed in the suggested location. I have not yet tested to see if openshift will actually use this auth with a 3rd party registry.

path: "{{ registry_auth_credentials_path }}"
when:
- registry_auth_user is defined
- openshift_examples_modify_imagestreams | bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I think openshift_examples_modify_imagestreams have nothing with registry auth here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could be right. Perhats registry_auth_user check is enough?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree, only need the first condition.

register: master_registry_auth_credentials_stat

- name: Create credentials for registry auth
command: "docker --config={{ registry_auth_credentials_path }} login -u {{ registry_auth_user }} -p {{ registry_auth_token }} {{ oreg_host }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

where should user define registry_auth_user and registry_auth_token? In inventory host file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I would put those values in a vault file in group_vars. You could also put those values in inventory, yes, if you don't mind your service account's username/password living in there. You can also pass those values via extra_vars.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to mention that in inventory/byo/hosts.ose.example, give some example to show user how to define registry_auth_user and registry_auth_token.

Copy link
Contributor

@jianlinliu jianlinliu left a comment

Choose a reason for hiding this comment

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

some comments from jialiu

@michaelgugino
Copy link
Contributor Author

so, the code I committed executes as expected. Also somewhat as expected, openshift still does not try to auth or consume those credentials in any way:

Aug 18 11:50:35 ip-172-18-13-138.ec2.internal origin-node[26303]: E0818 11:50:35.665096   26303 kuberuntime_manager.go:619] createPodSandbox for pod "docker-registry-1-deploy_default(579587e8-842b-11e7-bd06-0e81fb6035e4)" failed: rpc error: code = 2 desc = unable to pull sandbox image "registry.reg-aws.openshift.com:443/openshift3/ose-pod:v3.6.0": unauthorized: authentication required

@michaelgugino
Copy link
Contributor Author

michaelgugino commented Aug 18, 2017

Looks like the instructions from bugzilla were close. I'm going to try to update the location of the .docker/config.json to /root to see if that works. On origin /root is the home dir.

https://kubernetes.io/docs/concepts/containers/images/#configuring-nodes-to-authenticate-to-a-private-repository

@michaelgugino
Copy link
Contributor Author

This is currently blocked on: openshift/origin#15880

@michaelgugino
Copy link
Contributor Author

michaelgugino commented Aug 21, 2017

How to test:

# Change the following to "True" to replace existing credentials on master/nodes.
oreg_auth_credentials_replace: False
oreg_auth_user: some_user
oreg_auth_password: some_token

# For OpenShift registry, oreg_auth_password can be generated as follows:
# oc login --config=~/.kube/example.com --username=myuser --password='mypass' https://api.example.com
# oc --config=~/.kube/example.com -t

# port is optional
oreg_host: my.reg.url:443
oreg_url: my.reg.url:443/openshift3/ose-${component}:${version}

openshift_examples_modify_imagestreams: True

Currently blocked on 3.6, but works on 1.5.

@@ -19,3 +19,6 @@ r_openshift_master_os_firewall_allow:
- service: etcd embedded
port: 4001/tcp
cond: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"

registry_auth_credentials_path: "/var/lib/{{ openshift.common.service_type }}/.docker"
Copy link
Member

Choose a reason for hiding this comment

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

registry_auth_credentials_path: "{{ openshift.common.data_dir }}/.docker" instead? This should be pretty stable but that's the var we use elsewhere.

path: "{{ registry_auth_credentials_path }}"
when:
- registry_auth_user is defined
- openshift_examples_modify_imagestreams | bool
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree, only need the first condition.

# If oreg_url points to a registry requiring authentication, provide the following:
oreg_host: example.com:443
registry_auth_user: some_user
registry_auth_token: 'my-token'
Copy link
Member

Choose a reason for hiding this comment

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

Just to ensure commonality with most of our variables what about openshift_registry_auth_host openshift_registry_auth_user and openshift_registry_auth_password instead? Password over token because it's more generic, for our use case where it's an openshift registry it happens to be a token but elsewhere it may just be a password.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about oreg_* as it matches the bits that we're modifying?

oreg_auth_password seems fine.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should not we get oreg_host from oreg_url? Seem like oreg_host is a little redundant.

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 thought about this. I feel it should actually be the other way around, but that's outside the scope of this PR.

I suppose this would also work in something like this:
oreg_url: somehost.com:443/somedir/registry/openshift3/{{ component }}/{{ version }}
oreg_host: somehost.com:443/somedir/registry

What's the best way to parse oreg_url to derive oreg_host in both situations?
Better situation is this:
oreg_host = somehost.example.com
oreg_url = {{ oreg_host }}/{{ oreg_suffix }}

But that would probably break existing users and would require some refactoring.

Copy link
Member

Choose a reason for hiding this comment

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

There's a few places that parse oreg_url to get registry host.

registry_host: "{{ registry_url.split('/')[0] if '.' in registry_url.split('/')[0] else '' }}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and if someone's registry is sitting at example.com/myregistry (ie, it's sitting behind a reverse proxy or something of that nature) then this will break for this purpose. For example: https://docs.docker.com/registry/recipes/nginx/#setting-things-up

I'm happy to change it, but I think we're introducing a bug, and I think it's bad practice to split variables rather than combine them.

@michaelgugino michaelgugino force-pushed the reg-auth branch 2 times, most recently from e3338f3 to b0efbf6 Compare August 23, 2017 14:25
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 23, 2017
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 23, 2017
@@ -167,6 +167,13 @@ openshift_release=v3.6
# modify image streams to point at that registry by setting the following to true
#openshift_examples_modify_imagestreams=true

# If oreg_url points to a registry requiring authentication, provide the following:
oreg_auth_user=some_user
oreg_auth_password='my-pass'
Copy link
Member

Choose a reason for hiding this comment

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

Lets comment these and make it clear that you must set oreg_url for this to work, otherwise we don't have a registry host to log into. otherwise LGTM.

@sdodson
Copy link
Member

sdodson commented Aug 24, 2017

aos-ci-test

@sdodson
Copy link
Member

sdodson commented Aug 24, 2017

[merge]

@sdodson
Copy link
Member

sdodson commented Aug 24, 2017

Needs a release-3.6 branch backport too

@openshift-bot
Copy link

[test]ing while waiting on the merge queue

@openshift-bot
Copy link

error: aos-ci-jenkins/OS_3.6_containerized for de6ccdf (logs)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for de6ccdf (logs)

@sdodson
Copy link
Member

sdodson commented Aug 28, 2017

aos-ci-test

Added the ability to support authentication for independent / 3rd party
registries. This commit will allow users to provide a `oreg_auth_user` and
`oreg_auth_password` to dynmically generate a docker config.json file.

The docker config.json file can be used by openshift to authenticate to
independent / 3rd party registries. `oreg_host` must supply endpoint connection
info in the form of 'hostname.com:port', with (optional) port 443 default.

To update the config.json on a later run, the user can specify
`oreg_auth_credentials_replace=False` to update the credentials.

These settings must be used in tandem with `oreg_url`

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1316341
@openshift-bot
Copy link

Evaluated for openshift ansible merge up to 5815311

@openshift-bot
Copy link

Evaluated for openshift ansible test up to 5815311

@openshift-bot
Copy link

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible/549/) (Base Commit: ca5ebcb) (PR Branch Commit: 5815311)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for 5815311 (logs)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for 5815311 (logs)

@openshift-bot
Copy link

continuous-integration/openshift-jenkins/merge FAILURE (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_openshift_ansible/940/) (Base Commit: 60d5448) (PR Branch Commit: 5815311)

@sdodson sdodson merged commit 5e32de3 into openshift:master Aug 29, 2017
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