# Google Cloud: Managing Access to Groups

In this tutorial, you'll learn how to configure [#grant-kits](https://docs.abbey.io/how-abbey-works/concepts#grant-kits "mention") to automate access requests to an [Google Cloud Identity Group](https://cloud.google.com/identity/docs/groups#group-types) by attaching a [Google Cloud Identity Group Membership](https://cloud.google.com/identity/docs/groups#memberships_and_membership_properties). This use case models granting new users memberships to a GCP group.

The main terraform resources we'll be using for GCP are:

```hcl
google_cloud_identity_group
google_cloud_identity_group_membership
```

We will be using the [GCP Identity Starter Kit](https://github.com/abbeylabs/abbey-starter-kit-gcp-identity) as a base and replace configuration stubs for our use case.

## Before you start

1. **Make sure you have:**
   * An [Abbey account](https://app.abbey.so/sign-up)
   * An [Abbey API Token](https://docs.abbey.io/admin/managing-api-tokens#creating-new-api-tokens)
   * A GCP account
   * [`gcloud` CLI](https://cloud.google.com/sdk/gcloud) set up
2. **Make sure you setup:**
   1. An [GCP Identity Starter Kit](https://github.com/abbeylabs/abbey-starter-kit-gcp-identity) by following [get-a-starter-kit](https://docs.abbey.io/build-a-grant-kit/get-a-starter-kit "mention")
   2. A Connection to a repo by following [connect-a-repo](https://docs.abbey.io/build-a-grant-kit/connect-a-repo "mention")

## Step 1: Configure Your Grant Kit

### Configure Output

Grant Kits rely on your GitHub account and repository name to output access changes, which we'll set through Terraform local variables. Update the `locals` block in `main.tf` with your `account_name` and `repo_name`

{% code title="main.tf" %}

```hcl
 locals {
  account_name = "" #CHANGEME
  repo_name = "" #CHANGEME
  ...
}
```

{% endcode %}

### Configure Reviewers

Workflow defines who should approve an access request.&#x20;

Let's update the `reviewers` block by adding yourself as the reviewer by switching `replace-me@example.com` with the email address you use to sign into Abbey.&#x20;

{% code title="main.tf" %}

```diff
 resource "abbey_grant_kit" "..." {
   ...
   workflow = {
     steps = [
       {
         reviewers = {
-          one_of = ["replace-me@example.com"] # CHANGEME
+          one_of = ["alice@example.com"]
```

{% endcode %}

## Step 2: Link GCP with Abbey

Now you'll need to link [GCP with Abbey](https://developers.abbey.io/#operation/createAppData).&#x20;

{% code title="" %}

```diff
curl -X POST \
  -H "Authorization: Bearer $ABBEY_API_TOKEN" \
  -H 'Content-Type: application/json' \
  https://api.abbey.io/v1/users/<user_id>/apps \
  -d '{"type": "google", "data": {"id": "<your GCP id>"}}'
```

{% endcode %}

## Step 3: Configure GCP for Terraform

### **Configure GCP User**

{% hint style="info" %}
You can skip this step if your GCP user email address matches your Abbey email address.
{% endhint %}

Replace the value for `gcp_member` in the locals block to the google email address for the user you wish to add to group.

{% code title="main.tf" lineNumbers="true" %}

```diff
locals {
-  gcp_member = "{{ .user.google.id }}"
+  gcp_member = your-username@gmail.com
   ...
}
```

{% endcode %}

### **Configure GCP Billing Project**

Replace the `billing_project` field in the google provider block with your project ID and correct region.

{% code title="providers.tf" lineNumbers="true" %}

```diff
provider "google" {
-  billing_project     = "replace-me"
+  billing_project     = "your-project-id"
-  region              = "replace-me"
+  region              = "your-region"
}
```

{% endcode %}

### **Configure GCP Customer ID**

In the terminal run `gcloud organizations list`, which should output something like

```
DISPLAY_NAME            ID  DIRECTORY_CUSTOMER_ID
abbey.io      00000000              C1111111
```

Update the value for `gcp_customer_id` in the locals block with the DIRECTORY\_CUSTOMER\_ID

{% code title="main.tf" lineNumbers="true" %}

```diff
locals {
  ...
-  gcp_customer_id = "$replace-me-with-gcp-customer-id"
+  gcp_customer_id = "C1111111"
}
```

{% endcode %}

## Step 4: Configure GCP Permissions

{% hint style="info" %}
In this step we will

* Create and use GCP resources (Project, Service Account, Workload Identity Pool & Provider)
* Add Repository Secrets so Github Actions to make calls to GCP
  {% endhint %}

Create a new GCP project or use an existing one. Make sure that the **Cloud Identity API** is enabled for your project (<https://console.cloud.google.com/apis/api/cloudidentity.googleapis.com>)

After that, we need to configure Workload Identity Federation to allow Github Actions to make calls from your repo when managing the group membership. This allows Github to only gain secure temporary access tokens rather than exporting long-lived JSON secrets.

Follow these instructions to set it up <https://github.com/google-github-actions/auth#setting-up-workload-identity-federation>. Don't worry about making any changes to the actions YAML file, just save the Service Account email and the Workload Identity Provider ID - we'll add those as repository secrets.

Next, add the following repository secrets so Github Actions can access these credentials.

1. `GCP_SERVICE_ACCOUNT`
2. `GCP_WORKLOAD_IDENTITY_PROVIDER`
3. `ABBEY_TOKEN` - API token taken from [**Settings > API Tokens**](https://app.abbey.io/settings/developers)

You can do this via **Github repo page -> Settings -> Secrets and Variables -> Actions -> New Repository Secret** and create with the above names.

<details>

<summary>What should it look like?</summary>

<img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2F444HMrGnAHbWq7vS1MaI%2Fimage.png?alt=media&#x26;token=15aa74e3-456f-447e-b576-3a662be582f2" alt="" data-size="original">

</details>

## Step 5: Deploy Your Starter Kit

To deploy your Starter Kit, follow instructions from [deploying-your-grant-kit](https://docs.abbey.io/build-a-grant-kit/deploying-your-grant-kit "mention").

## Step 6: Automate Access Management

:tada: Congratulations! Abbey is now managing permissions to your Resource for you. :tada:

You can now start requesting and approving access by following the [requesting-access](https://docs.abbey.io/build-a-grant-kit/requesting-access "mention") and [approving-or-denying-access-requests](https://docs.abbey.io/build-a-grant-kit/approving-or-denying-access-requests "mention") guides.

{% hint style="success" %}
Abbey strives to help you automate and secure access management without being intrusive.

To that end, this Pull Request contains native Terraform HCL code using normal open source Terraform Provider libraries. It represents the permissions change. In this case, it's just a simple creation of a new Terraform Resource.
{% endhint %}

After approving the request, you should be able to see that the user has been added to the google group.

1. Navigate to <https://groups.google.com/all-groups>
2. Select the group you are adding a member to
3. View members

Finally, this starter kit comes with a time-based policy by default, the user will automatically be removed after 1 hour.

<figure><img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2F03tgETppErJ0MmHC2Ja9%2Fimage.png?alt=media&#x26;token=2cb7fa37-9945-47e9-9cbc-0aa91d5f6654" alt=""><figcaption></figcaption></figure>

## Next Steps

To learn more about what [resources](https://docs.abbey.io/resources "mention") you can configure, try one of our [](https://docs.abbey.io/getting-started/tutorials "mention").&#x20;

For more information on how Abbey works, visit the [concepts](https://docs.abbey.io/how-abbey-works/concepts "mention") or [grant-kits](https://docs.abbey.io/reference/grant-kits "mention") page.
