Skip to content

Commit 1cc19b7

Browse files
authoredFeb 10, 2025··
feat(option/internaloption): add new allowHardBoundTokens option (#2975)
Add allowHardBoundTokens option to the internaloption. This option will be used internally only to allow auto-generated clients to request a hard-bound tokens. Hard-bound tokens are tokens that include binding that must be enforced regardless of the IAM policy.
1 parent 6f4d4cd commit 1cc19b7

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
 

‎internal/settings.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type DialSettings struct {
6363
AllowNonDefaultServiceAccount bool
6464
DefaultUniverseDomain string
6565
UniverseDomain string
66+
AllowHardBoundTokens []string
6667
Logger *slog.Logger
6768
// Google API system parameters. For more information please read:
6869
// https://cloud.google.com/apis/docs/system-parameters

‎option/internaloption/internaloption.go

+27
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@ func (w enableJwtWithScope) Apply(o *internal.DialSettings) {
186186
o.EnableJwtWithScope = bool(w)
187187
}
188188

189+
// AllowHardBoundTokens returns a ClientOption that allows libraries to request a hard-bound token.
190+
// Obtaining hard-bound tokens requires the connection to be established using either Application
191+
// Layer Transport Security (ALTS) or mutual TLS (mTLS) with S2A. For more information on ALTS,
192+
// see: https://cloud.google.com/docs/security/encryption-in-transit/application-layer-transport-security
193+
//
194+
// The AllowHardBoundTokens option accepts the following values (or a combination thereof):
195+
//
196+
// - "MTLS_S2A": Allows obtaining hard-bound tokens when the connection uses mutual TLS with S2A.
197+
// - "ALTS": Allows obtaining hard-bound tokens when the connection uses ALTS.
198+
//
199+
// For example, to allow obtaining hard-bound tokens with either MTLS_S2A or ALTS, you would
200+
// provide both values (e.g., {"MTLS_S2A","ALTS"}). If no value is provided, hard-bound tokens
201+
// will not be requested.
202+
//
203+
// It should only be used internally by generated clients.
204+
// This is an EXPERIMENTAL API and may be changed or removed in the future.
205+
func AllowHardBoundTokens(protocol ...string) option.ClientOption {
206+
return allowHardBoundTokens(protocol)
207+
}
208+
209+
type allowHardBoundTokens []string
210+
211+
func (a allowHardBoundTokens) Apply(o *internal.DialSettings) {
212+
o.AllowHardBoundTokens = make([]string, len(a))
213+
copy(o.AllowHardBoundTokens, a)
214+
}
215+
189216
// WithCredentials returns a client option to specify credentials which will be used to authenticate API calls.
190217
// This credential takes precedence over all other credential options.
191218
func WithCredentials(creds *google.Credentials) option.ClientOption {

‎option/internaloption/internaloption_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func TestDefaultApply(t *testing.T) {
4040
WithDefaultScopes("a"),
4141
WithDefaultUniverseDomain("foo.com"),
4242
WithDefaultAudience("audience"),
43+
AllowHardBoundTokens("MTLS_S2A"),
4344
}
4445
var got internal.DialSettings
4546
for _, opt := range opts {
@@ -52,6 +53,7 @@ func TestDefaultApply(t *testing.T) {
5253
DefaultUniverseDomain: "foo.com",
5354
DefaultAudience: "audience",
5455
DefaultMTLSEndpoint: "http://mtls.example.com:445",
56+
AllowHardBoundTokens: []string{"MTLS_S2A"},
5557
}
5658
ignore := []cmp.Option{
5759
cmpopts.IgnoreUnexported(grpc.ClientConn{}),

0 commit comments

Comments
 (0)
Please sign in to comment.