Skip to content

Commit 0edb451

Browse files
authored
Conditionally enable AllowHardBoundTokens in gengrpc (#1635)
This PR to conditionally enable AllowHardBoundTokens for three initial services: - SecretManager - Cloudkms - Showcase This change is safe for the following reasons: 1- Mtls Hard Bound Tokens flow requires S2A to be enabled as well for the auth library to even read the AllowHardBoundTokens internaloption as shown in: https://togithub.com/googleapis/google-cloud-go/blob/942c7707bd5119a62a4e7d92803179f6af865eaa/auth/grpctransport/grpctransport.go#L308. Currently, S2A is off by default in the client library and is only enabled internally for selected users. 2- Getting hard bound tokens is guarded behind an experiment in Metadata server. Meaning even if an application has both S2A and AllowHardBoundTokens internal options enabled they need to be allowlisted in the MDS experiment to fetch a hard-bound token. 3- Hard-bound token flow is in audit mode (no enforcement). If an application is using hard-bound tokens and they don't have a policy in place the binding is not enforced.
1 parent b1e8dbd commit 0edb451

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

internal/gengapic/generator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ var enableWrapperTypesForPageSize = map[string]bool{
4141
"google.cloud.bigquery.v2": true,
4242
}
4343

44+
var enableMtlsHardBoundTokens = map[string]bool{
45+
"cloudkms.googleapis.com": true,
46+
"secretmanager.googleapis.com": true,
47+
"showcase.googleapis.com": true,
48+
}
49+
4450
type generator struct {
4551
pt printer.P
4652

internal/gengapic/gengrpc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func (g *generator) grpcClientOptions(serv *descriptorpb.ServiceDescriptorProto,
186186
p(" internaloption.WithDefaultAudience(%q),", generateDefaultAudience(host))
187187
p(" internaloption.WithDefaultScopes(DefaultAuthScopes()...),")
188188
p(" internaloption.EnableJwtWithScope(),")
189+
if _, ok := enableMtlsHardBoundTokens[g.serviceConfig.GetName()]; ok {
190+
p("internaloption.AllowHardBoundTokens(\"MTLS_S2A\"),")
191+
}
189192
p(" internaloption.EnableNewAuthLibrary(),")
190193
p(" option.WithGRPCDialOption(grpc.WithDefaultCallOptions(")
191194
p(" grpc.MaxCallRecvMsgSize(math.MaxInt32))),")

internal/gengapic/testdata/empty_opt.want

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func defaultGRPCClientOptions() []option.ClientOption {
2424
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
2525
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
2626
internaloption.EnableJwtWithScope(),
27+
internaloption.AllowHardBoundTokens("MTLS_S2A"),
2728
internaloption.EnableNewAuthLibrary(),
2829
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
2930
grpc.MaxCallRecvMsgSize(math.MaxInt32))),

internal/gengapic/testdata/foo_opt.want

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func defaultFooGRPCClientOptions() []option.ClientOption {
2424
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
2525
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
2626
internaloption.EnableJwtWithScope(),
27+
internaloption.AllowHardBoundTokens("MTLS_S2A"),
2728
internaloption.EnableNewAuthLibrary(),
2829
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
2930
grpc.MaxCallRecvMsgSize(math.MaxInt32))),

internal/gengapic/testdata/host_port_opt.want

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func defaultBarGRPCClientOptions() []option.ClientOption {
2222
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
2323
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
2424
internaloption.EnableJwtWithScope(),
25+
internaloption.AllowHardBoundTokens("MTLS_S2A"),
2526
internaloption.EnableNewAuthLibrary(),
2627
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
2728
grpc.MaxCallRecvMsgSize(math.MaxInt32))),

internal/gengapic/testdata/iam_override_opt.want

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func defaultBazGRPCClientOptions() []option.ClientOption {
2121
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
2222
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
2323
internaloption.EnableJwtWithScope(),
24+
internaloption.AllowHardBoundTokens("MTLS_S2A"),
2425
internaloption.EnableNewAuthLibrary(),
2526
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
2627
grpc.MaxCallRecvMsgSize(math.MaxInt32))),

0 commit comments

Comments
 (0)