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

fix panic caused by an invalid type assertion #1738

Merged

Conversation

frzifus
Copy link
Member

@frzifus frzifus commented Feb 8, 2022

Signed-off-by: Benedikt Bongartz [email protected]

Closes #1733

Which problem is this PR solving?

Short description of the changes

  • Check type before making a type association in (*Options).UnmarshalJSON method.
  • Return error if the elements of the argument list are not of type string.
  • If Options cant be decoded error 400 is returned.
controller-runtime.webhook.webhooks	received request	{"webhook": "/mutate-jaegertracing-io-v1-jaeger", "UID": "6c77a050-a28d-4172-abc4-56f61670baef", "kind": "jaegertracing.io/v1, Kind=Jaeger", "resource": {"group":"jaegertracing.io","version":"v1","resource":"jaegers"}}
controller-runtime.webhook.webhooks	wrote response	{"webhook": "/mutate-jaegertracing-io-v1-jaeger", "code": 400, "reason": "", "UID": "6c77a050-a28d-4172-abc4-56f61670baef", "allowed": false}

@frzifus frzifus force-pushed the feat/validate_jaeger_options_#1733 branch from 217ab67 to 2535c01 Compare February 8, 2022 22:18
@rubenvp8510 rubenvp8510 enabled auto-merge (squash) February 8, 2022 23:43
@codecov
Copy link

codecov bot commented Feb 9, 2022

Codecov Report

Merging #1738 (2535c01) into master (6382278) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1738      +/-   ##
==========================================
+ Coverage   87.46%   87.48%   +0.02%     
==========================================
  Files          99       99              
  Lines        5926     5937      +11     
==========================================
+ Hits         5183     5194      +11     
  Misses        570      570              
  Partials      173      173              
Impacted Files Coverage Δ
apis/v1/options.go 93.54% <100.00%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6382278...2535c01. Read the comment docs.

@rubenvp8510 rubenvp8510 merged commit 06f6880 into jaegertracing:master Feb 9, 2022
@pavolloffay
Copy link
Member

Didn't we talk about using validating webhook to catch this?

@@ -63,7 +63,9 @@ func (o *Options) UnmarshalJSON(b []byte) error {
if err := d.Decode(&entries); err != nil {
return err
}
o.parse(entries)
if err := o.parse(entries); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

is the return error propagated to the user at object creation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not this particular one. But an error that says your body of your request is invalid.
Its the "code": 400 in the webhook response.

Copy link
Member

Choose a reason for hiding this comment

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

If the error is wrapped here would that be propagated to user?

We should tell the user what was wrong in the CR if that is possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh seems i mixed things up. When you create Jeager with invalid Options it tells you whats wrong.

$ k apply -f invalid.yaml                                                     
Error from server: error when creating "invalid.yaml": admission webhook "mjaeger.kb.io" denied the request: v1.Jaeger.Spec: v1.JaegerSpec.Strategy: Storage: v1.JaegerStorageSpec.Type: Options: unmarshalerDecoder: invalid option type, expect: string, got: map[string]interface {}, error found in #10 byte of ...|":"test"}},"type":"c|..., bigger context ...|"datacenter":"dev","enabled":false,"mode":"test"}},"type":"cassandra"},"strategy":"production"}}|...

Looking at the logs, we could explain error 400 a bit better. But placing a description in the "reason": "" field needs to be done in controller-runtime.webhook.webhooks.

@frzifus
Copy link
Member Author

frzifus commented Feb 10, 2022

Didn't we talk about using validating webhook to catch this?

@pavolloffay you are right. In course of doing this, i noticed that the Jeager object is already a unmarshalled version of the spec.

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.

CRD validation does not catch invalid options
3 participants