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 ingress admission controller to restrict hostname updates #12653

Merged

Conversation

JacobTanenbaum
Copy link
Contributor

@JacobTanenbaum JacobTanenbaum commented Jan 24, 2017

This ensures that openshift's rules regarding who can serve a hostname does not
get violated by ingress objects. If upstream behavior is desired this controller can be
disabled in the master config file.

I wrote this assuming that we might have other needs for an admission controller with ingress
objects and it should not be difficult to extend this one.

Trello Card

@JacobTanenbaum
Copy link
Contributor Author

@knobunc I believe this is ready for review

@knobunc
Copy link
Contributor

knobunc commented Jan 25, 2017

Please fix the title:

  • Typo "ingress_s_"
  • Shorten it so it conforms to the preferred git style and doesn't get truncated. Perhaps "add ingress admission controller to restrict hostname updates"

Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

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

Nice start

@@ -69,6 +69,7 @@ import (
imageadmission "github.com/openshift/origin/pkg/image/admission"
imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
ingressadmit "github.com/openshift/origin/pkg/ingress/admission"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this ingressadmit when the rest seem to be ...admission?


// IngressAdmissionConfig is the configuration for the the ingress
// controller limiter plugin. It changes the behavior of ingress
//objects to behave better with openshift routes and routers.
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to be missing a space here after the //

type IngressAdmissionConfig struct {
unversioned.TypeMeta

//UpstreamHostnameUpdate when true causes updates that attempt
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to be missing a space here after the //

// controller limiter plugin. It changes the behavior of ingress
//objects to behave better with openshift routes and routers.
//*NOTE* Disabling this plugin causes ingress objects to behave
//the same as in upstream kubernetes
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to say that disabling this has potential security implications in the router when handling ingress objects.


//UpstreamHostnameUpdate when true causes updates that attempt
//to add or modify hostnames to succeed. Otherwise those updates
//fail in order to ensure hostname behavior
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be clarified to explain that we don't allow addition or renaming of hostnames in the ingress object when set to false. If set to true then we allow the changes, but that has security implications.

What is the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

booleans declared but not initialized are given false in golang. The code is structured so that if other options are added to IngressAdmissionConfig without enabling hostname updates they fail

"k8s.io/kubernetes/pkg/api/unversioned"
)

// IngressAdmissionConfig is the configuration for the the ingress
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments here as earlier file

return nil
}

func checkHostnames(oldIngress, newIngress *kextensions.Ingress) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this haveHostsChanged? Or something that makes the actual test more clear.

}

func checkHostnames(oldIngress, newIngress *kextensions.Ingress) bool {
m := make(map[string]int)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to use an int rather than a bool?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, an empty struct appears even better since then it can optimize away to 0 bytes for the value.

But... Kubernetes has sets.NewString() that makes a set of strings... perhaps we should use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does the sets.NewString() apply here? wouldn't I have to loop through the Ingress.Spec.Rules[] to extract the host strings?


for _, element := range newIngress.Spec.Rules {
_, present := m[element.Host]
if !present {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better style to do:
if _, present := m[element.Host]; present {

},
}
} else {
//Used to test deleteing a hostname
Copy link
Contributor

Choose a reason for hiding this comment

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

deleting

@JacobTanenbaum JacobTanenbaum changed the title add admission controller to restrict updates to ingresss objects host… add ingress admission controlle rto restrict hostname updates Jan 26, 2017
@JacobTanenbaum JacobTanenbaum changed the title add ingress admission controlle rto restrict hostname updates add ingress admission controller to restrict hostname updates Jan 26, 2017
@JacobTanenbaum JacobTanenbaum force-pushed the IngressAdmissionController branch from f3ee6cd to e4bd6b4 Compare January 27, 2017 11:02
@JacobTanenbaum
Copy link
Contributor Author

@openshift/networking

@JacobTanenbaum
Copy link
Contributor Author

@liggitt @derekwaynecarr Please review


func haveHostnamesChanged(oldIngress, newIngress *kextensions.Ingress) bool {
m := make(map[string]int)
for _, element := range oldIngress.Spec.Rules {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about TLS.Hosts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ingress rule hosts need to be immutable for the same reason as route hosts (prevent theft). TLS hosts are only used to match TLS configuration to a rule which doesn't need to be restricted (it's like changing tls conf for a route).

@knobunc knobunc requested a review from DirectXMan12 January 31, 2017 18:45
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

a couple of minor nits

}

func haveHostnamesChanged(oldIngress, newIngress *kextensions.Ingress) bool {
m := make(map[string]int)
Copy link
Contributor

Choose a reason for hiding this comment

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

the standard convention for sets is to use map[TYPE]struct{}, but even better is k8s.io/apimachinery/pkg/utils/sets.String, which is a pre-built string set with the operations that you want.

newHost: "foo.com",
oldHost: "bar.com",
testName: "Upstream Hostname updates enabled",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

should you also test adding a hostname?

@JacobTanenbaum JacobTanenbaum force-pushed the IngressAdmissionController branch from 097e6e5 to 2366482 Compare February 1, 2017 01:41
@JacobTanenbaum
Copy link
Contributor Author

[test]

@knobunc
Copy link
Contributor

knobunc commented Feb 2, 2017

[test]

@knobunc
Copy link
Contributor

knobunc commented Feb 2, 2017

--- FAIL: TestAdmissionPluginNames (0.00s)
	admissionconfig_test.go:94: openshift admission plugins must be prefixed with openshift.io/ IngressAdmission

@JacobTanenbaum JacobTanenbaum force-pushed the IngressAdmissionController branch from 0a38587 to 4d3e590 Compare February 2, 2017 18:02
…name field.

This ensures that openshift's rules regarding who can serve a hostname does not
get violated by ingress objects. If upstream behavior is desired this controller can be
disabled in the master config file.

I wrote this assuming that we might have other needs for an admission controller with ingress
objects and it should not be difficult to extend this one.
    github.com/openshift/origin/pkg/cmd/server/origin.TestAdmissionPluginNames
    github.com/openshift/origin/pkg/cmd/server/start.TestAdmissionOnOffCoverage
@JacobTanenbaum JacobTanenbaum force-pushed the IngressAdmissionController branch from 4d3e590 to 8c59f37 Compare February 2, 2017 19:29
@knobunc
Copy link
Contributor

knobunc commented Feb 3, 2017

@DirectXMan12 can you look over the recent change please?

@knobunc
Copy link
Contributor

knobunc commented Feb 3, 2017

FAILURE: Generated docs up to date, but generated man pages out of date. Please run hack/update-generated-docs.sh

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to dfd9fae

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13570/) (Base Commit: 01edb43)

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13570/) (Base Commit: 01edb43)

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@knobunc
Copy link
Contributor

knobunc commented Feb 3, 2017

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to dfd9fae

@openshift-bot
Copy link
Contributor

openshift-bot commented Feb 4, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13592/) (Base Commit: c74f1b8) (Image: devenv-rhel7_5856)

@openshift-bot openshift-bot merged commit ff53795 into openshift:master Feb 4, 2017
@lihongan
Copy link
Contributor

lihongan commented Feb 9, 2017

could you please give the example master config of disabling the ingress admission?

@smarterclayton
Copy link
Contributor

Remember to squash these in the future - didn't catch it at the time, but could have been reduced to 1 or 2 commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants