Configure Authentication for Private Repositories
This guide is specifically for GitLab repositories. The configuration steps are tailored for GitLab's authentication and API requirements.
This guide explains how to configure authentication for private repositories in PAC. Private repositories require authentication credentials to allow PAC to access and clone repository contents.
PAC uses authentication for private repositories:
- Git Provider API Authentication (
git_provider.secret): Used for API operations like creating webhooks, updating PR status, and accessing repository metadata. PAC also automatically creates a git clone authentication secret from this token for use in PipelineRuns.
TOC
PrerequisitesOverviewConfiguration StepsStep 1: Create Access Token in GitLabStep 2: Create Kubernetes SecretCreate Webhook Secret (Optional)Step 3: Update Repository CRVerifying Private Repository AccessCheck Repository CRCheck PAC Controller LogsTest Pipeline TriggerTroubleshootingCheck for Authentication ErrorsToken ExpiredBest Practices1. Token Management2. Secret Management3. SecurityNext StepsPrerequisites
Before configuring authentication for private repositories, ensure you have:
- PAC component deployed and running
- A Repository CR (Custom Resource) created for your repository. A Repository CR is a Kubernetes resource that tells PAC which Git repository to monitor and how to configure it
- Admin access to create Kubernetes Secrets
- Access tokens for your Git provider
A Repository CR is a Kubernetes Custom Resource that defines:
- The Git repository URL to monitor
- Git provider configuration (GitHub, GitLab, etc.)
- Authentication credentials
- Webhook settings
- Pipeline execution settings
PAC watches Repository CRs and automatically creates PipelineRuns when events occur in the configured Git repository.
Overview
PAC supports authentication for private GitLab repositories using Personal Access Tokens (PAT) with HTTPS URLs.
Configuration Steps
Follow these steps to configure authentication for private repositories.
Step 1: Create Access Token in GitLab
- Go to GitLab → User Settings → Access Tokens
- Create a token with
apiscope - Generate and copy the token
Step 2: Create Kubernetes Secret
Create a secret containing your GitLab access token:
Example output:
Note: PAC will use this token for Git provider API operations (webhook management, PR status updates, etc.) and automatically create a git clone authentication secret from it.
Create Webhook Secret (Optional)
If you plan to configure webhooks, create a secret for webhook validation:
Security Best Practices:
- Store tokens securely and use separate secrets for different repositories or environments
- PAC automatically creates git clone authentication secrets, so you don't need to create them manually
Step 3: Update Repository CR
Update your Repository CR to reference the authentication secret:
Note: PAC uses the git_provider.secret for API operations and automatically creates a git clone authentication secret from it for use in PipelineRuns.
Verifying Private Repository Access
After configuring authentication, verify that PAC can access your private repository:
Check Repository CR
Example output (abbreviated):
Check PAC Controller Logs
Look for authentication errors or issues connecting to your Git provider.
Test Pipeline Trigger
Trigger a test pipeline to verify access:
Example output:
Check if the PipelineRun is created successfully:
Example output:
Troubleshooting
Check for Authentication Errors
Problem: PAC cannot access the private repository.
Solutions:
-
Verify token permissions: Ensure the GitLab access token has the
apiscope -
Check secret exists: Verify the GitLab secret exists in the correct namespace:
Example output:
-
Verify secret key: Ensure the secret contains the token key:
Example output (abbreviated, token is base64 encoded):
-
Check Repository CR: Verify the secret reference in the Repository CR is correct:
Example output:
Token Expired
Problem: Access token has expired.
Solutions:
-
Generate a new access token from your Git provider
-
Update the Kubernetes Secret:
Example output:
-
Restart PAC controller pods if needed:
Example output:
Best Practices
1. Token Management
- Use separate tokens: Use different tokens for different repositories or environments
- Set expiration: Set expiration dates on tokens for better security
- Rotate regularly: Rotate access tokens periodically
- Limit scopes: Only grant minimum required permissions
2. Secret Management
- Use namespaces: Store secrets in appropriate namespaces
- RBAC: Use RBAC to control who can access secrets
- External secrets: Consider using external secret management tools (e.g., Sealed Secrets, Vault)
3. Security
- Least privilege: Grant minimum required permissions
- Audit access: Regularly audit who has access to repositories
- Monitor logs: Monitor PAC controller logs for authentication issues
Next Steps
- Configure Custom Certificates - Configure custom CA certificates for self-signed certificates
- Advanced Repository Configuration - Learn about advanced repository configuration options
- Configure GitLab Repository - GitLab-specific configuration guide
- Common Issues - Troubleshooting guide