-
Notifications
You must be signed in to change notification settings - Fork 481
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
hooks: add pre-access blocking hook #1077
base: main
Are you sure you want to change the base?
Conversation
bad9e4e
to
2467d64
Compare
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.
Wow, thank you very much for this huge PR! Congratulations on adding a new hook on your own. I can a look through it focusing on the implementation (and less on the tests and documentation) for now, and left a few comments. But overall this is looking great!
pkg/handler/hooks.go
Outdated
|
||
// All files info that will be access by http request | ||
// Use an array because of Upload-Concat that may target several files | ||
Files []FileInfo |
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.
Can we call this Uploads
, similar to the Upload
field in HookEvent
itself?
pkg/handler/hooks.go
Outdated
Files []FileInfo | ||
} | ||
|
||
func newHookEvent(c *httpContext, info *FileInfo, accessInfo *AccessInfo) HookEvent { |
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.
I would prefer to split the access-related logic into a new function
func newHookEvent(c *httpContext, mode AccessMode, uploads []FileInfo) HookEvent {
event := newHookEvent(c, nil)
event.Access = {
Mode: mode,
Uploads: uploads,
}
return event
}
while keeping access out of newHookEvent
:
func newHookEvent(c *httpContext, info *FileInfo) HookEvent {
Then we should also be able to remove newAccessInfo
.
What do you think?
pkg/handler/unrouted_handler.go
Outdated
@@ -338,7 +340,8 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) | |||
} | |||
|
|||
if handler.config.PreUploadCreateCallback != nil { | |||
resp2, changes, err := handler.config.PreUploadCreateCallback(newHookEvent(c, info)) | |||
access := newAccessInfo(AccessModeRead, partialFileInfos) | |||
resp2, changes, err := handler.config.PreUploadCreateCallback(newHookEvent(c, &info, &access)) |
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.
For concatenation, I think we should first emit a pre-access hook to check the permissions for read access on the partial uploads. If that succeeds we can continue with the upload creation and the corresponding pre-create hook. Then users don't have to duplicate access-related logic in pre-access and pre-create.
A good location for that hook is likely a few lines above after the call to handler.sizeOfUploads
.
return HookEvent{ | ||
Context: c, | ||
Upload: info, | ||
Upload: upload, |
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.
In hindsight, it would be great if we could set Upload: nil
, but that would a require a change to the type, which would be breaking.
to prepare pre-access hook
- on Head/Get/Patch/Delete request - use new AccessInfo in HookEvent with AccessMode and FileInfo list - use RejectAccess in response to return 403 by default if rejected
when Upload-Concat is used, to check authorization for instance
- add some README.md to guide usage - fix grpc example Makefile proto path
2467d64
to
9433698
Compare
I made the changes you suggested, except the last one to set |
Thank you for the updates, I will look into this in two weeks and then we should be able to get this merged. |
pre-resume
PR (hooks: add pre-resume blocking hook #1074)Access.Mode
andAccess.Files
toHookEvent
forpre-access
andpre-create
(when Upload-Concat) hook.Files
is an array because of Concatenation extension that access many files to make a new oneMode
is read (Get/Head) or write (Patch/Delete)pre-access
before each http request Get/Head/Patch/Delete.RejectAccess
in HookResponse. Http response status code will be 403, if not override in HttpResponse.close #1074