|
1 | 1 | --- |
2 | 2 | title: GitHub and GitHub Enterprise |
3 | 3 | linkTitle: GitHub |
4 | | -description: "How to bootstrap Flux with GitHub" |
| 4 | +description: "How to bootstrap Flux with GitHub and GitHub Enterprise" |
5 | 5 | weight: 20 |
6 | 6 | --- |
7 | 7 |
|
8 | | -The `bootstrap github` command creates a GitHub repository if one doesn't exist and |
9 | | -commits the Flux components manifests to specified branch. Then it |
10 | | -configures the target cluster to synchronize with that repository by |
11 | | -setting up an SSH deploy key or by using token-based authentication. |
| 8 | +The [flux bootstrap github](/flux/cmd/flux_bootstrap_github/) command deploys the Flux controllers |
| 9 | +on a Kubernetes cluster and configures the controllers to sync the cluster state from a GitHub repository. |
12 | 10 |
|
13 | | -Generate a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) |
14 | | -(PAT) that can create repositories by checking all permissions under `repo`. If |
15 | | -a pre-existing repository is to be used the PAT's user will require `admin` |
16 | | -[permissions](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-roles-for-an-organization#permissions-for-each-role) |
17 | | -on the repository in order to create a deploy key. |
| 11 | +Besides installing the controllers, the bootstrap command pushes the Flux manifests to the GitHub repository |
| 12 | +and configures Flux to update itself from Git. |
18 | 13 |
|
19 | | -Export your GitHub personal access token as an environment variable: |
| 14 | +{{% alert color="danger" title="Required permissions" %}} |
| 15 | +To bootstrap Flux, the person running the command must have **cluster admin rights** for the target Kubernetes cluster. |
| 16 | +It is also required that the person running the command to be the **owner** of the GitHub repository, |
| 17 | +or to have admin rights of a GitHub organization. |
| 18 | +{{% /alert %}} |
| 19 | + |
| 20 | +## GitHub PAT |
| 21 | + |
| 22 | +For accessing the GitHub API, the boostrap command requires a GitHub personal access token (PAT) |
| 23 | +with **admin permission**. |
| 24 | + |
| 25 | +The GitHub PAT can be exported as an environment variable: |
20 | 26 |
|
21 | 27 | ```sh |
22 | | -export GITHUB_TOKEN=<your-token> |
| 28 | +export GITHUB_TOKEN=<gh-token> |
23 | 29 | ``` |
24 | 30 |
|
| 31 | +If the `GITHUB_TOKEN` env var is not set, the bootstrap command will promote you to type it the token. |
| 32 | + |
| 33 | +You can also supply the token using a pipe e.g. `echo "<gh-token>" | flux bootstrap github`. |
| 34 | + |
| 35 | +## GitHub Personal Account |
| 36 | + |
| 37 | +If you want to bootstrap Flux for a repository owned by a personal account, you can generate a |
| 38 | +[GitHub PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) |
| 39 | +that can create repositories by checking all permissions under `repo`. |
| 40 | + |
| 41 | +If you want to use an existing repository, the PAT's user must have `admin` |
| 42 | +[permissions](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-roles-for-an-organization#permissions-for-each-role). |
| 43 | + |
25 | 44 | Run the bootstrap for a repository on your personal GitHub account: |
26 | 45 |
|
27 | 46 | ```sh |
28 | 47 | flux bootstrap github \ |
| 48 | + --token-auth \ |
29 | 49 | --owner=my-github-username \ |
30 | | - --repository=my-repository \ |
| 50 | + --repository=my-repository-name \ |
| 51 | + --branch=main \ |
31 | 52 | --path=clusters/my-cluster \ |
32 | 53 | --personal |
33 | 54 | ``` |
34 | 55 |
|
35 | | -{{% alert color="info" title="Deploy key" %}} |
36 | | -The bootstrap command creates an SSH key which it stores as a secret in the |
37 | | -Kubernetes cluster. The key is also used to create a deploy key in the GitHub |
38 | | -repository. The new deploy key will be linked to the personal access token used |
39 | | -to authenticate. **Removing the personal access token will also remove the deploy key.** |
| 56 | +If the specified repository does not exist, Flux will create it for you as private. If you wish to create |
| 57 | +a public repository, set `--private=false`. |
| 58 | + |
| 59 | +When using `--token-auth`, the CLI and the Flux controllers running on the cluster will use the GitHub PAT |
| 60 | +to access the Git repository over HTTPS. |
| 61 | + |
| 62 | +{{% alert color="danger" title="PAT secret" %}} |
| 63 | +Note that the GitHub PAT is stored in the cluster as a **Kubernetes Secret** named `flux-system` |
| 64 | +inside the `flux-system` namespace. If you want to avoid storing your PAT in the cluster, |
| 65 | +please see how to configure [GitHub Deploy Keys](#github-deploy-keys). |
40 | 66 | {{% /alert %}} |
41 | 67 |
|
| 68 | +## GitHub Organization |
| 69 | + |
| 70 | +If you want to bootstrap Flux for a repository owned by an GitHub organization, |
| 71 | +it is recommended to creat a dedicated user for Flux under your organization. |
| 72 | + |
| 73 | +Generate a GitHub PAT for the Flux user that can create repositories by checking all permissions under `repo`. |
| 74 | + |
| 75 | +If you want to use an existing repository, the Flux user must have `admin` permissions for that repository. |
| 76 | + |
42 | 77 | Run the bootstrap for a repository owned by a GitHub organization: |
43 | 78 |
|
44 | 79 | ```sh |
45 | 80 | flux bootstrap github \ |
| 81 | + --token-auth \ |
46 | 82 | --owner=my-github-organization \ |
47 | 83 | --repository=my-repository \ |
48 | | - --team=team1-slug \ |
49 | | - --team=team2-slug \ |
| 84 | + --branch=main \ |
50 | 85 | --path=clusters/my-cluster |
51 | 86 | ``` |
52 | 87 |
|
53 | | -When you specify a list of teams, those teams will be granted maintainer access to the repository. |
| 88 | +When creating a new repository, you can specify a list of GitHub teams with `--team=team1-slug,team2-slug`, |
| 89 | +those teams will be granted maintainer access to the repository. |
| 90 | + |
| 91 | +## GitHub Enterprise |
54 | 92 |
|
55 | 93 | To run the bootstrap for a repository hosted on GitHub Enterprise, you have to specify your GitHub hostname: |
56 | 94 |
|
57 | 95 | ```sh |
58 | 96 | flux bootstrap github \ |
| 97 | + --token-auth \ |
59 | 98 | --hostname=my-github-enterprise.com \ |
60 | | - --ssh-hostname=my-github-enterprise.com \ |
61 | 99 | --owner=my-github-organization \ |
62 | 100 | --repository=my-repository \ |
63 | 101 | --branch=main \ |
64 | 102 | --path=clusters/my-cluster |
65 | 103 | ``` |
66 | 104 |
|
67 | | -If your GitHub Enterprise has SSH access disabled, you can use HTTPS and token authentication with: |
| 105 | +If you want use SSH and [GitHub deploy keys](#github-deploy-keys), |
| 106 | +set `--token-auth=false` and provide the SSH hostname with `--ssh-hostname=my-github-enterprise.com`. |
68 | 107 |
|
69 | | -```sh |
70 | | -flux bootstrap github \ |
71 | | - --token-auth \ |
72 | | - --hostname=my-github-enterprise.com \ |
73 | | - --owner=my-github-organization \ |
74 | | - --repository=my-repository \ |
75 | | - --branch=main \ |
| 108 | +## GitHub Deploy Keys |
| 109 | + |
| 110 | +If you want to bootstrap Flux using SSH instead of HTTP/S, you can set `--token-auth=false` and the Flux CLI |
| 111 | +will use the GitHub PAT to set a deploy key for your repository. |
| 112 | + |
| 113 | +When using SSH, the bootstrap command will generate a SSH private key. The private key is stored |
| 114 | +in the cluster as a Kubernetes secret named `flux-system` inside the `flux-system` namespace. |
| 115 | + |
| 116 | +The generated SSH key defaults to `ECDSA P-384`, to change the format use `--ssh-key-algorithm` and `--ssh-ecdsa-curve`. |
| 117 | + |
| 118 | +The SSH public key, is used to create a GitHub deploy key. |
| 119 | +The deploy key is linked to the personal access token used to authenticate. |
| 120 | + |
| 121 | +By default, the GitHub deploy key is set to read-only access. |
| 122 | +If you're using Flux image automation, you must give it write access with `--read-write-key=true`. |
| 123 | + |
| 124 | +{{% alert color="info" title="Deploy Key rotation" %}} |
| 125 | +Note that when the PAT is removed or when it expires, the GitHub deploy key will stop working. |
| 126 | +To regenerate the deploy key, delete the `flux-system` secret from the cluster and re-run |
| 127 | +the bootstrap command using a valid GitHub PAT. |
| 128 | +{{% /alert %}} |
| 129 | + |
| 130 | +## Bootstrap without a GitHub PAT |
| 131 | + |
| 132 | +For existing GitHub repositories, you can bootstrap Flux over SSH without using a GitHub PAT. |
| 133 | + |
| 134 | +To use a SSH key instead of a GitHub PAT, the command changes to `flux bootstrap git`: |
| 135 | + |
| 136 | +```shell |
| 137 | +flux bootstrap git \ |
| 138 | + --url=ssh://git@github.com/<org>/<repository> \ |
| 139 | + --branch=<my-branch> \ |
| 140 | + --private-key-file=<path/to/ssh/private.key> \ |
| 141 | + --password=<key-passphrase> \ |
76 | 142 | --path=clusters/my-cluster |
77 | 143 | ``` |
| 144 | + |
| 145 | +**Note** that you must generate a SSH private key and set the public key as a deploy key on GitHub in advance. |
| 146 | + |
| 147 | +For more information on how to use the `flux bootstrap git` command, |
| 148 | +please see the generic Git server [documentation](generic-git-server.md). |
0 commit comments