content_length was 0 both for an empty body and for a body of unknown
length, e.g. a PUT with chunked transfer encoding. A policy could not
reject uploads that do not declare their size.
The lengths are now proto3 optional fields and the proxy sets
content_length whenever Go knows it, including 0 for an empty body.
An unknown length leaves the key out of the policy input. Rules that
compare a missing key do not apply, so existing limit rules keep
working, and a policy can reject an undeclared length explicitly with
`not "content_length" in object.keys(input.request)`.
We use field presence instead of -1, because a negative sentinel would
turn a request without lengths, e.g. in the postprocessing stage, into
an empty body.
related: https://github.com/opencloud-eu/opencloud/pull/3903#issuecomment-7273785513
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
The proxy policies middleware now passes the Content-Length of the
request body and the TUS Upload-Length header to the policies engine
as input.request.content_length and input.request.upload_length. This
allows rejecting uploads that are too big before any data is
transferred, instead of only in postprocessing after the upload has
completed.
We add them to the request instead of setting resource.size, because
the resource describes the target of the request (the middleware may
even stat it) and in postprocessing resource.size is the actual file
size.
This can only be an early check. The TUS concatenation extension
allows merging several smaller uploads into one file, so the file size
still has to be checked in postprocessing.
protojson encodes uint64 values as strings with camelCase keys, so
NewEnvironmentFromPB copies the lengths explicitly.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
* add policies service
add policies proxy middleware
add policies event service
add policies grpc service
prepare ci and git environments (ci, make, readme, doc)
* add webfinger to the drone conf
* fix docs
remove not used virus scan postprocessing step
* relocate example rego file
implicitly enable and disable proxy and postprocessing policy checking by setting the query.
update configuration descriptions
* move policies
update readme
* use converter func to convert pp environment to actual environment
expose and test custom rego functions
add engine unit tests
add opa unit tests
update policies readme
Co-authored-by: Martin <github@diemattels.at>
* relocate sample policies to the deployments folder
change and document policies service port
* update index.md and small fix
* add health command
add version command
add debug server
---------
Co-authored-by: Martin <github@diemattels.at>