Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 43ec8f4

Browse files
gabor-farkaslaurapaciliomegan07
authored
#127 Added more docs about authentication and authorization (#174)
* Added more docs about authentication and authorization, #127 * Update docs/index.md Co-authored-by: Laura Pacilio <[email protected]> * Update docs/index.md Co-authored-by: Laura Pacilio <[email protected]> * Update docs/index.md Co-authored-by: megan07 <[email protected]> Co-authored-by: Laura Pacilio <[email protected]> Co-authored-by: megan07 <[email protected]>
1 parent cc229fe commit 43ec8f4

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

docs/index.md

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,59 @@ provider "googleworkspace" {
2020
}
2121
```
2222

23+
## Authorization
24+
This provider uses [Admin SDK](https://developers.google.com/admin-sdk) API methods to manage resources on a Workspace customer domain. There are multiple ways to set up proper authorization for a service account:
25+
26+
* Enable [domain-wide delegation](#using-domain-wide-delegation) to impersonate a user that has super administrator privileges. You cannot directly grant super administrator privileges to service accounts.
27+
28+
* Assign [specific administrator roles](https://support.google.com/a/answer/9807615?hl=en&ref_topic=9832445) directly to the service account.
29+
2330
## Authentication
2431

25-
### Creating a Service Account and Credentials
32+
### Using Domain-Wide Delegation
33+
34+
#### Creating a Service Account and Credentials
35+
36+
Terraform uses a GCP service account to manage resources created by the provider. To create the service account and generate a service account key:
2637

27-
Terraform will use a GCP service account to manage resources created by the provider. To create the service account and
28-
generate a service account key see the documentation [here](https://developers.google.com/admin-sdk/directory/v1/guides/delegation#create_the_service_account_and_credentials).
29-
Once the key has been generated, save the json file locally and set the `GOOGLEWORKSPACE_CREDENTIALS` environment
30-
variable to the path of the service account key. Terraform will use that key for authentication.
38+
1. Follow the instructions in the [create service account and credentials documentation](https://developers.google.com/admin-sdk/directory/v1/guides/delegation#create_the_service_account_and_credentials).
39+
2. Save the json file containing your service account key credentials locally and set the `GOOGLEWORKSPACE_CREDENTIALS` environment variable to the path of that file. Terraform will now use that key for authentication.
3140

32-
### Configuring the Service Account
41+
#### Configuring the Service Account
3342

3443
To access user data on a Google Workspace domain, the service account that you created needs to be granted access
35-
by a super administrator for the domain. To delegate domain-wide authority to a service account, follow the instructions
36-
[here](https://developers.google.com/admin-sdk/directory/v1/guides/delegation#delegate_domain-wide_authority_to_your_service_account).
44+
by a super administrator for the domain. Follow the instructions in the
45+
[delegate domain-wide authority documentation](https://developers.google.com/admin-sdk/directory/v1/guides/delegation#delegate_domain-wide_authority_to_your_service_account).
3746

3847
* Note: The Oauth scopes granted to your service account must match, or be a superset, of the `oauth_scopes` granted to
3948
the `googleworkspace` provider.
4049

41-
### Impersonating a Google Workspace User
50+
#### Impersonating a Google Workspace User
51+
52+
Only users with access to the Admin APIs can access the Admin SDK Directory API, therefore your service account needs to impersonate one of those users to access the Admin SDK Directory API. This user's email
53+
must be set in the environment variable `GOOGLEWORKSPACE_IMPERSONATED_USER_EMAIL` or in the `impersonated_user_email` attribute in the provider. Additionally, the user must have logged in at least once and accepted the Google Workspace Terms of Service.
54+
55+
### Using Specific Administrator Roles
56+
You do not need to set up domain-wide delegation if you are granting more specific administrator roles to the service account. If the Terraform pipeline execution environment provides an appropriate token as Application Default Credentials (ADC), you can use the provider without any further setup.
57+
58+
When using gcloud locally, you can provide the required scopes for ADC login by adding the `--scopes` parameter to [`gcloud auth application-default login`](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login). For example, you can [provide additional scopes](https://cloud.google.com/sdk/gcloud/reference/beta/compute/instances/set-scopes) on Compute Engine. You can do this to configure access for both service accounts and end users.
59+
60+
```terraform
61+
provider "googleworkspace" {
62+
customer_id = "A01b123xz"
63+
}
64+
```
65+
66+
The approach outlined above does not work on Cloud Build because it does not (yet) support specifying additional scopes for service account tokens accessible during builds. Other pipeline setups use the `google_service_account_access_token` to impersonate a service account. This allows them to use a single identity regardless of who is initiating the execution. For these cases, set the `access_token` parameter to the appropriate credentials.
67+
68+
```terraform
69+
provider "googleworkspace" {
70+
customer_id = "A01b123xz"
71+
access_token = data.google_service_account_access_token.default.access_token
72+
}
73+
```
4274

43-
Only users with access to the Admin APIs can access the Admin SDK Directory API, therefore your service account needs
44-
to impersonate one of those users to access the Admin SDK Directory API. You can do this by granting the GCP IAM role
45-
`roles/iam.serviceAccountUser` to your service account, with member `user:<impersonated_user_email>`. This user's email
46-
must be set in the environment variable `GOOGLEWORKSPACE_IMPERSONATED_USER_EMAIL` or in the `impersonated_user_email`
47-
attribute in the provider. Additionally, the user must have logged in at least once and accepted the Google Workspace
48-
Terms of Service.
75+
You can also provide an exported service account key in the `credentials` parameter without specifying an `impersonated_user_email`.
4976

5077
<!-- schema generated by tfplugindocs -->
5178
## Schema

0 commit comments

Comments
 (0)