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

Admission plugin: openshift.io/ImageQualify #18020

Merged
merged 1 commit into from
Jan 19, 2018

Conversation

frobware
Copy link
Contributor

@frobware frobware commented Jan 8, 2018

This plugin allows administrators to set a policy for bare image names. A "bare" image name is a docker image reference that contains no domain component (e.g., "repository.io", "docker.io", etc).

The preferred domain component to use, and hence pull from, for a bare image name is computed from a set of path-based pattern matching rules defined in the admission configuration.

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

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 8, 2018
@smarterclayton
Copy link
Contributor

Why isn’t this part of image policy?

@frobware
Copy link
Contributor Author

frobware commented Jan 9, 2018

Why isn’t this part of image policy?

If you don't have that plugin enabled you would not be able to qualify images, hence a separate plugin.

/cc @liggitt

@@ -0,0 +1,7 @@
admissionConfig:
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this file, move to doc or PR description?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove this file, move to doc or PR description?

Yep, to be removed. Was here for my dev convenience.

I have a few unit tests to complete then I'll split the PR up into more discrete commits which should make it easier to review.

configuration:
kind: ImagePolicyConfig
apiVersion: v1
qualifyRulesFilename: /home/centos/rules
Copy link
Contributor

@liggitt liggitt Jan 9, 2018

Choose a reason for hiding this comment

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

since this admission plugin is distinct, we can just inline the rules in the plugin config type struct. if we want this externalized, we'd reference the whole plugin config externally:

master-config.yaml

...
admissionConfig:
  pluginConfig:
    openshift.io/ImageQualification:
      location: /path/to/plugin.yaml
...

plugin.yaml:

kind: ImageQualificationConfig
apiVersion: v1
rules:
- ...
- ...
- ...

@smarterclayton
Copy link
Contributor

smarterclayton commented Jan 10, 2018

We always run with image policy enabled.

Also, qualification has to happen after image reference policy, but before admission policy runs. So I don't think this can be a separate plugin.

Having them separate would be broken in this case:

  1. User provides mysql to a pod
  2. Image policy checks for local name references (finds none)
  3. Image policy applies naming policy (block execution of images that aren't from docker.io), assumes mysql means docker.io/library/mysql
  4. Image qualifier runs and turns mysql into foo.bar/mysql.

You can't run before, because you would break local name references.

@liggitt
Copy link
Contributor

liggitt commented Jan 10, 2018

Also, qualification has to happen after image reference policy, but before admission policy runs.

Shouldn't have to... that's what the mutation/validation split was for... both should get their shot at mutating, then both should get their shot at validating.

@frobware
Copy link
Contributor Author

then both should get their shot at validating.

Should qualification also happen in Validate()?

ATM, it does, but it was an open question (in my mind).

@frobware
Copy link
Contributor Author

We always run with image policy enabled.

Will that always be true? If that does change at some point in the future you may then be surprised that qualification no longer happens. Should they be coupled like this?

@smarterclayton
Copy link
Contributor

Shouldn't have to... that's what the mutation/validation split was for... both should get their shot at mutating, then both should get their shot at validating.

image policy was not split into mutation / validation that I'm aware of. You can't mutate before, you have to qualify within the image policy flow, not after.

@frobware frobware changed the title [WIP] image qualify admission Admission plugin: openshift.io/ImageQualify Jan 10, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 10, 2018
@smarterclayton
Copy link
Contributor

Note, I'm talking about OpenShift image policy, not upstream image policy. We don't use upstream image policy and have no plan to.

@frobware
Copy link
Contributor Author

/test verify

@frobware frobware force-pushed the qualify-images branch 2 times, most recently from d32d2af to dfa48de Compare January 12, 2018 14:01
return "", err
}
if domain != "" {
// image is already qualfied
Copy link

Choose a reason for hiding this comment

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

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typo

Thanks. I'm about to collapse all the commits into something sensible again. I ended up collapsing two packages and it should be more self contained now.

// "docker.io/busybox" -> domain is "docker.io"
// "docker.io/library/busybox" -> domain is "docker.io"
// "library/busybox:v1" -> domain is ""
func SplitImageName(image string) (string, string, error) {
Copy link

Choose a reason for hiding this comment

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

We already have such parsers. There's also docker's reference package which as de facto referential implementation.

input: "parser.test.io/foo/busybox:v1.2.3",
domain: "parser.test.io",
remainder: "foo/busybox:v1.2.3",
}} {
Copy link

Choose a reason for hiding this comment

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

Should test multiple slashes as well.

// Qualify qualifies image with a domain based on the set of patterns
// in rules. If there is a match then return true to indicate a match
// was found in rules together with the discrete domain name and a
// fully qualified image reference, otherwise returns false.
Copy link

Choose a reason for hiding this comment

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

false maybe as a string

@frobware frobware changed the title Admission plugin: openshift.io/ImageQualify [WIP] Admission plugin: openshift.io/ImageQualify Jan 12, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 12, 2018
@bparees
Copy link
Contributor

bparees commented Jan 16, 2018

Ben, does this look ok to you? Is there anywhere in the build component where fully qualified image names are not used?

only in places where that image name is fed directly to the docker daemon (thus qualification would continue to be handled by the docker daemon, which I assume is what we want)

// rules. Returns the Rule that matched, or nil if no match was found.
func matchImage(image string, rules []api.ImageQualifyRule) *api.ImageQualifyRule {
for i := range rules {
if ok, _ := path.Match(rules[i].Pattern, image); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure we want to support all the possible patterns path.Match allows... can we limit the charset of the pattern to characters that are allowed in image specs (something like a-zA-Z0-9_-/:@, I think), and *?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to support wildcards in the digest part?

I've looked at this in a number of ways:

  • take your suggested character set, and add "*", anything outside of that is bogus, though therre is the perennial risk that image specifications chnage underneath our feet
  • look at explicitly referencing these regexps, but a) they're internal and b) was curious as to why it's a copy

If we don't want to support wildcards in digests then (I think) an alternative pattern validation scheme may be:

    tmp := strings.Replace(rule.Pattern, "*", "a", -1))
    if _, _, _, err := parsers.ParseImageName(tmp); err != nil {
        // pattern is invalid.
    }

I had chosen to be liberal with patterns as we always validate the image reference when it gets qualified. It would, I agree, be nice to be aware up-front that the pattern is invalid. Either way, you would have to correct and restart whether we do validation up front or (possibly) much later when a match occurs.

Having attempted some validation I'm wondering if it really makes sense to have something like:

a/b@sha256:abcd*ff*11*

Part of me says I would prefer to fix my patterns vis-a-vis baking policy in and then having to wait for a binary release should things go south.

Copy link
Contributor

Choose a reason for hiding this comment

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

therre is the perennial risk that image specifications chnage underneath our feet

pretty sure we'd have other updates to make in that case as well. I'd rather start as limited as possible to address known use cases and expand further if needed.

return allErrs
}
for i, rule := range config.Rules {
if rule.Pattern == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

limit the charset in pattern to just characters valid in an image spec and *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we do checking in validation then by the time this is exercised only have valid patterns. Basically, you either have a correct config, or you don't. This is an internal call so validation should prevent you getting this far with a bad pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is where you would do that validation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, agreed. I had your two comments the wrong way round in my head.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

limit the charset in pattern to just characters valid in an image spec and *

Done.

)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: "", Version: "v1"}
Copy link
Contributor

Choose a reason for hiding this comment

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

@deads2k are we putting new config types in groups now? apiserver.config.openshift.io? I couldn't find any other config types in origin yet

Copy link
Contributor

Choose a reason for hiding this comment

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

@deads2k are we putting new config types in groups now? apiserver.config.openshift.io? I couldn't find any other config types in origin yet

"webconsole.config.openshift.io" from here https://github.com/openshift/api/blob/master/webconsole/v1/register.go#L10

For admission plugins it's going to be a question of versioning cadence. Because our admission plugins will be used in the openshift apiserver, I'm inclined to go "admission.config.openshift.io" without further subdivision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For admission plugins it's going to be a question of versioning cadence. Because our admission plugins will be used in the openshift apiserver, I'm inclined to go "admission.config.openshift.io" without further subdivision.

Is there any change I need to make here?

Copy link
Contributor

@liggitt liggitt Jan 18, 2018

Choose a reason for hiding this comment

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

here:

var GroupName = "admission.config.openshift.io"
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}

in the internal register.go:

var GroupName = "admission.config.openshift.io"
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}

wherever you have config data you load:

apiVersion: admission.config.openshift.io/v1

@liggitt
Copy link
Contributor

liggitt commented Jan 18, 2018

I didn't review the bash script
The rest lgtm, can go ahead and squash

@frobware
Copy link
Contributor Author

I didn't review the bash script

I know @sjenning has run it successfully on two online nodes, so it has been exercised in the wild.

This plugin allows administrators to set a policy for bare image
names. A "bare" image name is a docker image reference that contains
no domain component (e.g., "repository.io", "docker.io", etc).

The preferred domain component to use, and hence pull from, for a bare
image name is computed from a set of path-based pattern matching rules
defined in the admission configuration.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1518378
@liggitt
Copy link
Contributor

liggitt commented Jan 18, 2018

/retest

@liggitt
Copy link
Contributor

liggitt commented Jan 18, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 18, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: frobware, liggitt

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 18, 2018
@sjenning
Copy link
Contributor

/retest

@sjenning
Copy link
Contributor

flakes #14296 #18048
/retest

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 18129, 18152, 17403, 18020, 18165).

@openshift-merge-robot openshift-merge-robot merged commit 0acd4e2 into openshift:master Jan 19, 2018
openshift-merge-robot added a commit that referenced this pull request Jan 31, 2018
Automatic merge from submit-queue (batch tested with PRs 18225, 18351, 18331, 18340, 18326).

UPSTREAM: 58955: pkg: kubelet: do not assume anything about images names

kubernetes/kubernetes#58955

removes the need for #18020

see history:
kubernetes/kubernetes#51751
kubernetes/kubernetes#52110
kubernetes/kubernetes#53161

@liggitt @derekwaynecarr @frobware @mrunalp @runcom
openshift-publish-robot pushed a commit to openshift/kubernetes that referenced this pull request Jan 31, 2018
Automatic merge from submit-queue (batch tested with PRs 18225, 18351, 18331, 18340, 18326).

UPSTREAM: 58955: pkg: kubelet: do not assume anything about images names

kubernetes#58955

removes the need for openshift/origin#18020

see history:
kubernetes#51751
kubernetes#52110
kubernetes#53161

@liggitt @derekwaynecarr @frobware @mrunalp @runcom

Origin-commit: d91de347457d7f6f3d1859c671c7355cc193d038
openshift-merge-robot added a commit that referenced this pull request Feb 15, 2018
Automatic merge from submit-queue (batch tested with PRs 18624, 18605).

Revert "Admission plugin: openshift.io/ImageQualify"

This reverts commit 8bc3e07.  #18020

Render unneeded by upstream kubernetes/kubernetes#58955 and Origin pick #18340

Will live on forever in git history if we find a use case for it later.
openshift-publish-robot pushed a commit to openshift/kubernetes that referenced this pull request Feb 27, 2018
Automatic merge from submit-queue (batch tested with PRs 18225, 18351, 18331, 18340, 18326).

UPSTREAM: 58955: pkg: kubelet: do not assume anything about images names

kubernetes#58955

removes the need for openshift/origin#18020

see history:
kubernetes#51751
kubernetes#52110
kubernetes#53161

@liggitt @derekwaynecarr @frobware @mrunalp @runcom

Origin-commit: d91de347457d7f6f3d1859c671c7355cc193d038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved 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. needs-api-review size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants