Skip to content

Commit a0978d8

Browse files
authored
feat(auth): make package externalaccount public (#9633)
Port of: https://togithub.com/golang/oauth2/commit/95bec9538152e03de0cfbaf64cd3af163b8cef30
1 parent 48a9258 commit a0978d8

19 files changed

Lines changed: 1529 additions & 267 deletions

auth/credentials/doc.go

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,6 @@
2525
// For more information on using workload identity federation, refer to
2626
// https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation.
2727
//
28-
// # Workforce Identity Federation
29-
//
30-
// Workforce identity federation lets you use an external identity provider (IdP) to
31-
// authenticate and authorize a workforce—a group of users, such as employees, partners,
32-
// and contractors—using IAM, so that the users can access Google Cloud services.
33-
// Workforce identity federation extends Google Cloud's identity capabilities to support
34-
// syncless, attribute-based single sign on.
35-
//
36-
// With workforce identity federation, your workforce can access Google Cloud resources
37-
// using an external identity provider (IdP) that supports OpenID Connect (OIDC) or
38-
// SAML 2.0 such as Azure Active Directory (Azure AD), Active Directory Federation
39-
// Services (AD FS), Okta, and others.
40-
//
41-
// Follow the detailed instructions on how to configure Workload Identity Federation
42-
// in various platforms:
43-
//
44-
// - [Amazon Web Services (AWS)](https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#aws)
45-
// - [Azure AD](https://cloud.google.com/iam/docs/workforce-sign-in-azure-ad)
46-
// - [Okta](https://cloud.google.com/iam/docs/workforce-sign-in-okta)
47-
// - [OIDC identity provider](https://cloud.google.com/iam/docs/configuring-workforce-identity-federation#oidc)
48-
// - [SAML 2.0 identity provider](https://cloud.google.com/iam/docs/configuring-workforce-identity-federation#saml)
49-
//
50-
// For workforce identity federation, the library can retrieve tokens in three ways:
51-
// from a local file location (file-sourced credentials), from a server
52-
// (URL-sourced credentials), or from a local executable (executable-sourced
53-
// credentials).
54-
// For file-sourced credentials, a background process needs to be continuously
55-
// refreshing the file location with a new OIDC/SAML token prior to expiration.
56-
// For tokens with one hour lifetimes, the token needs to be updated in the file
57-
// every hour. The token can be stored directly as plain text or in JSON format.
58-
// For URL-sourced credentials, a local server needs to host a GET endpoint to
59-
// return the OIDC/SAML token. The response can be in plain text or JSON.
60-
// Additional required request headers can also be specified.
61-
// For executable-sourced credentials, an application needs to be available to
62-
// output the OIDC/SAML token and other information in a JSON format.
63-
// For more information on how these work (and how to implement
64-
// executable-sourced credentials), please check out:
65-
// https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials#generate_a_configuration_file_for_non-interactive_sign-in
66-
//
67-
// # Security considerations
68-
//
69-
// Note that this library does not perform any validation on the token_url,
70-
// token_info_url, or service_account_impersonation_url fields of the credential
71-
// configuration. It is not recommended to use a credential configuration that
72-
// you did not generate with the gcloud CLI unless you verify that the URL
73-
// fields point to a googleapis.com domain.
74-
//
7528
// # Credentials
7629
//
7730
// The [cloud.google.com/go/auth.Credentials] type represents Google
@@ -85,4 +38,8 @@
8538
// OpenID Connect (OIDC). Workload identity federation is recommended for
8639
// non-Google Cloud environments as it avoids the need to download, manage, and
8740
// store service account private keys locally.
41+
//
42+
// # Workforce Identity Federation
43+
//
44+
// For more information on this feature see [cloud.google.com/go/auth/credentials/externalaccount].
8845
package credentials
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package externalaccount provides support for creating workload identity
16+
// federation and workforce identity federation token providers that can be used
17+
// to access Google Cloud resources from external identity providers.
18+
//
19+
// # Workload Identity Federation
20+
//
21+
// Using workload identity federation, your application can access Google Cloud
22+
// resources from Amazon Web Services (AWS), Microsoft Azure or any identity
23+
// provider that supports OpenID Connect (OIDC) or SAML 2.0.
24+
// Traditionally, applications running outside Google Cloud have used service
25+
// account keys to access Google Cloud resources. Using identity federation,
26+
// you can allow your workload to impersonate a service account.
27+
// This lets you access Google Cloud resources directly, eliminating the
28+
// maintenance and security burden associated with service account keys.
29+
//
30+
// Follow the detailed instructions on how to configure Workload Identity
31+
// Federation in various platforms:
32+
//
33+
// - Amazon Web Services (AWS): https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#aws
34+
// - Microsoft Azure: https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#azure
35+
// - OIDC identity provider: https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#oidc
36+
// - SAML 2.0 identity provider: https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#saml
37+
//
38+
// For OIDC and SAML providers, the library can retrieve tokens in fours ways:
39+
// from a local file location (file-sourced credentials), from a server
40+
// (URL-sourced credentials), from a local executable (executable-sourced
41+
// credentials), or from a user defined function that returns an OIDC or SAML token.
42+
// For file-sourced credentials, a background process needs to be continuously
43+
// refreshing the file location with a new OIDC/SAML token prior to expiration.
44+
// For tokens with one hour lifetimes, the token needs to be updated in the file
45+
// every hour. The token can be stored directly as plain text or in JSON format.
46+
// For URL-sourced credentials, a local server needs to host a GET endpoint to
47+
// return the OIDC/SAML token. The response can be in plain text or JSON.
48+
// Additional required request headers can also be specified.
49+
// For executable-sourced credentials, an application needs to be available to
50+
// output the OIDC/SAML token and other information in a JSON format.
51+
// For more information on how these work (and how to implement
52+
// executable-sourced credentials), please check out:
53+
// https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#create_a_credential_configuration
54+
//
55+
// To use a custom function to supply the token, define a struct that implements
56+
// the [SubjectTokenProvider] interface for OIDC/SAML providers, or one that
57+
// implements [AwsSecurityCredentialsProvider] for AWS providers. This can then
58+
// be used when building a [Options].The [cloud.google.com/go/auth.Credentials]
59+
// created from the options using [NewCredentials] can then be used to access
60+
// Google Cloud resources. For instance, you can create a new client from the
61+
// [cloud.google.com/go/storage] package and pass in
62+
// option.WithTokenProvider(yourTokenProvider))
63+
//
64+
// # Workforce Identity Federation
65+
//
66+
// Workforce identity federation lets you use an external identity provider
67+
// (IdP) to authenticate and authorize a workforce—a group of users, such as
68+
// employees, partners, and contractors—using IAM, so that the users can access
69+
// Google Cloud services. Workforce identity federation extends Google Cloud's
70+
// identity capabilities to support syncless, attribute-based single sign on.
71+
//
72+
// With workforce identity federation, your workforce can access Google Cloud resources
73+
// using an external identity provider (IdP) that supports OpenID Connect (OIDC) or
74+
// SAML 2.0 such as Azure Active Directory (Azure AD), Active Directory Federation
75+
// Services (AD FS), Okta, and others.
76+
//
77+
// Follow the detailed instructions on how to configure Workload Identity Federation
78+
// in various platforms:
79+
//
80+
// - [Amazon Web Services (AWS)](https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#aws)
81+
// - [Azure AD](https://cloud.google.com/iam/docs/workforce-sign-in-azure-ad)
82+
// - [Okta](https://cloud.google.com/iam/docs/workforce-sign-in-okta)
83+
// - [OIDC identity provider](https://cloud.google.com/iam/docs/configuring-workforce-identity-federation#oidc)
84+
// - [SAML 2.0 identity provider](https://cloud.google.com/iam/docs/configuring-workforce-identity-federation#saml)
85+
//
86+
// For workforce identity federation, the library can retrieve tokens in three ways:
87+
// from a local file location (file-sourced credentials), from a server
88+
// (URL-sourced credentials), or from a local executable (executable-sourced
89+
// credentials).
90+
// For file-sourced credentials, a background process needs to be continuously
91+
// refreshing the file location with a new OIDC/SAML token prior to expiration.
92+
// For tokens with one hour lifetimes, the token needs to be updated in the file
93+
// every hour. The token can be stored directly as plain text or in JSON format.
94+
// For URL-sourced credentials, a local server needs to host a GET endpoint to
95+
// return the OIDC/SAML token. The response can be in plain text or JSON.
96+
// Additional required request headers can also be specified.
97+
// For executable-sourced credentials, an application needs to be available to
98+
// output the OIDC/SAML token and other information in a JSON format.
99+
// For more information on how these work (and how to implement
100+
// executable-sourced credentials), please check out:
101+
// https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials#generate_a_configuration_file_for_non-interactive_sign-in
102+
//
103+
// # Security considerations
104+
//
105+
// Note that this library does not perform any validation on the token_url,
106+
// token_info_url, or service_account_impersonation_url fields of the credential
107+
// configuration. It is not recommended to use a credential configuration that
108+
// you did not generate with the gcloud CLI unless you verify that the URL
109+
// fields point to a googleapis.com domain.
110+
package externalaccount

0 commit comments

Comments
 (0)