Argo CD with GitHub and GitLab: Repositories, Webhooks and SSO
Argo CD treats a Git repository as the source of truth for what should run in your cluster, so the first real integration most teams build is Argo CD GitHub or Argo CD GitLab access. That integration has three separate layers: credentials so Argo CD can read private repositories, webhooks so changes are picked up in seconds instead of minutes, and single sign-on so people log in with the accounts they already use. This guide walks through each layer for both platforms, with the commands and config you actually need.
You need a running Argo CD instance and the argocd CLI logged in as an admin. If you are not there yet, follow the installation guide and the login guide first.
How Argo CD talks to your Git provider
Argo CD is pull-based. The argocd-repo-server component clones your repository, renders the manifests (plain YAML, Kustomize, Helm or Jsonnet) and hands them to the application controller, which compares them with the live cluster. Nothing in GitHub or GitLab pushes manifests into the cluster. That has two practical consequences:
- Argo CD only needs read access. Give it the narrowest credential that can clone the repository.
- Change detection is polling by default. Argo CD checks repositories roughly every three minutes. Webhooks are an optimization, not a requirement.
Public repositories need no setup at all. Everything below is about private repositories, faster sync and user identity.
Connecting private repositories
You can register a repository over HTTPS with a token, over SSH with a key, or (GitHub only) with a GitHub App. Pick one method per repository URL; the URL form you register must match the repoURL used in your Application manifests exactly.
HTTPS with a token
For GitHub, create a fine-grained personal access token scoped to the repositories Argo CD should see, with read-only access to repository contents. A classic token with the repo scope also works but grants far more than Argo CD needs. For GitLab, prefer a project or group deploy token with the read_repository scope; it is not tied to a person, so it does not break when someone leaves the team.
# GitHub, fine-grained personal access token
argocd repo add https://github.com/my-org/platform-config.git \
--username git \
--password "$GITHUB_TOKEN"
# GitLab, deploy token (use the username GitLab generated for the token)
argocd repo add https://gitlab.com/my-group/platform-config.git \
--username gitlab+deploy-token-123456 \
--password "$GITLAB_DEPLOY_TOKEN"
For GitLab personal, project or group access tokens, the token goes in the password field and any non-empty username is accepted; oauth2 is a common convention.
SSH with a deploy key
SSH avoids token expiry policies and works well with read-only deploy keys, which both GitHub and GitLab support per repository.
ssh-keygen -t ed25519 -f ~/.ssh/argocd_deploy -N "" -C "argocd"
# add ~/.ssh/argocd_deploy.pub as a read-only deploy key in the repository settings
argocd repo add git@github.com:my-org/platform-config.git \
--ssh-private-key-path ~/.ssh/argocd_deploy
Argo CD verifies SSH host keys. It ships with known host keys for common providers such as github.com and gitlab.com in the argocd-ssh-known-hosts-cm ConfigMap. For a self-hosted GitLab or GitHub Enterprise Server, add your server's key:
ssh-keyscan gitlab.example.com | argocd cert add-ssh --batch
GitHub App credentials
A GitHub App is the cleanest option for organizations: it is owned by the org rather than a person, its permissions are granular, and it issues short-lived installation tokens automatically. Create an app with read-only Contents permission, install it on the repositories Argo CD needs, then register it:
argocd repo add https://github.com/my-org/platform-config.git \
--github-app-id 123456 \
--github-app-installation-id 7890123 \
--github-app-private-key-path ./argocd-app.private-key.pem
Credential templates for a whole org or group
Adding every repository one by one gets old quickly. A credential template matches any repository URL that starts with a given prefix, so one secret covers an entire GitHub organization or GitLab group:
argocd repocreds add https://github.com/my-org \
--username git --password "$GITHUB_TOKEN"
argocd repocreds add https://gitlab.com/my-group \
--username oauth2 --password "$GITLAB_GROUP_TOKEN"
If you manage Argo CD declaratively, the same thing is a Kubernetes Secret in the argocd namespace labeled argocd.argoproj.io/secret-type: repo-creds (or repository for a single repo). Keep those secrets out of plain Git; use Sealed Secrets, External Secrets or your cloud's secret manager.
| Method | GitHub | GitLab | Best for |
|---|---|---|---|
| HTTPS + token | Fine-grained PAT (contents read) | Deploy token or access token (read_repository) | Quick setup, credential templates |
| SSH key | Read-only deploy key | Read-only deploy key | One repo, no token expiry |
| GitHub App | Supported | Not applicable | Organizations, short-lived tokens |
| Credential template | Org URL prefix | Group URL prefix | Many repos with one secret |
Confirm the connection with argocd repo list. A repository showing Successful in the connection column is ready to use in an Application.
Setting up GitHub and GitLab webhooks
Without a webhook, a merged pull request may take a few minutes to show up as OutOfSync. A webhook tells Argo CD to refresh affected applications immediately. Both providers send events to the same endpoint:
https://argocd.example.com/api/webhook
Your Argo CD server must be reachable from GitHub or GitLab for this to work, which usually means an Ingress or LoadBalancer with a valid TLS certificate. A cluster reachable only through kubectl port-forward cannot receive webhooks; it will keep relying on polling.
Protect the endpoint with a shared secret
Store a random secret in argocd-secret, then enter the same value in the provider's webhook form. Argo CD rejects payloads that do not carry a matching signature or token.
WEBHOOK_SECRET=$(openssl rand -hex 32)
kubectl -n argocd patch secret argocd-secret --type merge -p \
"{\"stringData\":{\"webhook.github.secret\":\"$WEBHOOK_SECRET\",\"webhook.gitlab.secret\":\"$WEBHOOK_SECRET\"}}"
- GitHub: repository or organization Settings → Webhooks → Add webhook. Payload URL is the endpoint above, content type
application/json, secret is your value, and the push event is enough. - GitLab: project or group Settings → Webhooks. Enter the URL, put your value in Secret token, and enable Push events (add Tag push events if you deploy from tags).
Use an organization-level webhook on GitHub or a group-level webhook on GitLab if you have many config repositories. One hook then covers every repository, and Argo CD works out which applications are affected from the repository URL and changed paths in the payload.
Both providers keep a delivery log for each webhook. If a push does not trigger a refresh, check the response code there before digging into Argo CD logs; a 4xx usually means a secret mismatch or the request never reached the server.
Single sign-on with GitHub or GitLab
Argo CD bundles Dex, an identity broker with ready-made connectors for both platforms. You register an OAuth application with the provider, put the client ID in argocd-cm and the client secret in argocd-secret, then map teams or groups to Argo CD roles.
Register the OAuth application
On GitHub, create an OAuth App under your organization's developer settings. On GitLab, create an application under group or instance settings with the read_user and openid scopes. In both cases the callback URL is:
https://argocd.example.com/api/dex/callback
Configure the Dex connector
Store the client secret first, then edit argocd-cm. The url key must be the external address users open in the browser.
kubectl -n argocd patch secret argocd-secret --type merge -p \
'{"stringData":{"dex.github.clientSecret":"REPLACE_ME"}}'
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
url: https://argocd.example.com
dex.config: |
connectors:
- type: github
id: github
name: GitHub
config:
clientID: Iv1.example0client
clientSecret: $dex.github.clientSecret
orgs:
- name: my-org
- type: gitlab
id: gitlab
name: GitLab
config:
baseURL: https://gitlab.com
clientID: example-gitlab-client-id
clientSecret: $dex.gitlab.clientSecret
groups:
- my-group
The orgs list on GitHub and the groups list on GitLab restrict who can log in at all. Leave them out and anyone with an account on that provider could authenticate, even though they would get no permissions beyond the default role.
Map teams and groups to roles
Authentication tells Argo CD who someone is; RBAC in argocd-rbac-cm decides what they can do. GitHub teams arrive as org:team and GitLab groups by their path.
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-rbac-cm
namespace: argocd
data:
policy.default: role:readonly
policy.csv: |
g, my-org:platform-team, role:admin
g, my-group/platform, role:admin
p, role:deployer, applications, sync, */*, allow
g, my-org:app-developers, role:deployer
Users then click Log in via GitHub or Log in via GitLab in the web UI, or run argocd login argocd.example.com --sso from the CLI. Once SSO works, consider disabling the local admin account, as covered in the login guide.
Automating with ApplicationSet generators
The ApplicationSet controller can query GitHub and GitLab directly. The SCM Provider generator discovers repositories in an organization or group, and the Pull Request generator creates a short-lived preview application for each open pull or merge request.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: pr-previews
namespace: argocd
spec:
generators:
- pullRequest:
github:
owner: my-org
repo: storefront
tokenRef:
secretName: github-token
key: token
requeueAfterSeconds: 300
template:
metadata:
name: 'storefront-pr-{{number}}'
spec:
project: previews
source:
repoURL: https://github.com/my-org/storefront.git
targetRevision: '{{head_sha}}'
path: deploy/preview
destination:
server: https://kubernetes.default.svc
namespace: 'preview-{{number}}'
syncPolicy:
automated:
prune: true
syncOptions:
- CreateNamespace=true
Swap github for gitlab (with project and an optional api URL) to do the same against GitLab merge requests. When a pull request closes, its application and namespace are removed.
Security checklist
- Use read-only credentials everywhere; Argo CD never needs to push.
- Prefer GitHub Apps or GitLab group deploy tokens over personal tokens tied to one engineer.
- Always set a webhook secret and serve Argo CD over valid TLS.
- Restrict Dex connectors with
orgsorgroups, and keeppolicy.defaultatrole:readonlyor empty. - Use AppProjects to limit which repositories and destinations each team's applications can use.
- Rotate tokens on a schedule and track expiry dates; an expired token shows up as a ComparisonError on every application using it.
Frequently asked questions
Does Argo CD need write access to my GitHub or GitLab repository?
No. Argo CD only clones and reads the repository, so read-only credentials are enough. Write access is only needed by separate tools, such as a CI pipeline or Argo CD Image Updater configured to commit changes back to Git.
Will Argo CD notice a new commit without a webhook?
Yes. Argo CD polls connected repositories on a schedule, roughly every three minutes by default. A webhook simply removes that delay by telling Argo CD to refresh as soon as a push happens.
Can I use GitHub for SSO and GitLab for repositories at the same time?
Yes. Repository credentials and SSO are configured independently. You can log in through a GitHub Dex connector while Argo CD pulls manifests from GitLab, or the other way round, and you can even enable several Dex connectors at once.
Does Argo CD work with self-hosted GitHub Enterprise Server or GitLab?
Yes. Use your own server URL when adding repositories, point the Dex connector at your instance, and add the server's SSH host key and, if needed, its TLS certificate authority to Argo CD so connections are trusted.
Next steps
With repositories connected and webhooks firing, deploy something real by following the Argo CD tutorial. If a repository shows a connection error or a webhook never triggers a refresh, the troubleshooting guide covers the usual causes. For the full feature list, see Argo CD features on the homepage, or check the official Argo CD documentation for every connector option.