@@ -62,57 +62,6 @@ store service account private keys locally.
62
62
.. _Google Cloud SDK : https://cloud.google.com/sdk
63
63
64
64
65
- Service account private key files
66
- +++++++++++++++++++++++++++++++++
67
-
68
- A service account private key file can be used to obtain credentials for a
69
- service account. You can create a private key using the `Credentials page of the
70
- Google Cloud Console `_. Once you have a private key you can either obtain
71
- credentials one of three ways:
72
-
73
- 1. Set the ``GOOGLE_APPLICATION_CREDENTIALS `` environment variable to the full
74
- path to your service account private key file
75
-
76
- .. code-block :: bash
77
-
78
- $ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
79
-
80
- Then, use :ref: `application default credentials <application-default >`.
81
- :func: `default ` checks for the ``GOOGLE_APPLICATION_CREDENTIALS ``
82
- environment variable before all other checks, so this will always use the
83
- credentials you explicitly specify.
84
-
85
- 2. Use :meth: `service_account.Credentials.from_service_account_file
86
- <google.oauth2.service_account.Credentials.from_service_account_file> `::
87
-
88
- from google.oauth2 import service_account
89
-
90
- credentials = service_account.Credentials.from_service_account_file(
91
- '/path/to/key.json')
92
-
93
- scoped_credentials = credentials.with_scopes(
94
- ['https://www.googleapis.com/auth/cloud-platform'])
95
-
96
- 3. Use :meth: `service_account.Credentials.from_service_account_info
97
- <google.oauth2.service_account.Credentials.from_service_account_info> `::
98
-
99
- import json
100
-
101
- from google.oauth2 import service_account
102
-
103
- json_acct_info = json.loads(function_to_get_json_creds())
104
- credentials = service_account.Credentials.from_service_account_info(
105
- json_acct_info)
106
-
107
- scoped_credentials = credentials.with_scopes(
108
- ['https://www.googleapis.com/auth/cloud-platform'])
109
-
110
- .. warning :: Private keys must be kept secret. If you expose your private key it
111
- is recommended to revoke it immediately from the Google Cloud Console.
112
-
113
- .. _Credentials page of the Google Cloud Console :
114
- https://console.cloud.google.com/apis/credentials
115
-
116
65
Compute Engine, Container Engine, and the App Engine flexible environment
117
66
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118
67
@@ -231,6 +180,7 @@ You can also use :class:`google_auth_oauthlib.flow.Flow` to perform the OAuth
231
180
.. _requests-oauthlib :
232
181
https://requests-oauthlib.readthedocs.io/en/latest/
233
182
183
+
234
184
External credentials (Workload identity federation)
235
185
+++++++++++++++++++++++++++++++++++++++++++++++++++
236
186
@@ -981,7 +931,8 @@ Impersonated credentials
981
931
++++++++++++++++++++++++
982
932
983
933
Impersonated Credentials allows one set of credentials issued to a user or service account
984
- to impersonate another. The source credentials must be granted
934
+ to impersonate a service account. Impersonation is the preferred way of using service account for
935
+ local development over downloading the service account key. The source credentials must be granted
985
936
the "Service Account Token Creator" IAM role. ::
986
937
987
938
from google.auth import impersonated_credentials
@@ -1006,6 +957,63 @@ In the example above `source_credentials` does not have direct access to list bu
1006
957
in the target project. Using `ImpersonatedCredentials ` will allow the source_credentials
1007
958
to assume the identity of a target_principal that does have access.
1008
959
960
+ It is possible to provide a delegation chain through `delegates ` paramter while
961
+ initializing the impersonated credential. Refer `create short lived credentials delegated `_ for more details on delegation chain.
962
+
963
+ .. _create short lived credentials delegated : https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated
964
+
965
+
966
+ Service account private key files
967
+ +++++++++++++++++++++++++++++++++
968
+
969
+ A service account private key file can be used to obtain credentials for a service account. If you are not
970
+ able to use any of the authentication methods listed above, you can create a private key using `Credentials page of the
971
+ Google Cloud Console `_. Once you have a private key you can obtain
972
+ credentials one of three ways:
973
+
974
+ 1. Set the ``GOOGLE_APPLICATION_CREDENTIALS `` environment variable to the full
975
+ path to your service account private key file
976
+
977
+ .. code-block :: bash
978
+
979
+ $ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
980
+
981
+ Then, use :ref: `application default credentials <application-default >`.
982
+ :func: `default ` checks for the ``GOOGLE_APPLICATION_CREDENTIALS ``
983
+ environment variable before all other checks, so this will always use the
984
+ credentials you explicitly specify.
985
+
986
+ 2. Use :meth: `service_account.Credentials.from_service_account_file
987
+ <google.oauth2.service_account.Credentials.from_service_account_file> `::
988
+
989
+ from google.oauth2 import service_account
990
+
991
+ credentials = service_account.Credentials.from_service_account_file(
992
+ '/path/to/key.json')
993
+
994
+ scoped_credentials = credentials.with_scopes(
995
+ ['https://www.googleapis.com/auth/cloud-platform'])
996
+
997
+ 3. Use :meth: `service_account.Credentials.from_service_account_info
998
+ <google.oauth2.service_account.Credentials.from_service_account_info> `::
999
+
1000
+ import json
1001
+
1002
+ from google.oauth2 import service_account
1003
+
1004
+ json_acct_info = json.loads(function_to_get_json_creds())
1005
+ credentials = service_account.Credentials.from_service_account_info(
1006
+ json_acct_info)
1007
+
1008
+ scoped_credentials = credentials.with_scopes(
1009
+ ['https://www.googleapis.com/auth/cloud-platform'])
1010
+
1011
+ .. warning :: Private keys must be kept secret. If you expose your private key it
1012
+ is recommended to revoke it immediately from the Google Cloud Console.
1013
+
1014
+ .. _Credentials page of the Google Cloud Console :
1015
+ https://console.cloud.google.com/apis/credentials
1016
+
1009
1017
1010
1018
Downscoped credentials
1011
1019
++++++++++++++++++++++
0 commit comments