-
Notifications
You must be signed in to change notification settings - Fork 5.5k
rbac: add metadata support to rbac filter #3638
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
91c2423
rbac: add metadata support to rbac filter.
yangminzhu 75fcb1f
create seperate directory and namespace for matchers.
yangminzhu 5d009dc
fix api and docs.
yangminzhu 4301c1d
address comments.
yangminzhu 5d4e01d
rename matchers -> matcher, add NullMatch and PathSegment.
yangminzhu 530dedd
address comments, update docs and small updates.
yangminzhu a9467d4
address comments, make metadata.value not repeated.
yangminzhu 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
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
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,50 @@ | ||
| load("//bazel:api_build_system.bzl", "api_go_proto_library", "api_proto_library") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_library( | ||
| name = "metadata", | ||
| srcs = ["metadata.proto"], | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| ":number", | ||
| ":string", | ||
| ], | ||
| ) | ||
|
|
||
| api_go_proto_library( | ||
| name = "metadata", | ||
| proto = ":metadata", | ||
| deps = [ | ||
| ":number_go_proto", | ||
| ":string_go_proto", | ||
| ], | ||
| ) | ||
|
|
||
| api_proto_library( | ||
| name = "number", | ||
| srcs = ["number.proto"], | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//envoy/type:range", | ||
| ], | ||
| ) | ||
|
|
||
| api_go_proto_library( | ||
| name = "number", | ||
| proto = ":number", | ||
| deps = [ | ||
| "//envoy/type:range_go_proto", | ||
| ], | ||
| ) | ||
|
|
||
| api_proto_library( | ||
| name = "string", | ||
| srcs = ["string.proto"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| api_go_proto_library( | ||
| name = "string", | ||
| proto = ":string", | ||
| ) |
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,123 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.type.matcher; | ||
| option go_package = "matcher"; | ||
|
|
||
| import "envoy/type/matcher/string.proto"; | ||
| import "envoy/type/matcher/number.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#protodoc-title: MetadataMatcher] | ||
|
|
||
| // MetadataMatcher provides a general interface to check if a given value is matched in | ||
| // :ref:`Metadata <envoy_api_msg_core.Metadata>`. It uses `filter` and `path` to retrieve the value | ||
| // from the Metadata and then check if it's matched to the specified value. | ||
| // | ||
| // For example, for the following Metadata: | ||
| // | ||
| // .. code-block:: yaml | ||
| // | ||
| // filter_metadata: | ||
| // envoy.filters.http.rbac: | ||
| // fields: | ||
| // a: | ||
| // struct_value: | ||
| // fields: | ||
| // b: | ||
| // struct_value: | ||
| // fields: | ||
| // c: | ||
| // string_value: pro | ||
| // t: | ||
| // list_value: | ||
| // values: | ||
| // - string_value: m | ||
| // - string_value: n | ||
| // | ||
| // The following MetadataMatcher is matched as the path [a, b, c] will retrieve a string value "pro" | ||
| // from the Metadata which is matched to the specified prefix match. | ||
| // | ||
| // .. code-block:: yaml | ||
| // | ||
| // filter: envoy.filters.http.rbac | ||
| // path: | ||
| // - key: a | ||
| // - key: b | ||
| // - key: c | ||
| // value: | ||
| // string_match: | ||
| // prefix: pr | ||
| // | ||
| // The following MetadataMatcher is not matched as the path [a, t] is pointing to a list value in | ||
| // the Metadata which is not supported for now. | ||
| // | ||
| // .. code-block:: yaml | ||
| // | ||
| // filter: envoy.filters.http.rbac | ||
| // path: | ||
| // - key: a | ||
| // - key: t | ||
| // value: | ||
| // string_match: | ||
| // exact: m | ||
| // | ||
| // An example use of MetadataMatcher is specifying additional metadata in envoy.filters.http.rbac to | ||
| // enforce access control based on dynamic metadata in a request. See :ref:`Permission | ||
| // <envoy_api_msg_config.rbac.v2alpha.Permission>` and :ref:`Principal | ||
| // <envoy_api_msg_config.rbac.v2alpha.Principal>`. | ||
| message MetadataMatcher { | ||
| // Specifies the segment in a path to retrieve value from Metadata. | ||
| // Note: Currently it's not supported to retrieve a value from a list in Metadata. This means it | ||
| // will always be not matched if the associated value of the key is a list. | ||
| message PathSegment { | ||
| oneof segment { | ||
| option (validate.required) = true; | ||
|
|
||
| // If specified, use the key to retrieve the value in a Struct. | ||
| string key = 1 [(validate.rules).string.min_bytes = 1]; | ||
| } | ||
| } | ||
|
|
||
| // Specifies the value to match. Only primitive value are supported. For non-primitive values, the | ||
| // result is always not matched. | ||
| message Value { | ||
| // NullMatch is an empty message to specify a null value. | ||
| message NullMatch { | ||
| } | ||
|
|
||
| // Specifies how to match a value. | ||
| oneof match_pattern { | ||
| option (validate.required) = true; | ||
|
|
||
| // If specified, a match occurs if and only if the target value is a NullValue. | ||
| NullMatch null_match = 1; | ||
|
|
||
| // If specified, a match occurs if and only if the target value is a double value and is | ||
| // matched to this field. | ||
| DoubleMatcher double_match = 2; | ||
|
|
||
| // If specified, a match occurs if and only if the target value is a string value and is | ||
| // matched to this field. | ||
| StringMatcher string_match = 3; | ||
|
|
||
| // If specified, a match occurs if and only if the target value is a bool value and is equal | ||
| // to this field. | ||
| bool bool_match = 4; | ||
|
|
||
| // If specified, value match will be performed based on whether the path is referring to a | ||
| // valid primitive value in the metadata. If the path is referring to a non-primitive value, | ||
| // the result is always not matched. | ||
| bool present_match = 5; | ||
| } | ||
| } | ||
|
|
||
| // The filter name to retrieve the Struct from the Metadata. | ||
| string filter = 1 [(validate.rules).string.min_bytes = 1]; | ||
|
|
||
| // The path to retrieve the Value from the Struct. | ||
| repeated PathSegment path = 2 [(validate.rules).repeated .min_items = 1]; | ||
|
|
||
| // The MetadataMatcher is matched if the value retrieved by path is matched to this value. | ||
| Value value = 3 [(validate.rules).message.required = true]; | ||
| } | ||
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,24 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.type.matcher; | ||
| option go_package = "matcher"; | ||
|
|
||
| import "envoy/type/range.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#protodoc-title: NumberMatcher] | ||
|
|
||
| // Specifies the way to match a double value. | ||
| message DoubleMatcher { | ||
| oneof match_pattern { | ||
| option (validate.required) = true; | ||
|
|
||
| // If specified, the input double value must be in the range specified here. | ||
| // Note: The range is using half-open interval semantics [start, end). | ||
| envoy.type.DoubleRange range = 1; | ||
|
|
||
| // If specified, the input double value must be equal to the value specified here. | ||
| double exact = 2; | ||
| } | ||
| } |
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,49 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.type.matcher; | ||
| option go_package = "matcher"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#protodoc-title: StringMatcher] | ||
|
|
||
| // Specifies the way to match a string. | ||
| message StringMatcher { | ||
| oneof match_pattern { | ||
| option (validate.required) = true; | ||
|
|
||
| // The input string must match exactly the string specified here. | ||
| // | ||
| // Examples: | ||
| // | ||
| // * *abc* only matches the value *abc*. | ||
| string exact = 1; | ||
|
|
||
| // The input string must have the prefix specified here. | ||
| // Note: empty prefix is not allowed, please use regex instead. | ||
| // | ||
| // Examples: | ||
| // | ||
| // * *abc* matches the value *abc.xyz* | ||
| string prefix = 2 [(validate.rules).string.min_bytes = 1]; | ||
|
|
||
| // The input string must have the suffix specified here. | ||
| // Note: empty prefix is not allowed, please use regex instead. | ||
| // | ||
| // Examples: | ||
| // | ||
| // * *abc* matches the value *xyz.abc* | ||
| string suffix = 3 [(validate.rules).string.min_bytes = 1]; | ||
|
|
||
| // The input string must match the regular expression specified here. | ||
| // The regex grammar is defined `here | ||
| // <http://en.cppreference.com/w/cpp/regex/ecmascript>`_. | ||
| // | ||
| // Examples: | ||
| // | ||
| // * The regex *\d{3}* matches the value *123* | ||
| // * The regex *\d{3}* does not match the value *1234* | ||
| // * The regex *\d{3}* does not match the value *123.456* | ||
| string regex = 4; | ||
| } | ||
| } |
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 was deleted.
Oops, something went wrong.
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
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.
Shall we use fieldmask? You can write paths as "a.b.c".
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.
Fieldmask have some disadvantages, from my investigations, it cannot support either list or map which means we cannot use it directly here, unless we implement it by ourselves in Envoy.
Second, the semantics would be much more complicated, it won't be
a.b.c, you have to list all field names in the path, so it will be something likefields.a.struct_value.fields.b.struct_value.fields.c.string_value.Last, Envoy already have a well implemented metadataValue() method which satisfy all our needs here, so I think no need to use the fieldmask anymore.