github.com/argoproj/argo-cd/v3@v3.2.1/docs/user-guide/private-repositories.md (about) 1 # Private Repositories 2 3 !!!note 4 Some Git hosters - notably GitLab and possibly on-premise GitLab instances as well - require you to 5 specify the `.git` suffix in the repository URL, otherwise they will send a HTTP 301 redirect to the 6 repository URL suffixed with `.git`. Argo CD will **not** follow these redirects, so you have to 7 adapt your repository URL to be suffixed with `.git`. 8 9 ## Credentials 10 11 If application manifests are located in private repository then repository credentials have to be configured. Argo CD supports both HTTPS and SSH Git credentials. 12 13 ### HTTPS Username And Password Credential 14 15 Private repositories that require a username and password typically have a URL that start with `https://` rather than `git@` or `ssh://`. 16 17 Credentials can be configured using Argo CD CLI: 18 19 ```bash 20 argocd repo add https://github.com/argoproj/argocd-example-apps --username <username> --password <password> 21 ``` 22 23 or UI: 24 25 1. Navigate to `Settings/Repositories` 26 27  28 29 2. Click `Connect Repo using HTTPS` button and enter credentials 30 31  32 33 *Note: username in screenshot is for illustration purposes only , we have no relationship to this GitHub account should it exist.* 34 35 3. Click `Connect` to test the connection and have the repository added 36 37  38 39 #### Access Token 40 41 Instead of using username and password you might use access token. Following instructions of your Git hosting service to generate the token: 42 43 * [GitHub](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) 44 * [GitLab](https://docs.gitlab.com/ee/user/project/deploy_tokens/) 45 * [Bitbucket](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html) 46 * [Azure Repos](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page) 47 48 Then, connect the repository using any non-empty string as username and the access token value as a password. 49 50 !!!note 51 For some services, you might have to specify your account name as the username instead of any string. 52 53 ### TLS Client Certificates for HTTPS repositories 54 55 If your repository server requires you to use TLS client certificates for authentication, you can configure Argo CD repositories to make use of them. For this purpose, `--tls-client-cert-path` and `--tls-client-cert-key-path` switches to the `argocd repo add` command can be used to specify the files on your local system containing client certificate and the corresponding key, respectively: 56 57 ``` 58 argocd repo add https://repo.example.com/repo.git --tls-client-cert-path ~/mycert.crt --tls-client-cert-key-path ~/mycert.key 59 ``` 60 61 Of course, you can also use this in combination with the `--username` and `--password` switches, if your repository server should require this. The options `--tls-client-cert-path` and `--tls-client-cert-key-path` must always be specified together. 62 63 Your TLS client certificate and corresponding key can also be configured using the UI, see instructions for adding Git repos using HTTPS. 64 65 !!! note 66 Your client certificate and key data must be in PEM format, other formats (such as PKCS12) are not supported. Also make sure that your certificate's key is not password protected, otherwise it cannot be used by Argo CD. 67 68 !!! note 69 When pasting TLS client certificate and key in the text areas in the web UI, make sure they contain no unintended line breaks or additional characters. 70 71 ### SSH Private Key Credential 72 73 Private repositories that require an SSH private key have a URL that typically start with `git@` or `ssh://` rather than `https://`. 74 75 You can configure your Git repository using SSH either using the CLI or the UI. 76 77 !!! note 78 Argo CD 2.4 upgraded to OpenSSH 8.9. OpenSSH 8.8 79 [dropped support for the `ssh-rsa` SHA-1 key signature algorithm](https://www.openssh.com/txt/release-8.8). 80 See the [2.3 to 2.4 upgrade guide](../operator-manual/upgrading/2.3-2.4.md) for details about testing SSH servers 81 for compatibility with Argo CD and for working around servers that do not support newer algorithms. 82 83 Using the CLI: 84 85 ``` 86 argocd repo add git@github.com:argoproj/argocd-example-apps.git --ssh-private-key-path ~/.ssh/id_rsa 87 ``` 88 89 Using the UI: 90 91 1. Navigate to `Settings/Repositories` 92 93  94 95 2. Click `Connect Repo using SSH` button, enter the URL and paste the SSH private key 96 97  98 99 3. Click `Connect` to test the connection and have the repository added 100 101 !!!note 102 When pasting SSH private key in the UI, make sure there are no unintended line breaks or additional characters in the text area 103 104 !!!note 105 When your SSH repository is served from a non-standard port, you have to use `ssh://`-style URLs to specify your repository. The scp-style `git@yourgit.com:yourrepo` URLs do **not** support port specification, and will treat any port number as part of the repository's path. 106 107 ### GitHub App Credential 108 109 Private repositories that are hosted on GitHub.com or GitHub Enterprise can be accessed using credentials from a GitHub Application. Consult the [GitHub documentation](https://docs.github.com/en/developers/apps/about-apps#about-github-apps) on how to create an application. 110 111 !!!note 112 Ensure your application has at least `Read-only` permissions to the `Contents` of the repository. This is the minimum requirement. 113 114 You can configure access to your Git repository hosted by GitHub.com or GitHub Enterprise using the GitHub App method by either using the CLI or the UI. 115 116 Using the CLI: 117 118 ``` 119 argocd repo add https://github.com/argoproj/argocd-example-apps.git --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem 120 ``` 121 122 !!!note 123 To add a private Git repository on GitHub Enterprise using the CLI add `--github-app-enterprise-base-url https://ghe.example.com/api/v3` flag. 124 125 Using the UI: 126 127 1. Navigate to `Settings/Repositories` 128 129  130 131 2. Click `Connect Repo using GitHub App` button, choose type: `GitHub` or `GitHub Enterprise`, enter the URL, App Id, Installation Id, and the app's private key. 132 133 !!!note 134 Enter the GitHub Enterprise Base URL for type `GitHub Enterprise`. 135  136 137 3. Click `Connect` to test the connection and have the repository added 138 139 !!!note 140 When pasting GitHub App private key in the UI, make sure there are no unintended line breaks or additional characters in the text area 141 142 ### Google Cloud Source 143 144 Private repositories hosted on Google Cloud Source can be accessed using Google Cloud service account key in JSON format. Consult [Google Cloud documentation](https://cloud.google.com/iam/docs/creating-managing-service-accounts) on how to create a service account. 145 146 !!!note 147 Ensure your application has at least `Source Repository Reader` permissions for the Google Cloud project. This is the minimum requirement. 148 149 You can configure access to your Git repository hosted on Google Cloud Source using the CLI or the UI. 150 151 Using the CLI: 152 153 ``` 154 argocd repo add https://source.developers.google.com/p/my-google-cloud-project/r/my-repo --gcp-service-account-key-path service-account-key.json 155 ``` 156 157 Using the UI: 158 159 1. Navigate to `Settings/Repositories` 160 161  162 163 2. Click `Connect Repo using Google Cloud Source` button, enter the URL and the Google Cloud service account in JSON format. 164 165  166 167 3. Click `Connect` to test the connection and have the repository added 168 169 170 ### Azure Container Registry/Azure Repos using Azure Workload Identity 171 172 Before using this feature, you must perform the following steps to enable workload identity configuration in Argo CD: 173 174 - **Label the Pods:** Add the `azure.workload.identity/use: "true"` label to the repo-server pods. 175 - **Create Federated Identity Credential:** Generate an Azure federated identity credential for the repo-server service account. Refer to the [Federated Identity Credential](https://azure.github.io/azure-workload-identity/docs/topics/federated-identity-credential.html) documentation for detailed instructions. 176 - **Add Annotation to Service Account:** Add `azure.workload.identity/client-id: "$CLIENT_ID"` annotation to the repo-server service account, using the `CLIENT_ID` from the workload identity. 177 - Setup the permissions for Azure Container Registry/Azure Repos for the workload identity. 178 179 Using CLI for Helm OCI with Azure workload identity: 180 181 ``` 182 argocd repo add contoso.azurecr.io/charts --type helm --enable-oci --use-azure-workload-identity 183 ``` 184 185 Using CLI for Azure Repos with Azure workload identity: 186 187 ``` 188 argocd repo add https://contoso@dev.azure.com/my-projectcollection/my-project/_git/my-repo --use-azure-workload-identity 189 ``` 190 191 Using the UI: 192 193 - Navigate to `Settings/Repositories` 194 195  196 - Click on `+ Connect Repo` 197 - On the connection page: 198 - Choose Connection Method as `VIA HTTPS` 199 - Select the type as `git` or `helm` 200 - Enter the Repository URL 201 - Enter name, if the repo type is helm 202 - Select `Enable OCI`, if repo type is helm 203 - Select `Use Azure Workload Identity` 204 205  206 - Click `Connect` 207 208 Using secret definition: 209 210 ```yaml 211 apiVersion: v1 212 kind: Secret 213 metadata: 214 name: helm-private-repo 215 namespace: argocd 216 labels: 217 argocd.argoproj.io/secret-type: repository 218 stringData: 219 type: helm 220 url: contoso.azurecr.io/charts 221 name: contosocharts 222 enableOCI: "true" 223 useAzureWorkloadIdentity: "true" 224 --- 225 apiVersion: v1 226 kind: Secret 227 metadata: 228 name: git-private-repo 229 namespace: argocd 230 labels: 231 argocd.argoproj.io/secret-type: repository 232 stringData: 233 type: git 234 url: https://contoso@dev.azure.com/my-projectcollection/my-project/_git/my-repo 235 useAzureWorkloadIdentity: "true" 236 ``` 237 238 ## Credential templates 239 240 You can also set up credentials to serve as templates for connecting repositories, without having to repeat credential configuration. For example, if you setup credential templates for the URL prefix `https://github.com/argoproj`, these credentials will be used for all repositories with this URL as prefix (e.g. `https://github.com/argoproj/argocd-example-apps`) that do not have their own credentials configured. 241 242 To set up a credential template using the Web UI, simply fill in all relevant credential information in the __Connect repo using SSH__ or __Connect repo using HTTPS__ dialogues (as described above), but select __Save as credential template__ instead of __Connect__ to save the credential template. Be sure to only enter the prefix URL (i.e. `https://github.com/argoproj`) instead of the complete repository URL (i.e. `https://github.com/argoproj/argocd-example-apps`) in the field __Repository URL__ 243 244 To manage credential templates using the CLI, use the `repocreds` sub-command, for example `argocd repocreds add https://github.com/argoproj --username youruser --password yourpass` would setup a credential template for the URL prefix `https://github.com/argoproj` using the specified username/password combination. Similar to the `repo` sub-command, you can also list and remove repository credentials using the `argocd repocreds list` and `argocd repocreds rm` commands, respectively. 245 246 In order for Argo CD to use a credential template for any given repository, the following conditions must be met: 247 248 * The repository must either not be configured at all, or if configured, must not contain any credential information 249 * The URL configured for a credential template (e.g. `https://github.com/argoproj`) must match as prefix for the repository URL (e.g. `https://github.com/argoproj/argocd-example-apps`). 250 251 !!! note 252 Repositories that require authentication can be added using CLI or Web UI without specifying credentials only after a matching repository credential has been set up 253 254 !!! note 255 Matching credential template URL prefixes is done on a _best match_ effort, so the longest (best) match will take precedence. The order of definition is not important, as opposed to pre v1.4 configuration. 256 257 The following is an example CLI session, depicting repository credential set-up: 258 259 ```bash 260 # Try to add a private repository without specifying credentials, will fail 261 $ argocd repo add https://docker-build/repos/argocd-example-apps 262 FATA[0000] rpc error: code = Unknown desc = authentication required 263 264 # Setup a credential template for all repos under https://docker-build/repos 265 $ argocd repocreds add https://docker-build/repos --username test --password test 266 repository credentials for 'https://docker-build/repos' added 267 268 # Repeat first step, add repo without specifying credentials 269 # URL for template matches, will succeed 270 $ argocd repo add https://docker-build/repos/argocd-example-apps 271 repository 'https://docker-build/repos/argocd-example-apps' added 272 273 # Add another repo under https://docker-build/repos, specifying invalid creds 274 # Will fail, because it will not use the template (has own creds) 275 $ argocd repo add https://docker-build/repos/example-apps-part-two --username test --password invalid 276 FATA[0000] rpc error: code = Unknown desc = authentication required 277 ``` 278 279 ## Self-signed & Untrusted TLS Certificates 280 281 If you are connecting a repository on a HTTPS server using a self-signed certificate, or a certificate signed by a custom Certificate Authority (CA) which are not known to Argo CD, the repository will not be added due to security reasons. This is indicated by an error message such as `x509: certificate signed by unknown authority`. 282 283 1. You can let ArgoCD connect the repository in an insecure way, without verifying the server's certificate at all. This can be accomplished by using the `--insecure-skip-server-verification` flag when adding the repository with the `argocd` CLI utility. However, this should be done only for non-production setups, as it imposes a serious security issue through possible man-in-the-middle attacks. 284 285 2. You can configure ArgoCD to use a custom certificate for the verification of the server's certificate using the `cert add-tls` command of the `argocd` CLI utility. This is the recommended method and suitable for production use. In order to do so, you will need the server's certificate, or the certificate of the CA used to sign the server's certificate, in PEM format. 286 287 !!! note 288 For invalid server certificates, such as those without matching server name, or those that are expired, adding a CA certificate will not help. In this case, your only option will be to use the `--insecure-skip-server-verification` flag to connect the repository. You are strongly urged to use a valid certificate on the repository server, or to urge the server's administrator to replace the faulty certificate with a valid one. 289 290 !!! note 291 TLS certificates are configured on a per-server, not on a per-repository basis. If you connect multiple repositories from the same server, you only have to configure the certificates once for this server. 292 293 !!! note 294 It can take up to a couple of minutes until the changes performed by the `argocd cert` command are propagated across your cluster, depending on your Kubernetes setup. 295 296 ### Managing TLS certificates using the CLI 297 298 You can list all configured TLS certificates by using the `argocd cert list` command using the `--cert-type https` modifier: 299 300 ```bash 301 $ argocd cert list --cert-type https 302 HOSTNAME TYPE SUBTYPE FINGERPRINT/SUBJECT 303 docker-build https rsa CN=ArgoCD Test CA 304 localhost https rsa CN=localhost 305 ``` 306 307 Example for adding a HTTPS repository to ArgoCD without verifying the server's certificate (**Caution:** This is **not** recommended for production use): 308 309 ```bash 310 argocd repo add --insecure-skip-server-verification https://git.example.com/test-repo 311 312 ``` 313 314 Example for adding a CA certificate contained in file `~/myca-cert.pem` to properly verify the repository server: 315 316 ```bash 317 argocd cert add-tls git.example.com --from ~/myca-cert.pem 318 argocd repo add https://git.example.com/test-repo 319 ``` 320 321 You can also add more than one PEM for a server by concatenating them into the input stream. This might be useful if the repository server is about to replace the server certificate, possibly with one signed by a different CA. This way, you can have the old (current) as well as the new (future) certificate co-existing. If you already have the old certificate configured, use the `--upsert` flag and add the old and the new one in a single run: 322 323 ```bash 324 cat cert1.pem cert2.pem | argocd cert add-tls git.example.com --upsert 325 ``` 326 327 !!! note 328 To replace an existing certificate for a server, use the `--upsert` flag to the `cert add-tls` CLI command. 329 330 Finally, TLS certificates can be removed using the `argocd cert rm` command with the `--cert-type https` modifier: 331 332 ```bash 333 argocd cert rm --cert-type https localhost 334 ``` 335 336 ### Managing TLS certificates using the ArgoCD web UI 337 338 It is possible to add and remove TLS certificates using the ArgoCD web UI: 339 340 1. In the navigation pane to the left, click on "Settings" and choose "Certificates" from the settings menu 341 342 2. The following page lists all currently configured certificates and provides you with the option to add either a new TLS certificate or SSH known entries: 343 344  345 346 3. Click on "Add TLS certificate", fill in relevant data and click on "Create". Take care to specify only the FQDN of your repository server (not the URL) and that you C&P the complete PEM of your TLS certificate into the text area field, including the `----BEGIN CERTIFICATE----` and `----END CERTIFICATE----` lines: 347 348  349 350 4. To remove a certificate, click on the small three-dotted button next to the certificate entry, select "Remove" from the pop-up menu and confirm the removal in the following dialogue. 351 352  353 354 ### Managing TLS certificates using declarative configuration 355 356 You can also manage TLS certificates in a declarative, self-managed ArgoCD setup. All TLS certificates are stored in the ConfigMap object `argocd-tls-certs-cm`. 357 Please refer to the [Operator Manual](../../operator-manual/declarative-setup/#repositories-using-self-signed-tls-certificates-or-are-signed-by-custom-ca) for more information. 358 359 ## Unknown SSH Hosts 360 361 If you are using a privately hosted Git service over SSH, then you have the following options: 362 363 1. You can let ArgoCD connect the repository in an insecure way, without verifying the server's SSH host key at all. This can be accomplished by using the `--insecure-skip-server-verification` flag when adding the repository with the `argocd` CLI utility. However, this should be done only for non-production setups, as it imposes a serious security issue through possible man-in-the-middle attacks. 364 365 2. You can make the server's SSH public key known to ArgoCD by using the `cert add-ssh` command of the `argocd` CLI utility. This is the recommended method and suitable for production use. In order to do so, you will need the server's SSH public host key, in the `known_hosts` format understood by `ssh`. You can get the server's public SSH host key e.g. by using the `ssh-keyscan` utility. 366 367 !!! note 368 It can take up to a couple of minutes until the changes performed by the `argocd cert` command are propagated across your cluster, depending on your Kubernetes setup. 369 370 !!! note 371 When importing SSH known hosts key from a `known_hosts` file, the hostnames or IP addresses in the input data must **not** be hashed. If your `known_hosts` file contains hashed entries, it cannot be used as input source for adding SSH known hosts - neither in the CLI nor in the UI. If you absolutely wish to use hashed known hosts data, the only option will be using declarative setup (see below). Be aware that this will break CLI and UI certificate management, so it is generally not recommended. 372 373 ### Managing SSH Known Hosts using the CLI 374 375 You can list all configured SSH known host entries using the `argocd cert list` command with the `--cert-type ssh` modifier: 376 377 ```bash 378 $ argocd cert list --cert-type ssh 379 HOSTNAME TYPE SUBTYPE FINGERPRINT/SUBJECT 380 bitbucket.org ssh ssh-rsa SHA256:46OSHA1Rmj8E8ERTC6xkNcmGOw9oFxYr0WF6zWW8l1E 381 github.com ssh ssh-rsa SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s 382 gitlab.com ssh ecdsa-sha2-nistp256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw 383 gitlab.com ssh ssh-ed25519 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 384 gitlab.com ssh ssh-rsa SHA256:ROQFvPThGrW4RuWLoL9tq9I9zJ42fK4XywyRtbOz/EQ 385 ssh.dev.azure.com ssh ssh-rsa SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og 386 vs-ssh.visualstudio.com ssh ssh-rsa SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og 387 ``` 388 389 For adding SSH known host entries, the `argocd cert add-ssh` command can be used. You can either add from a file (using the `--from <file>` modifier), or by reading `stdin` when the `--batch` modifier was specified. In both cases, input must be in `known_hosts` format as understood by the OpenSSH client. 390 391 Example for adding all available SSH public host keys for a server to ArgoCD, as collected by `ssh-keyscan`: 392 393 ```bash 394 ssh-keyscan server.example.com | argocd cert add-ssh --batch 395 396 ``` 397 398 Example for importing an existing `known_hosts` file to ArgoCD: 399 400 ```bash 401 argocd cert add-ssh --batch --from /etc/ssh/ssh_known_hosts 402 ``` 403 404 Finally, SSH known host entries can be removed using the `argocd cert rm` command with the `--cert-type ssh` modifier: 405 406 ```bash 407 argocd cert rm bitbucket.org --cert-type ssh 408 ``` 409 410 If you have multiple SSH known host entries for a given host with different key sub-types (e.g. as for gitlab.com in the example above, there are keys of sub-types `ssh-rsa`, `ssh-ed25519` and `ecdsa-sha2-nistp256`) and you want to only remove one of them, you can further narrow down the selection using the `--cert-sub-type` modifier: 411 412 ```bash 413 argocd cert rm gitlab.com --cert-type ssh --cert-sub-type ssh-ed25519 414 ``` 415 416 ### Managing SSH known hosts data using the ArgoCD web UI 417 418 It is possible to add and remove SSH known hosts entries using the ArgoCD web UI: 419 420 1. In the navigation pane to the left, click on "Settings" and choose "Certificates" from the settings menu 421 422 2. The following page lists all currently configured certificates and provides you with the option to add either a new TLS certificate or SSH known entries: 423 424  425 426 3. Click on "Add SSH known hosts" and paste your SSH known hosts data in the following mask. **Important**: Make sure there are no line breaks in the entries (key data) when you paste the data. Afterwards, click on "Create". 427 428  429 430 4. To remove a certificate, click on the small three-dotted button next to the certificate entry, select "Remove" from the pop-up menu and confirm the removal in the following dialogue. 431 432  433 434 ### Managing SSH known hosts data using declarative setup 435 436 You can also manage SSH known hosts entries in a declarative, self-managed ArgoCD setup. All SSH public host keys are stored in the ConfigMap object `argocd-ssh-known-hosts-cm`. For more details, please refer to the [Operator Manual](../operator-manual/declarative-setup.md#ssh-known-host-public-keys). 437 438 ## Helm 439 440 Helm charts can be sourced from protected Helm repositories or OCI registries. You can configure access to protected Helm charts by using either the CLI or the UI by speciying `helm` as the _type_ of HTTPS based repository. 441 442 Using the CLI: 443 444 Specify the `--type` flag of the `argocd repo add` command: 445 446 ```bash 447 argocd repo add https://argoproj.github.io/argo-helm --type=helm <additional-flags> 448 ``` 449 450 Using the UI: 451 452 1. Navigate to `Settings/Repositories` 453 454  455 456 2. Click the `Connect Repo` button 457 458 3. Select `VIA HTTPS` as the Connection Method 459 460 4. Select `helm` as the Type. 461 462  463 464 5. Click `Connect` to test the connection and have the repository added 465 466 Helm charts stored in protected OCI registries should use the steps described previously as well as explicitly specifying that the source is an Helm chart stored in an OCI registry. 467 468 Using CLI: 469 470 Specify the `--enable-oci` flag of the `argocd repo add` command: 471 472 ```bash 473 argocd repo add registry-1.docker.io/bitnamicharts --type=helm --enable-oci=true <additional-flags> 474 ``` 475 476 !!! note 477 The protocol, such as `oci://` should be omitted when referencing an OCI registry 478 479 Using the UI: 480 481 Select the _Enable OCI_ checkbox when adding a HTTPS based _helm_ repository. 482 483 ## Git Submodules 484 485 Submodules are supported and will be picked up automatically. If the submodule repository requires authentication then the credentials will need to match the credentials of the parent repository. Set ARGOCD_GIT_MODULES_ENABLED=false to disable submodule support 486 487 ## Declarative Configuration 488 489 See [declarative setup](../operator-manual/declarative-setup.md#repositories) 490