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

WIP: Remove incomplete validation from webhook #478

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions pkg/webhook/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,6 @@ func (v *validator) validate(obj runtime.Object) (admission.Warnings, error) {
))
}

if target := bundle.Spec.Target.ConfigMap; target != nil {
path := path.Child("sources")
for i, source := range bundle.Spec.Sources {
if source.ConfigMap != nil && source.ConfigMap.Name == bundle.Name && source.ConfigMap.Key == target.Key {
Copy link
Member

Choose a reason for hiding this comment

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

We don't just check that the keys match, we also check that the bundle name matches the source config map name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, @inteon. I will make an effort to fix the currently broken validation smarter.

el = append(el, field.Forbidden(path.Child(fmt.Sprintf("[%d]", i), "configMap", source.ConfigMap.Name, source.ConfigMap.Key), "cannot define the same source as target"))
}
}
}

if target := bundle.Spec.Target.Secret; target != nil {
path := path.Child("sources")
for i, source := range bundle.Spec.Sources {
if source.Secret != nil && source.Secret.Name == bundle.Name && source.Secret.Key == target.Key {
el = append(el, field.Forbidden(path.Child(fmt.Sprintf("[%d]", i), "secret", source.Secret.Name, source.Secret.Key), "cannot define the same source as target"))
}
}
}

configMap := bundle.Spec.Target.ConfigMap
secret := bundle.Spec.Target.Secret

Expand Down
30 changes: 0 additions & 30 deletions pkg/webhook/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,36 +190,6 @@ func Test_validate(t *testing.T) {
field.Invalid(field.NewPath("spec", "sources", "[2]", "secret"), "key: test, includeAllKeys: true", "source secret key cannot be defined when includeAllKeys is true"),
}.ToAggregate().Error()),
},
"sources defines the same configMap target": {
bundle: &trustapi.Bundle{
ObjectMeta: metav1.ObjectMeta{Name: "test-bundle"},
Spec: trustapi.BundleSpec{
Sources: []trustapi.BundleSource{
{InLine: ptr.To("test")},
{ConfigMap: &trustapi.SourceObjectKeySelector{Name: "test-bundle", Key: "test"}},
},
Target: trustapi.BundleTarget{ConfigMap: &trustapi.KeySelector{Key: "test"}},
},
},
expErr: ptr.To(field.ErrorList{
field.Forbidden(field.NewPath("spec", "sources", "[1]", "configMap", "test-bundle", "test"), "cannot define the same source as target"),
}.ToAggregate().Error()),
},
"sources defines the same secret target": {
bundle: &trustapi.Bundle{
ObjectMeta: metav1.ObjectMeta{Name: "test-bundle"},
Spec: trustapi.BundleSpec{
Sources: []trustapi.BundleSource{
{InLine: ptr.To("test")},
{Secret: &trustapi.SourceObjectKeySelector{Name: "test-bundle", Key: "test"}},
},
Target: trustapi.BundleTarget{Secret: &trustapi.KeySelector{Key: "test"}},
},
},
expErr: ptr.To(field.ErrorList{
field.Forbidden(field.NewPath("spec", "sources", "[1]", "secret", "test-bundle", "test"), "cannot define the same source as target"),
}.ToAggregate().Error()),
},
"target configMap key not defined": {
bundle: &trustapi.Bundle{
Spec: trustapi.BundleSpec{
Expand Down