-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add file server filter #43243
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
Merged
Merged
Add file server filter #43243
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9d578d6
Add file server filter
ravenblackx 36edcd2
Improve coverage, fix docgen
ravenblackx ff9ba4f
Accommodate rename of com_github_cncf_xds
ravenblackx 2b32c67
Merge branch 'main' into file_server
ravenblackx ff97678
Move abslStatusToHttpStatus into its own library, and add coverage
ravenblackx f46d7dd
Add one more line of test coverage!
ravenblackx 908bee7
Remove unused usings
ravenblackx 16c41f0
Remove deps that are inherited anyway, to avoid conflicting with #43265
ravenblackx d0749b1
try_file->default_file, directory_list->list, drop oneof
ravenblackx edbbdba
Add virtual destructor to FileStreamerClient
ravenblackx 9b9b443
DirectoryList->List too
ravenblackx 0da1383
Format
ravenblackx 006ed2d
Double backticks
ravenblackx 52c4555
path_prefix->request_path_prefix, filesystem_prefix->file_path_prefix
ravenblackx 81ae8dc
Format
ravenblackx f0481d7
Address copilot comments
ravenblackx fa7ea2a
Hide the unused message type from docgen
ravenblackx e59c932
Merge branch 'main' into file_server
ravenblackx f80dfe8
Address comments
ravenblackx d2ef56c
Add wbpcode as CODEOWNER
ravenblackx 5cb575b
Make manager_config mandatory
ravenblackx 66e9e62
Fuzz tester limitation
ravenblackx 834c57a
Ensure config destruction happens in the same thread
ravenblackx eed2662
The right delete!
ravenblackx 2ec9d35
Merge branch 'main' into file_server
ravenblackx 2da03e3
Merge branch 'main' into file_server
ravenblackx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = [ | ||
| "//envoy/extensions/common/async_files/v3:pkg", | ||
| "@xds//udpa/annotations:pkg", | ||
| "@xds//xds/annotations/v3:pkg", | ||
| ], | ||
| ) |
85 changes: 85 additions & 0 deletions
85
api/envoy/extensions/filters/http/file_server/v3/file_server.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.filters.http.file_server.v3; | ||
|
|
||
| import "envoy/extensions/common/async_files/v3/async_file_manager.proto"; | ||
|
|
||
| import "xds/annotations/v3/status.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.filters.http.file_server.v3"; | ||
| option java_outer_classname = "FileServerProto"; | ||
| option java_multiple_files = true; | ||
| option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/file_server/v3;file_serverv3"; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
| option (xds.annotations.v3.file_status).work_in_progress = true; | ||
|
|
||
| // [#protodoc-title: FileServerConfig] | ||
| // [#extension: envoy.filters.http.file_server] | ||
|
|
||
| // A :ref:`file server <config_http_filters_file_server>` filter configuration. | ||
| // [#next-free-field: 6] | ||
| message FileServerConfig { | ||
| message PathMapping { | ||
| // If no ``request_path_prefix`` is matched, the filter does not intercept a request. | ||
| // | ||
| // If a ``request_path_prefix`` is matched, that prefix is removed from the request | ||
| // and replaced with ``file_path_prefix`` to form a filesystem path for | ||
| // the request. | ||
| // | ||
| // Prefix ``/`` will match all GET requests. | ||
| string request_path_prefix = 1 [(validate.rules).string = {min_len: 1}]; | ||
|
|
||
| // Replaces a matched ``request_path_prefix`` to form a filesystem path for a | ||
| // request. May be relative to the working directory of the envoy execution, | ||
| // or an absolute path. | ||
| string file_path_prefix = 2 [(validate.rules).string = {min_len: 1}]; | ||
| } | ||
|
|
||
| message DirectoryBehavior { | ||
| // [#not-implemented-hide:] Directory operations currently have no async implementation. | ||
| message List { | ||
| } | ||
|
|
||
| // Attempts to serve the given file within the directory, e.g. ``index.html``. | ||
| // Precisely one of ``default_file`` and ``list`` must be set per ``DirectoryBehavior``. | ||
| string default_file = 1 [(validate.rules).string = {pattern: "^[^/]*$"}]; | ||
|
|
||
| // Responds with an html formatted list of the files and subdirectories in the directory. | ||
| // Precisely one of ``default_file`` and ``list`` must be set per ``DirectoryBehavior``. | ||
| // [#not-implemented-hide:] Directory operations currently have no async implementation. | ||
| List list = 2; | ||
|
ravenblackx marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // A configuration for the AsyncFileManager to be used to read from the filesystem. | ||
| common.async_files.v3.AsyncFileManagerConfig manager_config = 1 | ||
| [(validate.rules).message = {required: true}]; | ||
|
|
||
| // The longest matching path_mapping takes precedence. | ||
| repeated PathMapping path_mappings = 2; | ||
|
|
||
| // A map from filename suffix to content type header. | ||
| // e.g. {"txt": "text/plain"} | ||
| // | ||
| // File suffixes may not contain ``.`` as the filename suffix after | ||
| // the last ``.`` is used to perform an O(1) lookup against the keys. | ||
| // | ||
| // An empty string suffix will only match files ending with a ``.``. | ||
| // | ||
| // Files with no suffix (e.g. ``README``) can be matched as the full string. | ||
| map<string, string> content_types = 3; | ||
|
|
||
| // If ``content_types`` does not contain a match for a file suffix, | ||
| // ``default_content_type`` is used. | ||
| // | ||
| // If there is no match and ``default_content_type`` is empty, the | ||
| // ``content-type`` header will be omitted from the response. | ||
| string default_content_type = 4; | ||
|
|
||
| // If the requested path refers to a directory, the given behaviors are | ||
| // tried in order until one succeeds. If the end of the list is reached | ||
| // with no success, the result is a 403 Forbidden. | ||
| repeated DirectoryBehavior directory_behaviors = 5; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
docs/root/configuration/http/http_filters/file_server_filter.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| .. _config_http_filters_file_server: | ||
|
|
||
| File Server | ||
| =========== | ||
|
|
||
| The file server filter can be used to respond with the contents of a file from the filesystem. | ||
|
|
||
| The ``content-length`` header will be the size of the file. | ||
|
|
||
| The ``content-type`` header will be set based on filename suffix and filter configuration. | ||
|
|
||
| .. note:: | ||
|
|
||
| This filter is not yet supported on Windows. | ||
|
|
||
| Configuration | ||
| ------------- | ||
|
|
||
| * This filter should be configured with the type URL ``type.googleapis.com/envoy.extensions.filters.http.file_server.v3.FileServerConfig``. | ||
| * :ref:`v3 API reference <envoy_v3_api_msg_extensions.filters.http.file_server.v3.FileServerConfig>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_extension", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "absl_status_to_http_status", | ||
| srcs = ["absl_status_to_http_status.cc"], | ||
| hdrs = ["absl_status_to_http_status.h"], | ||
| deps = [ | ||
| "//envoy/http:codes_interface", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "file_server_lib", | ||
| srcs = [ | ||
| "file_streamer.cc", | ||
| "filter.cc", | ||
| "filter_config.cc", | ||
| ], | ||
| hdrs = [ | ||
| "file_streamer.h", | ||
| "filter.h", | ||
| "filter_config.h", | ||
| ], | ||
| deps = [ | ||
| ":absl_status_to_http_status", | ||
| "//envoy/buffer:buffer_interface", | ||
| "//envoy/server:instance_interface", | ||
| "//source/common/common:enum_to_int", | ||
| "//source/common/common:radix_tree_lib", | ||
| "//source/common/http:codes_lib", | ||
| "//source/common/http:header_map_lib", | ||
| "//source/extensions/common/async_files", | ||
| "//source/extensions/filters/http/common:pass_through_filter_lib", | ||
| "@envoy_api//envoy/extensions/filters/http/file_server/v3:pkg_cc_proto", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_extension( | ||
| name = "config", | ||
| srcs = ["config.cc"], | ||
| hdrs = ["config.h"], | ||
| deps = [ | ||
| ":file_server_lib", | ||
| "//source/extensions/filters/http/common:factory_base_lib", | ||
| "@envoy_api//envoy/extensions/filters/http/file_server/v3:pkg_cc_proto", | ||
| ], | ||
| ) |
48 changes: 48 additions & 0 deletions
48
source/extensions/filters/http/file_server/absl_status_to_http_status.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include "source/extensions/filters/http/file_server/absl_status_to_http_status.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace FileServer { | ||
|
|
||
| Http::Code abslStatusToHttpStatus(absl::StatusCode code) { | ||
| switch (code) { | ||
| case absl::StatusCode::kOk: | ||
| return Http::Code::OK; | ||
| case absl::StatusCode::kCancelled: | ||
| return static_cast<Http::Code>(499); | ||
| case absl::StatusCode::kUnknown: | ||
| return Http::Code::InternalServerError; | ||
| case absl::StatusCode::kInvalidArgument: | ||
| return Http::Code::BadRequest; | ||
| case absl::StatusCode::kDeadlineExceeded: | ||
| return Http::Code::GatewayTimeout; | ||
| case absl::StatusCode::kNotFound: | ||
| return Http::Code::NotFound; | ||
| case absl::StatusCode::kAlreadyExists: | ||
| return Http::Code::Conflict; | ||
| case absl::StatusCode::kPermissionDenied: | ||
| return Http::Code::Forbidden; | ||
| case absl::StatusCode::kResourceExhausted: | ||
| return Http::Code::TooManyRequests; | ||
| case absl::StatusCode::kFailedPrecondition: | ||
| return Http::Code::BadRequest; | ||
| case absl::StatusCode::kAborted: | ||
| return Http::Code::Conflict; | ||
| case absl::StatusCode::kOutOfRange: | ||
| return Http::Code::RangeNotSatisfiable; | ||
| case absl::StatusCode::kUnimplemented: | ||
| return Http::Code::ServiceUnavailable; | ||
| case absl::StatusCode::kDataLoss: | ||
| return Http::Code::InternalServerError; | ||
| case absl::StatusCode::kUnauthenticated: | ||
| return Http::Code::Unauthorized; | ||
| default: | ||
| return Http::Code::InternalServerError; | ||
| } | ||
| } | ||
|
|
||
| } // namespace FileServer | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
17 changes: 17 additions & 0 deletions
17
source/extensions/filters/http/file_server/absl_status_to_http_status.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/http/codes.h" | ||
|
|
||
| #include "absl/status/status.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace FileServer { | ||
|
|
||
| Http::Code abslStatusToHttpStatus(absl::StatusCode code); | ||
|
|
||
| } // namespace FileServer | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: as a fresh new extension, I think any field that not implemented could be removed first because:
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.
We want it - the catch is just that it requires implementing async directory operations first which is going to be additional PRs that I didn't want to roll up into this already large PR.
And I wanted the API review before going for that implementation. :)