├── .github ├── CODEOWNERS └── workflows │ ├── github-ip-ranges.yaml │ ├── publish.yaml │ ├── release.yaml │ └── test.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── .prettierignore ├── .releaserc.yaml ├── .terraform-version ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── USAGE.md ├── apigw.tf ├── bun.lockb ├── cloudwatch.tf ├── dashboard.json ├── domain.tf ├── fixtures ├── invalid-payload-urlencoded.txt ├── valid-ping-payload.ts ├── valid-push-payload-user-repo.ts └── valid-push-payload.ts ├── github-hooks-ip-ranges.tf ├── lambda.tf ├── lambda ├── destination-host-is-allowed.ts ├── file-readers.ts ├── get-https-agent.ts ├── parse-request-body.ts ├── proxy.test.ts ├── proxy.ts ├── request-payload-is-valid.ts ├── schema.ts ├── types.ts └── url-is-valid.ts ├── locals.tf ├── outputs.tf ├── package.json ├── renovate.json ├── tsconfig.json ├── variables.tf ├── versions.tf └── vpc.tf /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Individuals or teams that are responsible for code in this repository. 2 | # Each line is a file pattern (for a specific dir) followed by one or more owners. 3 | 4 | # Default owners will be asked to review when someone opens a pull request. 5 | # * @github-webhook-proxy-admins 6 | -------------------------------------------------------------------------------- /.github/workflows/github-ip-ranges.yaml: -------------------------------------------------------------------------------- 1 | name: Check Github IP Ranges 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "0 0 * * 0" # once a week 7 | 8 | jobs: 9 | check: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | with: 15 | ref: ${{ github.event.pull_request.head.ref }} 16 | repository: ${{ github.event.pull_request.head.repo.full_name }} 17 | token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} 18 | 19 | - name: Generate GitHub IP Ranges 20 | run: | 21 | HOOKS=$(curl https://api.github.com/meta | jq -c .hooks) 22 | if [[ "$HOOKS" != 'null' ]]; then 23 | echo "locals {github_hooks_ip_ranges = $HOOKS}" > github-hooks-ip-ranges.tf 24 | fi 25 | 26 | - name: Setup 27 | uses: hashicorp/setup-terraform@v3 28 | 29 | - name: Format 30 | id: fmt 31 | run: terraform fmt 32 | 33 | - name: Check if IP Ranges Have Changed 34 | id: ip-check 35 | run: | 36 | if [[ $(git status --porcelain) ]]; then 37 | echo "New GitHub IP ranges detected." 38 | git status 39 | git fetch origin 40 | git config user.name "${{ github.actor }}" 41 | git config user.email "${{ github.actor }}@users.noreply.github.com" 42 | git checkout -b github-ip-range-update 43 | git add . 44 | git commit -m "fix: update github ip ranges" 45 | git push -u origin github-ip-range-update 46 | echo "::set-output name=NEW_IP_RANGES::true" 47 | fi 48 | 49 | - if: steps.ip-check.outputs.NEW_IP_RANGES == 'true' 50 | name: Open Pull Request if IP Ranges Have Changed 51 | uses: ExpediaGroup/github-helpers@v1 52 | with: 53 | helper: create-pr 54 | title: "fix: update Github IP ranges" 55 | body: The GitHub IP ranges for hooks have changed on the [meta endpoint](https://api.github.com/meta). 56 | head: github-ip-range-update 57 | github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} 58 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: Publish Assets 2 | 3 | on: 4 | release: 5 | types: 6 | - edited 7 | - published 8 | 9 | jobs: 10 | publish: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | 16 | - name: Setup Bun 17 | uses: oven-sh/setup-bun@v2 18 | with: 19 | bun-version-file: package.json 20 | 21 | - name: Install 22 | run: bun i 23 | 24 | - name: Build 25 | run: bun run build 26 | 27 | - name: Inject Mozilla Cert Bundles 28 | run: curl https://curl.se/ca/cacert.pem -o build/public-certs.pem 29 | 30 | - name: Zip Lambda 31 | run: zip -r -qq proxy-lambda.zip build node_modules 32 | 33 | - name: Upload Release Assets 34 | uses: softprops/action-gh-release@v2 35 | with: 36 | files: proxy-lambda.zip 37 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | 15 | - name: Setup Bun 16 | uses: oven-sh/setup-bun@v2 17 | with: 18 | bun-version-file: package.json 19 | 20 | - name: Setup Node 21 | uses: actions/setup-node@v4 22 | with: 23 | node-version: latest 24 | 25 | - name: Create Release 26 | run: bunx semantic-release 27 | env: 28 | GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} 29 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | lambda: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | 15 | - name: Setup Bun 16 | uses: oven-sh/setup-bun@v2 17 | with: 18 | bun-version-file: package.json 19 | 20 | - name: Install 21 | run: bun i 22 | 23 | - name: Format 24 | run: bun run format-check 25 | 26 | - name: Type Check 27 | run: bun tsc 28 | 29 | - name: Build 30 | run: bun run build 31 | 32 | - name: Test 33 | run: bun run test 34 | 35 | docs: 36 | runs-on: ubuntu-latest 37 | steps: 38 | - uses: actions/checkout@v4 39 | with: 40 | ref: ${{ github.event.pull_request.head.ref }} 41 | repository: ${{ github.event.pull_request.head.repo.full_name }} 42 | token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN || secrets.GITHUB_TOKEN }} 43 | 44 | - name: Terraform Docs 45 | uses: terraform-docs/gh-actions@v1.4.1 46 | with: 47 | git-push: true 48 | output-file: USAGE.md 49 | 50 | terraform: 51 | needs: docs 52 | runs-on: ubuntu-latest 53 | steps: 54 | - uses: actions/checkout@v4 55 | 56 | - name: Read .terraform-version 57 | run: echo TF_VERSION=`cat .terraform-version` >> $GITHUB_ENV 58 | 59 | - name: Setup 60 | uses: hashicorp/setup-terraform@v3 61 | with: 62 | terraform_version: ${{ env.TF_VERSION }} 63 | 64 | - name: Terraform Init 65 | run: terraform init -backend=false 66 | 67 | - name: Terraform Validate 68 | uses: dflook/terraform-validate@v1 69 | 70 | - name: Terraform FMT 71 | uses: dflook/terraform-fmt@v1 72 | 73 | - name: Terraform Lint 74 | uses: reviewdog/action-tflint@v1 75 | with: 76 | github_token: ${{ secrets.GITHUB_TOKEN }} 77 | fail_on_error: true 78 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Source: https://github.com/github/gitignore/blob/master/Terraform.gitignore 2 | 3 | .DS_Store 4 | 5 | # Local .terraform directories 6 | **/.terraform/* 7 | 8 | # .tfstate files 9 | *.tfstate 10 | *.tfstate.* 11 | 12 | # Crash log files 13 | crash.log 14 | 15 | # Exclude all .tfvars files, which are likely to contain sentitive data, such as 16 | # password, private keys, and other secrets. These should not be part of version 17 | # control as they are data points which are potentially sensitive and subject 18 | # to change depending on the environment. 19 | # 20 | *.tfvars 21 | 22 | # Ignore override files as they are usually used to override resources locally and so 23 | # are not checked in 24 | override.tf 25 | override.tf.json 26 | *_override.tf 27 | *_override.tf.json 28 | 29 | # Include override files you do wish to add to version control using negated pattern 30 | # 31 | # !example_override.tf 32 | 33 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 34 | # example: *tfplan* 35 | 36 | # Ignore CLI configuration files 37 | .terraformrc 38 | terraform.rc 39 | 40 | # Lambda ignore 41 | build 42 | node_modules 43 | *.zip 44 | 45 | .idea 46 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/antonbabenko/pre-commit-terraform 3 | rev: v1.71.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases 4 | hooks: 5 | - id: terraform_fmt 6 | - id: terraform_docs 7 | #- id: terraform_validate 8 | - id: terraform_tflint 9 | args: 10 | - "args=--deep" 11 | - "args=--enable-rule=terraform_documented_variables" 12 | - id: terraform_tfsec 13 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /.releaserc.yaml: -------------------------------------------------------------------------------- 1 | plugins: 2 | - - "@semantic-release/commit-analyzer" 3 | - preset: angular 4 | releaseRules: 5 | - breaking: true 6 | release: major 7 | - type: breaking 8 | release: major 9 | - type: docs 10 | release: patch 11 | - type: refactor 12 | release: patch 13 | - scope: no-release 14 | release: false 15 | - "@semantic-release/release-notes-generator" 16 | - - "@semantic-release/github" 17 | - assets: 18 | - proxy-lambda.zip 19 | branches: 20 | - main 21 | -------------------------------------------------------------------------------- /.terraform-version: -------------------------------------------------------------------------------- 1 | 1.12.1 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your patches and contributions to this project. There are just a few guidelines you need to follow which are described in detail below. 4 | 5 | ## How To Contribute 6 | 7 | ### 1. Fork this repo 8 | 9 | You should create a fork of this project in your account and work from there. You can create a fork by clicking the fork button in GitHub. 10 | 11 | ### 2. One feature, one branch 12 | 13 | Work for each new feature/issue should occur in its own branch. To create a new branch from the command line: 14 | 15 | ```shell 16 | git checkout -b my-new-feature 17 | ``` 18 | 19 | where "my-new-feature" describes what you're working on. 20 | 21 | ### 3. Add tests for any bug fixes or new functionality 22 | 23 | All functions must be tested with a unit test. Please follow the existing convention of one exported function per file with a corresponding file to test it. Run tests using `yarn test`, or using the [Jest CLI](https://jestjs.io/docs/cli). 24 | 25 | There is also an integration test present in the [test workflow](./.github/workflows/test.yaml), which will actually run this Github Action using the code from this repository. This allows you to test your change to the Github Action right within the pull request you make. 26 | 27 | Unfortunately, Github Action projects cannot be run locally. You must rely on the unit and integration tests to run your code. 28 | 29 | ### 4. Check code style 30 | 31 | Before opening a pull request, ensure that you have installed all dependencies so the pre-commit hooks will run. 32 | These hooks will run ESLint according to the [.eslintrc.json](./.eslintrc.json), 33 | style the code according to the [.prettierrc.json](./.prettierrc.json), and package the code into the `dist` directory which is required for Github Actions code. 34 | 35 | ### 5. Add documentation for new or updated functionality 36 | 37 | Please review all of the .md files in this project to see if they are impacted by your change and update them accordingly. 38 | 39 | ### 6. Format Commits 40 | 41 | This project uses [Semantic Release](https://github.com/semantic-release/semantic-release) for versioning. As such, commits need to follow the format: `(): `. All fields are required. 42 | 43 | ### 7. Submit Pull Request and describe the change 44 | 45 | Push your changes to your branch and open a pull request against the parent repo on GitHub. The project administrators will review your pull request and respond with feedback. 46 | 47 | ## How Your Contribution Gets Merged 48 | 49 | Upon Pull Request submission, your code will be reviewed by the maintainers. They will confirm at least the following: 50 | 51 | - Tests run successfully (unit, coverage, integration, style). 52 | - Contribution policy has been followed. 53 | 54 | One (human) reviewer will need to sign off on your Pull Request before it can be merged. 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-webhook-proxy 2 | 3 | `github-webhook-proxy` is a request forwarder 4 | for [GitHub webhooks](https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks) from github.com 5 | to internal enterprise destinations, designed for use in Github Enterprise Cloud. 6 | 7 | ## Usage 8 | 9 | To use this Terraform module, you will need an S3 bucket containing a `proxy-lambda.zip` asset attached to each release of this repository. 10 | This zip file can be uploaded using the following script: 11 | 12 | ```shell 13 | # Upload Lambda to s3_destination 14 | file="proxy-lambda.zip" 15 | curl -o "${file}" -fL https://github.com/ExpediaGroup/github-webhook-proxy/releases/download/"${version}"/"${file}" 16 | aws s3 cp "${file}" "${s3_destination}/${file}" 17 | ``` 18 | 19 | Optionally, you may create a Lambda layer which optionally contains the following files: 20 | 21 | - `allowed-destination-hosts.json`: An array of destination hosts that the proxy can forward to. If omitted, all destinations will be allowed. Wildcard matching is supported via [micromatch](https://github.com/micromatch/micromatch) 22 | - `ca.pem`: A root CA certificate for forwarding to internal destinations with self-signed certs 23 | - `cert.pem`: A chain certificate for forwarding to internal destinations with self-signed certs 24 | 25 | These files must be in a zipped `layer` directory, and this can be uploaded using the following script: 26 | 27 | ```shell 28 | # Zip and Upload Lambda Layer to s3_destination 29 | file="proxy-lambda-layer.zip" 30 | zip -r -qq "${file}" layer 31 | aws s3 cp "${file}" "${s3_destination}/${file}" 32 | ``` 33 | 34 | If the layer is used, its ARN must be passed to the `lambda_layer_arn` Terraform variable. 35 | 36 | ### Example Terraform Module Usage 37 | 38 | ```hcl 39 | module "github-webhook-proxy" { 40 | source = "git::https://github.com/ExpediaGroup/github-webhook-proxy.git?ref=v2" 41 | aws_region = var.aws_region 42 | 43 | vpc_id = data.aws_vpc.vpc.id 44 | subnet_ids = data.aws_subnets.subnets.ids 45 | 46 | lambda_bucket_name = local.lambda_bucket_name 47 | lambda_layer_arn = aws_lambda_layer_version.proxy_layer.arn 48 | enterprise_slug = 'my_enterprise' 49 | 50 | custom_tags = { 51 | "Application" = "github-webhook-proxy" 52 | } 53 | } 54 | 55 | data "aws_s3_object" "proxy_lambda_layer" { 56 | bucket = local.lambda_bucket_name 57 | key = "path/to/proxy-lambda-layer.zip" 58 | } 59 | 60 | resource "aws_lambda_layer_version" "proxy_layer" { 61 | layer_name = "github-webhook-proxy-layer" 62 | s3_bucket = data.aws_s3_object.proxy_lambda_layer.bucket 63 | s3_key = data.aws_s3_object.proxy_lambda_layer.key 64 | s3_object_version = data.aws_s3_object.proxy_lambda_layer.version_id 65 | } 66 | 67 | locals { 68 | lambda_bucket_name = "proxy-lambda-bucket" 69 | } 70 | ``` 71 | 72 | ### Adding a New Webhook 73 | 74 | 1. **Create the webhook proxy URL** 75 | 1. Obtain your desired destination URL, i.e. the internal endpoint where you want to send webhooks. 76 | 2. Encode your destination URL! An easy way to do this is to use `jq` in your terminal 77 | (install it [here](https://stedolan.github.io/jq/download/) if you don't have it already): `jq -rn --arg x 'YOUR_DESTINATION_URL_HERE' '$x|@uri'` 78 | 3. Paste the encoded URL at the end of the webhook proxy base URL (`https://YOUR_API_URL/webhook`). 79 | 2. **Add the webhook to your repository** 80 | 1. As an administrator, navigate to your repository settings -> Webhooks -> Add webhook 81 | 2. Paste your webhook proxy URL in the "Payload URL" box. You do not need to worry about "Content type". 82 | 3. By default, GitHub will only send requests on the "push" event, but you may configure it to send on other events as well. 83 | 4. Click "Add webhook" 84 | 85 | ### Example Webhook Proxy URL Creation 86 | 87 | Destination URL: `https://my-destination.url/endpoint` 88 | 89 | :arrow_down: 90 | 91 | Encoded destination URL: `https%3A%2F%2Fmy-destination.url%2Fendpoint%2F` 92 | 93 | :arrow_down: 94 | 95 | Webhook URL: `https://YOUR_API_URL/webhook/https%3A%2F%2Fmy-destination.url%2Fendpoint%2F` 96 | 97 | ## Technical Overview 98 | 99 | ### Incoming Request 100 | 101 | When a webhook from github.com is sent to https://YOUR_API_URL/webhook, it is routed 102 | to the API Gateway resource 103 | via [DNS mapping](https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html). 104 | The API Gateway has an [IP allowlist](https://github.com/ExpediaGroup/github-webhook-proxy/blob/main/github-hooks-ip-ranges.tf) which only accepts requests originating 105 | from [GitHub Hooks IP ranges](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-githubs-ip-addresses). 106 | This ensures that the proxy endpoint can only be accessed by webhook requests from github.com. 107 | 108 | ### Request Parsing 109 | 110 | The API Gateway then invokes the Lambda function, which parses the request body from the 111 | [supported content types](https://docs.github.com/en/developers/webhooks-and-events/webhooks/creating-webhooks#content-type) 112 | . 113 | Each request to the webhook proxy must adhere to the following format: 114 | `https://YOUR_API_URL/webhook/${endpointId}` 115 | where `endpointId` is an [encoded](https://www.w3schools.com/tags/ref_urlencode.asp) destination URL. The Lambda decodes 116 | the `endpointId` to make it a valid URL. 117 | 118 | ### Request Validation 119 | 120 | The Lambda then performs the following validations: 121 | 122 | - The request must have an enterprise slug which matches the `enterprise_slug` environment variable, OR the request must 123 | come from a personal repository where the username ends in the enterprise managed user suffix (if provided). 124 | The user suffix is passed via the `enterprise_managed_user_suffix` Terraform variable. 125 | - The request host must have an approved destination URL host, which is the decoded `endpointId` specified in the request 126 | URL. The list of allowed destination hosts is read from `allowed-destination-hosts.json` in the Lambda layer. 127 | 128 | ### TLS Support 129 | 130 | If a root and chain certificate are not provided in the Lambda layer, the runtime environment will supply certificates for requests. 131 | If these certificates are provided, however, the proxy will forward each request with `ca.pem` and `cert.pem` as the 132 | root and chain, respectively, with the root certificate appended to the [Mozilla CA certificate store](https://curl.se/docs/caextract.html). 133 | 134 | ### Webhook Proxy Responses 135 | 136 | If any of these validations fail, the webhook proxy will return a 403 unauthorized error. If all validations pass, the 137 | request payload and headers are forwarded to the specified destination URL, and the proxy will return the response it 138 | receives from the destination. If an unexpected error occurs, the webhook proxy will return a 500 internal server error. 139 | 140 | ## Repository Overview 141 | 142 | ### Terraform Module 143 | 144 | This repository contains Terraform (`*.tf`) files which are intended to be consumed as a Terraform module. 145 | The files are generally organized by resource type. See the "Resources" section in [USAGE.md](https://github.com/ExpediaGroup/github-webhook-proxy/tree/main/USAGE.md) for more infrastructure details. 146 | 147 | ### Lambda Function 148 | 149 | The Lambda function is a Node.js Lambda compiled from Typescript, and lives in the ["lambda" directory](https://github.com/ExpediaGroup/github-webhook-proxy/tree/main/lambda). 150 | 151 | ### GitHub IP Range Allowlist 152 | 153 | This repo has a GitHub Actions [workflow](https://github.com/ExpediaGroup/github-webhook-proxy/tree/main/.github/workflows/github-ip-ranges.yml) which checks that the [GitHub Hooks IP Ranges file](https://github.com/ExpediaGroup/github-webhook-proxy/tree/main/github-hooks-ip-ranges.tf) is up to date. 154 | It runs a script once a day which calls https://api.github.com/meta and ensures the IP ranges in "hooks" match our current IP allowlist in the API Gateway. 155 | If the list is out of date, it will create a PR to update it. 156 | -------------------------------------------------------------------------------- /USAGE.md: -------------------------------------------------------------------------------- 1 | 2 | ## Requirements 3 | 4 | | Name | Version | 5 | |------|---------| 6 | | [terraform](#requirement\_terraform) | 1.12.1 | 7 | 8 | ## Providers 9 | 10 | | Name | Version | 11 | |------|---------| 12 | | [aws](#provider\_aws) | n/a | 13 | 14 | ## Modules 15 | 16 | No modules. 17 | 18 | ## Resources 19 | 20 | | Name | Type | 21 | |------|------| 22 | | [aws_api_gateway_base_path_mapping.dns_mapping](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_base_path_mapping) | resource | 23 | | [aws_api_gateway_deployment.ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment) | resource | 24 | | [aws_api_gateway_domain_name.proxy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_domain_name) | resource | 25 | | [aws_api_gateway_integration.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration) | resource | 26 | | [aws_api_gateway_method.lambda_method](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource | 27 | | [aws_api_gateway_method_settings.log_settings](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_settings) | resource | 28 | | [aws_api_gateway_resource.lambda_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource | 29 | | [aws_api_gateway_resource.webhook](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource | 30 | | [aws_api_gateway_rest_api.ingress_api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api) | resource | 31 | | [aws_api_gateway_rest_api_policy.allow_list](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api_policy) | resource | 32 | | [aws_api_gateway_stage.ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_stage) | resource | 33 | | [aws_cloudwatch_dashboard.metrics](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_dashboard) | resource | 34 | | [aws_cloudwatch_log_group.apigw](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource | 35 | | [aws_cloudwatch_log_group.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource | 36 | | [aws_iam_role.proxy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | 37 | | [aws_iam_role_policy.apigw_logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource | 38 | | [aws_iam_role_policy.extra_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource | 39 | | [aws_iam_role_policy.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource | 40 | | [aws_iam_role_policy_attachment.basic_execution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | 41 | | [aws_iam_role_policy_attachment.vpc_execution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | 42 | | [aws_lambda_function.proxy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource | 43 | | [aws_lambda_permission.apigw_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource | 44 | | [aws_route53_record.proxy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | 45 | | [aws_security_group.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource | 46 | | [aws_iam_policy_document.allow_list](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 47 | | [aws_iam_policy_document.apigw_logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 48 | | [aws_iam_policy_document.lambda_logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 49 | | [aws_iam_policy_document.proxy_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 50 | | [aws_s3_object.proxy_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_object) | data source | 51 | 52 | ## Inputs 53 | 54 | | Name | Description | Type | Default | Required | 55 | |------|-------------|------|---------|:--------:| 56 | | [api\_gateway\_domain\_name](#input\_api\_gateway\_domain\_name) | Domain name for API gateway domain mapping | `string` | `null` | no | 57 | | [aws\_region](#input\_aws\_region) | The AWS region to deploy to (e.g. us-east-1) | `string` | n/a | yes | 58 | | [certificate\_arn](#input\_certificate\_arn) | Certificate ARN for API gateway domain name | `string` | `null` | no | 59 | | [custom\_tags](#input\_custom\_tags) | Additional tags to be applied to all resources applied by this module. | `map(string)` | `{}` | no | 60 | | [enterprise\_managed\_user\_suffix](#input\_enterprise\_managed\_user\_suffix) | Managed user suffix used for central identity management on GHEC | `string` | `""` | no | 61 | | [enterprise\_slug](#input\_enterprise\_slug) | The name (slug) of the enterprise on GHEC | `string` | n/a | yes | 62 | | [extra\_role\_policy](#input\_extra\_role\_policy) | jsonencoded string policy to include in the proxy lambda role | `string` | `null` | no | 63 | | [lambda\_bucket\_name](#input\_lambda\_bucket\_name) | S3 bucket with lambda and layer archives | `string` | n/a | yes | 64 | | [lambda\_layer\_arn](#input\_lambda\_layer\_arn) | Lambda layer ARN for data store | `string` | n/a | yes | 65 | | [lambda\_timeout\_seconds](#input\_lambda\_timeout\_seconds) | Number of seconds until lambda times out | `number` | `10` | no | 66 | | [log\_retention\_days](#input\_log\_retention\_days) | Number of days CloudWatch will retain logs | `number` | `7` | no | 67 | | [resource\_prefix](#input\_resource\_prefix) | Prefix of webhook proxy resources | `string` | `"gwp"` | no | 68 | | [route\_53\_record\_name](#input\_route\_53\_record\_name) | Record name for Route 53 record creation | `string` | `null` | no | 69 | | [subnet\_ids](#input\_subnet\_ids) | subnet\_ids for Lambda VPC config | `list(string)` | n/a | yes | 70 | | [vpc\_id](#input\_vpc\_id) | VPC id for Lambda VPC config | `string` | n/a | yes | 71 | | [zone\_id](#input\_zone\_id) | Zone id for Route53 record | `string` | `null` | no | 72 | 73 | ## Outputs 74 | 75 | | Name | Description | 76 | |------|-------------| 77 | | [apigateway\_ingress\_id](#output\_apigateway\_ingress\_id) | n/a | 78 | | [apigateway\_invoke\_url](#output\_apigateway\_invoke\_url) | n/a | 79 | 80 | -------------------------------------------------------------------------------- /apigw.tf: -------------------------------------------------------------------------------- 1 | resource "aws_api_gateway_rest_api" "ingress_api" { 2 | name = "${var.resource_prefix}-ingress" 3 | description = "Github Enterprise Cloud Webhook proxy." 4 | disable_execute_api_endpoint = local.api_gateway_domain_count > 0 ? true : false 5 | tags = var.custom_tags 6 | 7 | endpoint_configuration { 8 | types = ["REGIONAL"] 9 | } 10 | } 11 | 12 | resource "aws_api_gateway_resource" "webhook" { 13 | parent_id = aws_api_gateway_rest_api.ingress_api.root_resource_id 14 | path_part = "webhook" 15 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 16 | } 17 | 18 | resource "aws_api_gateway_resource" "lambda_endpoint" { 19 | parent_id = aws_api_gateway_resource.webhook.id 20 | path_part = "{endpointId}" 21 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 22 | } 23 | 24 | resource "aws_api_gateway_method" "lambda_method" { 25 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 26 | resource_id = aws_api_gateway_resource.lambda_endpoint.id 27 | authorization = "NONE" 28 | http_method = "POST" 29 | } 30 | 31 | resource "aws_api_gateway_integration" "lambda" { 32 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 33 | resource_id = aws_api_gateway_resource.lambda_endpoint.id 34 | http_method = aws_api_gateway_method.lambda_method.http_method 35 | integration_http_method = "POST" 36 | type = "AWS_PROXY" 37 | uri = aws_lambda_function.proxy.invoke_arn 38 | } 39 | 40 | resource "aws_lambda_permission" "apigw_lambda" { 41 | statement_id = "AllowExecutionFromAPIGateway" 42 | action = "lambda:InvokeFunction" 43 | function_name = aws_lambda_function.proxy.function_name 44 | principal = "apigateway.amazonaws.com" 45 | source_arn = "${aws_api_gateway_rest_api.ingress_api.execution_arn}/*/${aws_api_gateway_method.lambda_method.http_method}${aws_api_gateway_resource.lambda_endpoint.path}" 46 | } 47 | 48 | resource "aws_api_gateway_deployment" "ingress" { 49 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 50 | 51 | triggers = { 52 | # Terraform does not trigger a redeploy when dependent resources change 53 | # All resources that require a new deployment on change need to be added to this list 54 | # Apply needs to run twice, first run fails with `Error: Provider produced inconsistent final plan` 55 | redeployment = sha1(jsonencode([ 56 | aws_lambda_function.proxy, 57 | aws_api_gateway_resource.lambda_endpoint, 58 | aws_api_gateway_method.lambda_method, 59 | aws_api_gateway_integration.lambda, 60 | aws_api_gateway_rest_api_policy.allow_list 61 | ])) 62 | } 63 | 64 | lifecycle { 65 | create_before_destroy = true 66 | } 67 | } 68 | 69 | resource "aws_api_gateway_stage" "ingress" { 70 | depends_on = [ 71 | aws_api_gateway_deployment.ingress, 72 | aws_cloudwatch_log_group.apigw 73 | ] 74 | 75 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 76 | stage_name = "v1" 77 | deployment_id = aws_api_gateway_deployment.ingress.id 78 | tags = var.custom_tags 79 | xray_tracing_enabled = true 80 | 81 | access_log_settings { 82 | destination_arn = aws_cloudwatch_log_group.apigw.arn 83 | format = jsonencode({ 84 | "requestId" : "$context.requestId", 85 | "extendedRequestId" : "$context.extendedRequestId", 86 | "ip" : "$context.identity.sourceIp", 87 | "caller" : "$context.identity.caller", 88 | "user" : "$context.identity.user", 89 | "requestTime" : "$context.requestTime", 90 | "httpMethod" : "$context.httpMethod", 91 | "resourcePath" : "$context.resourcePath", 92 | "status" : "$context.status", 93 | "protocol" : "$context.protocol", 94 | "responseLength" : "$context.responseLength" 95 | }) 96 | } 97 | } 98 | 99 | resource "aws_api_gateway_method_settings" "log_settings" { 100 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 101 | stage_name = aws_api_gateway_stage.ingress.stage_name 102 | method_path = "*/*" 103 | 104 | settings { 105 | metrics_enabled = true 106 | logging_level = "INFO" 107 | } 108 | } 109 | 110 | data "aws_iam_policy_document" "allow_list" { 111 | statement { 112 | effect = "Allow" 113 | actions = ["execute-api:Invoke"] 114 | resources = ["*"] 115 | principals { 116 | identifiers = ["*"] 117 | type = "AWS" 118 | } 119 | } 120 | 121 | statement { 122 | effect = "Deny" 123 | actions = ["execute-api:Invoke"] 124 | resources = ["*"] 125 | principals { 126 | identifiers = ["*"] 127 | type = "AWS" 128 | } 129 | condition { 130 | test = "NotIpAddress" 131 | variable = "aws:SourceIp" 132 | values = local.github_hooks_ip_ranges 133 | } 134 | } 135 | } 136 | 137 | resource "aws_api_gateway_rest_api_policy" "allow_list" { 138 | rest_api_id = aws_api_gateway_rest_api.ingress_api.id 139 | policy = data.aws_iam_policy_document.allow_list.json 140 | } 141 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExpediaGroup/github-webhook-proxy/40d3144a0ce0a1228bc1abd1cf8b4360339b4cf4/bun.lockb -------------------------------------------------------------------------------- /cloudwatch.tf: -------------------------------------------------------------------------------- 1 | resource "aws_cloudwatch_log_group" "lambda" { 2 | name = "/aws/lambda/${aws_lambda_function.proxy.function_name}" 3 | retention_in_days = var.log_retention_days 4 | tags = var.custom_tags 5 | } 6 | 7 | data "aws_iam_policy_document" "lambda_logging" { 8 | statement { 9 | actions = ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"] 10 | effect = "Allow" 11 | resources = [aws_cloudwatch_log_group.lambda.arn] 12 | } 13 | } 14 | 15 | resource "aws_iam_role_policy" "lambda" { 16 | name = "${var.resource_prefix}-lambda-logging" 17 | role = aws_iam_role.proxy.name 18 | policy = data.aws_iam_policy_document.lambda_logging.json 19 | } 20 | 21 | data "aws_iam_policy_document" "apigw_logging" { 22 | statement { 23 | actions = ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"] 24 | effect = "Allow" 25 | resources = [aws_cloudwatch_log_group.apigw.arn] 26 | } 27 | } 28 | 29 | resource "aws_cloudwatch_log_group" "apigw" { 30 | name = "/aws/apigateway/${aws_api_gateway_rest_api.ingress_api.name}" 31 | retention_in_days = var.log_retention_days 32 | tags = var.custom_tags 33 | } 34 | 35 | resource "aws_iam_role_policy" "apigw_logging" { 36 | name = "${var.resource_prefix}-apigw-logging" 37 | role = aws_iam_role.proxy.name 38 | policy = data.aws_iam_policy_document.apigw_logging.json 39 | } 40 | 41 | resource "aws_cloudwatch_dashboard" "metrics" { 42 | dashboard_name = "${local.module_name}-metrics" 43 | dashboard_body = file("${path.module}/dashboard.json") 44 | } 45 | -------------------------------------------------------------------------------- /dashboard.json: -------------------------------------------------------------------------------- 1 | { 2 | "widgets": [ 3 | { 4 | "height": 6, 5 | "width": 10, 6 | "y": 0, 7 | "x": 0, 8 | "type": "log", 9 | "properties": { 10 | "query": "SOURCE '/aws/lambda/gwp-default-proxy' | filter @message like /Forwarding webhook for url/\n| parse @message \"Forwarding webhook for url: *\" as url\n| stats count() by url", 11 | "region": "us-west-2", 12 | "stacked": false, 13 | "title": "Proxy Destinations", 14 | "view": "table" 15 | } 16 | }, 17 | { 18 | "height": 6, 19 | "width": 8, 20 | "y": 0, 21 | "x": 10, 22 | "type": "log", 23 | "properties": { 24 | "query": "SOURCE '/aws/apigateway/gwp-default-ingress' | fields status\n| stats count() by status\n| sort status asc", 25 | "region": "us-west-2", 26 | "stacked": false, 27 | "title": "API Gateway Response Codes", 28 | "view": "bar" 29 | } 30 | }, 31 | { 32 | "height": 6, 33 | "width": 10, 34 | "y": 12, 35 | "x": 0, 36 | "type": "metric", 37 | "properties": { 38 | "metrics": [ 39 | [ 40 | "AWS/ApiGateway", 41 | "Latency", 42 | "ApiName", 43 | "gwp-default-ingress", 44 | "Resource", 45 | "/webhook/{endpointId}", 46 | "Stage", 47 | "v1", 48 | "Method", 49 | "POST" 50 | ], 51 | [ 52 | ".", 53 | "Count", 54 | ".", 55 | ".", 56 | ".", 57 | ".", 58 | ".", 59 | ".", 60 | ".", 61 | ".", 62 | { "visible": false } 63 | ], 64 | [ 65 | ".", 66 | "IntegrationLatency", 67 | ".", 68 | ".", 69 | ".", 70 | ".", 71 | ".", 72 | ".", 73 | ".", 74 | ".", 75 | { "visible": false } 76 | ], 77 | [ 78 | ".", 79 | "4XXError", 80 | ".", 81 | ".", 82 | ".", 83 | ".", 84 | ".", 85 | ".", 86 | ".", 87 | ".", 88 | { "visible": false } 89 | ], 90 | [ 91 | ".", 92 | "5XXError", 93 | ".", 94 | ".", 95 | ".", 96 | ".", 97 | ".", 98 | ".", 99 | ".", 100 | ".", 101 | { "visible": false } 102 | ] 103 | ], 104 | "view": "timeSeries", 105 | "region": "us-west-2", 106 | "period": 86400, 107 | "stat": "Average", 108 | "stacked": false, 109 | "title": "Execution Time" 110 | } 111 | }, 112 | { 113 | "height": 6, 114 | "width": 10, 115 | "y": 6, 116 | "x": 0, 117 | "type": "metric", 118 | "properties": { 119 | "metrics": [ 120 | [ 121 | "AWS/ApiGateway", 122 | "Count", 123 | "ApiName", 124 | "gwp-default-ingress", 125 | "Resource", 126 | "/webhook/{endpointId}", 127 | "Stage", 128 | "v1", 129 | "Method", 130 | "POST" 131 | ] 132 | ], 133 | "view": "timeSeries", 134 | "region": "us-west-2", 135 | "period": 86400, 136 | "stat": "Sum", 137 | "stacked": false, 138 | "title": "Webhooks Received" 139 | } 140 | }, 141 | { 142 | "height": 6, 143 | "width": 6, 144 | "y": 0, 145 | "x": 18, 146 | "type": "log", 147 | "properties": { 148 | "query": "SOURCE '/aws/lambda/gwp-default-proxy' | fields @message\n| filter @message like /result/\n| parse @message 'result {\"statusCode\":*,' as statusCode\n| stats count() by statusCode", 149 | "region": "us-west-2", 150 | "stacked": false, 151 | "title": "Webhook Response Codes", 152 | "view": "bar" 153 | } 154 | }, 155 | { 156 | "height": 6, 157 | "width": 14, 158 | "y": 6, 159 | "x": 10, 160 | "type": "log", 161 | "properties": { 162 | "query": "SOURCE '/aws/lambda/gwp-default-proxy' | fields @message\n| filter @message like /result/\n| parse @message 'result {\"statusCode\":*,' as statusCode\n| stats count() by bin(1d)", 163 | "region": "us-west-2", 164 | "stacked": false, 165 | "title": "Webhooks Proxied", 166 | "view": "timeSeries" 167 | } 168 | } 169 | ] 170 | } 171 | -------------------------------------------------------------------------------- /domain.tf: -------------------------------------------------------------------------------- 1 | resource "aws_api_gateway_base_path_mapping" "dns_mapping" { 2 | count = local.api_gateway_domain_count 3 | api_id = aws_api_gateway_rest_api.ingress_api.id 4 | stage_name = aws_api_gateway_stage.ingress.stage_name 5 | domain_name = aws_api_gateway_domain_name.proxy[0].domain_name 6 | } 7 | 8 | resource "aws_api_gateway_domain_name" "proxy" { 9 | count = local.api_gateway_domain_count 10 | domain_name = var.api_gateway_domain_name 11 | regional_certificate_arn = var.certificate_arn 12 | 13 | endpoint_configuration { 14 | types = ["REGIONAL"] 15 | } 16 | } 17 | 18 | resource "aws_route53_record" "proxy" { 19 | count = local.api_gateway_domain_count 20 | name = var.route_53_record_name 21 | type = "A" 22 | zone_id = var.zone_id 23 | 24 | alias { 25 | evaluate_target_health = true 26 | name = aws_api_gateway_domain_name.proxy[0].regional_domain_name 27 | zone_id = aws_api_gateway_domain_name.proxy[0].regional_zone_id 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /fixtures/invalid-payload-urlencoded.txt: -------------------------------------------------------------------------------- 1 | payload=%7B%22ref%22%3A%22refs%2Fheads%2Fmain%22%2C%22before%22%3A%22759a52dcba828d3f4a889b3e9ec58658506ff7c7%22%2C%22after%22%3A%2285dbc9897dc9fd2bd90f10989d92c5c9036e45db%22%2C%22repository%22%3A%7B%22id%22%3A434172499%2C%22node_id%22%3A%22R_kgDOGeDyUw%22%2C%22name%22%3A%22github-webhook-proxy%22%2C%22full_name%22%3A%22ExampleOrg%2Fgithub-webhook-proxy%22%2C%22private%22%3Afalse%2C%22owner%22%3A%7B%22name%22%3A%22ExampleOrg%22%2C%22email%22%3A%22oss%40ExampleOrg.com%22%2C%22login%22%3A%22ExampleOrg%22%2C%22id%22%3A38541875%2C%22node_id%22%3A%22MDEyOk9yZ2FuaXphdGlvbjM4NTQxODc1%22%2C%22avatar_url%22%3A%22https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F38541875%3Fv%3D4%22%2C%22gravatar_id%22%3A%22%22%2C%22url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%22%2C%22html_url%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%22%2C%22followers_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Ffollowers%22%2C%22following_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Ffollowing%7B%2Fother_user%7D%22%2C%22gists_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Fgists%7B%2Fgist_id%7D%22%2C%22starred_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Fstarred%7B%2Fowner%7D%7B%2Frepo%7D%22%2C%22subscriptions_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Fsubscriptions%22%2C%22organizations_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Forgs%22%2C%22repos_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Frepos%22%2C%22events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Fevents%7B%2Fprivacy%7D%22%2C%22received_events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2FExampleOrg%2Freceived_events%22%2C%22type%22%3A%22Organization%22%2C%22site_admin%22%3Afalse%7D%2C%22html_url%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy%22%2C%22description%22%3A%22A+Github+Action+for+validating+package.json+conventions.%22%2C%22fork%22%3Afalse%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy%22%2C%22forks_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fforks%22%2C%22keys_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fkeys%7B%2Fkey_id%7D%22%2C%22collaborators_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fcollaborators%7B%2Fcollaborator%7D%22%2C%22teams_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fteams%22%2C%22hooks_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fhooks%22%2C%22issue_events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fissues%2Fevents%7B%2Fnumber%7D%22%2C%22events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fevents%22%2C%22assignees_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fassignees%7B%2Fuser%7D%22%2C%22branches_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fbranches%7B%2Fbranch%7D%22%2C%22tags_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Ftags%22%2C%22blobs_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fgit%2Fblobs%7B%2Fsha%7D%22%2C%22git_tags_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fgit%2Ftags%7B%2Fsha%7D%22%2C%22git_refs_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fgit%2Frefs%7B%2Fsha%7D%22%2C%22trees_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fgit%2Ftrees%7B%2Fsha%7D%22%2C%22statuses_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fstatuses%2F%7Bsha%7D%22%2C%22languages_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Flanguages%22%2C%22stargazers_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fstargazers%22%2C%22contributors_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fcontributors%22%2C%22subscribers_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fsubscribers%22%2C%22subscription_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fsubscription%22%2C%22commits_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fcommits%7B%2Fsha%7D%22%2C%22git_commits_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fgit%2Fcommits%7B%2Fsha%7D%22%2C%22comments_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fcomments%7B%2Fnumber%7D%22%2C%22issue_comment_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fissues%2Fcomments%7B%2Fnumber%7D%22%2C%22contents_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fcontents%2F%7B%2Bpath%7D%22%2C%22compare_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fcompare%2F%7Bbase%7D...%7Bhead%7D%22%2C%22merges_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fmerges%22%2C%22archive_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2F%7Barchive_format%7D%7B%2Fref%7D%22%2C%22downloads_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fdownloads%22%2C%22issues_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fissues%7B%2Fnumber%7D%22%2C%22pulls_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fpulls%7B%2Fnumber%7D%22%2C%22milestones_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fmilestones%7B%2Fnumber%7D%22%2C%22notifications_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fnotifications%7B%3Fsince%2Call%2Cparticipating%7D%22%2C%22labels_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Flabels%7B%2Fname%7D%22%2C%22releases_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Freleases%7B%2Fid%7D%22%2C%22deployments_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FExampleOrg%2Fgithub-webhook-proxy%2Fdeployments%22%2C%22created_at%22%3A1638440199%2C%22updated_at%22%3A%222022-02-10T19%3A11%3A27Z%22%2C%22pushed_at%22%3A1650582327%2C%22git_url%22%3A%22git%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy.git%22%2C%22ssh_url%22%3A%22git%40github.com%3AExampleOrg%2Fgithub-webhook-proxy.git%22%2C%22clone_url%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy.git%22%2C%22svn_url%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy%22%2C%22homepage%22%3A%22%22%2C%22size%22%3A283%2C%22stargazers_count%22%3A2%2C%22watchers_count%22%3A2%2C%22language%22%3A%22TypeScript%22%2C%22has_issues%22%3Atrue%2C%22has_projects%22%3Atrue%2C%22has_downloads%22%3Atrue%2C%22has_wiki%22%3Atrue%2C%22has_pages%22%3Afalse%2C%22forks_count%22%3A1%2C%22mirror_url%22%3Anull%2C%22archived%22%3Afalse%2C%22disabled%22%3Afalse%2C%22open_issues_count%22%3A1%2C%22license%22%3A%7B%22key%22%3A%22apache-2.0%22%2C%22name%22%3A%22Apache+License+2.0%22%2C%22spdx_id%22%3A%22Apache-2.0%22%2C%22url%22%3A%22https%3A%2F%2Fapi.github.com%2Flicenses%2Fapache-2.0%22%2C%22node_id%22%3A%22MDc6TGljZW5zZTI%3D%22%7D%2C%22allow_forking%22%3Atrue%2C%22is_template%22%3Afalse%2C%22topics%22%3A%5B%5D%2C%22visibility%22%3A%22public%22%2C%22forks%22%3A1%2C%22open_issues%22%3A1%2C%22watchers%22%3A2%2C%22default_branch%22%3A%22main%22%2C%22stargazers%22%3A2%2C%22master_branch%22%3A%22main%22%2C%22organization%22%3A%22ExampleOrg%22%7D%2C%22pusher%22%3A%7B%22name%22%3A%22user%22%2C%22email%22%3A%22user%40gmail.com%22%7D%2C%22organization%22%3A%7B%22login%22%3A%22ExampleOrg%22%2C%22id%22%3A38541875%2C%22node_id%22%3A%22MDEyOk9yZ2FuaXphdGlvbjM4NTQxODc1%22%2C%22url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%22%2C%22repos_url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%2Frepos%22%2C%22events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%2Fevents%22%2C%22hooks_url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%2Fhooks%22%2C%22issues_url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%2Fissues%22%2C%22members_url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%2Fmembers%7B%2Fmember%7D%22%2C%22public_members_url%22%3A%22https%3A%2F%2Fapi.github.com%2Forgs%2FExampleOrg%2Fpublic_members%7B%2Fmember%7D%22%2C%22avatar_url%22%3A%22https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F38541875%3Fv%3D4%22%2C%22description%22%3A%22%22%7D%2C%22sender%22%3A%7B%22login%22%3A%22user%22%2C%22id%22%3A40922393%2C%22node_id%22%3A%22MDQ6VXNlcjQwOTIyMzkz%22%2C%22avatar_url%22%3A%22https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F40922393%3Fv%3D4%22%2C%22gravatar_id%22%3A%22%22%2C%22url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%22%2C%22html_url%22%3A%22https%3A%2F%2Fgithub.com%2Fuser%22%2C%22followers_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Ffollowers%22%2C%22following_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Ffollowing%7B%2Fother_user%7D%22%2C%22gists_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Fgists%7B%2Fgist_id%7D%22%2C%22starred_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Fstarred%7B%2Fowner%7D%7B%2Frepo%7D%22%2C%22subscriptions_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Fsubscriptions%22%2C%22organizations_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Forgs%22%2C%22repos_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Frepos%22%2C%22events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Fevents%7B%2Fprivacy%7D%22%2C%22received_events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Fusers%2Fuser%2Freceived_events%22%2C%22type%22%3A%22User%22%2C%22site_admin%22%3Afalse%7D%2C%22created%22%3Afalse%2C%22deleted%22%3Afalse%2C%22forced%22%3Atrue%2C%22base_ref%22%3Anull%2C%22compare%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy%2Fcompare%2F759a52dcba82...85dbc9897dc9%22%2C%22commits%22%3A%5B%5D%2C%22head_commit%22%3A%7B%22id%22%3A%2285dbc9897dc9fd2bd90f10989d92c5c9036e45db%22%2C%22tree_id%22%3A%224a0257d125f91c6fdb3a89f649bca04be1b13a7b%22%2C%22distinct%22%3Atrue%2C%22message%22%3A%22build%28deps-dev%29%3A+bump+type-fest+from+2.12.1+to+2.12.2+%28%2399%29%22%2C%22timestamp%22%3A%222022-04-06T08%3A31%3A33-05%3A00%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2FExampleOrg%2Fgithub-webhook-proxy%2Fcommit%2F85dbc9897dc9fd2bd90f10989d92c5c9036e45db%22%2C%22author%22%3A%7B%22name%22%3A%22dependabot%5Bbot%5D%22%2C%22email%22%3A%2249699333%2Bdependabot%5Bbot%5D%40users.noreply.github.com%22%2C%22username%22%3A%22dependabot%5Bbot%5D%22%7D%2C%22committer%22%3A%7B%22name%22%3A%22GitHub%22%2C%22email%22%3A%22noreply%40github.com%22%2C%22username%22%3A%22web-flow%22%7D%2C%22added%22%3A%5B%5D%2C%22removed%22%3A%5B%5D%2C%22modified%22%3A%5B%22package.json%22%2C%22yarn.lock%22%5D%7D%7D 2 | -------------------------------------------------------------------------------- /fixtures/valid-ping-payload.ts: -------------------------------------------------------------------------------- 1 | import { PingEvent } from "../lambda/types"; 2 | 3 | export const VALID_PING_EVENT: PingEvent = { 4 | zen: "Design for failure.", 5 | hook_id: 391282347, 6 | hook: { 7 | type: "Repository", 8 | id: 391282347, 9 | name: "web", 10 | active: true, 11 | events: ["push"], 12 | config: { 13 | content_type: "json", 14 | url: "https://approved.host/github-webhook/", 15 | insecure_ssl: "0", 16 | }, 17 | updated_at: "2022-12-05T20:28:34Z", 18 | created_at: "2022-12-05T20:28:34Z", 19 | url: "https://api.github.com/repos/github-org/github-repo/hooks/391282347", 20 | test_url: 21 | "https://api.github.com/repos/github-org/github-repo/hooks/391282347/test", 22 | ping_url: 23 | "https://api.github.com/repos/github-org/github-repo/hooks/391282347/pings", 24 | deliveries_url: 25 | "https://api.github.com/repos/github-org/github-repo/hooks/391282347/deliveries", 26 | last_response: { 27 | code: null, 28 | status: "unused", 29 | message: null, 30 | }, 31 | }, 32 | repository: { 33 | id: 567006112, 34 | node_id: "R_kgDOIcvToA", 35 | name: "github-repo", 36 | full_name: "github-org/github-repo", 37 | private: true, 38 | owner: { 39 | login: "github-org", 40 | id: 107203838, 41 | node_id: "O_kgDOBmPM_g", 42 | avatar_url: "https://avatars.githubusercontent.com/u/107203838?v=4", 43 | gravatar_id: "", 44 | url: "https://api.github.com/users/github-org", 45 | html_url: "https://github.com/github-org", 46 | followers_url: "https://api.github.com/users/github-org/followers", 47 | following_url: 48 | "https://api.github.com/users/github-org/following{/other_user}", 49 | gists_url: "https://api.github.com/users/github-org/gists{/gist_id}", 50 | starred_url: 51 | "https://api.github.com/users/github-org/starred{/owner}{/repo}", 52 | subscriptions_url: 53 | "https://api.github.com/users/github-org/subscriptions", 54 | organizations_url: "https://api.github.com/users/github-org/orgs", 55 | repos_url: "https://api.github.com/users/github-org/repos", 56 | events_url: "https://api.github.com/users/github-org/events{/privacy}", 57 | received_events_url: 58 | "https://api.github.com/users/github-org/received_events", 59 | type: "Organization", 60 | site_admin: false, 61 | }, 62 | html_url: "https://github.com/github-org/github-repo", 63 | description: null, 64 | fork: false, 65 | url: "https://api.github.com/repos/github-org/github-repo", 66 | forks_url: "https://api.github.com/repos/github-org/github-repo/forks", 67 | keys_url: 68 | "https://api.github.com/repos/github-org/github-repo/keys{/key_id}", 69 | collaborators_url: 70 | "https://api.github.com/repos/github-org/github-repo/collaborators{/collaborator}", 71 | teams_url: "https://api.github.com/repos/github-org/github-repo/teams", 72 | hooks_url: "https://api.github.com/repos/github-org/github-repo/hooks", 73 | issue_events_url: 74 | "https://api.github.com/repos/github-org/github-repo/issues/events{/number}", 75 | events_url: "https://api.github.com/repos/github-org/github-repo/events", 76 | assignees_url: 77 | "https://api.github.com/repos/github-org/github-repo/assignees{/user}", 78 | branches_url: 79 | "https://api.github.com/repos/github-org/github-repo/branches{/branch}", 80 | tags_url: "https://api.github.com/repos/github-org/github-repo/tags", 81 | blobs_url: 82 | "https://api.github.com/repos/github-org/github-repo/git/blobs{/sha}", 83 | git_tags_url: 84 | "https://api.github.com/repos/github-org/github-repo/git/tags{/sha}", 85 | git_refs_url: 86 | "https://api.github.com/repos/github-org/github-repo/git/refs{/sha}", 87 | trees_url: 88 | "https://api.github.com/repos/github-org/github-repo/git/trees{/sha}", 89 | statuses_url: 90 | "https://api.github.com/repos/github-org/github-repo/statuses/{sha}", 91 | languages_url: 92 | "https://api.github.com/repos/github-org/github-repo/languages", 93 | stargazers_url: 94 | "https://api.github.com/repos/github-org/github-repo/stargazers", 95 | contributors_url: 96 | "https://api.github.com/repos/github-org/github-repo/contributors", 97 | subscribers_url: 98 | "https://api.github.com/repos/github-org/github-repo/subscribers", 99 | subscription_url: 100 | "https://api.github.com/repos/github-org/github-repo/subscription", 101 | commits_url: 102 | "https://api.github.com/repos/github-org/github-repo/commits{/sha}", 103 | git_commits_url: 104 | "https://api.github.com/repos/github-org/github-repo/git/commits{/sha}", 105 | comments_url: 106 | "https://api.github.com/repos/github-org/github-repo/comments{/number}", 107 | issue_comment_url: 108 | "https://api.github.com/repos/github-org/github-repo/issues/comments{/number}", 109 | contents_url: 110 | "https://api.github.com/repos/github-org/github-repo/contents/{+path}", 111 | compare_url: 112 | "https://api.github.com/repos/github-org/github-repo/compare/{base}...{head}", 113 | merges_url: "https://api.github.com/repos/github-org/github-repo/merges", 114 | archive_url: 115 | "https://api.github.com/repos/github-org/github-repo/{archive_format}{/ref}", 116 | downloads_url: 117 | "https://api.github.com/repos/github-org/github-repo/downloads", 118 | issues_url: 119 | "https://api.github.com/repos/github-org/github-repo/issues{/number}", 120 | pulls_url: 121 | "https://api.github.com/repos/github-org/github-repo/pulls{/number}", 122 | milestones_url: 123 | "https://api.github.com/repos/github-org/github-repo/milestones{/number}", 124 | notifications_url: 125 | "https://api.github.com/repos/github-org/github-repo/notifications{?since,all,participating}", 126 | labels_url: 127 | "https://api.github.com/repos/github-org/github-repo/labels{/name}", 128 | releases_url: 129 | "https://api.github.com/repos/github-org/github-repo/releases{/id}", 130 | deployments_url: 131 | "https://api.github.com/repos/github-org/github-repo/deployments", 132 | created_at: "2022-11-16T21:46:21Z", 133 | updated_at: "2022-11-16T21:46:21Z", 134 | pushed_at: "2022-12-05T19:36:08Z", 135 | git_url: "git://github.com/github-org/github-repo.git", 136 | ssh_url: "git@github.com:github-org/github-repo.git", 137 | clone_url: "https://github.com/github-org/github-repo.git", 138 | svn_url: "https://github.com/github-org/github-repo", 139 | homepage: null, 140 | size: 25, 141 | stargazers_count: 0, 142 | watchers_count: 0, 143 | language: null, 144 | has_issues: true, 145 | has_projects: true, 146 | has_downloads: true, 147 | has_wiki: true, 148 | has_pages: false, 149 | forks_count: 0, 150 | mirror_url: null, 151 | archived: false, 152 | disabled: false, 153 | open_issues_count: 0, 154 | license: null, 155 | allow_forking: true, 156 | is_template: false, 157 | web_commit_signoff_required: false, 158 | topics: [], 159 | visibility: "internal", 160 | forks: 0, 161 | open_issues: 0, 162 | watchers: 0, 163 | default_branch: "main", 164 | }, 165 | sender: { 166 | login: "username_suffix", 167 | id: 118491937, 168 | node_id: "U_kgDOBxALIQ", 169 | avatar_url: "https://avatars.githubusercontent.com/u/118491937?v=4", 170 | gravatar_id: "", 171 | url: "https://api.github.com/users/username_suffix", 172 | html_url: "https://github.com/username_suffix", 173 | followers_url: "https://api.github.com/users/username_suffix/followers", 174 | following_url: 175 | "https://api.github.com/users/username_suffix/following{/other_user}", 176 | gists_url: "https://api.github.com/users/username_suffix/gists{/gist_id}", 177 | starred_url: 178 | "https://api.github.com/users/username_suffix/starred{/owner}{/repo}", 179 | subscriptions_url: 180 | "https://api.github.com/users/username_suffix/subscriptions", 181 | organizations_url: "https://api.github.com/users/username_suffix/orgs", 182 | repos_url: "https://api.github.com/users/username_suffix/repos", 183 | events_url: "https://api.github.com/users/username_suffix/events{/privacy}", 184 | received_events_url: 185 | "https://api.github.com/users/username_suffix/received_events", 186 | type: "User", 187 | site_admin: false, 188 | }, 189 | }; 190 | -------------------------------------------------------------------------------- /fixtures/valid-push-payload-user-repo.ts: -------------------------------------------------------------------------------- 1 | import { PushEvent } from "../lambda/types"; 2 | 3 | export const VALID_PUSH_PAYLOAD_USER_REPO: PushEvent = { 4 | ref: "refs/heads/main", 5 | before: "448223ee31c525296e09832c0da95559015f500c", 6 | after: "7119b388e221a96ced5e1dfa0528d51847828308", 7 | repository: { 8 | id: 482984142, 9 | node_id: "R_kgDOHMnAzg", 10 | name: "github-webhook-proxy", 11 | full_name: "username_suffix/github-webhook-proxy", 12 | private: true, 13 | owner: { 14 | name: "username_suffix", 15 | email: "user@ExampleOrg.com", 16 | login: "username_suffix", 17 | id: 103291641, 18 | node_id: "U_kgDOBiga-Q", 19 | avatar_url: "https://avatars.githubusercontent.com/u/103291641?v=4", 20 | gravatar_id: "", 21 | url: "https://api.github.com/users/username_suffix", 22 | html_url: "https://github.com/username_suffix", 23 | followers_url: "https://api.github.com/users/username_suffix/followers", 24 | following_url: 25 | "https://api.github.com/users/username_suffix/following{/other_user}", 26 | gists_url: "https://api.github.com/users/username_suffix/gists{/gist_id}", 27 | starred_url: 28 | "https://api.github.com/users/username_suffix/starred{/owner}{/repo}", 29 | subscriptions_url: 30 | "https://api.github.com/users/username_suffix/subscriptions", 31 | organizations_url: "https://api.github.com/users/username_suffix/orgs", 32 | repos_url: "https://api.github.com/users/username_suffix/repos", 33 | events_url: 34 | "https://api.github.com/users/username_suffix/events{/privacy}", 35 | received_events_url: 36 | "https://api.github.com/users/username_suffix/received_events", 37 | type: "User", 38 | site_admin: false, 39 | }, 40 | html_url: "https://github.com/username_suffix/github-webhook-proxy", 41 | description: null, 42 | fork: false, 43 | url: "https://github.com/username_suffix/github-webhook-proxy", 44 | forks_url: 45 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/forks", 46 | keys_url: 47 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/keys{/key_id}", 48 | collaborators_url: 49 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/collaborators{/collaborator}", 50 | teams_url: 51 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/teams", 52 | hooks_url: 53 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/hooks", 54 | issue_events_url: 55 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/issues/events{/number}", 56 | events_url: 57 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/events", 58 | assignees_url: 59 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/assignees{/user}", 60 | branches_url: 61 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/branches{/branch}", 62 | tags_url: 63 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/tags", 64 | blobs_url: 65 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/git/blobs{/sha}", 66 | git_tags_url: 67 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/git/tags{/sha}", 68 | git_refs_url: 69 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/git/refs{/sha}", 70 | trees_url: 71 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/git/trees{/sha}", 72 | statuses_url: 73 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/statuses/{sha}", 74 | languages_url: 75 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/languages", 76 | stargazers_url: 77 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/stargazers", 78 | contributors_url: 79 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/contributors", 80 | subscribers_url: 81 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/subscribers", 82 | subscription_url: 83 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/subscription", 84 | commits_url: 85 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/commits{/sha}", 86 | git_commits_url: 87 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/git/commits{/sha}", 88 | comments_url: 89 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/comments{/number}", 90 | issue_comment_url: 91 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/issues/comments{/number}", 92 | contents_url: 93 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/contents/{+path}", 94 | compare_url: 95 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/compare/{base}...{head}", 96 | merges_url: 97 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/merges", 98 | archive_url: 99 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/{archive_format}{/ref}", 100 | downloads_url: 101 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/downloads", 102 | issues_url: 103 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/issues{/number}", 104 | pulls_url: 105 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/pulls{/number}", 106 | milestones_url: 107 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/milestones{/number}", 108 | notifications_url: 109 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/notifications{?since,all,participating}", 110 | labels_url: 111 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/labels{/name}", 112 | releases_url: 113 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/releases{/id}", 114 | deployments_url: 115 | "https://api.github.com/repos/username_suffix/github-webhook-proxy/deployments", 116 | created_at: 1650312935, 117 | updated_at: "2022-04-19T12:27:56Z", 118 | pushed_at: 1650489516, 119 | git_url: "git://github.com/username_suffix/github-webhook-proxy.git", 120 | ssh_url: "git@github.com:username_suffix/github-webhook-proxy.git", 121 | clone_url: "https://github.com/username_suffix/github-webhook-proxy.git", 122 | svn_url: "https://github.com/username_suffix/github-webhook-proxy", 123 | homepage: null, 124 | size: 3, 125 | stargazers_count: 0, 126 | watchers_count: 0, 127 | language: null, 128 | has_issues: true, 129 | has_projects: true, 130 | has_downloads: true, 131 | has_wiki: true, 132 | has_pages: false, 133 | forks_count: 0, 134 | mirror_url: null, 135 | archived: false, 136 | disabled: false, 137 | open_issues_count: 0, 138 | license: null, 139 | allow_forking: true, 140 | is_template: false, 141 | web_commit_signoff_required: false, 142 | topics: [], 143 | visibility: "private", 144 | forks: 0, 145 | open_issues: 0, 146 | watchers: 0, 147 | default_branch: "main", 148 | stargazers: 0, 149 | master_branch: "main", 150 | has_discussions: false, 151 | }, 152 | pusher: { 153 | name: "username_suffix", 154 | email: "user@ExampleOrg.com", 155 | }, 156 | sender: { 157 | login: "username_suffix", 158 | id: 103291641, 159 | node_id: "U_kgDOBiga-Q", 160 | avatar_url: "https://avatars.githubusercontent.com/u/103291641?v=4", 161 | gravatar_id: "", 162 | url: "https://api.github.com/users/username_suffix", 163 | html_url: "https://github.com/username_suffix", 164 | followers_url: "https://api.github.com/users/username_suffix/followers", 165 | following_url: 166 | "https://api.github.com/users/username_suffix/following{/other_user}", 167 | gists_url: "https://api.github.com/users/username_suffix/gists{/gist_id}", 168 | starred_url: 169 | "https://api.github.com/users/username_suffix/starred{/owner}{/repo}", 170 | subscriptions_url: 171 | "https://api.github.com/users/username_suffix/subscriptions", 172 | organizations_url: "https://api.github.com/users/username_suffix/orgs", 173 | repos_url: "https://api.github.com/users/username_suffix/repos", 174 | events_url: "https://api.github.com/users/username_suffix/events{/privacy}", 175 | received_events_url: 176 | "https://api.github.com/users/username_suffix/received_events", 177 | type: "User", 178 | site_admin: false, 179 | }, 180 | created: false, 181 | deleted: false, 182 | forced: false, 183 | base_ref: null, 184 | compare: 185 | "https://github.com/username_suffix/github-webhook-proxy/compare/448223ee31c5...7119b388e221", 186 | commits: [ 187 | { 188 | id: "7119b388e221a96ced5e1dfa0528d51847828308", 189 | tree_id: "e5d86be93b96d8389e85e1e34560e936786e6ec2", 190 | distinct: true, 191 | message: "dummy commit", 192 | timestamp: "2022-04-20T17:18:32-04:00", 193 | url: "https://github.com/username_suffix/github-webhook-proxy/commit/7119b388e221a96ced5e1dfa0528d51847828308", 194 | author: { 195 | name: "user", 196 | email: "user@ExampleOrg.com", 197 | }, 198 | committer: { 199 | name: "user", 200 | email: "user@ExampleOrg.com", 201 | }, 202 | added: [], 203 | removed: [], 204 | modified: [], 205 | }, 206 | ], 207 | head_commit: { 208 | id: "7119b388e221a96ced5e1dfa0528d51847828308", 209 | tree_id: "e5d86be93b96d8389e85e1e34560e936786e6ec2", 210 | distinct: true, 211 | message: "dummy commit", 212 | timestamp: "2022-04-20T17:18:32-04:00", 213 | url: "https://github.com/username_suffix/github-webhook-proxy/commit/7119b388e221a96ced5e1dfa0528d51847828308", 214 | author: { 215 | name: "user", 216 | email: "user@ExampleOrg.com", 217 | }, 218 | committer: { 219 | name: "user", 220 | email: "user@ExampleOrg.com", 221 | }, 222 | added: [], 223 | removed: [], 224 | modified: [], 225 | }, 226 | }; 227 | -------------------------------------------------------------------------------- /fixtures/valid-push-payload.ts: -------------------------------------------------------------------------------- 1 | import { PushEvent } from "../lambda/types"; 2 | 3 | export const VALID_PUSH_PAYLOAD: PushEvent = { 4 | ref: "refs/heads/main", 5 | before: "448223ee31c525296e09832c0da95559015f500c", 6 | after: "7119b388e221a96ced5e1dfa0528d51847828308", 7 | repository: { 8 | id: 482984142, 9 | node_id: "R_kgDOHMnAzg", 10 | name: "github-webhook-proxy", 11 | full_name: "ExampleOrg/github-webhook-proxy", 12 | private: true, 13 | owner: { 14 | name: "ExampleOrg", 15 | email: "user@ExampleOrg.com", 16 | login: "ExampleOrg", 17 | id: 103291641, 18 | node_id: "U_kgDOBiga-Q", 19 | avatar_url: "https://avatars.githubusercontent.com/u/103291641?v=4", 20 | gravatar_id: "", 21 | url: "https://api.github.com/users/ExampleOrg", 22 | html_url: "https://github.com/ExampleOrg", 23 | followers_url: "https://api.github.com/users/ExampleOrg/followers", 24 | following_url: 25 | "https://api.github.com/users/ExampleOrg/following{/other_user}", 26 | gists_url: "https://api.github.com/users/ExampleOrg/gists{/gist_id}", 27 | starred_url: 28 | "https://api.github.com/users/ExampleOrg/starred{/owner}{/repo}", 29 | subscriptions_url: 30 | "https://api.github.com/users/ExampleOrg/subscriptions", 31 | organizations_url: "https://api.github.com/users/ExampleOrg/orgs", 32 | repos_url: "https://api.github.com/users/ExampleOrg/repos", 33 | events_url: "https://api.github.com/users/ExampleOrg/events{/privacy}", 34 | received_events_url: 35 | "https://api.github.com/users/ExampleOrg/received_events", 36 | type: "User", 37 | site_admin: false, 38 | }, 39 | html_url: "https://github.com/ExampleOrg/github-webhook-proxy", 40 | description: null, 41 | fork: false, 42 | url: "https://github.com/ExampleOrg/github-webhook-proxy", 43 | forks_url: 44 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/forks", 45 | keys_url: 46 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/keys{/key_id}", 47 | collaborators_url: 48 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/collaborators{/collaborator}", 49 | teams_url: 50 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/teams", 51 | hooks_url: 52 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/hooks", 53 | issue_events_url: 54 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/issues/events{/number}", 55 | events_url: 56 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/events", 57 | assignees_url: 58 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/assignees{/user}", 59 | branches_url: 60 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/branches{/branch}", 61 | tags_url: 62 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/tags", 63 | blobs_url: 64 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/git/blobs{/sha}", 65 | git_tags_url: 66 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/git/tags{/sha}", 67 | git_refs_url: 68 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/git/refs{/sha}", 69 | trees_url: 70 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/git/trees{/sha}", 71 | statuses_url: 72 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/statuses/{sha}", 73 | languages_url: 74 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/languages", 75 | stargazers_url: 76 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/stargazers", 77 | contributors_url: 78 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/contributors", 79 | subscribers_url: 80 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/subscribers", 81 | subscription_url: 82 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/subscription", 83 | commits_url: 84 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/commits{/sha}", 85 | git_commits_url: 86 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/git/commits{/sha}", 87 | comments_url: 88 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/comments{/number}", 89 | issue_comment_url: 90 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/issues/comments{/number}", 91 | contents_url: 92 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/contents/{+path}", 93 | compare_url: 94 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/compare/{base}...{head}", 95 | merges_url: 96 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/merges", 97 | archive_url: 98 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/{archive_format}{/ref}", 99 | downloads_url: 100 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/downloads", 101 | issues_url: 102 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/issues{/number}", 103 | pulls_url: 104 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/pulls{/number}", 105 | milestones_url: 106 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/milestones{/number}", 107 | notifications_url: 108 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/notifications{?since,all,participating}", 109 | labels_url: 110 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/labels{/name}", 111 | releases_url: 112 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/releases{/id}", 113 | deployments_url: 114 | "https://api.github.com/repos/ExampleOrg/github-webhook-proxy/deployments", 115 | created_at: 1650312935, 116 | updated_at: "2022-04-19T12:27:56Z", 117 | pushed_at: 1650489516, 118 | git_url: "git://github.com/ExampleOrg/github-webhook-proxy.git", 119 | ssh_url: "git@github.com:ExampleOrg/github-webhook-proxy.git", 120 | clone_url: "https://github.com/ExampleOrg/github-webhook-proxy.git", 121 | svn_url: "https://github.com/ExampleOrg/github-webhook-proxy", 122 | homepage: null, 123 | size: 3, 124 | stargazers_count: 0, 125 | watchers_count: 0, 126 | language: null, 127 | has_issues: true, 128 | has_projects: true, 129 | has_downloads: true, 130 | has_wiki: true, 131 | has_pages: false, 132 | forks_count: 0, 133 | mirror_url: null, 134 | archived: false, 135 | disabled: false, 136 | open_issues_count: 0, 137 | license: null, 138 | allow_forking: true, 139 | is_template: false, 140 | web_commit_signoff_required: false, 141 | topics: [], 142 | visibility: "private", 143 | forks: 0, 144 | open_issues: 0, 145 | watchers: 0, 146 | default_branch: "main", 147 | stargazers: 0, 148 | master_branch: "main", 149 | has_discussions: false, 150 | }, 151 | pusher: { 152 | name: "ExampleOrg", 153 | email: "user@ExampleOrg.com", 154 | }, 155 | organization: { 156 | login: "ExampleOrg", 157 | id: 102772738, 158 | node_id: "O_kgDOBiAwAg", 159 | url: "https://api.github.com/orgs/ExampleOrg", 160 | repos_url: "https://api.github.com/orgs/ExampleOrg/repos", 161 | events_url: "https://api.github.com/orgs/ExampleOrg/events", 162 | hooks_url: "https://api.github.com/orgs/ExampleOrg/hooks", 163 | issues_url: "https://api.github.com/orgs/ExampleOrg/issues", 164 | members_url: "https://api.github.com/orgs/ExampleOrg/members{/member}", 165 | public_members_url: 166 | "https://api.github.com/orgs/ExampleOrg/public_members{/member}", 167 | avatar_url: "https://avatars.githubusercontent.com/u/102772738?v=4", 168 | description: null, 169 | }, 170 | enterprise: { 171 | id: 123, 172 | slug: "some_enterprise", 173 | name: "Some Enterprise", 174 | node_id: "E_kgDNLDI", 175 | avatar_url: "https://avatars.githubusercontent.com/b/11314?v=4", 176 | description: null, 177 | website_url: null, 178 | html_url: "https://github.com/enterprises/some_enterprise", 179 | created_at: "2022-01-31T20:50:21Z", 180 | updated_at: "2022-02-03T03:52:22Z", 181 | }, 182 | sender: { 183 | login: "ExampleOrg", 184 | id: 103291641, 185 | node_id: "U_kgDOBiga-Q", 186 | avatar_url: "https://avatars.githubusercontent.com/u/103291641?v=4", 187 | gravatar_id: "", 188 | url: "https://api.github.com/users/ExampleOrg", 189 | html_url: "https://github.com/ExampleOrg", 190 | followers_url: "https://api.github.com/users/ExampleOrg/followers", 191 | following_url: 192 | "https://api.github.com/users/ExampleOrg/following{/other_user}", 193 | gists_url: "https://api.github.com/users/ExampleOrg/gists{/gist_id}", 194 | starred_url: 195 | "https://api.github.com/users/ExampleOrg/starred{/owner}{/repo}", 196 | subscriptions_url: "https://api.github.com/users/ExampleOrg/subscriptions", 197 | organizations_url: "https://api.github.com/users/ExampleOrg/orgs", 198 | repos_url: "https://api.github.com/users/ExampleOrg/repos", 199 | events_url: "https://api.github.com/users/ExampleOrg/events{/privacy}", 200 | received_events_url: 201 | "https://api.github.com/users/ExampleOrg/received_events", 202 | type: "User", 203 | site_admin: false, 204 | }, 205 | created: false, 206 | deleted: false, 207 | forced: false, 208 | base_ref: null, 209 | compare: 210 | "https://github.com/ExampleOrg/github-webhook-proxy/compare/448223ee31c5...7119b388e221", 211 | commits: [ 212 | { 213 | id: "7119b388e221a96ced5e1dfa0528d51847828308", 214 | tree_id: "e5d86be93b96d8389e85e1e34560e936786e6ec2", 215 | distinct: true, 216 | message: "dummy commit", 217 | timestamp: "2022-04-20T17:18:32-04:00", 218 | url: "https://github.com/ExampleOrg/github-webhook-proxy/commit/7119b388e221a96ced5e1dfa0528d51847828308", 219 | author: { 220 | name: "user", 221 | email: "user@ExampleOrg.com", 222 | }, 223 | committer: { 224 | name: "user", 225 | email: "user@ExampleOrg.com", 226 | }, 227 | added: [], 228 | removed: [], 229 | modified: [], 230 | }, 231 | ], 232 | head_commit: { 233 | id: "7119b388e221a96ced5e1dfa0528d51847828308", 234 | tree_id: "e5d86be93b96d8389e85e1e34560e936786e6ec2", 235 | distinct: true, 236 | message: "dummy commit", 237 | timestamp: "2022-04-20T17:18:32-04:00", 238 | url: "https://github.com/ExampleOrg/github-webhook-proxy/commit/7119b388e221a96ced5e1dfa0528d51847828308", 239 | author: { 240 | name: "user", 241 | email: "user@ExampleOrg.com", 242 | }, 243 | committer: { 244 | name: "user", 245 | email: "user@ExampleOrg.com", 246 | }, 247 | added: [], 248 | removed: [], 249 | modified: [], 250 | }, 251 | }; 252 | -------------------------------------------------------------------------------- /github-hooks-ip-ranges.tf: -------------------------------------------------------------------------------- 1 | locals { github_hooks_ip_ranges = ["192.30.252.0/22", "185.199.108.0/22", "140.82.112.0/20", "143.55.64.0/20", "2a0a:a440::/29", "2606:50c0::/32"] } 2 | -------------------------------------------------------------------------------- /lambda.tf: -------------------------------------------------------------------------------- 1 | data "aws_s3_object" "proxy_lambda" { 2 | bucket = var.lambda_bucket_name 3 | key = "${local.module_name}/proxy-lambda.zip" 4 | } 5 | 6 | resource "aws_lambda_function" "proxy" { 7 | handler = "build/proxy.handler" 8 | function_name = "${var.resource_prefix}-proxy" 9 | memory_size = 128 10 | role = aws_iam_role.proxy.arn 11 | runtime = "nodejs20.x" 12 | s3_bucket = data.aws_s3_object.proxy_lambda.bucket 13 | s3_key = data.aws_s3_object.proxy_lambda.key 14 | s3_object_version = data.aws_s3_object.proxy_lambda.version_id 15 | tags = var.custom_tags 16 | timeout = var.lambda_timeout_seconds 17 | layers = [var.lambda_layer_arn] 18 | environment { 19 | variables = { 20 | ENTERPRISE_SLUG = var.enterprise_slug 21 | ENTERPRISE_MANAGED_USER_SUFFIX = var.enterprise_managed_user_suffix 22 | } 23 | } 24 | 25 | tracing_config { 26 | mode = "Active" 27 | } 28 | 29 | vpc_config { 30 | subnet_ids = var.subnet_ids 31 | security_group_ids = [aws_security_group.lambda.id] 32 | } 33 | } 34 | 35 | data "aws_iam_policy_document" "proxy_service" { 36 | statement { 37 | actions = ["sts:AssumeRole"] 38 | principals { 39 | type = "Service" 40 | identifiers = ["lambda.amazonaws.com"] 41 | } 42 | } 43 | } 44 | 45 | resource "aws_iam_role" "proxy" { 46 | name = "${var.resource_prefix}-proxy-role" 47 | assume_role_policy = data.aws_iam_policy_document.proxy_service.json 48 | tags = var.custom_tags 49 | } 50 | 51 | resource "aws_iam_role_policy" "extra_policy" { 52 | count = var.extra_role_policy != null ? 1 : 0 53 | role = aws_iam_role.proxy.name 54 | policy = jsondecode(var.extra_role_policy) 55 | } 56 | 57 | resource "aws_iam_role_policy_attachment" "basic_execution" { 58 | role = aws_iam_role.proxy.name 59 | policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" 60 | } 61 | 62 | resource "aws_iam_role_policy_attachment" "vpc_execution" { 63 | role = aws_iam_role.proxy.name 64 | policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" 65 | } 66 | -------------------------------------------------------------------------------- /lambda/destination-host-is-allowed.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import { readFileFromLayer } from "./file-readers"; 15 | import micromatch from "micromatch"; 16 | 17 | export function destinationHostIsAllowed(url: string) { 18 | const allowedDestinationHostsContents = readFileFromLayer( 19 | "allowed-destination-hosts.json", 20 | ); 21 | if (!allowedDestinationHostsContents) { 22 | return true; 23 | } 24 | const allowedDestinationHosts: string[] = JSON.parse( 25 | allowedDestinationHostsContents, 26 | ); 27 | const host = new URL(url).host; 28 | const destinationHostIsAllowed = 29 | allowedDestinationHosts.includes(host) || 30 | micromatch.isMatch(host, allowedDestinationHosts); 31 | if (!destinationHostIsAllowed) { 32 | console.error( 33 | `Destination host ${host} does not match allowlist ${allowedDestinationHosts}`, 34 | ); 35 | } 36 | return destinationHostIsAllowed; 37 | } 38 | -------------------------------------------------------------------------------- /lambda/file-readers.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import { existsSync, readFileSync } from "fs"; 15 | 16 | export function readFileFromLayer(fileName: string) { 17 | const filePath = `/opt/layer/${fileName}`; 18 | if (!existsSync(filePath)) { 19 | return undefined; 20 | } 21 | 22 | return readFileSync(filePath).toString(); 23 | } 24 | 25 | export function getPublicCerts() { 26 | return readFileSync("build/public-certs.pem").toString(); 27 | } 28 | -------------------------------------------------------------------------------- /lambda/get-https-agent.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import https from "https"; 15 | import { getPublicCerts, readFileFromLayer } from "./file-readers"; 16 | 17 | export function getHttpsAgent() { 18 | const suppliedCertificateAuthority = readFileFromLayer("ca.pem"); 19 | const suppliedCertificate = readFileFromLayer("cert.pem"); 20 | if (!suppliedCertificateAuthority || !suppliedCertificate) { 21 | return undefined; 22 | } 23 | 24 | return new https.Agent({ 25 | ca: [getPublicCerts(), suppliedCertificateAuthority].join("\n"), 26 | cert: suppliedCertificate, 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /lambda/parse-request-body.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import { IncomingHttpHeaders } from "http"; 15 | import { bodySchema, CONTENT_TYPES, headersSchema } from "./schema"; 16 | import { EnterpriseProxyEvent } from "./types"; 17 | 18 | export function parseRequestBody( 19 | body: string, 20 | headers: IncomingHttpHeaders, 21 | ): EnterpriseProxyEvent | undefined { 22 | const headersResult = headersSchema.parse(headers); 23 | const contentType = headersResult["content-type"]; 24 | try { 25 | switch (contentType) { 26 | case CONTENT_TYPES.JSON: 27 | return JSON.parse(body); 28 | case CONTENT_TYPES.URL_ENCODED: 29 | const params = new URLSearchParams(body); 30 | const payloadParam = params.get("payload"); 31 | const { payload } = bodySchema.parse(payloadParam); 32 | return JSON.parse(decodeURIComponent(payload)); 33 | } 34 | } catch (error) { 35 | console.error(`Error parsing request body: ${error}`); 36 | return undefined; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lambda/proxy.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import { handler } from "./proxy"; 15 | import axios, { AxiosRequestHeaders, AxiosResponse } from "axios"; 16 | import { readFileSync } from "fs"; 17 | import { Agent } from "https"; 18 | import { readFileFromLayer } from "./file-readers"; 19 | import { APIGatewayProxyWithLambdaAuthorizerEvent } from "aws-lambda"; 20 | import { VALID_PING_EVENT } from "../fixtures/valid-ping-payload"; 21 | import { VALID_PUSH_PAYLOAD } from "../fixtures/valid-push-payload"; 22 | import { VALID_PUSH_PAYLOAD_USER_REPO } from "../fixtures/valid-push-payload-user-repo"; 23 | const urlencodedPayload = readFileSync( 24 | "fixtures/invalid-payload-urlencoded.txt", 25 | ).toString(); 26 | 27 | jest.mock("axios"); 28 | jest.mock("./file-readers"); 29 | const axiosResponse: AxiosResponse = { 30 | status: 200, 31 | data: { 32 | some: "data", 33 | }, 34 | headers: { 35 | response: "headers", 36 | }, 37 | statusText: "status", 38 | config: { 39 | headers: {} as AxiosRequestHeaders, 40 | }, 41 | }; 42 | (axios.post as jest.Mock).mockResolvedValue(axiosResponse); 43 | const expectedResponseObject = { 44 | statusCode: 200, 45 | body: '{"some":"data"}', 46 | headers: { response: "headers" }, 47 | }; 48 | const stringifiedPayload = JSON.stringify(VALID_PUSH_PAYLOAD); 49 | const baseEvent: APIGatewayProxyWithLambdaAuthorizerEvent = { 50 | body: stringifiedPayload, 51 | headers: { 52 | Accept: "*/*", 53 | "content-type": "application/json", 54 | Host: "some-api.us-west-2.amazonaws.com", 55 | }, 56 | pathParameters: { 57 | endpointId: encodeURIComponent("https://approved.host/github-webhook/"), 58 | }, 59 | multiValueHeaders: {}, 60 | httpMethod: "POST", 61 | isBase64Encoded: false, 62 | path: "", 63 | queryStringParameters: {}, 64 | multiValueQueryStringParameters: {}, 65 | stageVariables: {}, 66 | requestContext: {} as any, 67 | resource: "", 68 | }; 69 | const fileMap: Record = { 70 | "allowed-destination-hosts.json": JSON.stringify([ 71 | "approved.host", 72 | "another.approved.host", 73 | "a.wildcard.*.host", 74 | ]), 75 | }; 76 | (readFileFromLayer as jest.Mock).mockImplementation( 77 | (fileName: string) => fileMap[fileName], 78 | ); 79 | 80 | describe("proxy", () => { 81 | beforeEach(() => { 82 | process.env.ENTERPRISE_SLUG = "some_enterprise"; 83 | process.env.ENTERPRISE_MANAGED_USER_SUFFIX = ""; 84 | }); 85 | 86 | it("should reject a request with an invalid urlencoded payload", async () => { 87 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 88 | ...baseEvent, 89 | headers: { 90 | ...baseEvent.headers, 91 | "content-type": "application/x-www-form-urlencoded", 92 | }, 93 | body: urlencodedPayload, 94 | }; 95 | const result = await handler(event); 96 | expect(result).toEqual({ statusCode: 403, body: "Access denied" }); 97 | expect(axios.post).not.toHaveBeenCalled(); 98 | }); 99 | 100 | it("should reject a request with an endpointId which is not an encoded URL", async () => { 101 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 102 | ...baseEvent, 103 | pathParameters: { 104 | endpointId: "some-invalid-endpoint", 105 | }, 106 | }; 107 | const result = await handler(event); 108 | expect(result).toEqual({ statusCode: 403, body: "Access denied" }); 109 | expect(axios.post).not.toHaveBeenCalled(); 110 | }); 111 | 112 | it("should allow a request from a managed user suffix when supplied", async () => { 113 | process.env.ENTERPRISE_MANAGED_USER_SUFFIX = "suffix"; 114 | const destinationUrl = "https://approved.host/github-webhook/"; 115 | const endpointId = encodeURIComponent(destinationUrl); 116 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 117 | ...baseEvent, 118 | body: JSON.stringify(VALID_PUSH_PAYLOAD_USER_REPO), 119 | pathParameters: { 120 | endpointId, 121 | }, 122 | }; 123 | const result = await handler(event); 124 | expect(result).toEqual(expectedResponseObject); 125 | expect(axios.post).toHaveBeenCalled(); 126 | }); 127 | 128 | it("should forward a request when header is Content-Type", async () => { 129 | const destinationUrl = "https://approved.host/github-webhook/"; 130 | const endpointId = encodeURIComponent(destinationUrl); 131 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 132 | ...baseEvent, 133 | headers: { 134 | Accept: "*/*", 135 | "Content-Type": "application/json", 136 | Host: "some-api.us-west-2.amazonaws.com", 137 | }, 138 | body: JSON.stringify(VALID_PUSH_PAYLOAD), 139 | pathParameters: { 140 | endpointId, 141 | }, 142 | }; 143 | const result = await handler(event); 144 | expect(result).toEqual(expectedResponseObject); 145 | expect(axios.post).toHaveBeenCalled(); 146 | }); 147 | 148 | it("should not forward a request that does not come from an enterprise or managed user suffix", async () => { 149 | const destinationUrl = "https://approved.host/github-webhook/"; 150 | const endpointId = encodeURIComponent(destinationUrl); 151 | const payload = { 152 | ...VALID_PUSH_PAYLOAD, 153 | enterprise: undefined, 154 | }; 155 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 156 | ...baseEvent, 157 | body: JSON.stringify(payload), 158 | pathParameters: { 159 | endpointId, 160 | }, 161 | }; 162 | const result = await handler(event); 163 | expect(result).toEqual({ statusCode: 403, body: "Access denied" }); 164 | expect(axios.post).not.toHaveBeenCalled(); 165 | }); 166 | 167 | it("should not forward a request that does not have an approved host", async () => { 168 | const destinationUrl = "https://not-an-approved.host/github-webhook/"; 169 | const endpointId = encodeURIComponent(destinationUrl); 170 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 171 | ...baseEvent, 172 | pathParameters: { 173 | endpointId, 174 | }, 175 | }; 176 | const result = await handler(event); 177 | expect(result).toEqual({ statusCode: 403, body: "Access denied" }); 178 | expect(axios.post).not.toHaveBeenCalled(); 179 | }); 180 | 181 | it("should forward a request that has an approved host which matches a wildcard", async () => { 182 | const destinationUrl = "https://a.wildcard.test.host/github-webhook/"; 183 | const endpointId = encodeURIComponent(destinationUrl); 184 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 185 | ...baseEvent, 186 | pathParameters: { 187 | endpointId, 188 | }, 189 | }; 190 | const result = await handler(event); 191 | expect(result).toEqual(expectedResponseObject); 192 | }); 193 | 194 | it("should forward a request from an enterprise and github org without supplied certs", async () => { 195 | const destinationUrl = "https://approved.host/github-webhook/"; 196 | const endpointId = encodeURIComponent(destinationUrl); 197 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 198 | ...baseEvent, 199 | pathParameters: { 200 | endpointId, 201 | }, 202 | }; 203 | const result = await handler(event); 204 | expect(axios.post).toHaveBeenCalledWith( 205 | destinationUrl, 206 | stringifiedPayload, 207 | { 208 | headers: { 209 | Accept: "*/*", 210 | "content-type": "application/json", 211 | }, 212 | }, 213 | ); 214 | expect(result).toEqual(expectedResponseObject); 215 | }); 216 | 217 | it("should forward a request from an enterprise and github org with supplied certs", async () => { 218 | const newFileMap: Record = { 219 | ...fileMap, 220 | "ca.pem": "some ca", 221 | "cert.pem": "some cert", 222 | }; 223 | (readFileFromLayer as jest.Mock).mockImplementation( 224 | (fileName: string) => newFileMap[fileName], 225 | ); 226 | const destinationUrl = "https://approved.host/github-webhook/"; 227 | const endpointId = encodeURIComponent(destinationUrl); 228 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 229 | ...baseEvent, 230 | pathParameters: { 231 | endpointId, 232 | }, 233 | }; 234 | const result = await handler(event); 235 | expect(axios.post).toHaveBeenCalledWith( 236 | destinationUrl, 237 | stringifiedPayload, 238 | { 239 | headers: { 240 | Accept: "*/*", 241 | "content-type": "application/json", 242 | }, 243 | httpsAgent: expect.any(Agent), 244 | }, 245 | ); 246 | expect(result).toEqual(expectedResponseObject); 247 | }); 248 | 249 | it("should return a 404 when no endpointId is found", async () => { 250 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 251 | ...baseEvent, 252 | pathParameters: {}, 253 | }; 254 | const result = await handler(event); 255 | expect(result).toEqual({ statusCode: 404, body: "Not found" }); 256 | expect(axios.post).not.toHaveBeenCalled(); 257 | }); 258 | 259 | it("should forward a ping event from a managed user suffix when supplied", async () => { 260 | process.env.ENTERPRISE_MANAGED_USER_SUFFIX = "suffix"; 261 | const destinationUrl = "https://approved.host/github-webhook/"; 262 | const endpointId = encodeURIComponent(destinationUrl); 263 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 264 | ...baseEvent, 265 | body: JSON.stringify(VALID_PING_EVENT), 266 | pathParameters: { 267 | endpointId, 268 | }, 269 | }; 270 | const result = await handler(event); 271 | expect(result).toEqual(expectedResponseObject); 272 | expect(axios.post).toHaveBeenCalled(); 273 | }); 274 | 275 | it("should return error response from axios", async () => { 276 | const axiosErrorResponse: AxiosResponse = { 277 | status: 400, 278 | data: { 279 | some: "error", 280 | }, 281 | headers: { 282 | response: "headers", 283 | }, 284 | statusText: "bad request", 285 | config: { 286 | headers: {} as AxiosRequestHeaders, 287 | }, 288 | }; 289 | (axios.post as jest.Mock).mockRejectedValue({ 290 | response: axiosErrorResponse, 291 | }); 292 | 293 | process.env.ENTERPRISE_MANAGED_USER_SUFFIX = "suffix"; 294 | const destinationUrl = "https://approved.host/github-webhook/"; 295 | const endpointId = encodeURIComponent(destinationUrl); 296 | const event: APIGatewayProxyWithLambdaAuthorizerEvent = { 297 | ...baseEvent, 298 | body: JSON.stringify(VALID_PUSH_PAYLOAD_USER_REPO), 299 | pathParameters: { 300 | endpointId, 301 | }, 302 | }; 303 | const result = await handler(event); 304 | expect(result).toEqual({ 305 | statusCode: 400, 306 | body: '{"some":"error"}', 307 | headers: { response: "headers" }, 308 | }); 309 | expect(axios.post).toHaveBeenCalled(); 310 | }); 311 | }); 312 | -------------------------------------------------------------------------------- /lambda/proxy.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import axios, { AxiosResponse } from "axios"; 15 | import { APIGatewayProxyWithLambdaAuthorizerEvent } from "aws-lambda"; 16 | import { requestPayloadIsValid } from "./request-payload-is-valid"; 17 | import { destinationHostIsAllowed } from "./destination-host-is-allowed"; 18 | import { getHttpsAgent } from "./get-https-agent"; 19 | import { parseRequestBody } from "./parse-request-body"; 20 | import { EnterpriseProxyEvent } from "./types"; 21 | import { urlIsValid } from "./url-is-valid"; 22 | import { axiosErrorSchema } from "./schema"; 23 | 24 | export async function handler( 25 | event: APIGatewayProxyWithLambdaAuthorizerEvent, 26 | ) { 27 | try { 28 | console.info("Incoming event:", JSON.stringify(event)); 29 | 30 | const { body, headers, pathParameters } = event; 31 | const endpointId = pathParameters?.endpointId; 32 | 33 | if (!endpointId || !body) { 34 | console.error( 35 | `EndpointId or body is missing. endpointId: ${endpointId}, body: ${body}`, 36 | ); 37 | return { statusCode: 404, body: "Not found" }; 38 | } 39 | 40 | const requestPayload = parseRequestBody(body, headers); 41 | const url = decodeURIComponent(endpointId); 42 | 43 | if ( 44 | !urlIsValid(url) || 45 | !requestPayloadIsValid(requestPayload) || 46 | !destinationHostIsAllowed(url) 47 | ) { 48 | return { statusCode: 403, body: "Access denied" }; 49 | } 50 | 51 | // Forward all headers except `Host` 52 | delete headers["Host"]; 53 | 54 | console.info("Forwarding webhook for url:", url); 55 | const { 56 | status: statusCode, 57 | data, 58 | headers: responseHeaders, 59 | } = await axios.post(url, body, { headers, httpsAgent: getHttpsAgent() }); 60 | console.info("Request was forwarded successfully!"); 61 | console.info( 62 | "result", 63 | JSON.stringify({ statusCode, body: data, headers: responseHeaders }), 64 | ); 65 | return { statusCode, body: JSON.stringify(data), headers: responseHeaders }; 66 | } catch (error) { 67 | const safeError = axiosErrorSchema.safeParse(error); 68 | if (safeError.success) { 69 | console.warn("Request was forwarded but got an error response."); 70 | const { 71 | status: statusCode, 72 | data, 73 | headers: responseHeaders, 74 | } = safeError.data.response as AxiosResponse; 75 | console.warn( 76 | "result", 77 | JSON.stringify({ statusCode, body: data, headers: responseHeaders }), 78 | ); 79 | return { 80 | statusCode, 81 | body: JSON.stringify(data), 82 | headers: responseHeaders, 83 | }; 84 | } 85 | 86 | console.error("An unknown error occurred.", error); 87 | return { statusCode: 500, body: `Internal server error: ${error}` }; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /lambda/request-payload-is-valid.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Expedia, Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | https://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | import { EnterpriseProxyEvent } from "./types"; 15 | 16 | export function requestPayloadIsValid(payload?: EnterpriseProxyEvent) { 17 | const { sender, enterprise } = payload ?? {}; 18 | return ( 19 | requestCameFromValidEnterprise(enterprise) || 20 | senderLoginEndsWithUserSuffix(sender?.login) 21 | ); 22 | } 23 | 24 | function requestCameFromValidEnterprise( 25 | enterprise?: EnterpriseProxyEvent["enterprise"], 26 | ) { 27 | const requestCameFromValidEnterprise = 28 | process.env.ENTERPRISE_SLUG && 29 | enterprise?.slug === process.env.ENTERPRISE_SLUG; 30 | if (!requestCameFromValidEnterprise) { 31 | console.error( 32 | `ENTERPRISE_SLUG environment variable ${process.env.ENTERPRISE_SLUG} does not equal enterprise slug ${enterprise?.slug}`, 33 | ); 34 | } 35 | return requestCameFromValidEnterprise; 36 | } 37 | 38 | function senderLoginEndsWithUserSuffix(senderLogin?: string) { 39 | const senderLoginEndsWithUserSuffix = 40 | process.env.ENTERPRISE_MANAGED_USER_SUFFIX && 41 | senderLogin?.endsWith(`_${process.env.ENTERPRISE_MANAGED_USER_SUFFIX}`); 42 | if (!senderLoginEndsWithUserSuffix) { 43 | console.error( 44 | `Sender login ${senderLogin} does not end with ENTERPRISE_MANAGED_USER_SUFFIX environment variable ${process.env.ENTERPRISE_MANAGED_USER_SUFFIX}`, 45 | ); 46 | } 47 | return senderLoginEndsWithUserSuffix; 48 | } 49 | -------------------------------------------------------------------------------- /lambda/schema.ts: -------------------------------------------------------------------------------- 1 | import { z } from "zod"; 2 | import mapKeys from "lodash.mapkeys"; 3 | 4 | export const urlSchema = z.string().url(); 5 | 6 | export const bodySchema = z.object({ 7 | payload: z.string(), 8 | }); 9 | 10 | export const CONTENT_TYPES = { 11 | JSON: "application/json", 12 | URL_ENCODED: "application/x-www-form-urlencoded", 13 | } as const; 14 | 15 | export const headersSchema = z.preprocess( 16 | (obj) => { 17 | if (obj && typeof obj == "object") { 18 | return mapKeys(obj, (_, key) => key.toLowerCase()); 19 | } 20 | }, 21 | z.object({ 22 | "content-type": z.nativeEnum(CONTENT_TYPES), 23 | }), 24 | ); 25 | 26 | export const axiosErrorSchema = z.object({ 27 | response: z.object({ 28 | status: z.number(), 29 | headers: z.any(), 30 | data: z.any(), 31 | }), 32 | }); 33 | -------------------------------------------------------------------------------- /lambda/types.ts: -------------------------------------------------------------------------------- 1 | import { components } from "@octokit/openapi-types"; 2 | 3 | export type EnterprisePayload = { 4 | enterprise?: components["schemas"]["enterprise"]; 5 | }; 6 | export type PingEvent = components["schemas"]["webhook-ping"]; 7 | export type PushEvent = components["schemas"]["webhook-push"]; 8 | 9 | export type EnterpriseProxyEvent = (PushEvent | PingEvent) & EnterprisePayload; 10 | -------------------------------------------------------------------------------- /lambda/url-is-valid.ts: -------------------------------------------------------------------------------- 1 | import { urlSchema } from "./schema"; 2 | 3 | export function urlIsValid(url: string) { 4 | const urlIsValid = urlSchema.safeParse(url).success; 5 | if (!urlIsValid) { 6 | console.error("Invalid URL:", url); 7 | } 8 | return urlIsValid; 9 | } 10 | -------------------------------------------------------------------------------- /locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | module_name = "github-webhook-proxy" 3 | api_gateway_domain_count = ( 4 | var.api_gateway_domain_name != null && 5 | var.route_53_record_name != null && 6 | var.certificate_arn != null && 7 | var.zone_id != null 8 | ) ? 1 : 0 9 | } 10 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "apigateway_invoke_url" { 2 | value = aws_api_gateway_stage.ingress.invoke_url 3 | } 4 | 5 | output "apigateway_ingress_id" { 6 | value = aws_api_gateway_deployment.ingress.id 7 | } 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-webhook-proxy", 3 | "packageManager": "bun@1.1.4", 4 | "main": "lambdas/proxy/index.js", 5 | "type": "module", 6 | "scripts": { 7 | "build": "bun build lambda/proxy.ts --outdir build/ --target node", 8 | "format": "prettier --write .", 9 | "format-check": "prettier --check", 10 | "test": "bun jest" 11 | }, 12 | "dependencies": { 13 | "axios": "1.9.0", 14 | "lodash.mapkeys": "4.6.0", 15 | "zod": "3.25.28" 16 | }, 17 | "devDependencies": { 18 | "@octokit/webhooks": "14.0.0", 19 | "@swc/jest": "0.2.38", 20 | "@types/aws-lambda": "8.10.149", 21 | "@types/jest": "29.5.14", 22 | "@types/lodash.mapkeys": "4.6.9", 23 | "@types/micromatch": "4.0.9", 24 | "jest": "29.7.0", 25 | "prettier": "3.5.3", 26 | "typescript": "5.8.3" 27 | }, 28 | "jest": { 29 | "transform": { 30 | "^.+\\.(t|j)sx?$": "@swc/jest" 31 | }, 32 | "moduleNameMapper": { 33 | "^(\\.{1,2}/.*)\\.js$": "$1" 34 | }, 35 | "extensionsToTreatAsEsm": [ 36 | ".ts" 37 | ], 38 | "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", 39 | "clearMocks": true 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["local>ExpediaGroup/renovate-config"], 4 | "assignAutomerge": true, 5 | "assigneesFromCodeOwners": true, 6 | "packageRules": [ 7 | { 8 | "matchDepTypes": ["dependencies", "devDependencies"], 9 | "matchUpdateTypes": ["patch", "minor"], 10 | "groupName": "dependencies", 11 | "automerge": true 12 | }, 13 | { 14 | "matchPackagePatterns": ["terraform"], 15 | "groupName": "dependencies" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "moduleDetection": "force", 5 | "moduleResolution": "node", 6 | "module": "esnext", 7 | "target": "esnext", 8 | "types": ["jest", "node"], 9 | "noEmit": true, 10 | "noImplicitAny": true, 11 | "noUncheckedIndexedAccess": true, 12 | "resolveJsonModule": true, 13 | "skipLibCheck": true, 14 | "strict": true 15 | }, 16 | "exclude": ["build"] 17 | } 18 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | # Global terraform vars 2 | variable "aws_region" { 3 | description = "The AWS region to deploy to (e.g. us-east-1)" 4 | type = string 5 | } 6 | 7 | variable "resource_prefix" { 8 | description = "Prefix of webhook proxy resources" 9 | type = string 10 | default = "gwp" 11 | } 12 | 13 | variable "custom_tags" { 14 | type = map(string) 15 | description = "Additional tags to be applied to all resources applied by this module." 16 | default = {} 17 | } 18 | 19 | variable "log_retention_days" { 20 | description = "Number of days CloudWatch will retain logs" 21 | type = number 22 | default = 7 23 | } 24 | 25 | variable "lambda_timeout_seconds" { 26 | description = "Number of seconds until lambda times out" 27 | type = number 28 | default = 10 29 | } 30 | 31 | // https://docs.github.com/en/enterprise-cloud@latest/admin/identity-and-access-management/using-enterprise-managed-users-and-saml-for-iam/about-enterprise-managed-users 32 | variable "enterprise_managed_user_suffix" { 33 | description = "Managed user suffix used for central identity management on GHEC" 34 | type = string 35 | default = "" 36 | } 37 | 38 | variable "enterprise_slug" { 39 | description = "The name (slug) of the enterprise on GHEC" 40 | type = string 41 | } 42 | 43 | variable "lambda_bucket_name" { 44 | description = "S3 bucket with lambda and layer archives" 45 | type = string 46 | } 47 | 48 | variable "lambda_layer_arn" { 49 | description = "Lambda layer ARN for data store" 50 | type = string 51 | } 52 | 53 | variable "extra_role_policy" { 54 | description = "jsonencoded string policy to include in the proxy lambda role" 55 | type = string 56 | default = null 57 | } 58 | 59 | variable "vpc_id" { 60 | description = "VPC id for Lambda VPC config" 61 | type = string 62 | } 63 | 64 | variable "subnet_ids" { 65 | description = "subnet_ids for Lambda VPC config" 66 | type = list(string) 67 | } 68 | 69 | variable "api_gateway_domain_name" { 70 | description = "Domain name for API gateway domain mapping" 71 | type = string 72 | default = null 73 | } 74 | 75 | variable "route_53_record_name" { 76 | description = "Record name for Route 53 record creation" 77 | type = string 78 | default = null 79 | } 80 | 81 | variable "certificate_arn" { 82 | description = "Certificate ARN for API gateway domain name" 83 | type = string 84 | default = null 85 | } 86 | 87 | variable "zone_id" { 88 | description = "Zone id for Route53 record" 89 | type = string 90 | default = null 91 | } 92 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "1.12.1" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vpc.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "lambda" { 2 | description = "Allow outbound from GitHub Webhook Proxy Lambda" 3 | vpc_id = var.vpc_id 4 | tags = var.custom_tags 5 | 6 | egress { 7 | cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:AWS009 8 | from_port = 0 9 | to_port = 0 10 | protocol = "-1" 11 | } 12 | } 13 | --------------------------------------------------------------------------------