Every time I connect to postgresql database I authorize my IP in Google Cloud. As I am going to use AWS(it gives a new IP on every connection), I want to automatically authorize those IPs. So how can I do it? Is there any certificate or json files that I can use for this?
1 Answer
The most secure way to do it would be to use the Cloud SQL proxy, which allows you to connect without Authorized IPs.
Another, less secure way would be to use the Cloud SQL Admin API to authorize your IP address as needed - you can use gcloud or a REST call to programmatically do this as needed. Please note that:
- The IP will be authorized until removed, even if you stop using it
- Configuring new authorized networks replaces any existing authorized networks. You'll either need to GET the current list and append (but be wary of race conditions!) OR use a shared value store to make sure the list of IPs is currently up to date.