grpc 1.17.1 → 1.18.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +1228 -988
- data/etc/roots.pem +242 -30
- data/include/grpc/grpc.h +2 -1
- data/include/grpc/grpc_security_constants.h +3 -3
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +2 -0
- data/include/grpc/impl/codegen/compression_types.h +2 -1
- data/include/grpc/impl/codegen/grpc_types.h +1 -1
- data/include/grpc/impl/codegen/port_platform.h +9 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
- data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
- data/src/core/ext/filters/client_channel/request_routing.h +177 -0
- data/src/core/ext/filters/client_channel/resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
- data/src/core/ext/filters/client_channel/server_address.cc +103 -0
- data/src/core/ext/filters/client_channel/server_address.h +108 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
- data/src/core/ext/filters/client_channel/subchannel.h +9 -6
- data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
- data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
- data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +19 -18
- data/src/core/lib/channel/channelz.h +7 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -2
- data/src/core/lib/debug/trace.cc +3 -0
- data/src/core/lib/debug/trace.h +5 -3
- data/src/core/lib/gpr/sync_posix.cc +96 -4
- data/src/core/lib/gprpp/inlined_vector.h +25 -19
- data/src/core/lib/gprpp/memory.h +2 -11
- data/src/core/lib/gprpp/orphanable.h +18 -82
- data/src/core/lib/gprpp/ref_counted.h +75 -84
- data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
- data/src/core/lib/http/httpcli_security_connector.cc +101 -94
- data/src/core/lib/http/parser.h +5 -5
- data/src/core/lib/iomgr/buffer_list.cc +16 -5
- data/src/core/lib/iomgr/buffer_list.h +10 -3
- data/src/core/lib/iomgr/call_combiner.cc +50 -2
- data/src/core/lib/iomgr/call_combiner.h +29 -2
- data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +3 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +15 -7
- data/src/core/lib/iomgr/ev_posix.h +10 -0
- data/src/core/lib/iomgr/exec_ctx.cc +13 -0
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
- data/src/core/lib/iomgr/internal_errqueue.h +7 -1
- data/src/core/lib/iomgr/iomgr.cc +7 -0
- data/src/core/lib/iomgr/iomgr.h +4 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
- data/src/core/lib/iomgr/port.h +1 -2
- data/src/core/lib/iomgr/resource_quota.cc +1 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +95 -35
- data/src/core/lib/iomgr/tcp_windows.cc +4 -1
- data/src/core/lib/iomgr/timer_manager.cc +6 -0
- data/src/core/lib/security/context/security_context.cc +75 -108
- data/src/core/lib/security/context/security_context.h +59 -35
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
- data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
- data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
- data/src/core/lib/security/credentials/credentials.cc +18 -142
- data/src/core/lib/security/credentials/credentials.h +119 -95
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
- data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
- data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
- data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
- data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
- data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
- data/src/core/lib/security/security_connector/security_connector.cc +41 -124
- data/src/core/lib/security/security_connector/security_connector.h +102 -105
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
- data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
- data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/transport/security_handshaker.cc +82 -66
- data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +13 -11
- data/src/core/lib/surface/server.h +6 -6
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +1 -0
- data/src/core/lib/transport/static_metadata.cc +228 -221
- data/src/core/lib/transport/static_metadata.h +75 -71
- data/src/core/lib/transport/transport.cc +2 -1
- data/src/core/lib/transport/transport.h +5 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
- data/src/core/tsi/ssl_transport_security.cc +35 -24
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
- data/src/ruby/lib/grpc/generic/service.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +2 -3
- data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
- data/src/ruby/spec/support/services.rb +1 -0
- metadata +37 -32
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -21,6 +21,7 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
24
25
|
#include "src/core/lib/security/credentials/credentials.h"
|
25
26
|
|
26
27
|
#define GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY "gcloud"
|
@@ -39,11 +40,33 @@
|
|
39
40
|
"/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE
|
40
41
|
#endif
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
class grpc_google_default_channel_credentials
|
44
|
+
: public grpc_channel_credentials {
|
45
|
+
public:
|
46
|
+
grpc_google_default_channel_credentials(
|
47
|
+
grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds,
|
48
|
+
grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds)
|
49
|
+
: grpc_channel_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_GOOGLE_DEFAULT),
|
50
|
+
alts_creds_(std::move(alts_creds)),
|
51
|
+
ssl_creds_(std::move(ssl_creds)) {}
|
52
|
+
|
53
|
+
~grpc_google_default_channel_credentials() override = default;
|
54
|
+
|
55
|
+
grpc_core::RefCountedPtr<grpc_channel_security_connector>
|
56
|
+
create_security_connector(
|
57
|
+
grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
|
58
|
+
const char* target, const grpc_channel_args* args,
|
59
|
+
grpc_channel_args** new_args) override;
|
60
|
+
|
61
|
+
const grpc_channel_credentials* alts_creds() const {
|
62
|
+
return alts_creds_.get();
|
63
|
+
}
|
64
|
+
const grpc_channel_credentials* ssl_creds() const { return ssl_creds_.get(); }
|
65
|
+
|
66
|
+
private:
|
67
|
+
grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds_;
|
68
|
+
grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds_;
|
69
|
+
};
|
47
70
|
|
48
71
|
namespace grpc_core {
|
49
72
|
namespace internal {
|
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
#include <string.h>
|
24
24
|
|
25
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
25
26
|
#include "src/core/lib/surface/api_trace.h"
|
26
27
|
|
27
28
|
#include <grpc/support/alloc.h>
|
@@ -29,32 +30,37 @@
|
|
29
30
|
#include <grpc/support/string_util.h>
|
30
31
|
#include <grpc/support/sync.h>
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
reinterpret_cast<grpc_google_iam_credentials*>(creds);
|
35
|
-
grpc_credentials_mdelem_array_destroy(&c->md_array);
|
33
|
+
grpc_google_iam_credentials::~grpc_google_iam_credentials() {
|
34
|
+
grpc_credentials_mdelem_array_destroy(&md_array_);
|
36
35
|
}
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
grpc_error** error) {
|
44
|
-
grpc_google_iam_credentials* c =
|
45
|
-
reinterpret_cast<grpc_google_iam_credentials*>(creds);
|
46
|
-
grpc_credentials_mdelem_array_append(md_array, &c->md_array);
|
37
|
+
bool grpc_google_iam_credentials::get_request_metadata(
|
38
|
+
grpc_polling_entity* pollent, grpc_auth_metadata_context context,
|
39
|
+
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
|
40
|
+
grpc_error** error) {
|
41
|
+
grpc_credentials_mdelem_array_append(md_array, &md_array_);
|
47
42
|
return true;
|
48
43
|
}
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
grpc_error* error) {
|
45
|
+
void grpc_google_iam_credentials::cancel_get_request_metadata(
|
46
|
+
grpc_credentials_mdelem_array* md_array, grpc_error* error) {
|
53
47
|
GRPC_ERROR_UNREF(error);
|
54
48
|
}
|
55
49
|
|
56
|
-
|
57
|
-
|
50
|
+
grpc_google_iam_credentials::grpc_google_iam_credentials(
|
51
|
+
const char* token, const char* authority_selector)
|
52
|
+
: grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_IAM) {
|
53
|
+
grpc_mdelem md = grpc_mdelem_from_slices(
|
54
|
+
grpc_slice_from_static_string(GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY),
|
55
|
+
grpc_slice_from_copied_string(token));
|
56
|
+
grpc_credentials_mdelem_array_add(&md_array_, md);
|
57
|
+
GRPC_MDELEM_UNREF(md);
|
58
|
+
md = grpc_mdelem_from_slices(
|
59
|
+
grpc_slice_from_static_string(GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY),
|
60
|
+
grpc_slice_from_copied_string(authority_selector));
|
61
|
+
grpc_credentials_mdelem_array_add(&md_array_, md);
|
62
|
+
GRPC_MDELEM_UNREF(md);
|
63
|
+
}
|
58
64
|
|
59
65
|
grpc_call_credentials* grpc_google_iam_credentials_create(
|
60
66
|
const char* token, const char* authority_selector, void* reserved) {
|
@@ -66,21 +72,7 @@ grpc_call_credentials* grpc_google_iam_credentials_create(
|
|
66
72
|
GPR_ASSERT(reserved == nullptr);
|
67
73
|
GPR_ASSERT(token != nullptr);
|
68
74
|
GPR_ASSERT(authority_selector != nullptr);
|
69
|
-
grpc_google_iam_credentials
|
70
|
-
|
71
|
-
|
72
|
-
c->base.vtable = &iam_vtable;
|
73
|
-
gpr_ref_init(&c->base.refcount, 1);
|
74
|
-
grpc_mdelem md = grpc_mdelem_from_slices(
|
75
|
-
grpc_slice_from_static_string(GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY),
|
76
|
-
grpc_slice_from_copied_string(token));
|
77
|
-
grpc_credentials_mdelem_array_add(&c->md_array, md);
|
78
|
-
GRPC_MDELEM_UNREF(md);
|
79
|
-
md = grpc_mdelem_from_slices(
|
80
|
-
grpc_slice_from_static_string(GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY),
|
81
|
-
grpc_slice_from_copied_string(authority_selector));
|
82
|
-
grpc_credentials_mdelem_array_add(&c->md_array, md);
|
83
|
-
GRPC_MDELEM_UNREF(md);
|
84
|
-
|
85
|
-
return &c->base;
|
75
|
+
return grpc_core::MakeRefCounted<grpc_google_iam_credentials>(
|
76
|
+
token, authority_selector)
|
77
|
+
.release();
|
86
78
|
}
|
@@ -23,9 +23,23 @@
|
|
23
23
|
|
24
24
|
#include "src/core/lib/security/credentials/credentials.h"
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
class grpc_google_iam_credentials : public grpc_call_credentials {
|
27
|
+
public:
|
28
|
+
grpc_google_iam_credentials(const char* token,
|
29
|
+
const char* authority_selector);
|
30
|
+
~grpc_google_iam_credentials() override;
|
31
|
+
|
32
|
+
bool get_request_metadata(grpc_polling_entity* pollent,
|
33
|
+
grpc_auth_metadata_context context,
|
34
|
+
grpc_credentials_mdelem_array* md_array,
|
35
|
+
grpc_closure* on_request_metadata,
|
36
|
+
grpc_error** error) override;
|
37
|
+
|
38
|
+
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
|
39
|
+
grpc_error* error) override;
|
40
|
+
|
41
|
+
private:
|
42
|
+
grpc_credentials_mdelem_array md_array_;
|
43
|
+
};
|
30
44
|
|
31
45
|
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_IAM_IAM_CREDENTIALS_H */
|
@@ -23,6 +23,8 @@
|
|
23
23
|
#include <inttypes.h>
|
24
24
|
#include <string.h>
|
25
25
|
|
26
|
+
#include "src/core/lib/gprpp/ref_counted.h"
|
27
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
26
28
|
#include "src/core/lib/surface/api_trace.h"
|
27
29
|
|
28
30
|
#include <grpc/support/alloc.h>
|
@@ -30,71 +32,66 @@
|
|
30
32
|
#include <grpc/support/string_util.h>
|
31
33
|
#include <grpc/support/sync.h>
|
32
34
|
|
33
|
-
|
34
|
-
GRPC_MDELEM_UNREF(
|
35
|
-
|
36
|
-
if (
|
37
|
-
gpr_free(
|
38
|
-
|
35
|
+
void grpc_service_account_jwt_access_credentials::reset_cache() {
|
36
|
+
GRPC_MDELEM_UNREF(cached_.jwt_md);
|
37
|
+
cached_.jwt_md = GRPC_MDNULL;
|
38
|
+
if (cached_.service_url != nullptr) {
|
39
|
+
gpr_free(cached_.service_url);
|
40
|
+
cached_.service_url = nullptr;
|
39
41
|
}
|
40
|
-
|
42
|
+
cached_.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME);
|
41
43
|
}
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
gpr_mu_destroy(&c->cache_mu);
|
45
|
+
grpc_service_account_jwt_access_credentials::
|
46
|
+
~grpc_service_account_jwt_access_credentials() {
|
47
|
+
grpc_auth_json_key_destruct(&key_);
|
48
|
+
reset_cache();
|
49
|
+
gpr_mu_destroy(&cache_mu_);
|
49
50
|
}
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
grpc_closure* on_request_metadata,
|
56
|
-
grpc_error** error) {
|
57
|
-
grpc_service_account_jwt_access_credentials* c =
|
58
|
-
reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
|
52
|
+
bool grpc_service_account_jwt_access_credentials::get_request_metadata(
|
53
|
+
grpc_polling_entity* pollent, grpc_auth_metadata_context context,
|
54
|
+
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
|
55
|
+
grpc_error** error) {
|
59
56
|
gpr_timespec refresh_threshold = gpr_time_from_seconds(
|
60
57
|
GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN);
|
61
58
|
|
62
59
|
/* See if we can return a cached jwt. */
|
63
60
|
grpc_mdelem jwt_md = GRPC_MDNULL;
|
64
61
|
{
|
65
|
-
gpr_mu_lock(&
|
66
|
-
if (
|
67
|
-
strcmp(
|
68
|
-
!GRPC_MDISNULL(
|
69
|
-
(gpr_time_cmp(
|
70
|
-
|
71
|
-
|
72
|
-
jwt_md = GRPC_MDELEM_REF(
|
62
|
+
gpr_mu_lock(&cache_mu_);
|
63
|
+
if (cached_.service_url != nullptr &&
|
64
|
+
strcmp(cached_.service_url, context.service_url) == 0 &&
|
65
|
+
!GRPC_MDISNULL(cached_.jwt_md) &&
|
66
|
+
(gpr_time_cmp(
|
67
|
+
gpr_time_sub(cached_.jwt_expiration, gpr_now(GPR_CLOCK_REALTIME)),
|
68
|
+
refresh_threshold) > 0)) {
|
69
|
+
jwt_md = GRPC_MDELEM_REF(cached_.jwt_md);
|
73
70
|
}
|
74
|
-
gpr_mu_unlock(&
|
71
|
+
gpr_mu_unlock(&cache_mu_);
|
75
72
|
}
|
76
73
|
|
77
74
|
if (GRPC_MDISNULL(jwt_md)) {
|
78
75
|
char* jwt = nullptr;
|
79
76
|
/* Generate a new jwt. */
|
80
|
-
gpr_mu_lock(&
|
81
|
-
|
82
|
-
jwt = grpc_jwt_encode_and_sign(&
|
83
|
-
|
77
|
+
gpr_mu_lock(&cache_mu_);
|
78
|
+
reset_cache();
|
79
|
+
jwt = grpc_jwt_encode_and_sign(&key_, context.service_url, jwt_lifetime_,
|
80
|
+
nullptr);
|
84
81
|
if (jwt != nullptr) {
|
85
82
|
char* md_value;
|
86
83
|
gpr_asprintf(&md_value, "Bearer %s", jwt);
|
87
84
|
gpr_free(jwt);
|
88
|
-
|
89
|
-
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
|
90
|
-
|
91
|
-
|
85
|
+
cached_.jwt_expiration =
|
86
|
+
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), jwt_lifetime_);
|
87
|
+
cached_.service_url = gpr_strdup(context.service_url);
|
88
|
+
cached_.jwt_md = grpc_mdelem_from_slices(
|
92
89
|
grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
|
93
90
|
grpc_slice_from_copied_string(md_value));
|
94
91
|
gpr_free(md_value);
|
95
|
-
jwt_md = GRPC_MDELEM_REF(
|
92
|
+
jwt_md = GRPC_MDELEM_REF(cached_.jwt_md);
|
96
93
|
}
|
97
|
-
gpr_mu_unlock(&
|
94
|
+
gpr_mu_unlock(&cache_mu_);
|
98
95
|
}
|
99
96
|
|
100
97
|
if (!GRPC_MDISNULL(jwt_md)) {
|
@@ -106,29 +103,15 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds,
|
|
106
103
|
return true;
|
107
104
|
}
|
108
105
|
|
109
|
-
|
110
|
-
|
111
|
-
grpc_error* error) {
|
106
|
+
void grpc_service_account_jwt_access_credentials::cancel_get_request_metadata(
|
107
|
+
grpc_credentials_mdelem_array* md_array, grpc_error* error) {
|
112
108
|
GRPC_ERROR_UNREF(error);
|
113
109
|
}
|
114
110
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
grpc_call_credentials
|
119
|
-
grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
|
120
|
-
grpc_auth_json_key key, gpr_timespec token_lifetime) {
|
121
|
-
grpc_service_account_jwt_access_credentials* c;
|
122
|
-
if (!grpc_auth_json_key_is_valid(&key)) {
|
123
|
-
gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
|
124
|
-
return nullptr;
|
125
|
-
}
|
126
|
-
c = static_cast<grpc_service_account_jwt_access_credentials*>(
|
127
|
-
gpr_zalloc(sizeof(grpc_service_account_jwt_access_credentials)));
|
128
|
-
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_JWT;
|
129
|
-
gpr_ref_init(&c->base.refcount, 1);
|
130
|
-
c->base.vtable = &jwt_vtable;
|
131
|
-
c->key = key;
|
111
|
+
grpc_service_account_jwt_access_credentials::
|
112
|
+
grpc_service_account_jwt_access_credentials(grpc_auth_json_key key,
|
113
|
+
gpr_timespec token_lifetime)
|
114
|
+
: grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_JWT), key_(key) {
|
132
115
|
gpr_timespec max_token_lifetime = grpc_max_auth_token_lifetime();
|
133
116
|
if (gpr_time_cmp(token_lifetime, max_token_lifetime) > 0) {
|
134
117
|
gpr_log(GPR_INFO,
|
@@ -136,10 +119,20 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
|
|
136
119
|
static_cast<int>(max_token_lifetime.tv_sec));
|
137
120
|
token_lifetime = grpc_max_auth_token_lifetime();
|
138
121
|
}
|
139
|
-
|
140
|
-
gpr_mu_init(&
|
141
|
-
|
142
|
-
|
122
|
+
jwt_lifetime_ = token_lifetime;
|
123
|
+
gpr_mu_init(&cache_mu_);
|
124
|
+
reset_cache();
|
125
|
+
}
|
126
|
+
|
127
|
+
grpc_core::RefCountedPtr<grpc_call_credentials>
|
128
|
+
grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
|
129
|
+
grpc_auth_json_key key, gpr_timespec token_lifetime) {
|
130
|
+
if (!grpc_auth_json_key_is_valid(&key)) {
|
131
|
+
gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
|
132
|
+
return nullptr;
|
133
|
+
}
|
134
|
+
return grpc_core::MakeRefCounted<grpc_service_account_jwt_access_credentials>(
|
135
|
+
key, token_lifetime);
|
143
136
|
}
|
144
137
|
|
145
138
|
static char* redact_private_key(const char* json_key) {
|
@@ -182,9 +175,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
|
|
182
175
|
}
|
183
176
|
GPR_ASSERT(reserved == nullptr);
|
184
177
|
grpc_core::ExecCtx exec_ctx;
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
return creds;
|
178
|
+
return grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
|
179
|
+
grpc_auth_json_key_create_from_string(json_key), token_lifetime)
|
180
|
+
.release();
|
190
181
|
}
|
@@ -24,25 +24,44 @@
|
|
24
24
|
#include "src/core/lib/security/credentials/credentials.h"
|
25
25
|
#include "src/core/lib/security/credentials/jwt/json_token.h"
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
class grpc_service_account_jwt_access_credentials
|
28
|
+
: public grpc_call_credentials {
|
29
|
+
public:
|
30
|
+
grpc_service_account_jwt_access_credentials(grpc_auth_json_key key,
|
31
|
+
gpr_timespec token_lifetime);
|
32
|
+
~grpc_service_account_jwt_access_credentials() override;
|
33
|
+
|
34
|
+
bool get_request_metadata(grpc_polling_entity* pollent,
|
35
|
+
grpc_auth_metadata_context context,
|
36
|
+
grpc_credentials_mdelem_array* md_array,
|
37
|
+
grpc_closure* on_request_metadata,
|
38
|
+
grpc_error** error) override;
|
39
|
+
|
40
|
+
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
|
41
|
+
grpc_error* error) override;
|
42
|
+
|
43
|
+
const gpr_timespec& jwt_lifetime() const { return jwt_lifetime_; }
|
44
|
+
const grpc_auth_json_key& key() const { return key_; }
|
45
|
+
|
46
|
+
private:
|
47
|
+
void reset_cache();
|
29
48
|
|
30
49
|
// Have a simple cache for now with just 1 entry. We could have a map based on
|
31
50
|
// the service_url for a more sophisticated one.
|
32
|
-
gpr_mu
|
51
|
+
gpr_mu cache_mu_;
|
33
52
|
struct {
|
34
|
-
grpc_mdelem jwt_md;
|
35
|
-
char* service_url;
|
53
|
+
grpc_mdelem jwt_md = GRPC_MDNULL;
|
54
|
+
char* service_url = nullptr;
|
36
55
|
gpr_timespec jwt_expiration;
|
37
|
-
}
|
56
|
+
} cached_;
|
38
57
|
|
39
|
-
grpc_auth_json_key
|
40
|
-
gpr_timespec
|
41
|
-
}
|
58
|
+
grpc_auth_json_key key_;
|
59
|
+
gpr_timespec jwt_lifetime_;
|
60
|
+
};
|
42
61
|
|
43
62
|
// Private constructor for jwt credentials from an already parsed json key.
|
44
63
|
// Takes ownership of the key.
|
45
|
-
grpc_call_credentials
|
64
|
+
grpc_core::RefCountedPtr<grpc_call_credentials>
|
46
65
|
grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
|
47
66
|
grpc_auth_json_key key, gpr_timespec token_lifetime);
|
48
67
|
|
@@ -29,49 +29,36 @@
|
|
29
29
|
|
30
30
|
#define GRPC_CREDENTIALS_TYPE_LOCAL "Local"
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
static grpc_security_status local_create_security_connector(
|
37
|
-
grpc_channel_credentials* creds,
|
38
|
-
grpc_call_credentials* request_metadata_creds, const char* target_name,
|
39
|
-
const grpc_channel_args* args, grpc_channel_security_connector** sc,
|
32
|
+
grpc_core::RefCountedPtr<grpc_channel_security_connector>
|
33
|
+
grpc_local_credentials::create_security_connector(
|
34
|
+
grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
|
35
|
+
const char* target_name, const grpc_channel_args* args,
|
40
36
|
grpc_channel_args** new_args) {
|
41
37
|
return grpc_local_channel_security_connector_create(
|
42
|
-
|
38
|
+
this->Ref(), std::move(request_metadata_creds), args, target_name);
|
43
39
|
}
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
return grpc_local_server_security_connector_create(
|
41
|
+
grpc_core::RefCountedPtr<grpc_server_security_connector>
|
42
|
+
grpc_local_server_credentials::create_security_connector() {
|
43
|
+
return grpc_local_server_security_connector_create(this->Ref());
|
48
44
|
}
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
static const grpc_server_credentials_vtable local_server_credentials_vtable = {
|
55
|
-
local_server_credentials_destruct, local_server_create_security_connector};
|
46
|
+
grpc_local_credentials::grpc_local_credentials(
|
47
|
+
grpc_local_connect_type connect_type)
|
48
|
+
: grpc_channel_credentials(GRPC_CREDENTIALS_TYPE_LOCAL),
|
49
|
+
connect_type_(connect_type) {}
|
56
50
|
|
57
51
|
grpc_channel_credentials* grpc_local_credentials_create(
|
58
52
|
grpc_local_connect_type connect_type) {
|
59
|
-
|
60
|
-
gpr_zalloc(sizeof(grpc_local_credentials)));
|
61
|
-
creds->connect_type = connect_type;
|
62
|
-
creds->base.type = GRPC_CREDENTIALS_TYPE_LOCAL;
|
63
|
-
creds->base.vtable = &local_credentials_vtable;
|
64
|
-
gpr_ref_init(&creds->base.refcount, 1);
|
65
|
-
return &creds->base;
|
53
|
+
return grpc_core::New<grpc_local_credentials>(connect_type);
|
66
54
|
}
|
67
55
|
|
56
|
+
grpc_local_server_credentials::grpc_local_server_credentials(
|
57
|
+
grpc_local_connect_type connect_type)
|
58
|
+
: grpc_server_credentials(GRPC_CREDENTIALS_TYPE_LOCAL),
|
59
|
+
connect_type_(connect_type) {}
|
60
|
+
|
68
61
|
grpc_server_credentials* grpc_local_server_credentials_create(
|
69
62
|
grpc_local_connect_type connect_type) {
|
70
|
-
|
71
|
-
gpr_zalloc(sizeof(grpc_local_server_credentials)));
|
72
|
-
creds->connect_type = connect_type;
|
73
|
-
creds->base.type = GRPC_CREDENTIALS_TYPE_LOCAL;
|
74
|
-
creds->base.vtable = &local_server_credentials_vtable;
|
75
|
-
gpr_ref_init(&creds->base.refcount, 1);
|
76
|
-
return &creds->base;
|
63
|
+
return grpc_core::New<grpc_local_server_credentials>(connect_type);
|
77
64
|
}
|