<button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">Version 1.10 (unsupported)</button>

- [Latest](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/latest/installing/configure-sa)
- [Version 1.16](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.16/installing/configure-sa.md.txt)
- [Earlier versions (unsupported)](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.10/getting-support.md.txt#version-support)

<br />

In addition to meeting the installation, hardware, and operating system prerequisites,
you must configure and set up Google Cloud projects, APIs, and
service accounts to run Google Distributed Cloud.

Note that the `bmctl` command can automatically enable service accounts and APIs
at cluster creation time, but you can also manually set up these services
for finer control of operations.

## Enabling APIs

In order to enable APIs in your project, one of the following roles needs
to have been assigned to your account: `roles/owner`, `roles/editor`, or
`roles/serviceusage.serviceUsageAdmin`.

For additional information, see
[Grant a single role](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt#grant-single-role).

## Set your default Google Cloud project ID and roles

You can set your default `project id` in addition to configuring service
accounts.

You must have `owner` or `editor` roles on your project for
Google Distributed Cloud.

To set the default project, issue the following command, and replace
<var translate="no">PROJECT_ID</var> with your Google Cloud project ID:

```
gcloud config set project PROJECT_ID
```

<br />

## Configure service accounts manually

The `bmctl` command of Google Distributed Cloud can automatically set up Google
service accounts and APIs when you create clusters.

However, for more control over your system, or to streamline cluster creation
with a default set of services, accounts, and projects, you can set
up these services manually.

Google Distributed Cloud connects your clusters to Google Cloud. This connection
enables the following functionality:

- [Connect](https://docs.cloud.google.com/anthos/multicluster-management/connect/overview) to connect your bare metal cluster to Google Cloud. This enables access to cluster and to workload management features, including a unified user interface, Cloud console, to interact with your cluster.
- [Logging](https://docs.cloud.google.com/logging/docs.md.txt) and [Monitoring](https://docs.cloud.google.com/monitoring/docs.md.txt) to view logs and metrics from the cluster in the Cloud console.
- Automatic uploads of [cluster snapshots](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.10/troubleshooting/bmctl-snapshot.md.txt) to Cloud Storage buckets.

The process for manually configuring access includes:

- Enabling the necessary Google services in your Cloud project.
- Creating the following service accounts with the necessary roles:
  - **connect-agent service account**: Connect uses this service account to maintain a connection between your cluster and Google Cloud.
  - **connect-register service account**: Connect uses this service account to register your clusters with Google Cloud.
  - **logging-monitoring service account**: Connect uses this service account to export logs and metrics from clusters to Logging and Monitoring.
  - **storage-agent service account** : `bmctl` uses this service account to automatically store snapshots of clusters to Cloud Storage.

  <br />

- Downloading the JSON key files for each service account.

<br />

You then add references to the JSON key files to the appropriate cluster
config files. See [Creating clusters: overview](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.10/installing/creating-clusters/create-clusters-overview.md.txt) for more
information.

### Configure service accounts for use with Connect

To create the service accounts and key files:

1. Make sure you are in the `baremetal` directory.
2. Enable the necessary Google services in your Cloud project:

```
gcloud services enable --project=PROJECT_ID \
    gkeconnect.googleapis.com \
    gkehub.googleapis.com \
    cloudresourcemanager.googleapis.com \
    anthos.googleapis.com
```
3. Create the connect-agent service account with the necessary role and download the key file. These steps create the `connect-agent.json` key file in the `baremetal` directory:
   1. Create service account:

   ```
   gcloud iam service-accounts create connect-agent-svc-account --project=PROJECT_ID
   ```
   2. Grant the gkehub.connect role:

   ```
   gcloud projects add-iam-policy-binding  PROJECT_ID \
       --member="serviceAccount:connect-agent-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role="roles/gkehub.connect"
   ```
   3. Download the service account JSON key file:

   ```
   gcloud iam service-accounts keys create connect-agent.json \
       --project=PROJECT_ID \
       --iam-account=connect-agent-svc-account@PROJECT_ID.iam.gserviceaccount.com
   ```
4. Create the connect-register service account with the necessary role and download the key file. These steps create the connect-`register.json` key file in the `baremetal` directory:
   1. Create service account:

   ```
   gcloud iam service-accounts create connect-register-svc-account \
       --project=PROJECT_ID
   ```
   2. Grant the gkehub.admin role:

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member="serviceAccount:connect-register-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role=roles/gkehub.admin
   ```
   3. Download the service account JSON key file:

   ```
   gcloud iam service-accounts keys create connect-register.json \
       --project=PROJECT_ID \
       --iam-account=connect-register-svc-account@PROJECT_ID.iam.gserviceaccount.com
   ```

### Configure a service account to audit logs and monitor projects

To create the service account and key file for logging and monitoring:

1. Make sure you are in the `baremetal` directory.
2. Enable the necessary Google services in your Cloud project:

```
gcloud services enable --project PROJECT_ID \
    anthos.googleapis.com \
    anthosaudit.googleapis.com \
    anthosgke.googleapis.com \
    cloudresourcemanager.googleapis.com \
    gkeconnect.googleapis.com \
    gkehub.googleapis.com \
    serviceusage.googleapis.com \
    stackdriver.googleapis.com \
    monitoring.googleapis.com \
    logging.googleapis.com \
    opsconfigmonitoring.googleapis.com
```
3. Create the logging-monitoring service account with the necessary roles and download the key file. These steps create the `cloud-ops.json` key file in the `baremetal` directory:
   1. Create service account

   ```
   gcloud iam service-accounts create logging-monitoring-svc-account \
       --project=PROJECT_ID
   ```
   2. Grant the logging.logWriter role

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member="serviceAccount:logging-monitoring-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role="roles/logging.logWriter"
   ```
   3. Grant the monitoring.metricWriter role

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member="serviceAccount:logging-monitoring-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role="roles/monitoring.metricWriter"
   ```
   4. Grant the roles/stackdriver.resourceMetadata.writer role

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member="serviceAccount:logging-monitoring-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role="roles/stackdriver.resourceMetadata.writer"
   ```
   5. Grant the roles/opsconfigmonitoring.resourceMetadata.writer role

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member="serviceAccount:logging-monitoring-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role="roles/opsconfigmonitoring.resourceMetadata.writer"
   ```
   6. Grant the roles/monitoring.dashboardEditor role

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member="serviceAccount:logging-monitoring-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
       --role="roles/monitoring.dashboardEditor"
   ```
   7. Download the service account JSON key file:

   ```
   gcloud iam service-accounts keys create cloud-ops.json \
       --project=PROJECT_ID \
       --iam-account=logging-monitoring-svc-account@PROJECT_ID.iam.gserviceaccount.com
   ```

### Configure a service account that can upload to Cloud Storage bucket

To create the service account and key file which enables snapshots of clusters
to be automatically uploaded to Cloud Storage buckets:

1. Make sure you are in the `baremetal` directory.
2. Enable the necessary Google services in your Cloud project:

```
gcloud services enable --project=PROJECT_ID \
    storage.googleapis.com
```
3. Create a service account that the `bmctl check cluster --snapshot` command will use to automatically upload a cluster snapshot to a Cloud Storage bucket:

```
gcloud iam service-accounts create storage-agent-svc-account \
  --project=PROJECT_ID
```
4. Grant a `storage.admin` role to the service account so that the service account can upload data to a Cloud Storage bucket.:

```
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="serviceAccount:storage-agent-svc-account@PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/storage.admin"
```
5. Download the service account JSON key file:

```
gcloud iam service-accounts keys create storage-agent.json \
    --iam-account=storage-agent-svc-account@PROJECT_ID.iam.gserviceaccount.com
```

For more information about how to create cluster snapshots and
automatically upload them to a Cloud Storage bucket, see
[Create snapshots to help diagnose cluster problems](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.10/troubleshooting/bmctl-snapshot.md.txt).