Skip to content
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

[Audit Logging] Xds Audit Logger Registry. #32828

Merged
merged 29 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3f49062
Create the structure of the xDS audit logger registry.
rockspore Apr 6, 2023
d67fa5f
newlines
rockspore Apr 6, 2023
4ffc396
newline again
rockspore Apr 6, 2023
d302af3
generate projects
rockspore Apr 6, 2023
2fbdced
add stdout logger factory
rockspore Apr 6, 2023
34c5c8d
fix includes
rockspore Apr 6, 2023
e7f4471
iwyu
rockspore Apr 6, 2023
33c569a
iwyu again
rockspore Apr 7, 2023
54ec1b9
fix header
rockspore Apr 7, 2023
0960d97
add port_platform header
rockspore Apr 7, 2023
8a29aec
Merge branch 'master' of https://github.com/grpc/grpc into xds-audit-…
rockspore Apr 7, 2023
2d00e8d
IWYU pragma
rockspore Apr 10, 2023
682c68f
add parsing in http rbac and test
rockspore Apr 10, 2023
01ce316
Merge branch 'master' of https://github.com/grpc/grpc into xds-audit-…
rockspore Apr 10, 2023
87d69b9
pull upstream to fix errors.status() call
rockspore Apr 10, 2023
c312c64
iwyu for http rbac
rockspore Apr 10, 2023
f5312ba
clang tidy
rockspore Apr 11, 2023
86a3c88
copy stream.proto into testing/
rockspore Apr 14, 2023
5fe48fa
generate projects
rockspore Apr 14, 2023
51fb0ca
IWYU pragma
rockspore Apr 14, 2023
6967b16
IWYU pragma
rockspore Apr 14, 2023
f275f0b
trailing newline
rockspore Apr 14, 2023
21bf892
comments
rockspore Apr 20, 2023
259eb25
Merge branch 'master' of github.com:grpc/grpc into xds-audit-registry
rockspore Apr 20, 2023
f17c235
new upb header
rockspore Apr 20, 2023
bb5ff41
iwyu
rockspore Apr 21, 2023
d17a2b6
address comments
rockspore Apr 24, 2023
08aa62d
remove rbac header
rockspore Apr 24, 2023
537be0d
add back rbac header
rockspore Apr 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 104 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.w32

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gRPC-C++.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions gRPC-Core.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions grpc.gemspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions grpc.gyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,7 @@ grpc_cc_library(
srcs = [
"ext/xds/certificate_provider_store.cc",
"ext/xds/file_watcher_certificate_provider_factory.cc",
"ext/xds/xds_audit_logger_registry.cc",
"ext/xds/xds_bootstrap_grpc.cc",
"ext/xds/xds_certificate_provider.cc",
"ext/xds/xds_client_grpc.cc",
Expand All @@ -3880,6 +3881,7 @@ grpc_cc_library(
hdrs = [
"ext/xds/certificate_provider_store.h",
"ext/xds/file_watcher_certificate_provider_factory.h",
"ext/xds/xds_audit_logger_registry.h",
"ext/xds/xds_bootstrap_grpc.h",
"ext/xds/xds_certificate_provider.h",
"ext/xds/xds_client_grpc.h",
Expand Down
100 changes: 100 additions & 0 deletions src/core/ext/xds/xds_audit_logger_registry.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <grpc/support/port_platform.h>

#include "src/core/ext/xds/xds_audit_logger_registry.h"

#include <utility>

#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "absl/types/variant.h"
#include "envoy/config/core/v3/extension.upb.h"
#include "envoy/config/rbac/v3/rbac.upb.h"

#include "src/core/ext/xds/xds_common_types.h"
#include "src/core/lib/gprpp/validation_errors.h"
#include "src/core/lib/json/json.h"

namespace grpc_core {

namespace {

class StdoutLoggerConfigFactory : public XdsAuditLoggerRegistry::ConfigFactory {
public:
Json::Object ConvertXdsAuditLoggerConfig(
const XdsResourceType::DecodeContext& /*context*/,
absl::string_view /*configuration*/,
ValidationErrors* /*errors*/) override {
return Json::Object{{"stdout_logger", Json::Object()}};
}

absl::string_view type() override { return Type(); }

static absl::string_view Type() {
return "envoy.extensions.rbac.audit_loggers.stream.v3.StdoutAuditLog";
}
};

} // namespace

XdsAuditLoggerRegistry::XdsAuditLoggerRegistry() {
audit_logger_config_factories_.emplace(
StdoutLoggerConfigFactory::Type(),
std::make_unique<StdoutLoggerConfigFactory>());
}

Json XdsAuditLoggerRegistry::ConvertXdsAuditLoggerConfig(
const XdsResourceType::DecodeContext& context,
const envoy_config_rbac_v3_RBAC_AuditLoggingOptions_AuditLoggerConfig*
logger_config,
ValidationErrors* errors) const {
const auto* typed_extension_config =
envoy_config_rbac_v3_RBAC_AuditLoggingOptions_AuditLoggerConfig_audit_logger(
logger_config);
// It is okay if this is not present.
markdroth marked this conversation as resolved.
Show resolved Hide resolved
if (typed_extension_config == nullptr) {
return Json(); // A null Json object.
} else {
ValidationErrors::ScopedField field(errors,
".typed_extension_config.typed_config");
markdroth marked this conversation as resolved.
Show resolved Hide resolved
const auto* typed_config =
envoy_config_core_v3_TypedExtensionConfig_typed_config(
typed_extension_config);
auto extension = ExtractXdsExtension(context, typed_config, errors);
if (!extension.has_value()) return Json();
// Check for registered audit logger type.
absl::string_view* serialized_value =
absl::get_if<absl::string_view>(&extension->value);
if (serialized_value != nullptr) {
auto config_factory_it =
audit_logger_config_factories_.find(extension->type);
if (config_factory_it != audit_logger_config_factories_.end()) {
gtcooke94 marked this conversation as resolved.
Show resolved Hide resolved
return config_factory_it->second->ConvertXdsAuditLoggerConfig(
markdroth marked this conversation as resolved.
Show resolved Hide resolved
context, *serialized_value, errors);
}
}
}
markdroth marked this conversation as resolved.
Show resolved Hide resolved
// TODO(lwge): Check for third-party audit logger type.
markdroth marked this conversation as resolved.
Show resolved Hide resolved
// Add validation error only if the config is not marked optional.
if (!envoy_config_rbac_v3_RBAC_AuditLoggingOptions_AuditLoggerConfig_is_optional(
logger_config)) {
errors->AddError("unsupported audit logger type");
}
return Json();
}
} // namespace grpc_core