I am trying to service a public website from a Google Cloud SQL database (MySQL).
Since it is a public website, I found out the only way for me to gain access in to use an API Key, and add it it to the request like that:
If I understand correctly, the Cloud SQL DB end point should look something like that:
Since it is a PUBLIC, ANONYMOUS website, I cannot use any of the Google provided libraries for Apps Script or connection/authentication methods, as the end user is not known, nor identified or logged-into any known Google account from any known IP address. Hence, the API Key method.
Can anyone point me in the right directions please?
In short; you shouldn’t do this as it is an insecure practice and API keys are unsupported by the MySQL database engine. You generally don’t want to allow public access even to connect to your database, as it can expose security risks.
Typically, websites handle this by using API calls to the backend server, which are authenticated in some way. You could replicate this pattern by hosting your own service (perhaps in Cloud Functions or Cloud Run) that authenticates requests and performs queries needed to the instance.
Alternatively, consider using a managed service (perhaps Firestore) that does have this functionality. Firestore will also be “pay for what you use”, meaning it’s cost will scale with your traffic.