Skip to content

Commit 71119f8

Browse files
authored
feat: support GitHub App authentication (#1988)
Adds support for using GitHub Apps as a form of authentication
1 parent 2712e2e commit 71119f8

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

cmd/proxy/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ RUN chmod 644 /config/config.toml
4343
# Add tini, see https://github.com/gomods/athens/issues/1155 for details.
4444
RUN apk add --update git git-lfs mercurial openssh-client subversion procps fossil tini
4545

46+
# Add git-credential-github-app for native integration with GitHub Apps
47+
RUN wget -O git-credential-github-app.tar.gz https://github.com/bdellegrazie/git-credential-github-app/releases/download/v0.3.0/git-credential-github-app_v0.2.0_Linux_x86_64.tar.gz \
48+
&& tar xvzf 'git-credential-github-app.tar.gz' git-credential-github-app -C /usr/local/bin \
49+
&& rm git-credential-github-app.tar.gz || true;
50+
4651
ARG USER=athens
4752
RUN adduser -D -h /home/$USER $USER
4853

docs/content/configuration/authentication.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,49 @@ $ docker run --rm -d \
308308
-e "SSH_AUTH_SOCK=/.ssh_agent_sock" \
309309
-e ATHENS_DISK_STORAGE_ROOT=/var/lib/athens -e ATHENS_STORAGE_TYPE=disk --name athens-proxy -p 3000:3000 gomods/athens:canary
310310
```
311+
312+
## GitHub Apps
313+
314+
Instead of using a Machine User on GitHub, it is possible to create a GitHub App and authenticate via it.
315+
316+
Create a GitHub App in **Settings > Developer settings > GitHub Apps** and install it. The AppID/ClientID, Installation ID and Private Key are
317+
required from the App.
318+
319+
Install the [GitHub App Git Credential Helper](https://github.com/bdellegrazie/git-credential-github-app) in your `$PATH`. The Athens Docker image comes
320+
with this pre-installed.
321+
322+
Configure your [global Git config](https://git-scm.com/docs/git-config) as follows:
323+
324+
```
325+
[credential "https://github.com/your-org"]
326+
helper = "github-app -username <app-name> -appId <app-id> -privateKeyFile <path-to-private-key> -installationId <installation-id>"
327+
useHttpPath = true
328+
329+
[credential "https://github.com"]
330+
helper = "cache --timeout=3600"
331+
332+
[url "https://github.com"]
333+
insteadOf = ssh://[email protected]
334+
```
335+
336+
This instructs Git to authenticate with the GitHub App and cache the results for 3600s (the authentication token is valid for 1 hour).
337+
338+
Now, builds executed through the Athens proxy should be able to clone the `github.com/your-org/your-repo` dependency over GitHub Apps.
339+
340+
### GitHub Enterprise Self-hosted
341+
342+
To authenticate against a self-hosted GitHub Enterprise, the instructions are the same for GitHub hosted Apps
343+
with the exception for the Git config, which should include your domain, as follows:
344+
345+
```
346+
[credential "https://github.example.com/your-org"]
347+
helper = "github-app -username <app-name> -appId <app-id> -privateKeyFile <path-to-private-key> -installationId <installation-id> -domain github.example.com"
348+
useHttpPath = true
349+
350+
[credential "https://github.example.com"]
351+
helper = "cache --timeout=3600"
352+
353+
[url "https://github.example.com"]
354+
insteadOf = ssh://[email protected]
355+
```
356+

0 commit comments

Comments
 (0)