github.com/argoproj/argo-cd/v2@v2.10.5/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 understood. 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 Using the UI: 123 124 1. Navigate to `Settings/Repositories` 125 126  127 128 2. Click `Connect Repo using GitHub App` button, enter the URL, App Id, Installation Id, and the app's private key. 129 130  131 132 3. Click `Connect` to test the connection and have the repository added 133 134 !!!note 135 When pasting GitHub App private key in the UI, make sure there are no unintended line breaks or additional characters in the text area 136 137 ### Google Cloud Source 138 139 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. 140 141 !!!note 142 Ensure your application has at least `Source Repository Reader` permissions for the Google Cloud project. This is the minimum requirement. 143 144 You can configure access to your Git repository hosted on Google Cloud Source using the CLI or the UI. 145 146 Using the CLI: 147 148 ``` 149 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 150 ``` 151 152 Using the UI: 153 154 1. Navigate to `Settings/Repositories` 155 156  157 158 2. Click `Connect Repo using Google Cloud Source` button, enter the URL and the Google Cloud service account in JSON format. 159 160  161 162 3. Click `Connect` to test the connection and have the repository added 163 164 ## Credential templates 165 166 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. 167 168 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__ 169 170 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. 171 172 In order for Argo CD to use a credential template for any given repository, the following conditions must be met: 173 174 * The repository must either not be configured at all, or if configured, must not contain any credential information 175 * 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`). 176 177 !!! note 178 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 179 180 !!! note 181 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. 182 183 The following is an example CLI session, depicting repository credential set-up: 184 185 ```bash 186 # Try to add a private repository without specifying credentials, will fail 187 $ argocd repo add https://docker-build/repos/argocd-example-apps 188 FATA[0000] rpc error: code = Unknown desc = authentication required 189 190 # Setup a credential template for all repos under https://docker-build/repos 191 $ argocd repocreds add https://docker-build/repos --username test --password test 192 repository credentials for 'https://docker-build/repos' added 193 194 # Repeat first step, add repo without specifying credentials 195 # URL for template matches, will succeed 196 $ argocd repo add https://docker-build/repos/argocd-example-apps 197 repository 'https://docker-build/repos/argocd-example-apps' added 198 199 # Add another repo under https://docker-build/repos, specifying invalid creds 200 # Will fail, because it will not use the template (has own creds) 201 $ argocd repo add https://docker-build/repos/example-apps-part-two --username test --password invalid 202 FATA[0000] rpc error: code = Unknown desc = authentication required 203 ``` 204 205 ## Self-signed & Untrusted TLS Certificates 206 207 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`. 208 209 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. 210 211 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. 212 213 !!! note 214 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. 215 216 !!! note 217 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. 218 219 !!! note 220 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. 221 222 ### Managing TLS certificates using the CLI 223 224 You can list all configured TLS certificates by using the `argocd cert list` command using the `--cert-type https` modifier: 225 226 ```bash 227 $ argocd cert list --cert-type https 228 HOSTNAME TYPE SUBTYPE FINGERPRINT/SUBJECT 229 docker-build https rsa CN=ArgoCD Test CA 230 localhost https rsa CN=localhost 231 ``` 232 233 Example for adding a HTTPS repository to ArgoCD without verifying the server's certificate (**Caution:** This is **not** recommended for production use): 234 235 ```bash 236 argocd repo add --insecure-skip-server-verification https://git.example.com/test-repo 237 238 ``` 239 240 Example for adding a CA certificate contained in file `~/myca-cert.pem` to properly verify the repository server: 241 242 ```bash 243 argocd cert add-tls git.example.com --from ~/myca-cert.pem 244 argocd repo add https://git.example.com/test-repo 245 ``` 246 247 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: 248 249 ```bash 250 cat cert1.pem cert2.pem | argocd cert add-tls git.example.com --upsert 251 ``` 252 253 !!! note 254 To replace an existing certificate for a server, use the `--upsert` flag to the `cert add-tls` CLI command. 255 256 Finally, TLS certificates can be removed using the `argocd cert rm` command with the `--cert-type https` modifier: 257 258 ```bash 259 argocd cert rm --cert-type https localhost 260 ``` 261 262 ### Managing TLS certificates using the ArgoCD web UI 263 264 It is possible to add and remove TLS certificates using the ArgoCD web UI: 265 266 1. In the navigation pane to the left, click on "Settings" and choose "Certificates" from the settings menu 267 268 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: 269 270  271 272 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: 273 274  275 276 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. 277 278  279 280 ### Managing TLS certificates using declarative configuration 281 282 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`. 283 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. 284 285 ## Unknown SSH Hosts 286 287 If you are using a privately hosted Git service over SSH, then you have the following options: 288 289 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. 290 291 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. 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 !!! note 297 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. 298 299 ### Managing SSH Known Hosts using the CLI 300 301 You can list all configured SSH known host entries using the `argocd cert list` command with the `--cert-type ssh` modifier: 302 303 ```bash 304 $ argocd cert list --cert-type ssh 305 HOSTNAME TYPE SUBTYPE FINGERPRINT/SUBJECT 306 bitbucket.org ssh ssh-rsa SHA256:46OSHA1Rmj8E8ERTC6xkNcmGOw9oFxYr0WF6zWW8l1E 307 github.com ssh ssh-rsa SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s 308 gitlab.com ssh ecdsa-sha2-nistp256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw 309 gitlab.com ssh ssh-ed25519 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 310 gitlab.com ssh ssh-rsa SHA256:ROQFvPThGrW4RuWLoL9tq9I9zJ42fK4XywyRtbOz/EQ 311 ssh.dev.azure.com ssh ssh-rsa SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og 312 vs-ssh.visualstudio.com ssh ssh-rsa SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og 313 ``` 314 315 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. 316 317 Example for adding all available SSH public host keys for a server to ArgoCD, as collected by `ssh-keyscan`: 318 319 ```bash 320 ssh-keyscan server.example.com | argocd cert add-ssh --batch 321 322 ``` 323 324 Example for importing an existing `known_hosts` file to ArgoCD: 325 326 ```bash 327 argocd cert add-ssh --batch --from /etc/ssh/ssh_known_hosts 328 ``` 329 330 Finally, SSH known host entries can be removed using the `argocd cert rm` command with the `--cert-type ssh` modifier: 331 332 ```bash 333 argocd cert rm bitbucket.org --cert-type ssh 334 ``` 335 336 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: 337 338 ```bash 339 argocd cert rm gitlab.com --cert-type ssh --cert-sub-type ssh-ed25519 340 ``` 341 342 ### Managing SSH known hosts data using the ArgoCD web UI 343 344 It is possible to add and remove SSH known hosts entries using the ArgoCD web UI: 345 346 1. In the navigation pane to the left, click on "Settings" and choose "Certificates" from the settings menu 347 348 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: 349 350  351 352 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". 353 354  355 356 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. 357 358  359 360 ### Managing SSH known hosts data using declarative setup 361 362 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). 363 364 ## Git Submodules 365 366 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 367 368 ## Declarative Configuration 369 370 See [declarative setup](../operator-manual/declarative-setup.md#repositories) 371