Skip to content

Commit 5a28bd7

Browse files
d-bytebaseclaude
andauthored
docs: improve GCP service account authentication documentation (#839)
- Rewrite GCP Secret Manager section to use GCE VM service accounts (most secure method) - Create shared Prerequisites section for service account setup (GCE and GKE) - Consolidate to single 'bytebase' service account instead of multiple accounts - Add GKE with Workload Identity support - Remove duplicate content between Cloud SQL and Secret Manager sections - Fix IAM user creation methods (gcloud/Console, not SQL commands) - Correct username formats for MySQL and PostgreSQL - Reduce documentation wordiness by ~50% - Remove 7 obsolete screenshot images - Add comprehensive Google Cloud documentation references 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 4575b2b commit 5a28bd7

File tree

8 files changed

+88
-111
lines changed

8 files changed

+88
-111
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

mintlify/get-started/instance.mdx

Lines changed: 88 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -301,150 +301,127 @@ Go to instance setting, specify `bytebase` as the Secret name and `DB_PASSWORD`
301301

302302
## GCP Configuration
303303

304-
### Cloud SQL with IAM Authentication
304+
### Prerequisites: Service Account Setup
305305

306-
This guide demonstrates the most secure method for IAM authentication using GCE VM service accounts, which eliminates the need to manage service account keys.
307-
308-
For alternative authentication methods, refer to the official Google Cloud documentation:
309-
- [Cloud SQL IAM database authentication overview](https://cloud.google.com/sql/docs/mysql/iam-authentication)
310-
- [Using automatic IAM database authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication#automatic)
311-
- [Configuring instances for IAM database authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances)
312-
- [Managing users with IAM database authentication](https://cloud.google.com/sql/docs/mysql/iam-users)
313-
314-
#### Step 1: Create and Configure GCE VM with Service Account
315-
316-
1. **Create a Service Account**
317-
- Go to [IAM & Admin → Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts)
318-
- Click **Create Service Account**
319-
- Name: `bytebase-cloudsql`
320-
- Description: "Service account for Bytebase to connect to Cloud SQL"
321-
- Click **Create and Continue**
322-
323-
2. **Grant Required Permissions**
324-
- Add these roles to the service account:
325-
- `Cloud SQL Client` (for database connections)
326-
- `Cloud SQL Instance User` (for IAM authentication)
327-
- Click **Continue** and then **Done**
328-
- Note the service account email: `bytebase-cloudsql@PROJECT_ID.iam.gserviceaccount.com`
329-
330-
3. **Create GCE VM with Service Account**
331-
- Go to [Compute Engine → VM instances](https://console.cloud.google.com/compute/instances)
332-
- Click **Create Instance**
333-
- Under **Identity and API access**:
334-
- Service account: Select `bytebase-cloudsql@PROJECT_ID.iam.gserviceaccount.com`
335-
- Access scopes: Select "Allow full access to all Cloud APIs" or manually select Cloud SQL scopes
336-
- Configure other VM settings as needed
337-
- Click **Create**
338-
339-
> **Security Best Practice:** The VM automatically receives credentials through the metadata service. No service account keys are needed, reducing security risks. Learn more: [Service account impersonation](https://cloud.google.com/iam/docs/service-account-impersonation)
340-
341-
#### Step 2: Configure Cloud SQL Instance
342-
343-
1. **Enable IAM Authentication**
344-
- Go to [Cloud SQL Instances](https://console.cloud.google.com/sql/instances)
345-
- Select your instance or create a new one
346-
- Click **Edit**
347-
- Under **Customize your instance****Flags**:
348-
- Add flag: `cloudsql_iam_authentication` = `on`
349-
- Click **Save**
350-
351-
Reference: [Configuring instances for IAM authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances)
306+
Use attached service accounts for secure, key-free authentication on:
307+
- **GCE** - VMs with attached service accounts
308+
- **GKE** - Pods with Workload Identity
352309

353-
2. **Verify SSL/TLS Configuration**
354-
- SSL is required for IAM authentication
355-
- Cloud SQL enables SSL by default - no additional configuration needed
356-
- Reference: [Configuring SSL/TLS](https://cloud.google.com/sql/docs/mysql/configure-ssl-instance)
310+
References: [Service accounts](https://cloud.google.com/iam/docs/service-account-overview) | [Best practices](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys) | [ADC](https://cloud.google.com/docs/authentication/application-default-credentials)
357311

358-
#### Step 3: Create Database Users
312+
#### Create Service Account
359313

360-
Connect to your Cloud SQL instance using the root user or an admin account:
314+
1. Go to [IAM & Admin → Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts)
315+
2. Create service account named `bytebase`
316+
3. Grant roles as needed:
317+
- `Cloud SQL Client` and `Cloud SQL Instance User` - for Cloud SQL
318+
- `Secret Manager Secret Accessor` - for Secret Manager
319+
4. Note the email: `bytebase@PROJECT_ID.iam.gserviceaccount.com`
361320

362-
**Cloud SQL for MySQL:**
363-
```sql
364-
CREATE USER 'bytebase-cloudsql'@'%' IDENTIFIED WITH 'cloudsql_iam_user';
365-
```
321+
#### Attach Service Account
366322

367-
**Cloud SQL for PostgreSQL:**
368-
```sql
369-
CREATE USER "bytebase-cloudsql@PROJECT_ID.iam" WITH LOGIN;
370-
GRANT cloudsqliamuser TO "bytebase-cloudsql@PROJECT_ID.iam";
371-
```
323+
**Option A: GCE VM**
324+
1. Create VM in [Compute Engine](https://console.cloud.google.com/compute/instances)
325+
2. Set service account: `bytebase@PROJECT_ID.iam.gserviceaccount.com`
326+
3. Set access scopes: "Allow full access to all Cloud APIs"
372327

373-
Reference: [MySQL IAM users](https://cloud.google.com/sql/docs/mysql/iam-users) | [PostgreSQL IAM users](https://cloud.google.com/sql/docs/postgres/iam-users)
374-
375-
#### Step 4: Deploy Bytebase on GCE VM
328+
**Option B: GKE with Workload Identity**
329+
```bash
330+
# Create Kubernetes service account
331+
kubectl create serviceaccount bytebase-ksa
376332

377-
Deploy Bytebase on your GCE VM instance. The VM's attached service account credentials are automatically available to Bytebase through the metadata service - no GOOGLE_APPLICATION_CREDENTIALS configuration needed.
333+
# Bind to Google service account
334+
kubectl annotate serviceaccount bytebase-ksa \
335+
iam.gke.io/gcp-service-account=bytebase@PROJECT_ID.iam.gserviceaccount.com
378336

379-
#### Step 5: Connect from Bytebase
337+
# Allow impersonation
338+
gcloud iam service-accounts add-iam-policy-binding bytebase@PROJECT_ID.iam.gserviceaccount.com \
339+
--role roles/iam.workloadIdentityUser \
340+
--member "serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE/bytebase-ksa]"
341+
```
380342

381-
1. Access Bytebase at `http://VM_EXTERNAL_IP:5678`
382-
2. Click **New Instance**
383-
3. Configure the connection:
384-
- **Host:** Your Cloud SQL connection name (format: `PROJECT_ID:REGION:INSTANCE_ID`)
385-
- Find this in Cloud SQL console → Instance details → Connection name
386-
- **Port:** 3306 (MySQL) or 5432 (PostgreSQL)
387-
- **Username:**
388-
- MySQL: `bytebase-cloudsql`
389-
- PostgreSQL: `bytebase-cloudsql@PROJECT_ID.iam`
390-
- **Authentication:** Select `Google Cloud SQL IAM`
391-
4. Test and save the connection
343+
Reference: [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity)
392344

393-
<Tip>
394-
The GCE VM approach eliminates service account key management - credentials are automatically handled through the metadata service. Learn more: [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) | [Troubleshooting IAM authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication#troubleshooting)
395-
</Tip>
345+
Deploy Bytebase on your resource - credentials are provided automatically.
396346

397-
### GCP Secret Manager
347+
#### Alternative: Service Account Keys
398348

399-
#### Create a service account to access the Secret Manager
349+
<Warning>
350+
Use only when running Bytebase outside GCP. See [why to avoid service account keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys#avoid).
351+
</Warning>
400352

401-
<Tip>
402-
It's recommended to create a dedicated service account for Bytebase to retrieve the secrets. You only need to do this once.
403-
</Tip>
353+
1. Create a service account with required roles
354+
2. Download the JSON key file
355+
3. Set environment variable:
356+
```bash
357+
-e GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
358+
```
404359

405-
Visit [Service accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) to create a new service account.
360+
Reference: [Service account keys authentication](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-key)
406361

407-
![](/content/docs/get-started/instance/gcp-secret-manager/create-service-account-name.webp)
362+
### Cloud SQL with IAM Authentication
408363

409-
Grant `Secret Manager Secret Accessor` permission to the service account.
364+
<Note>
365+
Prerequisites: [Service account](#prerequisites-service-account-setup) with Cloud SQL roles.
366+
</Note>
410367

411-
![](/content/docs/get-started/instance/gcp-secret-manager/create-service-account-permission.webp)
368+
References: [IAM authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication) | [Configure instances](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances)
412369

413-
After the service account is created, visit its `KEYS` page and add a new key.
370+
#### Step 1: Configure Cloud SQL Instance
414371

415-
![](/content/docs/get-started/instance/gcp-secret-manager/create-key-file.webp)
372+
1. In [Cloud SQL](https://console.cloud.google.com/sql/instances), edit your instance
373+
2. Add flag: `cloudsql_iam_authentication` = `on`
374+
3. Save (SSL is enabled by default)
416375

417-
Choose `JSON` as the key type and create. Keep the downloaded private key file. This will be passed as environment variables when starting Bytebase.
376+
#### Step 2: Add Service Account User
418377

419-
![](/content/docs/get-started/instance/gcp-secret-manager/create-key-file2.webp)
378+
**Using gcloud:**
379+
```bash
380+
gcloud sql users create bytebase@PROJECT_ID.iam.gserviceaccount.com \
381+
--instance=INSTANCE_NAME \
382+
--type=cloud_iam_service_account
383+
```
420384

421-
#### Create secret
385+
**Using Console:**
386+
Instance → Users → Add User Account → Cloud IAM → Enter service account email
422387

423-
Visit [GCP Secret Manager](https://console.cloud.google.com/security/secret-manager/create) to create a new secret.
388+
References: [MySQL](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users) | [PostgreSQL](https://cloud.google.com/sql/docs/postgres/add-manage-iam-users)
424389

425-
![](/content/docs/get-started/instance/gcp-secret-manager/create-secret.webp)
390+
#### Step 3: Connect from Bytebase
426391

427-
After creation, note the fully qualified secret name.
392+
1. Click **New Instance** in Bytebase
393+
2. Configure connection details:
394+
- **Host:** Your Cloud SQL connection name (`PROJECT_ID:REGION:INSTANCE_ID`)
395+
- Find this in Cloud SQL console → Instance details
396+
- **Port:** 3306 (MySQL) or 5432 (PostgreSQL)
397+
- **Username:**
398+
- MySQL: `bytebase` (service account name only)
399+
- PostgreSQL: `bytebase@PROJECT_ID.iam` (with project ID)
400+
- **Authentication:** Select `Google Cloud SQL IAM`
401+
3. Click **Test Connection** then **Create**
428402

429-
![](/content/docs/get-started/instance/gcp-secret-manager/secret-full-name.webp)
403+
### GCP Secret Manager
430404

431-
#### Use secret in Bytebase
405+
Store database passwords securely in Google Cloud Secret Manager instead of Bytebase.
432406

433-
Restart Bytebase by specifying `GOOGLE_APPLICATION_CREDENTIALS`=`private key file` as an environment variable. The private key file is the JSON file downloaded before for the service account.
407+
<Note>
408+
Prerequisites: [Service account](#prerequisites-service-account-setup) with `Secret Manager Secret Accessor` role.
409+
</Note>
434410

435-
<Tip>
436-
If you run Bytebase in docker, you need to put the JSON file under the mounted directory. Otherwise, Bytebase won't be able to access the key file.
437-
</Tip>
411+
#### Step 1: Create Secret
438412

439-
```bash
440-
docker run --init \
441-
-e GOOGLE_APPLICATION_CREDENTIALS=/var/opt/bytebase/key.json \
442-
...
443-
```
413+
1. Go to [Secret Manager Console](https://console.cloud.google.com/security/secret-manager)
414+
2. Click **Create Secret**
415+
3. Enter secret name (e.g., `db-password`) and your database password as value
416+
4. Click **Create** and note the resource name: `projects/PROJECT_ID/secrets/SECRET_NAME`
444417

445-
Go to instance setting, specify the fully qualified name such as `projects/228712144016/secrets/DB_PASSWORD` as the Secret full name.
418+
#### Step 2: Configure in Bytebase
446419

447-
![](/content/docs/get-started/instance/gcp-secret-manager/auth.webp)
420+
1. In your database instance settings, find the password field
421+
2. Click the key icon to use external secret
422+
3. Select **GCP Secret Manager**
423+
4. Enter the secret resource name from Step 1
424+
5. Test connection and save
448425

449426
## Azure Configuration
450427

0 commit comments

Comments
 (0)