The ACS Git server supports automatic mirroring of external Git repositories. When these repositories require authentication, you can configure credentials using Kubernetes secrets.
To configure authentication for external repositories, you need to:
- Create a Kubernetes secret containing the credentials
- Reference the secret in the Git repository configuration
- Configure the Git service to mount the secret
Create a Kubernetes secret containing the authentication credentials. The secret can be in one of two formats:
apiVersion: v1
kind: Secret
metadata:
name: my-git-credentials
type: Opaque
stringData:
github-credentials: |
{
"username": "myusername",
"password": "mypassword"
}apiVersion: v1
kind: Secret
metadata:
name: my-git-credentials
type: Opaque
stringData:
github-credentials: "myusername:mypassword"The key name in the secret (e.g., github-credentials) will be used as the reference in the Git repository configuration.
When creating a Git repository configuration in ConfigDB, include an auth object with a secretRef property in the pull configuration:
{
"path": "shared/example-repo",
"pull": {
"main": {
"url": "https://github.com/example/private-repo.git",
"ref": "main",
"interval": "1h",
"auth": {
"secretRef": "github-credentials"
}
}
}
}The secretRef value should match the key name in the Kubernetes secret.
Update your Helm values to include the credentials secrets:
git:
enabled: true
verbosity: "INFO"
credentialsSecrets:
- my-git-credentials
- other-git-credentialsThis will mount the specified secrets in the Git service pod at /git-secrets, making them available for authentication.
When you specify secrets in the credentialsSecrets list, Kubernetes will:
- Create a volume containing all the specified secrets
- Mount this volume at
/git-secretsin the Git service container - Each key in each secret will be available as a file in this directory
For example, if you have a secret named my-git-credentials with a key github-credentials, it will be available at:
/git-secrets/github-credentials
This is why the secretRef in your repository configuration should match the key name in the secret, not the secret name itself.
- Credentials are stored in Kubernetes secrets, which are base64-encoded but not encrypted
- The Git service caches credentials in memory to avoid frequent secret reads
- Credentials are cleared from the cache if authentication fails
If you encounter authentication issues:
-
Check the Git service logs for authentication errors:
kubectl logs deployment/git -n <namespace>
-
Verify that the secret is correctly mounted in the pod:
kubectl exec -it deployment/git -n <namespace> -- ls -la /git-secrets
-
Check the content of the mounted secrets (don't do this in production environments):
kubectl exec -it deployment/git -n <namespace> -- cat /git-secrets/<secret-key>
-
Ensure the credentials have the necessary permissions for the external repository
-
Check that the
secretRefin the repository configuration matches the key in the secret
If you see a log message like "Secret not found: github-credentials", check:
- The secret exists in the namespace
- The secret is included in the
git.credentialsSecretslist in your Helm values - The key name in the secret matches the
secretRefin your repository configuration
If authentication fails, check:
- The credentials are correct and have access to the repository
- For GitHub tokens, make sure you're using the format:
{ "username": "oauth2", "password": "<token>" }
If the pod fails to start with mount errors:
- Check if there are any conflicts with other volume mounts
- Verify that the Kubernetes version supports the volume configuration
- Check if the secret exists before the pod starts
Here's a complete example of setting up a Git repository with GitHub authentication:
- Create a secret with GitHub credentials:
apiVersion: v1
kind: Secret
metadata:
name: github-credentials
namespace: amrc-connectivity-stack
type: Opaque
stringData:
github-token: |
{
"username": "oauth2",
"password": "ghp_1234567890abcdefghijklmnopqrstuvwxyz"
}- Update Helm values to include the secret:
git:
enabled: true
verbosity: "INFO"
credentialsSecrets:
- github-credentials- Create a Git repository configuration:
const uuid = await fplus.ConfigDB.create_object(UUIDs.Class.Repo);
await fplus.ConfigDB.put_config(Git.App.Config, uuid, {
path: "shared/github-repo",
pull: {
main: {
url: "https://github.com/myorg/private-repo.git",
ref: "main",
interval: "1h",
auth: {
secretRef: "github-token"
}
}
}
});This will create a Git repository that automatically pulls from the private GitHub repository using the provided token.