I'm having a k8s deployment on GCP, and I'm connecting to the SQL database with SQL proxy. I'm deploying with a service account. I gave the service account owner permissions (it's just a test project), and CloudSQL client, CloudSQL instance user, CloudSQL admin.
The whole deployment goes all good, but it cannot connect to the proxy saying:
errors parsing config:
Get "https://sqladmin.googleapis.com/sql/v1beta4/projects/org/instances/europe-west2~testProject/connectSettings?alt=json&prettyPrint=false": compute: Received 403 `Unable to generate access token; IAM returned 403 Forbidden: The caller does not have permission
This error could be caused by a missing IAM policy binding on the target IAM service account.
For more information, refer to the Workload Identity documentation:
https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#authenticating_to
And this is the manifest file (relevant parts of it):
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
iam.gke.io/gcp-service-account: testProject@org.iam.gserviceaccount.com
name: testProject
labels:
app.kubernetes.io/instance: testProject
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: testProject
app.kubernetes.io/instance: testProject
name: testProject
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: testProject
strategy:
rollingUpdate:
maxSurge: 2
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: testProject
spec:
serviceAccountName: testProject
containers:
# app
- name: cloud-sql-proxy
command:
- /cloud_sql_proxy
- -enable_iam_login
- -instances=org:europe-west2:testProject-db-staging=tcp:5432
- -ip_address_types=PRIVATE,PUBLIC
- -structured_logs
- -term_timeout=5s
image: gcr.io/cloudsql-docker/gce-proxy:1.30.0
# ...options
Why can't it connect to the database?