Skip to content

Commit e4bd6b4

Browse files
addresses Ben's initial comments
1 parent c474d26 commit e4bd6b4

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

pkg/cmd/server/origin/master_config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import (
6969
imageadmission "github.com/openshift/origin/pkg/image/admission"
7070
imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
7171
imageapi "github.com/openshift/origin/pkg/image/api"
72-
ingressadmit "github.com/openshift/origin/pkg/ingress/admission"
72+
ingressadmission "github.com/openshift/origin/pkg/ingress/admission"
7373
accesstokenregistry "github.com/openshift/origin/pkg/oauth/registry/oauthaccesstoken"
7474
accesstokenetcd "github.com/openshift/origin/pkg/oauth/registry/oauthaccesstoken/etcd"
7575
projectauth "github.com/openshift/origin/pkg/project/auth"
@@ -362,7 +362,7 @@ var (
362362
"SCCExecRestrictions",
363363
"PersistentVolumeLabel",
364364
"OwnerReferencesPermissionEnforcement",
365-
ingressadmit.IngressAdmission,
365+
ingressadmission.IngressAdmission,
366366
// NOTE: quotaadmission and ClusterResourceQuota must be the last 2 plugins.
367367
// DO NOT ADD ANY PLUGINS AFTER THIS LINE!
368368
quotaadmission.PluginName,
@@ -400,7 +400,7 @@ var (
400400
"SCCExecRestrictions",
401401
"PersistentVolumeLabel",
402402
"OwnerReferencesPermissionEnforcement",
403-
ingressadmit.IngressAdmission,
403+
ingressadmission.IngressAdmission,
404404
// NOTE: quotaadmission and ClusterResourceQuota must be the last 2 plugins.
405405
// DO NOT ADD ANY PLUGINS AFTER THIS LINE!
406406
quotaadmission.PluginName,

pkg/ingress/admission/api/types.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66

77
// IngressAdmissionConfig is the configuration for the the ingress
88
// controller limiter plugin. It changes the behavior of ingress
9-
//objects to behave better with openshift routes and routers.
10-
//*NOTE* Disabling this plugin causes ingress objects to behave
11-
//the same as in upstream kubernetes
9+
// objects to behave better with openshift routes and routers.
10+
// *NOTE* This has security implications in the router when handling
11+
// ingress objects
1212
type IngressAdmissionConfig struct {
1313
unversioned.TypeMeta
1414

15-
//UpstreamHostnameUpdate when true causes updates that attempt
16-
//to add or modify hostnames to succeed. Otherwise those updates
17-
//fail in order to ensure hostname behavior
18-
UpstreamHostnameUpdate bool
15+
// AllowHostnameChanges when false or unset openshift does not
16+
// allow changing or adding hostnames to ingress objects. If set
17+
// to true then hostnames can be added or modified which has
18+
// security implications in the router.
19+
AllowHostnameChanges bool
1920
}

pkg/ingress/admission/api/v1/defaults_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestDefaults(t *testing.T) {
4242
{
4343
original: &ingressv1.IngressAdmissionConfig{},
4444
expected: &ingressv1.IngressAdmissionConfig{
45-
UpstreamHostnameUpdate: false,
45+
AllowHostnameChanges: false,
4646
},
4747
},
4848
}

pkg/ingress/admission/api/v1/register.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"k8s.io/kubernetes/pkg/runtime"
66
)
77

8-
//SchemeGroupVersion is gorup version used to register these objects
8+
// SchemeGroupVersion is group version used to register these objects
99
var SchemeGroupVersion = unversioned.GroupVersion{Group: "", Version: "v1"}
1010

1111
var (

pkg/ingress/admission/api/v1/swagger_doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package v1
66
// ==== DO NOT EDIT THIS FILE MANUALLY ====
77

88
var map_IngressAdmissionConfig = map[string]string{
9-
"": "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. *NOTE* Disabling this plugin causes ingress objects to behave the same as in upstream kubernetes",
10-
"upstreamHostnameUpdate": "UpstreamHostnameUpdate when true causes updates that attempt to add or modify hostnames to succeed. Otherwise those updates fail in order to ensure hostname behavior",
9+
"": "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. *NOTE* This has security implications in the router when handling ingress objects",
10+
"allowHostnameChanges": "AllowHostnameChanges when false or unset openshift does not allow changing or adding hostnames to ingress objects. If set to true then hostnames can be added or modified which has security implications in the router.",
1111
}
1212

1313
func (IngressAdmissionConfig) SwaggerDoc() map[string]string {

pkg/ingress/admission/api/v1/types.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66

77
// IngressAdmissionConfig is the configuration for the the ingress
88
// controller limiter plugin. It changes the behavior of ingress
9-
//objects to behave better with openshift routes and routers.
10-
//*NOTE* Disabling this plugin causes ingress objects to behave
11-
//the same as in upstream kubernetes
9+
// objects to behave better with openshift routes and routers.
10+
// *NOTE* This has security implications in the router when handling
11+
// ingress objects
1212
type IngressAdmissionConfig struct {
1313
unversioned.TypeMeta `json:",inline"`
1414

15-
//UpstreamHostnameUpdate when true causes updates that attempt
16-
//to add or modify hostnames to succeed. Otherwise those updates
17-
//fail in order to ensure hostname behavior
18-
UpstreamHostnameUpdate bool `json:"upstreamHostnameUpdate"`
15+
// AllowHostnameChanges when false or unset openshift does not
16+
// allow changing or adding hostnames to ingress objects. If set
17+
// to true then hostnames can be added or modified which has
18+
// security implications in the router.
19+
AllowHostnameChanges bool `json:"allowHostnameChanges"`
1920
}

pkg/ingress/admission/ingress_admission.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func readConfig(reader io.Reader) (*api.IngressAdmissionConfig, error) {
6262

6363
func (r *ingressAdmission) Admit(a kadmission.Attributes) error {
6464
if a.GetResource().GroupResource() == kextensions.Resource("ingresses") && a.GetOperation() == kadmission.Update {
65-
if r.config == nil || r.config.UpstreamHostnameUpdate == false {
65+
if r.config == nil || r.config.AllowHostnameChanges == false {
6666
oldIngress, ok := a.GetOldObject().(*kextensions.Ingress)
6767
if !ok {
6868
return nil
@@ -71,23 +71,22 @@ func (r *ingressAdmission) Admit(a kadmission.Attributes) error {
7171
if !ok {
7272
return nil
7373
}
74-
if !checkHostnames(oldIngress, newIngress) {
74+
if !haveHostnamesChanged(oldIngress, newIngress) {
7575
return fmt.Errorf("cannot change hostname")
7676
}
7777
}
7878
}
7979
return nil
8080
}
8181

82-
func checkHostnames(oldIngress, newIngress *kextensions.Ingress) bool {
82+
func haveHostnamesChanged(oldIngress, newIngress *kextensions.Ingress) bool {
8383
m := make(map[string]int)
8484
for _, element := range oldIngress.Spec.Rules {
8585
m[element.Host] = 1
8686
}
8787

8888
for _, element := range newIngress.Spec.Rules {
89-
_, present := m[element.Host]
90-
if !present {
89+
if _, present := m[element.Host]; !present {
9190
return false
9291
}
9392
}

pkg/ingress/admission/ingress_admission_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestAdmission(t *testing.T) {
8181
},
8282
}
8383
} else {
84-
//Used to test deleteing a hostname
84+
//Used to test deleting a hostname
8585
newIngress = &kextensions.Ingress{
8686
ObjectMeta: kapi.ObjectMeta{Name: "test"},
8787
}
@@ -120,12 +120,12 @@ func emptyConfig() *api.IngressAdmissionConfig {
120120

121121
func testConfigUpdateAllow() *api.IngressAdmissionConfig {
122122
return &api.IngressAdmissionConfig{
123-
UpstreamHostnameUpdate: true,
123+
AllowHostnameChanges: true,
124124
}
125125
}
126126

127127
func testConfigUpdateDeny() *api.IngressAdmissionConfig {
128128
return &api.IngressAdmissionConfig{
129-
UpstreamHostnameUpdate: false,
129+
AllowHostnameChanges: false,
130130
}
131131
}

0 commit comments

Comments
 (0)