-
Notifications
You must be signed in to change notification settings - Fork 474
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
Added cross-namespace validation support for Sidecar's egress listener host, considering exported ServiceEntries. #4387
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ func TestEgressHostFormatCorrect(t *testing.T) { | |
"~/*", | ||
"./*", | ||
"./reviews.bookinfo.svc.cluster.local", | ||
"./*.bookinfo.svc.cluster.com", | ||
"./*.bookinfo.svc.cluster.local", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep both of them. The old one was a very specific service entry that might help identify some logics for service entries. Does it make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the "bookinfo" in this FQDN makes a confusion, and it worked before because of "if strings.HasPrefix(host.Service, "*")" and now fails because of "if host.IsWildcard() && host.Namespace == itemNamespace". |
||
"./wikipedia.org", | ||
"bookinfo/*", | ||
"bookinfo/*.bookinfo.svc.cluster.local", | ||
|
@@ -39,7 +39,157 @@ func TestEgressHostFormatCorrect(t *testing.T) { | |
assert.True(valid) | ||
} | ||
|
||
func TestEgressHostCrossNamespace(t *testing.T) { | ||
func TestEgressExportedInternalServiceEntryPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshInternalServiceEntry("details-se", "bookinfo3", []string{"details.bookinfo2.svc.cluster.local"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/details.bookinfo2.svc.cluster.local", | ||
}), | ||
}.Check() | ||
|
||
assert.Empty(vals) | ||
assert.True(valid) | ||
} | ||
|
||
func TestEgressExportedExternalServiceEntryPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshExternalServiceEntry("details-se", "bookinfo3", []string{"www.myhost.com"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/www.myhost.com", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it wasn't covered before, but should we try to test for a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning back to this request after several researches. In the validation logic of Sidecar's hosts, the "" is ignored and not checked it's further existance, so even if host is "bookinfo/.mywronghost.com" the error message will not be shown. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
}), | ||
}.Check() | ||
|
||
assert.Empty(vals) | ||
assert.True(valid) | ||
} | ||
|
||
func TestWildcardHostEgressExportedExternalServiceEntryNotPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshExternalServiceEntry("details-se", "bookinfo3", []string{"www.myhost.com"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/*.myhost.com", | ||
}), | ||
}.Check() | ||
|
||
assert.NotEmpty(vals) | ||
assert.True(valid) | ||
assert.Equal(models.WarningSeverity, vals[0].Severity) | ||
assert.Equal("spec/egress[0]/hosts[0]", vals[0].Path) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("sidecar.egress.servicenotfound", vals[0])) | ||
} | ||
|
||
func TestEgressExportedExternalWildcardServiceEntryPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshExternalServiceEntry("details-se", "bookinfo3", []string{"*.myhost.com"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/www.myhost.com", | ||
}), | ||
}.Check() | ||
|
||
assert.Empty(vals) | ||
assert.True(valid) | ||
} | ||
|
||
func TestEgressExportedInternalServiceEntryNotPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshInternalServiceEntry("details-se", "bookinfo3", []string{"details.bookinfo2.svc.cluster.local"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/details.bookinfo.svc.cluster.local", | ||
}), | ||
}.Check() | ||
|
||
assert.NotEmpty(vals) | ||
assert.True(valid) | ||
assert.Equal(models.WarningSeverity, vals[0].Severity) | ||
assert.Equal("spec/egress[0]/hosts[0]", vals[0].Path) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("sidecar.egress.servicenotfound", vals[0])) | ||
} | ||
|
||
func TestEgressExportedExternalServiceEntryNotPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshExternalServiceEntry("details-se", "bookinfo3", []string{"www.myhost.com"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/www.wrong.com", | ||
}), | ||
}.Check() | ||
|
||
assert.NotEmpty(vals) | ||
assert.True(valid) | ||
assert.Equal(models.WarningSeverity, vals[0].Severity) | ||
assert.Equal("spec/egress[0]/hosts[0]", vals[0].Path) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("sidecar.egress.servicenotfound", vals[0])) | ||
} | ||
|
||
func TestEgressExportedWildcardInternalServiceEntryPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshInternalServiceEntry("details-se", "bookinfo3", []string{"*.bookinfo2.svc.cluster.local"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/details.bookinfo2.svc.cluster.local", | ||
}), | ||
}.Check() | ||
|
||
assert.Empty(vals) | ||
assert.True(valid) | ||
} | ||
|
||
func TestEgressExportedWildcardInternalServiceEntryNotPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshInternalServiceEntry("details-se", "bookinfo3", []string{"*.bookinfo3.svc.cluster.local"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/*.bookinfo2.svc.cluster.local", | ||
}), | ||
}.Check() | ||
|
||
assert.NotEmpty(vals) | ||
assert.True(valid) | ||
assert.Equal(models.WarningSeverity, vals[0].Severity) | ||
assert.Equal("spec/egress[0]/hosts[0]", vals[0].Path) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("sidecar.egress.servicenotfound", vals[0])) | ||
} | ||
|
||
func TestEgressExportedNonFQDNInternalServiceEntryNotPresent(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
vals, valid := EgressHostChecker{ | ||
Services: []core_v1.Service{}, | ||
ServiceEntries: kubernetes.ServiceEntryHostnames([]networking_v1alpha3.ServiceEntry{*data.CreateEmptyMeshInternalServiceEntry("details-se", "bookinfo3", []string{"details"})}), | ||
Sidecar: *sidecarWithHosts([]string{ | ||
"bookinfo/details.bookinfo2.svc.cluster.local", | ||
}), | ||
}.Check() | ||
|
||
assert.NotEmpty(vals) | ||
assert.True(valid) | ||
assert.Equal(models.WarningSeverity, vals[0].Severity) | ||
assert.Equal("spec/egress[0]/hosts[0]", vals[0].Path) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("sidecar.egress.servicenotfound", vals[0])) | ||
} | ||
|
||
func TestEgressHostCrossNamespaceServiceNotFound(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
hosts := []string{ | ||
|
@@ -62,9 +212,9 @@ func TestEgressHostCrossNamespace(t *testing.T) { | |
assert.True(valid) | ||
|
||
for i, c := range vals { | ||
assert.Equal(models.Unknown, c.Severity) | ||
assert.Equal(models.WarningSeverity, c.Severity) | ||
assert.Equal(fmt.Sprintf("spec/egress[0]/hosts[%d]", i), c.Path) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("validation.unable.cross-namespace", c)) | ||
assert.NoError(validations.ConfirmIstioCheckMessage("sidecar.egress.servicenotfound", c)) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking of cross-namespace validations. I think we should change this method to cover the cross-namespace at some point. It sounds better to have a match between a
Host
and aService
instead of aservice name
and aservice
.However, It might be approached in another issue since the services past in this checker are only from one namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we have a separate task for it: #4317