Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
1045f09
rbac: add support for upstream ip policy.
conqerAtapple Jul 23, 2021
f0fd31a
Changed message id for upstream_ip.
conqerAtapple Aug 11, 2021
1adb961
Removed trailing whitespace.
conqerAtapple Aug 12, 2021
dfc6845
format fixes.
conqerAtapple Aug 12, 2021
746300d
Fixed API documentation.
conqerAtapple Aug 12, 2021
bf98fd5
Fixing clang tidy reported issue.
conqerAtapple Aug 12, 2021
4b2afa2
Fix matcher logic for early return.
conqerAtapple Aug 12, 2021
5bb36ca
fixing callback argument.
conqerAtapple Aug 14, 2021
6896019
Added debug for matching ip and range.
conqerAtapple Aug 17, 2021
b8d4be4
Added rbac filter unit tests.
conqerAtapple Aug 17, 2021
5174905
Minor changes.
conqerAtapple Aug 18, 2021
0ee890a
Added unit tests for dynamic forward proxy.
conqerAtapple Aug 18, 2021
296bc67
Temporarily removing null check and its test.
conqerAtapple Aug 18, 2021
3037ac8
Adding back null check and test.
conqerAtapple Aug 19, 2021
060c2bd
Review changes.
conqerAtapple Aug 19, 2021
a5d607d
Introduced RBAC Matcher extension.
conqerAtapple Aug 24, 2021
df99181
Review comments addressed.
conqerAtapple Sep 2, 2021
0d1dca1
Removed comments.
conqerAtapple Sep 2, 2021
a37818e
Changed package name for upstream matchers.
conqerAtapple Sep 2, 2021
51c82b3
Removed extension attribute.
conqerAtapple Sep 3, 2021
70d7234
Moved upstream extension package.
conqerAtapple Sep 3, 2021
6b02593
Fixing ext category/
conqerAtapple Sep 3, 2021
0a1efa8
Updated extensions_check.
conqerAtapple Sep 3, 2021
d5c9306
Updated api BUILD.
conqerAtapple Sep 3, 2021
8f57013
Changed extension and package names.
conqerAtapple Sep 3, 2021
9d33975
Updated extensions_check.py.
conqerAtapple Sep 3, 2021
192cc7a
Moved matcher extension directory.
conqerAtapple Sep 7, 2021
f76d0c9
Added doc on filter state.
conqerAtapple Sep 7, 2021
e07ee7d
Added logger to matchers.
conqerAtapple Sep 7, 2021
951d9e9
ci/do_ci.sh passes locally.
conqerAtapple Sep 7, 2021
bd29b9f
Fix test builds.
conqerAtapple Sep 7, 2021
0bcd80c
clang-tidy test.
conqerAtapple Sep 7, 2021
02c40c4
Added port matcher tests.
conqerAtapple Sep 8, 2021
a6f2ca1
CI fixes.
conqerAtapple Sep 9, 2021
bcc9c5b
Review comments.
conqerAtapple Sep 9, 2021
469ec05
Review comment - ValidationVisitor
conqerAtapple Sep 9, 2021
399afaa
Split matchers
conqerAtapple Sep 10, 2021
0afea0c
Update api BUILD file.
conqerAtapple Sep 10, 2021
770db03
Simplified upstream address set key.
conqerAtapple Sep 10, 2021
344a412
removing repo dependency.
conqerAtapple Sep 10, 2021
fbf1add
Docs for upstream matchers
conqerAtapple Sep 10, 2021
5c7be4c
Fixed rbac matchers docs.
conqerAtapple Sep 10, 2021
c6d4fdd
Added back dependency.
conqerAtapple Sep 10, 2021
812bd25
Fix build
conqerAtapple Sep 10, 2021
ad0c2f5
fix test build.
conqerAtapple Sep 10, 2021
a7d8fd4
Added check in the func.
conqerAtapple Sep 13, 2021
8959fad
updated API docs and codeowners
conqerAtapple Sep 13, 2021
f152be6
Deleted generated_api_shadow
conqerAtapple Sep 13, 2021
ac87d9d
Review comments
conqerAtapple Sep 14, 2021
dee8660
Added release notes.
conqerAtapple Sep 15, 2021
d54b0f5
Review comments
conqerAtapple Sep 15, 2021
bc11d45
Fix release note.
conqerAtapple Sep 15, 2021
706322e
Fix double ticks.
conqerAtapple Sep 15, 2021
3fc48b4
Review comments
conqerAtapple Sep 15, 2021
2cbe65d
Renamed fileobject key
conqerAtapple Sep 15, 2021
8eb031b
Added test for null address.
conqerAtapple Sep 16, 2021
4ada7b9
Disabled rbac integration test on windows.
conqerAtapple Sep 16, 2021
3f3577d
test coverage
conqerAtapple Sep 16, 2021
aaed4c5
Merge branch 'main' into rbac-upstream-dynamic-proxy
conqerAtapple Sep 16, 2021
51eb89a
Review comments
conqerAtapple Sep 16, 2021
df959de
Review changes.
conqerAtapple Sep 20, 2021
630be7b
Review comments
conqerAtapple Sep 21, 2021
fd0f2f7
Fix comments
conqerAtapple Sep 21, 2021
82424b1
Changed upstream set to single address.
conqerAtapple Sep 23, 2021
45ba98a
Moved upstream_ip matcher to upstream_ip_port matcher.
conqerAtapple Sep 23, 2021
d3a0a01
More documentation.
conqerAtapple Sep 23, 2021
c5d5f2a
Merge branch 'main' into rbac-upstream-dynamic-proxy
conqerAtapple Sep 24, 2021
d1e227b
Added comment about optional field.
conqerAtapple Sep 26, 2021
6486f62
Merge branch 'main' into rbac-upstream-dynamic-proxy
conqerAtapple Sep 26, 2021
0fb4bf8
Combined IP and Port matcher.
conqerAtapple Sep 27, 2021
0812a31
Merge branch 'main' into rbac-upstream-dynamic-proxy
conqerAtapple Sep 27, 2021
26dae37
format.
conqerAtapple Sep 27, 2021
594f3d8
Fix clang tidy.
conqerAtapple Sep 27, 2021
88ae18f
Merge branch 'main' into rbac-upstream-dynamic-proxy
conqerAtapple Sep 27, 2021
4104388
Review comments.
conqerAtapple Sep 28, 2021
c027553
Merge branch 'main' into rbac-upstream-dynamic-proxy
conqerAtapple Sep 28, 2021
3c166dd
Better error message/docs.
conqerAtapple Sep 28, 2021
20cd653
Updated doc.
conqerAtapple Sep 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extensions/filters/common/original_src @snowp @klarose
/*/extensions/filters/common/fault @rshriram @alyssawilk
/*/extensions/filters/http/grpc_json_transcoder @qiwzhang @lizan
/*/extensions/filters/http/router @alyssawilk @mattklein123 @snowp
/*/extensions/filters/common/rbac/matchers @conqerAtapple @ggreenway @alyssawilk
/*/extensions/filters/http/grpc_web @fengli79 @lizan
/*/extensions/filters/http/grpc_stats @kyessenov @lizan
/*/extensions/filters/common/original_src @klarose @snowp
Expand Down
1 change: 1 addition & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ proto_library(
"//envoy/extensions/quic/crypto_stream/v3:pkg",
"//envoy/extensions/quic/proof_source/v3:pkg",
"//envoy/extensions/rate_limit_descriptors/expr/v3:pkg",
"//envoy/extensions/rbac/matchers/upstream_ip_port/v3:pkg",
"//envoy/extensions/request_id/uuid/v3:pkg",
"//envoy/extensions/resource_monitors/fixed_heap/v3:pkg",
"//envoy/extensions/resource_monitors/injected_resource/v3:pkg",
Expand Down
7 changes: 6 additions & 1 deletion api/envoy/config/rbac/v3/rbac.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package envoy.config.rbac.v3;

import "envoy/config/core/v3/address.proto";
import "envoy/config/core/v3/extension.proto";
import "envoy/config/route/v3/route_components.proto";
import "envoy/type/matcher/v3/metadata.proto";
import "envoy/type/matcher/v3/path.proto";
Expand Down Expand Up @@ -146,7 +147,7 @@ message Policy {
}

// Permission defines an action (or actions) that a principal can take.
// [#next-free-field: 12]
// [#next-free-field: 13]
message Permission {
option (udpa.annotations.versioning).previous_message_type = "envoy.config.rbac.v2.Permission";

Expand Down Expand Up @@ -218,6 +219,10 @@ message Permission {
// Please refer to :ref:`this FAQ entry <faq_how_to_setup_sni>` to learn to
// setup SNI.
type.matcher.v3.StringMatcher requested_server_name = 9;

// Extension for configuring custom matchers for RBAC.
// [#extension-category: envoy.rbac.matchers]
core.v3.TypedExtensionConfig matcher = 12;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ message FilterConfig {
// <envoy_v3_api_field_extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig.dns_cache_config>`.
common.dynamic_forward_proxy.v3.DnsCacheConfig dns_cache_config = 1
[(validate.rules).message = {required: true}];

// When this flag is set, the filter will add the resolved upstream address in the filter
// state. The state should be saved with key
// `envoy.stream.upstream_address` (See
// :repo:`upstream_address.h<source/common/stream_info/upstream_address.h>`).
bool save_upstream_address = 2;
}

// Per route Configuration for the dynamic forward proxy HTTP filter.
Expand Down
13 changes: 13 additions & 0 deletions api/envoy/extensions/rbac/matchers/upstream_ip_port/v3/BUILD
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/config/core/v3:pkg",
"//envoy/type/v3:pkg",
"@com_github_cncf_udpa//udpa/annotations:pkg",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
syntax = "proto3";

package envoy.extensions.rbac.matchers.upstream_ip_port.v3;

import "envoy/config/core/v3/address.proto";
import "envoy/type/v3/range.proto";

import "udpa/annotations/status.proto";

option java_package = "io.envoyproxy.envoy.extensions.rbac.matchers.upstream_ip_port.v3";
option java_outer_classname = "UpstreamIpPortMatcherProto";
option java_multiple_files = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: RBAC upstream IP and port matcher plugin]
// [#extension: envoy.rbac.matchers.upstream_ip_port]

// This is configuration for matching upstream ip and port.
// Note that although both fields are optional, at least one of IP or port must be supplied. If only
// one is supplied the other is a wildcard match.
// This matcher requires a filter in the chain to have saved the upstream address in the
// filter state before the matcher is executed by RBAC filter. The state should be saved with key
// `envoy.stream.upstream_address` (See
// :repo:`upstream_address.h<source/common/stream_info/upstream_address.h>`).
// Also, See :repo:`proxy_filter.cc<
// source/extensions/filters/http/dynamic_forward_proxy/proxy_filter.cc>` for an example of a
// filter which populates the FilterState.
message UpstreamIpPortMatcher {
// A CIDR block that will be used to match the upstream IP.
// Both Ipv4 and Ipv6 ranges can be matched.
config.core.v3.CidrRange upstream_ip = 1;

// A port range that will be used to match the upstream port.
type.v3.Int64Range upstream_port_range = 2;
}
1 change: 1 addition & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ proto_library(
"//envoy/extensions/quic/crypto_stream/v3:pkg",
"//envoy/extensions/quic/proof_source/v3:pkg",
"//envoy/extensions/rate_limit_descriptors/expr/v3:pkg",
"//envoy/extensions/rbac/matchers/upstream_ip_port/v3:pkg",
"//envoy/extensions/request_id/uuid/v3:pkg",
"//envoy/extensions/resource_monitors/fixed_heap/v3:pkg",
"//envoy/extensions/resource_monitors/injected_resource/v3:pkg",
Expand Down
2 changes: 2 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ REPOSITORY_LOCATIONS_SPEC = dict(
"envoy.filters.network.rbac",
"envoy.filters.network.wasm",
"envoy.stat_sinks.wasm",
"envoy.rbac.matchers.upstream_ip_port",
],
release_date = "2021-06-28",
cpe = "N/A",
Expand All @@ -899,6 +900,7 @@ REPOSITORY_LOCATIONS_SPEC = dict(
"envoy.filters.network.rbac",
"envoy.filters.network.wasm",
"envoy.stat_sinks.wasm",
"envoy.rbac.matchers.upstream_ip_port",
],
release_date = "2020-04-02",
cpe = "N/A",
Expand Down
1 change: 1 addition & 0 deletions docs/root/api-v3/config/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Extensions
quic/quic_extensions
formatter/formatter
contrib/contrib
rbac/matchers
8 changes: 8 additions & 0 deletions docs/root/api-v3/config/rbac/matchers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RBAC Matchers
=============

.. toctree::
:glob:
:maxdepth: 2

matchers/matchers
8 changes: 8 additions & 0 deletions docs/root/api-v3/config/rbac/matchers/matchers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RBAC Matchers
===

.. toctree::
:glob:
:maxdepth: 2

upstream/upstream
8 changes: 8 additions & 0 deletions docs/root/api-v3/config/rbac/matchers/upstream/upstream.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Upstream Matchers
=================

.. toctree::
:glob:
:maxdepth: 2

../../../../extensions/rbac/matchers/upstream_ip_port/v3/upstream_ip_port_matcher.proto
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ New Features
* matcher: added :ref:`invert <envoy_v3_api_field_type.matcher.v3.MetadataMatcher.invert>` for inverting the match result in the metadata matcher.
* overload: add a new overload action that resets streams using a lot of memory. To enable the tracking of allocated bytes in buffers that a stream is using we need to configure the minimum threshold for tracking via:ref:`buffer_factory_config <envoy_v3_api_field_config.overload.v3.OverloadManager.buffer_factory_config>`. We have an overload action ``Envoy::Server::OverloadActionNameValues::ResetStreams`` that takes advantage of the tracking to reset the most expensive stream first.
* rbac: added :ref:`destination_port_range <envoy_v3_api_field_config.rbac.v3.Permission.destination_port_range>` for matching range of destination ports.
* rbac: added :ref:`matcher<envoy_v3_api_field_config.rbac.v3.Permission.matcher>` along with extension category ``extension_category_envoy.rbac.matchers`` for custom RBAC permission matchers. Added reference implementation for matchers :ref:`envoy.rbac.matchers.upstream_ip_port <extension_envoy.rbac.matchers.upstream_ip_port>`.
* route config: added :ref:`dynamic_metadata <envoy_v3_api_field_config.route.v3.RouteMatch.dynamic_metadata>` for routing based on dynamic metadata.
* router: added retry options predicate extensions configured via
:ref:` <envoy_v3_api_field_config.route.v3.RetryPolicy.retry_options_predicates>`. These
Expand Down
8 changes: 8 additions & 0 deletions source/common/stream_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ envoy_cc_library(
"//envoy/stream_info:uint32_accessor_interface",
],
)

envoy_cc_library(
name = "upstream_address_lib",
hdrs = ["upstream_address.h"],
deps = [
"//envoy/stream_info:filter_state_interface",
],
)
24 changes: 24 additions & 0 deletions source/common/stream_info/upstream_address.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "envoy/network/address.h"
#include "envoy/stream_info/filter_state.h"

#include "absl/container/flat_hash_set.h"

namespace Envoy {
namespace StreamInfo {

/*
* A FilterState object that wraps a network address shared pointer.
*/
class UpstreamAddress : public FilterState::Object {
public:
static const std::string& key() {
CONSTRUCT_ON_FIRST_USE(std::string, "envoy.stream.upstream_address");
}

Network::Address::InstanceConstSharedPtr address_;
};

} // namespace StreamInfo
} // namespace Envoy
6 changes: 6 additions & 0 deletions source/extensions/extensions_build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ EXTENSIONS = {
#

"envoy.key_value.file_based": "//source/extensions/key_value/file_based:config_lib",

#
# RBAC matchers
#

"envoy.rbac.matchers.upstream_ip_port": "//source/extensions/filters/common/rbac/matchers:upstream_ip_port_lib",
}

# These can be changed to ["//visibility:public"], for downstream builds which
Expand Down
5 changes: 5 additions & 0 deletions source/extensions/extensions_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,8 @@ envoy.key_value.file_based:
- envoy.common.key_value
security_posture: data_plane_agnostic
status: alpha
envoy.rbac.matchers.upstream_ip_port:
categories:
- envoy.rbac.matchers
security_posture: unknown
status: alpha
6 changes: 5 additions & 1 deletion source/extensions/filters/common/rbac/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ envoy_cc_library(
envoy_cc_library(
name = "matchers_lib",
srcs = ["matchers.cc"],
hdrs = ["matchers.h"],
hdrs = [
"matcher_extension.h",
"matchers.h",
],
external_deps = ["abseil_optional"],
deps = [
"//envoy/http:header_map_interface",
"//envoy/network:connection_interface",
"//source/common/common:assert_lib",
"//source/common/common:matchers_lib",
"//source/common/config:utility_lib",
"//source/common/http:header_utility_lib",
"//source/common/network:cidr_range_lib",
"//source/extensions/filters/common/expr:evaluator_lib",
Expand Down
6 changes: 4 additions & 2 deletions source/extensions/filters/common/rbac/engine_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace Common {
namespace RBAC {

RoleBasedAccessControlEngineImpl::RoleBasedAccessControlEngineImpl(
const envoy::config::rbac::v3::RBAC& rules, const EnforcementMode mode)
const envoy::config::rbac::v3::RBAC& rules,
ProtobufMessage::ValidationVisitor& validation_visitor, const EnforcementMode mode)
: action_(rules.action()), mode_(mode) {
// guard expression builder by presence of a condition in policies
for (const auto& policy : rules.policies()) {
Expand All @@ -22,7 +23,8 @@ RoleBasedAccessControlEngineImpl::RoleBasedAccessControlEngineImpl(
}

for (const auto& policy : rules.policies()) {
policies_.emplace(policy.first, std::make_unique<PolicyMatcher>(policy.second, builder_.get()));
policies_.emplace(policy.first, std::make_unique<PolicyMatcher>(policy.second, builder_.get(),
validation_visitor));
}
}

Expand Down
1 change: 1 addition & 0 deletions source/extensions/filters/common/rbac/engine_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum class EnforcementMode { Enforced, Shadow };
class RoleBasedAccessControlEngineImpl : public RoleBasedAccessControlEngine, NonCopyable {
public:
RoleBasedAccessControlEngineImpl(const envoy::config::rbac::v3::RBAC& rules,
ProtobufMessage::ValidationVisitor& validation_visitor,
const EnforcementMode mode = EnforcementMode::Enforced);

bool handleAction(const Network::Connection& connection,
Expand Down
57 changes: 57 additions & 0 deletions source/extensions/filters/common/rbac/matcher_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#include "envoy/common/pure.h"
#include "envoy/config/typed_config.h"
#include "envoy/protobuf/message_validator.h"

#include "source/extensions/filters/common/rbac/matchers.h"

namespace Envoy {
namespace Extensions {
namespace Filters {
namespace Common {
namespace RBAC {

// Matcher extension factory for RBAC filter. Matchers could be extended to support IP address,
// header value etc.
class MatcherExtensionFactory : public Envoy::Config::TypedFactory {
public:
/**
* Function to create Matchers from the specified config.
* @param config supplies the matcher configuration
* @return a new MatcherExtension
*/
virtual MatcherConstSharedPtr create(const Protobuf::Message& config,
ProtobufMessage::ValidationVisitor& validation_visitor) PURE;

// @brief the category of the matcher extension type for factory registration.
std::string category() const override { return "envoy.rbac.matchers"; }
};

// Base RBAC matcher extension factory. This facilitates easy creation of matcher extension
// factories. The factory is templated by:
// M: Matcher extension implementation
// P: Protobuf definition of the matcher.
template <typename M, typename P>
class BaseMatcherExtensionFactory : public Filters::Common::RBAC::MatcherExtensionFactory {
public:
Filters::Common::RBAC::MatcherConstSharedPtr
create(const Protobuf::Message& config,
ProtobufMessage::ValidationVisitor& validation_visitor) override {
const auto& matcher_typed_config =
MessageUtil::downcastAndValidate<const envoy::config::core::v3::TypedExtensionConfig&>(
config, validation_visitor);
Comment on lines +41 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This downcastAndValidate doesn't validate the typed config, it should be done after anyConvert with downcastAndValidate<const P&>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lizan .Not sure I follow. Is there an example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lizan I assume MessageUtil::anyConvertAndValidate would do both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but usually create takes a parameter after anyConvert. See network filter factory base as example:
https://github.com/envoyproxy/envoy/blob/main/source/extensions/filters/network/common/factory_base.h#L22-L27


const auto proto_message = MessageUtil::anyConvert<P>(matcher_typed_config.typed_config());

return std::make_shared<M>(proto_message);
}

ProtobufTypes::MessagePtr createEmptyConfigProto() override { return std::make_unique<P>(); }
};

} // namespace RBAC
} // namespace Common
} // namespace Filters
} // namespace Extensions
} // namespace Envoy
Loading