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

Consider putting the admission review on the webhook context #2656

Open
dprotaso opened this issue Nov 30, 2022 · 11 comments
Open

Consider putting the admission review on the webhook context #2656

dprotaso opened this issue Nov 30, 2022 · 11 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@dprotaso
Copy link
Member

    > The use case is that I need to parse again the AdmissionRequest from Request.Body to perform further checks in the validating/mutating phase.

Would it make more sense for the AdmissionRequest go object to be on the context - instead of having the raw request body and parsing it again yourself?

Originally posted by @dprotaso in #2583 (comment)

@elfotografo007
Copy link
Contributor

Yes it does. It does not only help to prevent us from parsing the request again, but also helps not to consume the Request.Body bytes when we do so.

@dprotaso
Copy link
Member Author

dprotaso commented Jan 4, 2023

/good-first-issue

@knative-prow
Copy link

knative-prow bot commented Jan 4, 2023

@dprotaso:
This request has been marked as suitable for new contributors.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue command.

In response to this:

/good-first-issue

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow knative-prow bot added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Jan 4, 2023
@rahulii
Copy link
Contributor

rahulii commented Apr 3, 2023

/assign

@rahulii
Copy link
Contributor

rahulii commented Apr 3, 2023

hey @dprotaso @elfotografo007 , could you give some pointers to where could I start looking into?
thanks!

@elfotografo007
Copy link
Contributor

First, you can check this PR. Reading the HTTP request body r.Body will consume the bytes and you are not able to read it again afterwards. The PR reads it and sets a copy again in r.Body so it can be read a second time. The purpose of this issue is to make the AdmissionRequest go object to be available in the context cxt for later use.

To accomplish this, you may need to create something similar to ctx = apis.WithHTTPRequest(ctx, r) like ctx = apis.WithAdmissionRequest(ctx, r) to set it and apis.GetAdmissionRequest(ctx) to read it afterwards.

I really don't know about Knative internals so I cannot help you any further than this.

@dprotaso
Copy link
Member Author

dprotaso commented Apr 4, 2023

I would also remove apis.WithHTTPRequest - since we would want folks to use these GetAdmissionRequest helper

@rahulii
Copy link
Contributor

rahulii commented Apr 7, 2023

First, you can check this PR. Reading the HTTP request body r.Body will consume the bytes and you are not able to read it again afterwards. The PR reads it and sets a copy again in r.Body so it can be read a second time. The purpose of this issue is to make the AdmissionRequest go object to be available in the context cxt for later use.

@elfotografo007 got it .
I gad one naive doubt though - why can't it read for the second time? In the previous PR its mentioned it returns EOF? 🤔

@elfotografo007
Copy link
Contributor

When you read the bytes, they are consumed and gone forever. I mitigated the issue by using a TeeReader that reads the bytes and copies them back so they can be read again. This has a problem that if you read them again and don't copy them back, they are gone.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2023

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 7, 2023
@dprotaso
Copy link
Member Author

dprotaso commented Jul 7, 2023

/lifecycle frozen

@knative-prow knative-prow bot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants