ERROR: The connection consistently fails during the SASL handshake, resulting in either a client-side KafkaError{code=_MSG_TIMED_OUT} or a broker-side SaslAuthenticationException: Authentication failed due to invalid credentials.
WIF is enabled on the cluster (workload_pool is set) and the node pool (mode: GKE_METADATA). A ServiceAccount is annotated with iam.gke.io/return-principal-id-as-email: “true” and is used by the application pods. A Google Service Account (GSA) has the roles/managedkafka.client and roles/iam.serviceAccountTokenCreator roles. The Kubernetes Service Account is bound to this GSA with the roles/iam.workloadIdentityUser role. The Python client is configured for SASL_SSL with sasl.mechanism: OAUTHBEARER and uses google.auth.default() within an oauth_cb callback to provide the authentication token.
I have validated network connectivity (via socket tests), all IAM/GKE/K8s policies and annotations, and Kafka ACLs (including User:*)—every component is correctly configured as per the docs.
the authentication fails with both the direct federation (return-principal-id-as-email annotation) and the KSA-to-GSA impersonation (gcp-service-account annotation) methods of Workload Identity.
ERROR: The connection consistently fails during the SASL handshake, resulting in either a client-side
KafkaError{code=_MSG_TIMED_OUT}or a broker-sideSaslAuthenticationException: Authentication failed due to invalid credentials.WIF is enabled on the cluster (
workload_poolis set) and the node pool (mode: GKE_METADATA). AServiceAccountis annotated withiam.gke.io/return-principal-id-as-email: “true”and is used by the application pods. A Google Service Account (GSA) has theroles/managedkafka.clientandroles/iam.serviceAccountTokenCreatorroles. The Kubernetes Service Account is bound to this GSA with theroles/iam.workloadIdentityUserrole. The Python client is configured forSASL_SSLwithsasl.mechanism: OAUTHBEARERand usesgoogle.auth.default()within anoauth_cbcallback to provide the authentication token.I have validated network connectivity (via socket tests), all IAM/GKE/K8s policies and annotations, and Kafka ACLs (including
User:*)—every component is correctly configured as per the docs.the authentication fails with both the direct federation (
return-principal-id-as-emailannotation) and the KSA-to-GSA impersonation (gcp-service-accountannotation) methods of Workload Identity.