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

Do not allow extra fields when validating CRDs #297

Closed
bobcatfish opened this issue Dec 3, 2018 · 7 comments · Fixed by #1081
Closed

Do not allow extra fields when validating CRDs #297

bobcatfish opened this issue Dec 3, 2018 · 7 comments · Fixed by #1081
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.

Comments

@bobcatfish
Copy link
Collaborator

Expected Behavior

If I typo a field in an optional field in a CRD (i.e. provide an extra field), the validation webhook (or worst case, runtime check) should tell me the CRD is invalid.

Actual Behavior

"Extra" fields are ignored, for example in the demo pipeline, there was a bug where one of the instances of inputSourceBindings was not renamed to resources:

https://github.com/knative/build-pipeline/blob/c9341e7f0e5dae53a4c5b1638401b4d65401f1b3/examples/pipeline.yaml#L24-L44

This was ignored (and everything still worked b/c at that time the Pipeline executed in the order it was declared in).

Steps to Reproduce the Problem

  1. Add an extra invalid field to a CRD, for example you can modify the build-push.yaml example spec to have the extra field helloIDoNotBelong: foo:
apiVersion: pipeline.knative.dev/v1alpha1
kind: Task
metadata:
  name: build-push
  namespace: default
spec:
  helloIDoNotBelong: foo
  inputs:
...
  1. Apply the CRD:
kubectl apply -f examples/build-push.yaml
  1. Notice that it applies just fine and the extra field is ignored!
@bobcatfish bobcatfish added the kind/bug Categorizes issue or PR as related to a bug. label Dec 3, 2018
bobcatfish added a commit to bobcatfish/pipeline that referenced this issue Dec 3, 2018
We renamed `inputSourceBindings` (and `outputSourceBindings`) to
`resources` in tektoncd#148 where we also moved the specification of these
bindings into the `PipelineRun` - now the `resources` section in the
`Pipeline` itself exists just to specify dependencies between resources.

But we missed one in the example!

Also created tektoncd#297 to follow up on catching this in validation.
@bobcatfish bobcatfish added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Dec 3, 2018
knative-prow-robot pushed a commit that referenced this issue Dec 3, 2018
We renamed `inputSourceBindings` (and `outputSourceBindings`) to
`resources` in #148 where we also moved the specification of these
bindings into the `PipelineRun` - now the `resources` section in the
`Pipeline` itself exists just to specify dependencies between resources.

But we missed one in the example!

Also created #297 to follow up on catching this in validation.
@hoegaarden
Copy link

For this to be fixed we'd need pruning to be enabled in kubernetes -- it is not implemented yet.
This needs to be implemented in the APIServer, when our code is invoked we do not have access to those additional fields.

@bobcatfish
Copy link
Collaborator Author

Thanks for the links @hoegaarden !!

Question about pruning @hoegaarden - if we prune away the extra fields, does that imply we're ignoring them? I think we definitely want to tell the user they provided some incorrect fields?

In the meantime, maybe we could create our own hacky sort of solution, e.g. inspect the fields somehow before or after deserializing? Maybe we can make openapi validation help us?

@dgageot
Copy link
Contributor

dgageot commented Jan 9, 2019

@bobcatfish I have a prototype that uses the content of the kubectl.kubernetes.io/last-applied-configuration annotation.

This is basically the json form of the resource that the kubctl cli puts here.
We search this json for extra fields.

wdyt?

@bobcatfish
Copy link
Collaborator Author

(whoops @dgageot sorry this took so long to reply to!)

That's an interesting idea - in that case, would we only realize there were extra fields after the resource is created? I'd be interested in seeing the prototype!

@dgageot
Copy link
Contributor

dgageot commented Jan 23, 2019

@bobcatfish see #422

@dlorenc
Copy link
Contributor

dlorenc commented Jan 28, 2019

@jonjohnsonjr mentioned we might want to leave these here to make schema upgrades easier. Is that still the case?

@jonjohnsonjr
Copy link
Contributor

It doesn't make schema upgrades easier, but it does make downgrades possible.

If you don't allow unknown fields and you ever plan to add a new field, your users won't be able to downgrade build-pipeline, because the new field will be unrecognized by the old build-pipeline.

You can get around this by staging new fields for 1 release (but disallowing them) and only allowing n-1 downgrades, but it's a bit delicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants