doc.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package google provides support for making OAuth2 authorized and authenticated
  5. // HTTP requests to Google APIs. It supports the Web server flow, client-side
  6. // credentials, service accounts, Google Compute Engine service accounts,
  7. // Google App Engine service accounts and workload identity federation
  8. // from non-Google cloud platforms.
  9. //
  10. // A brief overview of the package follows. For more information, please read
  11. // https://developers.google.com/accounts/docs/OAuth2
  12. // and
  13. // https://developers.google.com/accounts/docs/application-default-credentials.
  14. // For more information on using workload identity federation, refer to
  15. // https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation.
  16. //
  17. // # OAuth2 Configs
  18. //
  19. // Two functions in this package return golang.org/x/oauth2.Config values from Google credential
  20. // data. Google supports two JSON formats for OAuth2 credentials: one is handled by ConfigFromJSON,
  21. // the other by JWTConfigFromJSON. The returned Config can be used to obtain a TokenSource or
  22. // create an http.Client.
  23. //
  24. // # Workload Identity Federation
  25. //
  26. // Using workload identity federation, your application can access Google Cloud
  27. // resources from Amazon Web Services (AWS), Microsoft Azure or any identity
  28. // provider that supports OpenID Connect (OIDC) or SAML 2.0.
  29. // Traditionally, applications running outside Google Cloud have used service
  30. // account keys to access Google Cloud resources. Using identity federation,
  31. // you can allow your workload to impersonate a service account.
  32. // This lets you access Google Cloud resources directly, eliminating the
  33. // maintenance and security burden associated with service account keys.
  34. //
  35. // Follow the detailed instructions on how to configure Workload Identity Federation
  36. // in various platforms:
  37. //
  38. // Amazon Web Services (AWS): https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#aws
  39. // Microsoft Azure: https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#azure
  40. // OIDC identity provider: https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#oidc
  41. // SAML 2.0 identity provider: https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#saml
  42. //
  43. // For OIDC and SAML providers, the library can retrieve tokens in three ways:
  44. // from a local file location (file-sourced credentials), from a server
  45. // (URL-sourced credentials), or from a local executable (executable-sourced
  46. // credentials).
  47. // For file-sourced credentials, a background process needs to be continuously
  48. // refreshing the file location with a new OIDC/SAML token prior to expiration.
  49. // For tokens with one hour lifetimes, the token needs to be updated in the file
  50. // every hour. The token can be stored directly as plain text or in JSON format.
  51. // For URL-sourced credentials, a local server needs to host a GET endpoint to
  52. // return the OIDC/SAML token. The response can be in plain text or JSON.
  53. // Additional required request headers can also be specified.
  54. // For executable-sourced credentials, an application needs to be available to
  55. // output the OIDC/SAML token and other information in a JSON format.
  56. // For more information on how these work (and how to implement
  57. // executable-sourced credentials), please check out:
  58. // https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#create_a_credential_configuration
  59. //
  60. // Note that this library does not perform any validation on the token_url, token_info_url,
  61. // or service_account_impersonation_url fields of the credential configuration.
  62. // It is not recommended to use a credential configuration that you did not generate with
  63. // the gcloud CLI unless you verify that the URL fields point to a googleapis.com domain.
  64. //
  65. // # Workforce Identity Federation
  66. //
  67. // Workforce identity federation lets you use an external identity provider (IdP) to
  68. // authenticate and authorize a workforce—a group of users, such as employees, partners,
  69. // and contractors—using IAM, so that the users can access Google Cloud services.
  70. // Workforce identity federation extends Google Cloud's identity capabilities to support
  71. // syncless, attribute-based single sign on.
  72. //
  73. // With workforce identity federation, your workforce can access Google Cloud resources
  74. // using an external identity provider (IdP) that supports OpenID Connect (OIDC) or
  75. // SAML 2.0 such as Azure Active Directory (Azure AD), Active Directory Federation
  76. // Services (AD FS), Okta, and others.
  77. //
  78. // Follow the detailed instructions on how to configure Workload Identity Federation
  79. // in various platforms:
  80. //
  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, token_info_url,
  106. // or service_account_impersonation_url fields of the credential configuration.
  107. // It is not recommended to use a credential configuration that you did not generate with
  108. // the gcloud CLI unless you verify that the URL fields point to a googleapis.com domain.
  109. //
  110. // # Credentials
  111. //
  112. // The Credentials type represents Google credentials, including Application Default
  113. // Credentials.
  114. //
  115. // Use FindDefaultCredentials to obtain Application Default Credentials.
  116. // FindDefaultCredentials looks in some well-known places for a credentials file, and
  117. // will call AppEngineTokenSource or ComputeTokenSource as needed.
  118. //
  119. // Application Default Credentials also support workload identity federation to
  120. // access Google Cloud resources from non-Google Cloud platforms including Amazon
  121. // Web Services (AWS), Microsoft Azure or any identity provider that supports
  122. // OpenID Connect (OIDC). Workload identity federation is recommended for
  123. // non-Google Cloud environments as it avoids the need to download, manage and
  124. // store service account private keys locally.
  125. //
  126. // DefaultClient and DefaultTokenSource are convenience methods. They first call FindDefaultCredentials,
  127. // then use the credentials to construct an http.Client or an oauth2.TokenSource.
  128. //
  129. // Use CredentialsFromJSON to obtain credentials from either of the two JSON formats
  130. // described in OAuth2 Configs, above. The TokenSource in the returned value is the
  131. // same as the one obtained from the oauth2.Config returned from ConfigFromJSON or
  132. // JWTConfigFromJSON, but the Credentials may contain additional information
  133. // that is useful is some circumstances.
  134. package google // import "golang.org/x/oauth2/google"