Skip to content

configure imagePolicyConfig:allowedRegistriesForImport #7197

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

Merged
merged 1 commit into from
Jun 25, 2018

Conversation

miminar
Copy link

@miminar miminar commented Feb 19, 2018

Currently the allowedRegistriesForImport are not configured by ansible scripts,
which effectively disables whitelisting. This PR sets the default registry
whitelist and allowes for simple overrides.

Related upstream PR: openshift/origin#17783
Related doc PR: openshift/openshift-docs#7788

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 19, 2018
@@ -77,6 +77,9 @@
kube_admission_plugin_config: "{{openshift_master_kube_admission_plugin_config | default(None) }}" # deprecated, merged with admission_plugin_config
oauth_always_show_provider_selection: "{{ openshift_master_oauth_always_show_provider_selection | default(None) }}"
image_policy_config: "{{ openshift_master_image_policy_config | default(None) }}"
image_policy_allowed_registries_for_import: "{{ openshift_master_image_policy_allowed_registries_for_import | default(None) }}"
image_policy_additional_allowed_registries_for_import: "{{ openshift_master_image_policy_additional_allowed_registries_for_import | default(None) }}"
default_image_policy_allowed_registries_for_import: "{{ default_image_policy_allowed_registries_for_import }}"
Copy link
Author

@miminar miminar Feb 19, 2018

Choose a reason for hiding this comment

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

Instead of setting the defaults here, is it possible to load them from set_allowed_registries()? Not sure it's the best way but the current approach is not consistent with anything around.

Copy link
Author

Choose a reason for hiding this comment

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

Resolved. By default, everything is allowed.

@miminar miminar force-pushed the allowed_registries_for_import branch 5 times, most recently from b9d4e24 to 7192178 Compare February 19, 2018 09:02
# Keep in sync with DefaultAllowedRegistriesForImport in
# openshift/origin/blob/master/pkg/cmd/server/apis/config/types.go
default_image_policy_allowed_registries_for_import:
allowedRegistriesForImport:
Copy link
Author

@miminar miminar Feb 19, 2018

Choose a reason for hiding this comment

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

Could this be maybe generated by the openshift binary and fetched from the library module when needed?

(the binary already generates this on openshift start master --write, I'm just not sure, how to utilize that here)

@miminar miminar force-pushed the allowed_registries_for_import branch 3 times, most recently from 5a698a6 to de67599 Compare February 19, 2018 13:28
@miminar
Copy link
Author

miminar commented Feb 19, 2018

Just realized that there is a lot of variables like:

#oreg_url_master=example.com/openshift3/ose-${component}:${version}
#oreg_url_node=example.com/openshift3/ose-${component}:${version}
#oreg_url=example.com/openshift3/ose-${component}:${version}
#openshift_cockpit_deployer_prefix=registry.example.com/myrepo/
#openshift_metrics_image_prefix=docker.io/openshift/origin-
#openshift_metrics_image_prefix=registry.access.redhat.com/openshift3/

If the admin overrides any of those to some custom registry without touching *_allowed_registries_for_import, he will certainly fail.

Should those prefixes be added to the defaults? Or should we run some sanity check at the beginning?

@miminar
Copy link
Author

miminar commented Feb 19, 2018

/assign @sdodson @jim-minter

@bparees FYI

@miminar
Copy link
Author

miminar commented Feb 19, 2018

Some of the extended tests are now failing:

/go/src/github.com/openshift/origin/_output/local/go/src/github.com/openshift/origin/test/extended/builds/new_app.go:49
Expected error:
    <*errors.errorString | 0xc4217d2550>: {
        s: "The build \"a234567890123456789012345678901234567890123456789012345678-1\" status is \"Failed\"",
    }
    The build "a234567890123456789012345678901234567890123456789012345678-1" status is "Failed"
not to have occurred
/go/src/github.com/openshift/origin/_output/local/go/src/github.com/openshift/origin/test/extended/builds/new_app.go:59
...
2018-02-19T14:19:20.024979251Z error: build error: Failed to push image: received unexpected HTTP status: 500 Internal Server Error

And this looks to be the reason (forbidden translated to 500):

time="2018-02-19T14:23:29.223383892Z" level=error msg="error creating ImageStreamMapping: ImageStream \"nodejsroot\" is invalid: status.tags[latest].items[0].dockerImageReference: Forbidden: registry \"172.30.73.52:5000\" not allowed by whitelist: \"docker-registry.default.svc:5000\", \"docker.io:443\", \"*.docker.io:443\", \"*.redhat.com:443\", and 5 more ..." go.version=go1.9.2 http.request.contenttype=application/vnd.docker.distribution.manifest.v2+json http.request.host="docker-registry.default.svc:5000" http.request.id=b4d7546f-73e4-438d-bbe6-46ad83c9b465 http.request.method=PUT http.request.remoteaddr="172.16.6.1:49410" http.request.uri=/v2/extended-test-s2i-build-root-fvr68-b5776/nodejsroot/manifests/latest http.request.useragent="docker/1.12.6 go/go1.8.3 kernel/3.10.0-693.17.1.el7.x86_64 os/linux arch/amd64 UpstreamClient(go-dockerclient)" instance.id=c760f887-3d08-4e75-a7b4-61522c8e0880 openshift.auth.user="system:serviceaccount:extended-test-s2i-build-root-fvr68-b5776:builder" vars.name=extended-test-s2i-build-root-fvr68-b5776/nodejsroot vars.reference=latest 
time="2018-02-19T14:23:29.223538513Z" level=error msg="response completed with error" err.code=unknown err.detail="ImageStream \"nodejsroot\" is invalid: status.tags[latest].items[0].dockerImageReference: Forbidden: registry \"172.30.73.52:5000\" not allowed by whitelist: \"docker-registry.default.svc:5000\", \"docker.io:443\", \"*.docker.io:443\", \"*.redhat.com:443\", and 5 more ..." err.message="unknown error" go.version=go1.9.2 http.request.contenttype=application/vnd.docker.distribution.manifest.v2+json http.request.host="docker-registry.default.svc:5000" http.request.id=b4d7546f-73e4-438d-bbe6-46ad83c9b465 http.request.method=PUT http.request.remoteaddr="172.16.6.1:49410" http.request.uri=/v2/extended-test-s2i-build-root-fvr68-b5776/nodejsroot/manifests/latest http.request.useragent="docker/1.12.6 go/go1.8.3 kernel/3.10.0-693.17.1.el7.x86_64 os/linux arch/amd64 UpstreamClient(go-dockerclient)" http.response.contenttype="application/json; charset=utf-8" http.response.duration=698.99085ms http.response.status=500 http.response.written=783 instance.id=c760f887-3d08-4e75-a7b4-61522c8e0880 openshift.auth.user="system:serviceaccount:extended-test-s2i-build-root-fvr68-b5776:builder" vars.name=extended-test-s2i-build-root-fvr68-b5776/nodejsroot vars.reference=latest 

The docker-registry is not configured to use the same dns name as the cluster (http.request.host="docker-registry.default.svc:5000"). I'll take a look around and try to find the jenkins job that sets up the registry. If somebody knows already, please let me know.

@miminar
Copy link
Author

miminar commented Feb 19, 2018

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 19, 2018
@miminar
Copy link
Author

miminar commented Feb 19, 2018

Tentative fix: openshift/origin#18663

@bparees
Copy link
Contributor

bparees commented Feb 19, 2018

@miminar i'm puzzled by why this change is causing problems. The existing behavior was such that the ansible install didn't set a whitelist, which should have meant we fell back to the hardcoded whitelist, right? And the hardcoded whitelist is the same as the whitelist you've introduced explicilty.

@bparees bparees self-assigned this Feb 19, 2018
@miminar
Copy link
Author

miminar commented Feb 20, 2018

We don't fall-back to hardcoded whitelist. If the policy whitelist is not configured in the master config file, no whitelist will be used - meaning "allow all".

The thing I don't understand right now is why the job ci/openshift-jenkins/gcp launches registry without dns name configured. Which leads to creation of imagestreammappings with dockerImageReference having "{REGISTRY_SERVICE_IP}:5000" which is not whitelisted.

Similar job for openshift/origin repository has the same parent job https://github.com/openshift/aos-cd-jobs/blob/master/sjb/config/common/test_cases/origin_release_install_gce.yml that does the setup. The origin job properly configures the registry with REGISTRY_OPENSHIFT_SERVER_ADDR=docker-registry.default.svc:5000 that gets whitelisted and resulting images have this prefix. Not sure why it's not the case for the former job. I've added some debug statements to the ansible scripts that maybe clear some unknowns.

@miminar miminar force-pushed the allowed_registries_for_import branch 2 times, most recently from 7157c3c to cbd3995 Compare February 20, 2018 17:06
@miminar
Copy link
Author

miminar commented Feb 21, 2018

@bparees So the problem is related to your #6913. The image used for testing (origin-docker-registry:v3.9.0-alpha.4) doesn't have @legionus' fix yet.

And there is just REGISTRY_OPENSHIFT_SERVER_ADDR set to docker-registry.default.svc:5000. The registry defaults to service ip:port and thus the resulting image doesn't pass the whitelisting.

I'd prefer to set OPENSHIFT_DEFAULT_REGISTRY variable as well in the ansible scripts to deal with earlier registry versions. What do you think?

@bparees
Copy link
Contributor

bparees commented Feb 21, 2018

I'd prefer to set OPENSHIFT_DEFAULT_REGISTRY variable as well in the ansible scripts to deal with earlier registry versions. What do you think?

i can live with it.

@miminar miminar force-pushed the allowed_registries_for_import branch 3 times, most recently from 318cdfc to be3157a Compare February 23, 2018 15:52
@bparees
Copy link
Contributor

bparees commented Feb 26, 2018

@miminar I do wonder if for existing clusters that do not have an imageimport policy already, we should not be setting this as we could potentially break them if they are using registries that are not in the default whitelist.

Also I suspect we don't want to drop this on 3.9 at this point since auto-defining/defaulting the registry whitelist could have some unexpected effects.

@miminar
Copy link
Author

miminar commented May 2, 2018

/retest

@smarterclayton
Copy link
Contributor

Adding a hold as well.

/hold

Probably need to have a discussion about the point of this now.

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 4, 2018
@bparees
Copy link
Contributor

bparees commented Jun 19, 2018

Probably need to have a discussion about the point of this now.

@smarterclayton what sort of discussion? Don't we still want admins to be able to set this value at install time, even if the default behavior is to allow all registries?

@miminar miminar force-pushed the allowed_registries_for_import branch from fba6d35 to 0897ec4 Compare June 20, 2018 08:07
@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 20, 2018
@miminar miminar force-pushed the allowed_registries_for_import branch from 0897ec4 to 0e613a2 Compare June 20, 2018 08:10
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 20, 2018
@miminar
Copy link
Author

miminar commented Jun 20, 2018

Rebased.

/retest

@miminar
Copy link
Author

miminar commented Jun 20, 2018

/retest

@miminar
Copy link
Author

miminar commented Jun 20, 2018

The gcp test succeeded finally. Don't ask me why.

@miminar
Copy link
Author

miminar commented Jun 20, 2018

Probably need to have a discussion about the point of this now.

@smarterclayton No registry whitelist is configured by default which matches origin's latest behaviour. This only allows for whitelist configuration if the admin desires.

@sdodson
Copy link
Member

sdodson commented Jun 20, 2018

bot, retest this please

@miminar miminar force-pushed the allowed_registries_for_import branch from 0e613a2 to 8e50a18 Compare June 20, 2018 12:22
@miminar
Copy link
Author

miminar commented Jun 20, 2018

Squashed and removed debug statements.

Copy link
Member

@mtnbikenc mtnbikenc left a comment

Choose a reason for hiding this comment

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

Lint fixes needed

if not image_policy_config:
return image_policy_config

if isinstance(image_policy_config, basestring):
Copy link
Member

Choose a reason for hiding this comment

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

s/basestring/str/

""" turns a list of wildcard registries to allowedRegistriesForImport json setting """
return {
"allowedRegistriesForImport": [
{'domainName': reg} if isinstance(reg, basestring) else reg for reg in registry_list
Copy link
Member

Choose a reason for hiding this comment

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

s/basestring/str/

vague definition of port defaulting based on insecure flag. Moreover, most
of the registries will be listed without the port and insecure flag.
"""
item = "schema://" + item.lstrip("http://").lstrip("https://")
Copy link
Member

Choose a reason for hiding this comment

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

Use .replace() to remove multi character strings.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. Changed to .split('://',1)[-1] instead.

@miminar miminar force-pushed the allowed_registries_for_import branch from 8e50a18 to c95dc5a Compare June 20, 2018 14:49
@bparees
Copy link
Contributor

bparees commented Jun 22, 2018

anything else needed here?

@sdodson
Copy link
Member

sdodson commented Jun 22, 2018

/lgtm
ansible code looks fine, if you think @smarterclayton's /hold is outdated go ahead and remove it

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 22, 2018
@sdodson
Copy link
Member

sdodson commented Jun 22, 2018

bot, retest this please

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: miminar, sdodson

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bparees
Copy link
Contributor

bparees commented Jun 22, 2018

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 22, 2018
@sdodson
Copy link
Member

sdodson commented Jun 22, 2018

bot, retest this please

@openshift-ci-robot
Copy link

@miminar: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/extended_conformance_install_crio fe83785 link /test crio
ci/openshift-jenkins/system-containers fba6d35 link /test system-containers
ci/openshift-jenkins/gcp c95dc5a link /test gcp

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@sdodson sdodson merged commit 0843306 into openshift:master Jun 25, 2018
@miminar miminar deleted the allowed_registries_for_import branch July 24, 2018 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants