Skip to content

Commit 9b55796

Browse files
committed
Refactor Bootstrap GitHub docs
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent bafbb66 commit 9b55796

File tree

1 file changed

+101
-30
lines changed
  • content/en/flux/installation/bootstrap

1 file changed

+101
-30
lines changed
Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,148 @@
11
---
22
title: GitHub and GitHub Enterprise
33
linkTitle: GitHub
4-
description: "How to bootstrap Flux with GitHub"
4+
description: "How to bootstrap Flux with GitHub and GitHub Enterprise"
55
weight: 20
66
---
77

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.
1210

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.
1813

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:
2026

2127
```sh
22-
export GITHUB_TOKEN=<your-token>
28+
export GITHUB_TOKEN=<gh-token>
2329
```
2430

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+
2544
Run the bootstrap for a repository on your personal GitHub account:
2645

2746
```sh
2847
flux bootstrap github \
48+
--token-auth \
2949
--owner=my-github-username \
30-
--repository=my-repository \
50+
--repository=my-repository-name \
51+
--branch=main \
3152
--path=clusters/my-cluster \
3253
--personal
3354
```
3455

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).
4066
{{% /alert %}}
4167

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+
4277
Run the bootstrap for a repository owned by a GitHub organization:
4378

4479
```sh
4580
flux bootstrap github \
81+
--token-auth \
4682
--owner=my-github-organization \
4783
--repository=my-repository \
48-
--team=team1-slug \
49-
--team=team2-slug \
84+
--branch=main \
5085
--path=clusters/my-cluster
5186
```
5287

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
5492

5593
To run the bootstrap for a repository hosted on GitHub Enterprise, you have to specify your GitHub hostname:
5694

5795
```sh
5896
flux bootstrap github \
97+
--token-auth \
5998
--hostname=my-github-enterprise.com \
60-
--ssh-hostname=my-github-enterprise.com \
6199
--owner=my-github-organization \
62100
--repository=my-repository \
63101
--branch=main \
64102
--path=clusters/my-cluster
65103
```
66104

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`.
68107

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> \
76142
--path=clusters/my-cluster
77143
```
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

Comments
 (0)