Skip to content

Commit ca9294b

Browse files
chore: add "Configuring IAM Database Authentication" to README (#2353)
1 parent f6b2efa commit ca9294b

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,44 @@ query param:
338338
> ./cloud-sql-proxy --unix-socket C:\cloudsql myproject:my-region:mysql
339339
> ```
340340

341+
### Configuring IAM Database Authentication
342+
343+
The Proxy supports [Automatic IAM Database Authentication][iam-auth] for MySQL
344+
and Postgres instances, allowing IAM principal's to authenticate and connect
345+
as database users.
346+
347+
Make sure to configure your [Cloud SQL instance to allow IAM authentication][iam-auth-config]
348+
and to [add your IAM principal as a database user][iam-auth-user].
349+
350+
```shell
351+
./cloud-sql-proxy --auto-iam-authn <INSTANCE_CONNECTION_NAME>
352+
```
353+
354+
> [!IMPORTANT]
355+
>
356+
> Make sure to run the Proxy as the same IAM principal as the database user
357+
> you want to log in as. Only the IAM principal that is attached to the
358+
> [sourced credentials](#credentials) will be able to successfully log in
359+
> via automatic IAM database authentication.
360+
>
361+
> When logging in using an IAM database user, Cloud SQL truncates usernames
362+
> based on the engine type in order to not exceed character limits.
363+
> PostgreSQL's username character limit is 63, while MySQL's is 32.
364+
>
365+
> Cloud SQL IAM database usernames are formatted in the following way:
366+
>
367+
> **Postgres**:
368+
> * For an IAM user account, this is the user's email address.
369+
> * For a service account, it is the service account's email without the
370+
> `.gserviceaccount.com` domain suffix.
371+
>
372+
> **MySQL**:
373+
> * For an IAM user account, this is the user's email address,
374+
> without the `@` or domain name. For example, for `test-user@gmail.com`,
375+
> the database user would be `test-user`.
376+
> * For a service account, this is the service account's email address without
377+
> the `@project-id.iam.gserviceaccount.com` suffix.
378+
341379
### Testing Connectivity
342380
343381
The Proxy includes support for a connection test on startup. This test helps
@@ -712,7 +750,9 @@ By participating in this project you agree to abide by its terms. See
712750
[connection-overview]: https://cloud.google.com/sql/docs/mysql/connect-overview
713751
[contributing]: CONTRIBUTING.md
714752
[health-check-example]: https://github.com/GoogleCloudPlatform/cloudsql-proxy/tree/main/examples/k8s-health-check#cloud-sql-proxy-health-checks
715-
[iam-auth]: https://cloud.google.com/sql/docs/postgres/authentication#automatic
753+
[iam-auth]: https://cloud.google.com/sql/docs/postgres/iam-authentication#auto-iam-auth
754+
[iam-auth-config]: https://cloud.google.com/sql/docs/postgres/create-edit-iam-instances#configure-iam-db-instance
755+
[iam-auth-user]: https://cloud.google.com/sql/docs/postgres/add-manage-iam-users#creating-a-database-user
716756
[pkg-badge]: https://pkg.go.dev/badge/github.com/GoogleCloudPlatform/cloudsql-proxy.svg
717757
[pkg-docs]: https://pkg.go.dev/github.com/GoogleCloudPlatform/cloudsql-proxy
718758
[private-ip]: https://cloud.google.com/sql/docs/mysql/private-ip#requirements_for_private_ip

0 commit comments

Comments
 (0)