mirror of https://github.com/grpc/grpc.git
commit
7aadac509c
58 changed files with 1174 additions and 255 deletions
@ -0,0 +1,142 @@ |
|||||||
|
//
|
||||||
|
// Copyright 2020 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
// This filter reads GRPC_ARG_SERVICE_CONFIG and populates ServiceConfigCallData
|
||||||
|
// in the call context per call for direct channels.
|
||||||
|
|
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include "src/core/ext/filters/client_channel/service_config_call_data.h" |
||||||
|
#include "src/core/lib/channel/channel_args.h" |
||||||
|
#include "src/core/lib/channel/channel_stack.h" |
||||||
|
#include "src/core/lib/channel/channel_stack_builder.h" |
||||||
|
#include "src/core/lib/surface/channel_init.h" |
||||||
|
|
||||||
|
namespace grpc_core { |
||||||
|
|
||||||
|
namespace { |
||||||
|
|
||||||
|
class ServiceConfigChannelArgChannelData { |
||||||
|
public: |
||||||
|
explicit ServiceConfigChannelArgChannelData( |
||||||
|
const grpc_channel_element_args* args) { |
||||||
|
const char* service_config_str = grpc_channel_args_find_string( |
||||||
|
args->channel_args, GRPC_ARG_SERVICE_CONFIG); |
||||||
|
if (service_config_str != nullptr) { |
||||||
|
grpc_error* service_config_error = GRPC_ERROR_NONE; |
||||||
|
auto service_config = |
||||||
|
ServiceConfig::Create(service_config_str, &service_config_error); |
||||||
|
if (service_config_error == GRPC_ERROR_NONE) { |
||||||
|
service_config_ = std::move(service_config); |
||||||
|
} else { |
||||||
|
gpr_log(GPR_ERROR, "%s", grpc_error_string(service_config_error)); |
||||||
|
} |
||||||
|
GRPC_ERROR_UNREF(service_config_error); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
RefCountedPtr<ServiceConfig> service_config() const { |
||||||
|
return service_config_; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
RefCountedPtr<ServiceConfig> service_config_; |
||||||
|
}; |
||||||
|
|
||||||
|
class ServiceConfigChannelArgCallData { |
||||||
|
public: |
||||||
|
ServiceConfigChannelArgCallData(grpc_call_element* elem, |
||||||
|
const grpc_call_element_args* args) { |
||||||
|
ServiceConfigChannelArgChannelData* chand = |
||||||
|
static_cast<ServiceConfigChannelArgChannelData*>(elem->channel_data); |
||||||
|
RefCountedPtr<ServiceConfig> service_config = chand->service_config(); |
||||||
|
if (service_config != nullptr) { |
||||||
|
GPR_DEBUG_ASSERT(args->context != nullptr); |
||||||
|
const auto* method_params_vector = |
||||||
|
service_config->GetMethodParsedConfigVector(args->path); |
||||||
|
args->arena->New<ServiceConfigCallData>( |
||||||
|
std::move(service_config), method_params_vector, args->context); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
grpc_error* ServiceConfigChannelArgInitCallElem( |
||||||
|
grpc_call_element* elem, const grpc_call_element_args* args) { |
||||||
|
ServiceConfigChannelArgCallData* calld = |
||||||
|
static_cast<ServiceConfigChannelArgCallData*>(elem->call_data); |
||||||
|
new (calld) ServiceConfigChannelArgCallData(elem, args); |
||||||
|
return GRPC_ERROR_NONE; |
||||||
|
} |
||||||
|
|
||||||
|
void ServiceConfigChannelArgDestroyCallElem( |
||||||
|
grpc_call_element* elem, const grpc_call_final_info* /* final_info */, |
||||||
|
grpc_closure* /* then_schedule_closure */) { |
||||||
|
ServiceConfigChannelArgCallData* calld = |
||||||
|
static_cast<ServiceConfigChannelArgCallData*>(elem->call_data); |
||||||
|
calld->~ServiceConfigChannelArgCallData(); |
||||||
|
} |
||||||
|
|
||||||
|
grpc_error* ServiceConfigChannelArgInitChannelElem( |
||||||
|
grpc_channel_element* elem, grpc_channel_element_args* args) { |
||||||
|
ServiceConfigChannelArgChannelData* chand = |
||||||
|
static_cast<ServiceConfigChannelArgChannelData*>(elem->channel_data); |
||||||
|
new (chand) ServiceConfigChannelArgChannelData(args); |
||||||
|
return GRPC_ERROR_NONE; |
||||||
|
} |
||||||
|
|
||||||
|
void ServiceConfigChannelArgDestroyChannelElem(grpc_channel_element* elem) { |
||||||
|
ServiceConfigChannelArgChannelData* chand = |
||||||
|
static_cast<ServiceConfigChannelArgChannelData*>(elem->channel_data); |
||||||
|
chand->~ServiceConfigChannelArgChannelData(); |
||||||
|
} |
||||||
|
|
||||||
|
const grpc_channel_filter ServiceConfigChannelArgFilter = { |
||||||
|
grpc_call_next_op, |
||||||
|
grpc_channel_next_op, |
||||||
|
sizeof(ServiceConfigChannelArgCallData), |
||||||
|
ServiceConfigChannelArgInitCallElem, |
||||||
|
grpc_call_stack_ignore_set_pollset_or_pollset_set, |
||||||
|
ServiceConfigChannelArgDestroyCallElem, |
||||||
|
sizeof(ServiceConfigChannelArgChannelData), |
||||||
|
ServiceConfigChannelArgInitChannelElem, |
||||||
|
ServiceConfigChannelArgDestroyChannelElem, |
||||||
|
grpc_channel_next_get_info, |
||||||
|
"service_config_channel_arg"}; |
||||||
|
|
||||||
|
bool maybe_add_service_config_channel_arg_filter( |
||||||
|
grpc_channel_stack_builder* builder, void* /* arg */) { |
||||||
|
const grpc_channel_args* channel_args = |
||||||
|
grpc_channel_stack_builder_get_channel_arguments(builder); |
||||||
|
if (grpc_channel_args_want_minimal_stack(channel_args) || |
||||||
|
grpc_channel_args_find_string(channel_args, GRPC_ARG_SERVICE_CONFIG) == |
||||||
|
nullptr) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return grpc_channel_stack_builder_prepend_filter( |
||||||
|
builder, &ServiceConfigChannelArgFilter, nullptr, nullptr); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
} // namespace grpc_core
|
||||||
|
|
||||||
|
void grpc_service_config_channel_arg_filter_init(void) { |
||||||
|
grpc_channel_init_register_stage( |
||||||
|
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, |
||||||
|
grpc_core::maybe_add_service_config_channel_arg_filter, nullptr); |
||||||
|
} |
||||||
|
|
||||||
|
void grpc_service_config_channel_arg_filter_shutdown(void) {} |
@ -0,0 +1,153 @@ |
|||||||
|
#!/usr/bin/env ruby |
||||||
|
# |
||||||
|
# Copyright 2016 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. |
||||||
|
|
||||||
|
this_dir = File.expand_path(File.dirname(__FILE__)) |
||||||
|
protos_lib_dir = File.join(this_dir, 'lib') |
||||||
|
grpc_lib_dir = File.join(File.dirname(this_dir), 'lib') |
||||||
|
$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir) |
||||||
|
$LOAD_PATH.unshift(protos_lib_dir) unless $LOAD_PATH.include?(protos_lib_dir) |
||||||
|
$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) |
||||||
|
|
||||||
|
require 'grpc' |
||||||
|
require 'end2end_common' |
||||||
|
|
||||||
|
def create_channel_creds |
||||||
|
test_root = File.join(File.dirname(__FILE__), '..', 'spec', 'testdata') |
||||||
|
files = ['ca.pem', 'client.key', 'client.pem'] |
||||||
|
creds = files.map { |f| File.open(File.join(test_root, f)).read } |
||||||
|
GRPC::Core::ChannelCredentials.new(creds[0], creds[1], creds[2]) |
||||||
|
end |
||||||
|
|
||||||
|
def client_cert |
||||||
|
test_root = File.join(File.dirname(__FILE__), '..', 'spec', 'testdata') |
||||||
|
cert = File.open(File.join(test_root, 'client.pem')).read |
||||||
|
fail unless cert.is_a?(String) |
||||||
|
cert |
||||||
|
end |
||||||
|
|
||||||
|
def create_server_creds |
||||||
|
test_root = File.join(File.dirname(__FILE__), '..', 'spec', 'testdata') |
||||||
|
GRPC.logger.info("test root: #{test_root}") |
||||||
|
files = ['ca.pem', 'server1.key', 'server1.pem'] |
||||||
|
creds = files.map { |f| File.open(File.join(test_root, f)).read } |
||||||
|
GRPC::Core::ServerCredentials.new( |
||||||
|
creds[0], |
||||||
|
[{ private_key: creds[1], cert_chain: creds[2] }], |
||||||
|
true) # force client auth |
||||||
|
end |
||||||
|
|
||||||
|
# Useful to update a value within a do block |
||||||
|
class MutableValue |
||||||
|
attr_accessor :value |
||||||
|
|
||||||
|
def initialize(value) |
||||||
|
@value = value |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize |
||||||
|
# rubocop:disable Metrics/MethodLength |
||||||
|
def main |
||||||
|
server_runner = ServerRunner.new(EchoServerImpl) |
||||||
|
server_runner.server_creds = create_server_creds |
||||||
|
server_port = server_runner.run |
||||||
|
channel_args = { |
||||||
|
GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr' |
||||||
|
} |
||||||
|
token_fetch_attempts = MutableValue.new(0) |
||||||
|
token_fetch_attempts_mu = Mutex.new |
||||||
|
jwt_aud_uri_extraction_success_count = MutableValue.new(0) |
||||||
|
jwt_aud_uri_extraction_success_count_mu = Mutex.new |
||||||
|
expected_jwt_aud_uri = 'https://foo.test.google.fr/echo.EchoServer' |
||||||
|
jwt_aud_uri_failure_values = [] |
||||||
|
times_out_first_time_auth_proc = proc do |args| |
||||||
|
# We check the value of jwt_aud_uri not necessarily as a test for |
||||||
|
# the correctness of jwt_aud_uri w.r.t. its expected semantics, but |
||||||
|
# more for as an indirect way to check for memory corruption. |
||||||
|
jwt_aud_uri_extraction_success_count_mu.synchronize do |
||||||
|
if args[:jwt_aud_uri] == expected_jwt_aud_uri |
||||||
|
jwt_aud_uri_extraction_success_count.value += 1 |
||||||
|
else |
||||||
|
jwt_aud_uri_failure_values << args[:jwt_aud_uri] |
||||||
|
end |
||||||
|
end |
||||||
|
token_fetch_attempts_mu.synchronize do |
||||||
|
old_val = token_fetch_attempts.value |
||||||
|
token_fetch_attempts.value += 1 |
||||||
|
if old_val.zero? |
||||||
|
STDERR.puts 'call creds plugin sleeping for 4 seconds' |
||||||
|
sleep 4 |
||||||
|
STDERR.puts 'call creds plugin done with 4 second sleep' |
||||||
|
raise 'test exception thrown purposely from call creds plugin' |
||||||
|
end |
||||||
|
end |
||||||
|
{ 'authorization' => 'fake_val' }.merge(args) |
||||||
|
end |
||||||
|
channel_creds = create_channel_creds.compose( |
||||||
|
GRPC::Core::CallCredentials.new(times_out_first_time_auth_proc)) |
||||||
|
stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", |
||||||
|
channel_creds, |
||||||
|
channel_args: channel_args) |
||||||
|
STDERR.puts 'perform a first few RPCs to try to get things into a bad state...' |
||||||
|
threads = [] |
||||||
|
got_at_least_one_failure = MutableValue.new(false) |
||||||
|
2000.times do |
||||||
|
threads << Thread.new do |
||||||
|
begin |
||||||
|
# 2 seconds is chosen as deadline here because it is less than the 4 second |
||||||
|
# sleep that the first call creds user callback does. The idea here is that |
||||||
|
# a lot of RPCs will be made concurrently all with 2 second deadlines, and they |
||||||
|
# will all queue up onto the call creds user callback thread, and will all |
||||||
|
# have to wait for the first 4 second sleep to finish. When the deadlines |
||||||
|
# of the associated calls fire ~2 seconds in, some of their C-core data |
||||||
|
# will have ownership dropped, and they will hit the user-after-free in |
||||||
|
# https://github.com/grpc/grpc/issues/19195 if this isn't handled correctly. |
||||||
|
stub.echo(Echo::EchoRequest.new(request: 'hello'), deadline: Time.now + 2) |
||||||
|
rescue GRPC::BadStatus |
||||||
|
got_at_least_one_failure.value = true |
||||||
|
# We don't care if these RPCs succeed or fail. The purpose of these |
||||||
|
# RPCs is just to try to induce a specific use-after-free bug, and to get |
||||||
|
# the call credentials callback thread into a bad state. |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
threads.each(&:join) |
||||||
|
unless got_at_least_one_failure.value |
||||||
|
fail 'expected at least one of the initial RPCs to fail' |
||||||
|
end |
||||||
|
# Expect three more RPCs to succeed |
||||||
|
STDERR.puts 'now perform another RPC and expect OK...' |
||||||
|
stub.echo(Echo::EchoRequest.new(request: 'hello'), deadline: Time.now + 10) |
||||||
|
STDERR.puts 'now perform another RPC and expect OK...' |
||||||
|
stub.echo(Echo::EchoRequest.new(request: 'hello'), deadline: Time.now + 10) |
||||||
|
STDERR.puts 'now perform another RPC and expect OK...' |
||||||
|
stub.echo(Echo::EchoRequest.new(request: 'hello'), deadline: Time.now + 10) |
||||||
|
jwt_aud_uri_extraction_success_count_mu.synchronize do |
||||||
|
if jwt_aud_uri_extraction_success_count.value != 2003 |
||||||
|
fail "Expected to get jwt_aud_uri:#{expected_jwt_aud_uri} passed to call creds |
||||||
|
user callback 2003 times, but it was only passed to the call creds user callback |
||||||
|
#{jwt_aud_uri_extraction_success_count.value} times. This suggests that either: |
||||||
|
a) the expected jwt_aud_uri value is incorrect |
||||||
|
b) there is some corruption of the jwt_aud_uri argument |
||||||
|
Here are are the values of the jwt_aud_uri parameter that were passed to the call |
||||||
|
creds user callback that did not match #{expected_jwt_aud_uri}: |
||||||
|
#{jwt_aud_uri_failure_values}" |
||||||
|
end |
||||||
|
end |
||||||
|
server_runner.stop |
||||||
|
end |
||||||
|
|
||||||
|
main |
@ -0,0 +1,38 @@ |
|||||||
|
#!/bin/bash |
||||||
|
# Copyright 2020 The 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. |
||||||
|
|
||||||
|
echo "It's recommended that you run this script from a virtual environment." |
||||||
|
|
||||||
|
set -e |
||||||
|
|
||||||
|
BASEDIR=$(dirname "$0") |
||||||
|
BASEDIR=$(realpath "$BASEDIR")/../.. |
||||||
|
|
||||||
|
(cd "$BASEDIR"; |
||||||
|
pip install --upgrade cython; |
||||||
|
python setup.py install; |
||||||
|
pushd tools/distrib/python/grpcio_tools; |
||||||
|
../make_grpcio_tools.py |
||||||
|
GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install . |
||||||
|
popd; |
||||||
|
pushd src/python; |
||||||
|
for PACKAGE in ./grpcio_*; do |
||||||
|
pushd "${PACKAGE}"; |
||||||
|
python setup.py preprocess; |
||||||
|
python setup.py install; |
||||||
|
popd; |
||||||
|
done |
||||||
|
popd; |
||||||
|
) |
@ -0,0 +1,30 @@ |
|||||||
|
# Copyright 2020 The 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. |
||||||
|
|
||||||
|
# Docker file for building gRPC manylinux Python artifacts. |
||||||
|
# Updated: 2020-06-25 |
||||||
|
|
||||||
|
FROM quay.io/pypa/manylinux2014_x86_64 |
||||||
|
|
||||||
|
# Update the package manager |
||||||
|
RUN yum update -y |
||||||
|
RUN yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel |
||||||
|
|
||||||
|
################################### |
||||||
|
# Install Python build requirements |
||||||
|
RUN /opt/python/cp35-cp35m/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp36-cp36m/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp37-cp37m/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp38-cp38/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp39-cp39/bin/pip install --upgrade cython |
@ -0,0 +1,30 @@ |
|||||||
|
# Copyright 2020 The 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. |
||||||
|
|
||||||
|
# Docker file for building gRPC manylinux Python artifacts. |
||||||
|
# Updated: 2020-06-25 |
||||||
|
|
||||||
|
FROM quay.io/pypa/manylinux2014_i686 |
||||||
|
|
||||||
|
# Update the package manager |
||||||
|
RUN yum update -y |
||||||
|
RUN yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel |
||||||
|
|
||||||
|
################################### |
||||||
|
# Install Python build requirements |
||||||
|
RUN /opt/python/cp35-cp35m/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp36-cp36m/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp37-cp37m/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp38-cp38/bin/pip install --upgrade cython |
||||||
|
RUN /opt/python/cp39-cp39/bin/pip install --upgrade cython |
Loading…
Reference in new issue