You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
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)
312
352
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**.
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.
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)
330
374
331
-
9. Then you can get the Cloud SQL IAM user: `bytebase`.
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.
335
378
336
-
1. Start Bytebase with Google IAM credentials by passing `GOOGLE_APPLICATION_CREDENTIALS` as an environment variable:
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.
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)
0 commit comments