Skip to content

Commit 39e79fc

Browse files
d-bytebaseclaude
andauthored
docs: improve Cloud SQL IAM authentication documentation for enhanced security (#837)
- Rewrite Cloud SQL IAM auth section to use GCE VM service accounts instead of key files - Remove dependency on GOOGLE_APPLICATION_CREDENTIALS and JSON key management - Add comprehensive Google Cloud documentation references - Simplify SQL user creation examples for MySQL and PostgreSQL - Remove 8 unnecessary screenshot images from gcp-iam directory - Align formatting with AWS RDS IAM authentication section This approach improves security by eliminating service account key management and leveraging GCE metadata service for automatic credential handling. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 8eaca64 commit 39e79fc

File tree

9 files changed

+79
-29
lines changed

9 files changed

+79
-29
lines changed
Binary file not shown.
Binary file not shown.
-23.3 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-37.7 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

mintlify/get-started/instance.mdx

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -303,46 +303,96 @@ Go to instance setting, specify `bytebase` as the Secret name and `DB_PASSWORD`
303303

304304
### Cloud SQL with IAM Authentication
305305

306-
#### Create a service account
307-
308-
1. Visit [Service accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) to create a new service account `bytebase`.
309-
310-
2. Grant `Cloud SQL Admin` permission to the service account.
311-
![](/content/docs/get-started/instance/gcp-iam/grant-cloud-sql-admin.webp)
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)
312352

313-
3. After the service account is created, you may view the email for the service account `bytebase@<<your-project-name>>.iam.gserviceaccount.com`. Go to **KEYS**.
314-
![](/content/docs/get-started/instance/gcp-iam/service-account-keys.webp)
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)
315357

316-
4. Click **ADD KEY** and then **Create new key**.
317-
![](/content/docs/get-started/instance/gcp-secret-manager/create-key-file.webp)
358+
#### Step 3: Create Database Users
318359

319-
5. Choose `JSON` as the key type and click **CREATE**. Keep the downloaded private key file. This will be passed as environment variables when starting Bytebase.
320-
![](/content/docs/get-started/instance/gcp-iam/create-pk.webp)
360+
Connect to your Cloud SQL instance using the root user or an admin account:
321361

322-
6. Go to Cloud SQL database instance detail page, and make sure `cloudsql_iam_authentication` is enabled.
323-
![](/content/docs/get-started/instance/gcp-iam/cloudsql-iam-auth-on.webp)
362+
**Cloud SQL for MySQL:**
363+
```sql
364+
CREATE USER 'bytebase-cloudsql'@'%' IDENTIFIED WITH 'cloudsql_iam_user';
365+
```
324366

325-
7. Go to **Users** tab, and click **ADD USER ACCOUNT**.
326-
![](/content/docs/get-started/instance/gcp-iam/sql-users.webp)
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+
```
327372

328-
8. Select `Cloud IAM` and copy/paste the service account email `bytebase@<<your-project-name>>.iam.gserviceaccount.com`.
329-
![](/content/docs/get-started/instance/gcp-iam/user-account-type.webp)
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)
330374

331-
9. Then you can get the Cloud SQL IAM user: `bytebase`.
332-
![](/content/docs/get-started/instance/gcp-iam/user-added-bytebase.webp)
375+
#### Step 4: Deploy Bytebase on GCE VM
333376

334-
#### Use IAM Auth in Bytebase
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.
335378

336-
1. Start Bytebase with Google IAM credentials by passing `GOOGLE_APPLICATION_CREDENTIALS` as an environment variable:
379+
#### Step 5: Connect from Bytebase
337380

338-
```bash
339-
docker run --init \
340-
-e GOOGLE_APPLICATION_CREDENTIALS=<<your-json-file>> \
341-
...
342-
```
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
343392

344-
2. Go to SQL overview page, you'll find the **Connection name**, use it as the host. Choose `Google Cloud SQL IAM` along with your user `bytebase` to connect to the database.
345-
![](/content/docs/get-started/instance/gcp-iam/connection-name.webp)
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>
346396

347397
### GCP Secret Manager
348398

0 commit comments

Comments
 (0)