flux2 icon indicating copy to clipboard operation
flux2 copied to clipboard

GCP plugin for Flux WIF does not support anything other than the public IP endpoint.

Open bm1216 opened this issue 10 months ago • 6 comments

Describe the bug

Flux support for Workload Identity Federation was added recently and documented here (For GCP) - https://fluxcd.io/flux/integrations/gcp/#for-google-kubernetes-engine

We wanted to use it to manage GKE clusters remotely. It's used by creating a ConfigMap with the following information -

data:
  provider: gcp
  cluster: projects/<GCP_PROJECT_ID>/locations/<REGION>/clusters/<GCP_CLUSTER_NAME>

This only uses the public IP endpoint of the GKE cluster. If you want to connect to the cluster in other ways, for example - internal IP or DNS, then tough luck. This can cause issues due to public IP whitelisting rules on the control-plane.

We tried to get around this by manually setting the address via data.address but you get the following error (in our case, we set it to the DNS endpoint of the control plane)-

GKE endpoint 'PUBLIC_IP_ENDPOINT' does not match specified address: 'https://gke-SOME_HASH.europe-west2.gke.goog'

Looking at the source code on flux/pkg https://github.com/fluxcd/pkg/blob/2f71d01eaa4ceb8630debd343ab7656075315fb0/auth/gcp/implementation.go#L46

The implementation gets the Endpoint field from the Cluster struct which by default just points to the public IPv4 address. Looking at https://pkg.go.dev/google.golang.org/api/container/v1#Cluster, we can get the other endpoints from Cluster.ControlPlaneEndpointsConfig which has both IP (public and private) and DNS endpoints and let the user decide which they want to use via a field.

The above is for the GCP implementation only and I'm not sure how it behaves for the other cloud providers.

Steps to reproduce

  1. Create 2 GKE clusters, A and B.
  2. Install Flux with the WIF feature gate enabled on cluster A
  3. Add a ConfigMap with the following WIF config
data:
  provider: gcp
  cluster: projects/<GCP_PROJECT_ID>/locations/<REGION>/clusters/B
  1. Create a HelmRelease/Kustomization with kubeConfig.configMapRef.name set to the above configmap.
  2. If Cluster-A can't talk to the public IP address of Cluster-B, the above fails.

Expected behavior

Flux would allow us to choose which endpoint of the GKE cluster to connect to. Available options -

  1. Public IP
  2. Internal IP
  3. DNS Endpoint

Suggestion -

  1. Allow users to specify data.address
  2. When the check happens which compares data.address to the cluster endpoint, compare instead to ALL the endpoints and use the data.address to connect to the cluster

Screenshots and recordings

No response

OS / Distro

COS_CONTAINERD (cos-121-18867-294-38)

Flux version

v2.7.5

Flux check

► checking prerequisites ✔ Kubernetes 1.33.5-gke.2019000 >=1.32.0-0 ► checking version in cluster ✔ distribution: flux-v2.7.5 ✔ bootstrapped: true ► checking controllers ✔ helm-controller: deployment ready ► ghcr.io/fluxcd/helm-controller:v1.4.5 ✔ kustomize-controller: deployment ready ► ghcr.io/fluxcd/kustomize-controller:v1.7.3 ✔ notification-controller: deployment ready ► ghcr.io/fluxcd/notification-controller:v1.7.5 ✔ source-controller: deployment ready ► ghcr.io/fluxcd/source-controller:v1.7.4 ► checking crds ✔ alerts.notification.toolkit.fluxcd.io/v1beta3 ✔ buckets.source.toolkit.fluxcd.io/v1 ✔ externalartifacts.source.toolkit.fluxcd.io/v1 ✔ gitrepositories.source.toolkit.fluxcd.io/v1 ✔ helmcharts.source.toolkit.fluxcd.io/v1 ✔ helmreleases.helm.toolkit.fluxcd.io/v2 ✔ helmrepositories.source.toolkit.fluxcd.io/v1 ✔ kustomizations.kustomize.toolkit.fluxcd.io/v1 ✔ ocirepositories.source.toolkit.fluxcd.io/v1 ✔ providers.notification.toolkit.fluxcd.io/v1beta3 ✔ receivers.notification.toolkit.fluxcd.io/v1 ✔ all checks passed

Git provider

No response

Container Registry provider

No response

Additional context

No response

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

bm1216 avatar Jan 13 '26 15:01 bm1216

Fix will land in Flux 2.8, end of Feb 2026

matheuscscp avatar Jan 13 '26 16:01 matheuscscp

Thanks for the quick response mate

bm1216 avatar Jan 13 '26 16:01 bm1216

What fluxcd/pkg#1071 Fixed (and What It Didn't)

PR #1071 removed the address matching validation from the GCP provider. Previously, if you set address in the ConfigMap to anything other than the cluster's public IP endpoint, Flux would reject it with "GKE endpoint does not match specified address".

Removed code (auth/gcp/provider.go):

// Compare specified address and address from the cluster resource.
endpoint := clusterResource.Endpoint
if host != "" {
    canonicalAddress, _ := auth.ParseClusterAddress(host)
    canonicalEndpoint, _ := auth.ParseClusterAddress(endpoint)
    if canonicalAddress != canonicalEndpoint {
        return nil, fmt.Errorf("GKE endpoint '%s' does not match specified address: '%s'", endpoint, host)
    }
}

This fix allows specifying a DNS endpoint or any alternative address. However, the PR did not change how CAData is handled. The provider still fetches the cluster's self-signed CA from MasterAuth.ClusterCaCertificate and uses it for TLS verification — which is incorrect for DNS endpoints that use Google Trust Services certificates.

Might be a Root Cause

The issue might be in the GCP provider's NewRESTConfig function (auth/gcp/provider.go):

host = o.ClusterAddress   // DNS endpoint from ConfigMap
caData = o.CAData          // empty

if host == "" || caData == "" {
    // Fetches cluster details from GKE API
    clusterResource, _ := p.impl().GetCluster(ctx, cluster, client)
    // Sets caData to the cluster's self-signed CA
    caData, _ = base64.StdEncoding.DecodeString(
        clusterResource.MasterAuth.ClusterCaCertificate)
}

When address is provided but caData is not:

  1. host is set to the DNS endpoint (*.gke.goog)
  2. caData is empty, so the provider fetches the cluster's self-signed CA from the GKE API
  3. The DNS endpoint serves a certificate signed by Google Trust Services (a public CA)
  4. The self-signed cluster CA cannot verify the Google Trust Services certificate
  5. TLS handshake fails with x509: certificate signed by unknown authority

This is a mismatch: the IP-based endpoint uses the cluster's self-signed CA, but the DNS endpoint uses a publicly-signed certificate from Google Trust Services.

Expected Behaviour

When dnsLookup: "true" is set, the GCP provider should not use the cluster's self-signed CA (MasterAuth.ClusterCaCertificate). Instead, it should rely on the system's trusted root CA bundle, which includes Google Trust Services and can verify the DNS endpoint's certificate.

Suggested Fix

In NewRESTConfig, when the DNS endpoint is being used (i.e., dnsLookup is enabled or the host is a *.gke.goog address), skip setting CAData from the cluster resource and let the system root CAs handle verification:

// Only use cluster CA for IP-based endpoints, not DNS endpoints
if !isDNSEndpoint(host) {
    caData, err = base64.StdEncoding.DecodeString(
        clusterResource.MasterAuth.ClusterCaCertificate)
}

nirmeshjaingothane avatar May 12 '26 08:05 nirmeshjaingothane

When dnsLookup: "true"

What is dnsLookup? There's no such thing in github.com/fluxcd/pkg: https://github.com/search?q=repo%3Afluxcd%2Fpkg%20dnsLookup&type=code

matheuscscp avatar May 12 '26 08:05 matheuscscp

In any case, you can either provide a CA yourself (along the address that you are already providing), or get the one from the GKE cluster resource.

matheuscscp avatar May 12 '26 09:05 matheuscscp

Furthermore, if anything, your comment is a feature requst. Not a bug. If you have good reasons to pursue the feature, please open a dedicated issue.

matheuscscp avatar May 12 '26 09:05 matheuscscp