Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Cognito Proxy for Github #7014

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

soceanainn
Copy link
Contributor

@soceanainn soceanainn commented Dec 12, 2023

Summary

Github / Netlify seats are expensive. Creating an authenticated proxy of the Github API using AWS Cognito is very cost effective (if less performant due to nature of proxying).

This was solved by introducing a new aws-cognito-github-proxy backend that shims the github backend. The authentication page is generic and uses the existing PKCE authenticator for AWS Cognito login.

Some actions will not be available to the proxied bot user (e.g. forking repos). Avatar URL for logged in user defaults to the repo owner avatar in Github.

The changes required in existing packages to achieve this goal were as follows:

  1. Update PKCE authenticator to accept auth_token_endpoint_content_type as input (AWS Cognito requires application/x-www-form-urlencoded, existing implementations for gitea / gitlab use application/json). Also make redirect_uri configurable.
  2. Update Github API to make 'tokenKeyword' configurable. Github uses token for JWTs (and sometimes allows use of Bearer), AWS Cognito uses Bearer at all times.
  3. Allow bypassing 'writeAccess' check for proxy. This is because Github App tokens are different from class user / Oauth app tokens in Github, and will never have explicit push permissions for the repository.
  4. Centralize getUser()/currentUser()/user() calls (fetching user information from Github or alternate sources) and make that configurable (so we can pass from 'backend' implementation into 'API' implementation and override for Git Gateway / Cognito proxy).
  5. Allow passing base_url (authorization base URL) around in Github backend + API, so we can use this to fetch info from AWS Cognito for aws-cognito-github-proxy. Existing docs / code sometimes put this field in backend configuration, sometimes it's a top level line item. I went with documented location (backend config) instead of where it was specified in typescript (meaning it's now present in two locations there).
  6. Export GitHubUser type so we can cast custom object to it. This seems like the wrong type to be using across Github backend/API - the User interface is probably better but that is a large refactoring than I wanted to do with feature changes.

Test plan

I built this using yarn run build then copied it into my private repo. I tested the full log-in flow and the editorial workflow for simple changes to some pages.

Specific backend configuration for this new backend (ignoring shared Github options) is something like:

  name: aws-cognito-github-proxy
  base_url: https://cognito.example.com
  app_id: {{ COGNITO CLIENT ID }}
  api_root: {{ GITHUB API PROXY URL }}

Detailed examples of the proxy I created to run this, and on setting this up using AWS Cloudformation are visible in this repo:
https://github.com/gael-cms/aws-cognito-github-proxy

Checklist

Please add a x inside each checkbox:

Copy link

netlify bot commented Dec 12, 2023

‼️ Deploy request for cms-demo rejected.

Name Link
🔨 Latest commit e978f0e

Copy link

netlify bot commented Dec 12, 2023

Deploy Preview for decap-www canceled.

Name Link
🔨 Latest commit 4a3b90c
🔍 Latest deploy log https://app.netlify.com/sites/decap-www/deploys/65b8f796b199c20008d19084

@soceanainn soceanainn force-pushed the gael-cms/aws-cognito-support branch 2 times, most recently from c144ba6 to e978f0e Compare December 13, 2023 12:19
demshy
demshy previously approved these changes Dec 19, 2023
@demshy
Copy link
Member

demshy commented Dec 20, 2023

@seamuswn you mind getting this up to date with the latest master? I'm ready to merge this and then release the new beta version

@soceanainn soceanainn force-pushed the gael-cms/aws-cognito-support branch from e978f0e to e01f4f6 Compare December 22, 2023 17:17
@soceanainn
Copy link
Contributor Author

@demshy apologies for the delay - stuff was a bit hectic here before the winter break.

I just rebased and I'm testing everything E2E again to make sure it's all working. I'll let you know when I'm finished testing again.

@soceanainn
Copy link
Contributor Author

Looks good on my side after rebasing, rebuilding and running locally!

@demshy
Copy link
Member

demshy commented Jan 16, 2024

Hey @soceanainn I'm sorry but stuff has now been hectic on our side as well but I finally got some time that I can put into the project. I noticed that the tests failed due to a lint error. Would you mind formatting the code and rebasing the latest master again?

@soceanainn soceanainn force-pushed the gael-cms/aws-cognito-support branch from fd5b3d8 to 363d1f9 Compare January 28, 2024 15:44
@soceanainn soceanainn requested a review from a team as a code owner January 28, 2024 15:44
@soceanainn soceanainn requested a review from demshy January 28, 2024 15:44
@demshy demshy enabled auto-merge (squash) January 30, 2024 08:24
@demshy
Copy link
Member

demshy commented Jan 30, 2024

this is great, all we need is another master update and it's done :)

auto-merge was automatically disabled January 30, 2024 13:20

Head branch was pushed to by a user without write access

@soceanainn soceanainn force-pushed the gael-cms/aws-cognito-support branch from 363d1f9 to 4a3b90c Compare January 30, 2024 13:20
@martinjagodic martinjagodic enabled auto-merge (squash) January 30, 2024 13:33
@martinjagodic martinjagodic merged commit 4f419dd into decaporg:master Jan 30, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants