Resolved

FluxCD authentication failure for private GitHub repositories

FluxCD
GitOps
GitHub
SSH
Authentication
DevOps

FluxCD failed to clone a private GitHub repository due to authentication errors, resolved by switching to SSH deploy keys and updating GitRepository configurations.

Issue

FluxCD encountered authentication failures when attempting to clone a private GitHub repository. The GitRepository resource remained in a failed state due to missing credentials and incorrect URL formats, preventing manifest synchronization and subsequent deployments.

Culprit

The authentication issues stemmed from two main problems:

  1. HTTP URL Usage: The GitRepository was configured with an HTTPS URL, which requires username/password or token authentication. However, no credentials were provided.
  2. Missing Secret Reference: The GitRepository configuration lacked a secretRef field to reference authentication credentials, even though the credentials were available.

Solution

SSH Authentication Setup

  1. Generated SSH Deploy Key: Created an SSH deploy key using the Flux CLI to enable SSH-based authentication for GitHub repositories.
  2. Added Public Key to GitHub: Configured GitHub to accept the generated SSH public key with appropriate access permissions.

Configuration Updates

  1. Updated URL to SSH Format: Changed the GitRepository URL from HTTPS to SSH format (e.g., ssh://git@github.com/name/mcp-rag-sdk).
  2. Added Secret Reference: Included a secretRef field in the GitRepository specification to reference the authentication secret.

Additional Fixes

  1. HelmRelease API Version Update: Updated the API version in HelmRelease manifests from helm.toolkit.fluxcd.io/v2beta1 to helm.toolkit.fluxcd.io/v2 to align with the cluster’s supported API version.

This solution enabled FluxCD to successfully authenticate with GitHub and clone private repositories, ensuring seamless manifest synchronization and deployment.