Skip to content

Commit 0e2e0f0

Browse files
rissetthockin
authored andcommitted
Add support for GitHub app authentication
Signed-off-by: Liam Wyllie <[email protected]>
1 parent 69d2395 commit 0e2e0f0

32 files changed

+2584
-14
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,29 @@ OPTIONS
313313
- off: Disable explicit git garbage collection, which may be a good
314314
fit when also using --one-time.
315315
316+
--github-base-url <string>, $GITSYNC_GITHUB_BASE_URL
317+
The GitHub base URL to use in GitHub requests when GitHub app
318+
authentication is used. If not specified, defaults to
319+
https://api.github.com/.
320+
321+
--github-app-private-key-file <string>, $GITSYNC_GITHUB_APP_PRIVATE_KEY_FILE
322+
The file from which the private key to use for GitHub app
323+
authentication will be read.
324+
325+
--github-app-installation-id <int>, $GITSYNC_GITHUB_APP_INSTALLATION_ID
326+
The installation ID of the GitHub app used for GitHub app
327+
authentication.
328+
329+
--github-app-application-id <int>, $GITSYNC_GITHUB_APP_APPLICATION_ID
330+
The app ID of the GitHub app used for GitHub app authentication.
331+
One of --github-app-application-id or --github-app-client-id is required
332+
when GitHub app authentication is used.
333+
334+
--github-app-client-id <int>, $GITSYNC_GITHUB_APP_CLIENT_ID
335+
The client ID of the GitHub app used for GitHub app authentication.
336+
One of --github-app-application-id or --github-app-client-id is required
337+
when GitHub app authentication is used.
338+
316339
--group-write, $GITSYNC_GROUP_WRITE
317340
Ensure that data written to disk (including the git repo metadata,
318341
checked out files, worktrees, and symlink) are all group writable.
@@ -529,6 +552,23 @@ AUTHENTICATION
529552
When --cookie-file ($GITSYNC_COOKIE_FILE) is specified, the
530553
associated cookies can contain authentication information.
531554
555+
github app
556+
When --github-app-private-key-file ($GITSYNC_GITHUB_APP_PRIVATE_KEY_FILE),
557+
--github-app-application-id ($GITSYNC_GITHUB_APP_APPLICATION_ID) or
558+
--github-app-client-id ($GITSYNC_GITHUB_APP_CLIENT_ID)
559+
and --github-app-installation_id ($GITSYNC_GITHUB_APP_INSTALLATION_ID)
560+
are specified, GitHub app authentication will be used.
561+
562+
These credentials are used to request a short-lived token which
563+
is used for authentication. The base URL of the GitHub request made
564+
to retrieve the token can also be specified via
565+
--github-base-url ($GITSYNC_GITHUB_BASE_URL), which defaults to
566+
https://api.github.com/.
567+
568+
The GitHub app must have sufficient access to the repository to sync.
569+
It should be installed to the repository or organization containing
570+
the repository, and given read access (see github docs).
571+
532572
HOOKS
533573
534574
Webhooks and exechooks are executed asynchronously from the main git-sync
@@ -547,3 +587,4 @@ HOOKS
547587
if a hook fails and a new hash is synced during the backoff period, the
548588
retried hook will fire for the newest hash.
549589
```
590+

docs/dev/testing_github_app_auth.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Testing GitHub app auth
2+
3+
## Step 1: Create and install a dummy GitHub app for testing with
4+
5+
Go to https://github.com/settings/apps/new
6+
7+
1. Enter a name for the app (needs to be unique across GitHub).
8+
2. Set the required `homepage URL` field (can be any valid URL).
9+
3. Under `Webhook`, uncheck the `Active` checkbox.
10+
4. Click on `Repository permissions` under `Permissions`, and set `Contents` to `Read-only`
11+
5. Click on `Create GitHub App` at the bottom of the page.
12+
6. You should be navigated to a new page with a `Registration successful. You must generate a private key in order to install your GitHub App.` message. Click on the `generate a private key` link, and then the `Generate a private key` button, and save it somewhere; it will be used to test the app authentication.
13+
7. Click on the `Install App` tab on the left, and then click on `Install` on the right.
14+
8. Select `Only select repositories`, and pick any private repository that contains a "LICENSE" file (may need to be created beforehand).
15+
16+
## Step 2: Export the necessary environment variables
17+
18+
The following environment variables are *required* to run the git-sync github app auth tests:
19+
- `GITHUB_APP_PRIVATE_KEY`
20+
- `GITHUB_APP_APPLICATION_ID`
21+
- `GITHUB_APP_CLIENT_ID`
22+
- `GITHUB_APP_INSTALLATION_ID`
23+
- `GITHUB_APP_AUTH_TEST_REPO`
24+
25+
### GITHUB_APP_PRIVATE_KEY
26+
Should have been saved when creating the app
27+
28+
### GITHUB_APP_APPLICATION_ID
29+
The value after "App ID" in the app's settings page
30+
31+
### GITHUB_APP_CLIENT_ID
32+
The value after "Client ID" in the app's settings page
33+
34+
### GITHUB_APP_INSTALLATION_ID
35+
Found in the URL of the app's installation page if you installed it to a repository: https://github.com/settings/installations/<installation_id>
36+
37+
### GITHUB_APP_AUTH_TEST_REPO
38+
Should be set to the repository that the github app is installed to.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module k8s.io/git-sync
22

33
require (
44
github.com/go-logr/logr v1.2.3
5+
github.com/golang-jwt/jwt/v4 v4.5.0
56
github.com/prometheus/client_golang v1.14.0
67
github.com/spf13/pflag v1.0.5
78
go.uber.org/goleak v1.2.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
7373
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
7474
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
7575
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
76+
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
77+
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
7678
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
7779
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
7880
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=

0 commit comments

Comments
 (0)