Skip to content

X-Hub-Signature is not getting verified #2287

Closed

Description

@anshulpatel25

Description

The webhook lambda shows 'Unable to verify signature!' in the logs.
The X-Hub-Signature which is generated by Github enterprise is not getting verified in the webhook lambda.

I have already verified the secret value is same in webhook configuration in Github enterprise and AWS SSM

Software version

  • terraform-aws-github-runner: v1.5.0
  • Github Enterprise version: 3.5.1

Activity

  1. anshulpatel25 commented on Jul 27, 2022

    @anshulpatel25
    ContributorAuthor

    Upon further investigation, following changes worked for my setup

    diff --git a/modules/webhook/lambdas/webhook/src/webhook/handler.ts b/modules/webhook/lambdas/webhook/src/webhook/handler.ts
    index 983a11c..72d6cd4 100644
    --- a/modules/webhook/lambdas/webhook/src/webhook/handler.ts
    +++ b/modules/webhook/lambdas/webhook/src/webhook/handler.ts
    @@ -96,7 +96,7 @@ async function verifySignature(
       body: string,
       environment: string,
     ): Promise<number> {
    -  const signature = headers['x-hub-signature'] as string;
    +  const signature = headers['x-hub-signature-256'] as string;
       if (!signature) {
         logger.error(
           "Github event doesn't have signature. This webhook requires a secret to be configured.",
    @@ -110,7 +110,7 @@ async function verifySignature(
       const webhooks = new Webhooks({
         secret: secret,
       });
    -  if (!(await webhooks.verify(body, signature))) {
    +  if (!(await webhooks.verify(JSON.parse(body), signature))) {
         logger.error('Unable to verify signature!', LogFields.print());
         return 401;
       }
  2. npalm commented on Aug 3, 2022

    @npalm
    Member

    Quickly checked the events sent from github.com, they contain both a sha1 and a sha255

    X-Hub-Signature: sha1=
    X-Hub-Signature-256: sha256=
    

    Need to check, but indeed maybe we should upgrade the webhook to use the sha256 as default (maybe with fall back to old one). We don't sue GHES, so can't test the module on GHES.

  3. added
    help wanted
    on Aug 3, 2022
  4. anshulpatel25 commented on Aug 4, 2022

    @anshulpatel25
    ContributorAuthor

    Thanks @npalm for providing insights, Octokit itself says that sha1 is supported for legacy reasons
    reference: https://github.com/octokit/webhooks-methods.js/#sign

  5. added
    good first issue
    on Aug 9, 2022
  6. michaelstepner commented on Aug 19, 2022

    @michaelstepner

    Hi @npalm, my team is currently upgrading from a very old version of
    philips-labs/terraform-aws-github-runner to the latest (v1.7.0) and we're encountering this issue as well. I've described our software versions below.

    The effect of this bug is that the "scale up" lambda never gets successfully triggered. So runners aren't starting at all. This seems like a major bug if it's affecting other users too.

    We've also confirmed that the value of the webhook secret is the same in the Github App configuration and in the terraform state. Unlike @anshulpatel25, we are using Github.com not Github Enterprise.

    Do you have an update on the bugfix above or any workarounds? In the meantime, our plan is to identify which older version of the terraform-aws-github-runner module predates the introduction of this bug, and upgrade to that older version.

    Software version

    terraform-aws-github-runner module: v1.7.0
    Terraform version: 1.2.4
    Terraform module hashicorp/aws ~> 4.15
    Github.com hosted repo

  7. michaelstepner commented on Aug 19, 2022

    @michaelstepner

    With further debugging, it seems that the issue we're encountering is not the same as @anshulpatel25: the patch proposed above didn't resolve the issue. We're debugging further.

  8. bjonnh-work commented on Sep 7, 2022

    @bjonnh-work
    Contributor

    @anshulpatel25 could you make a PR out of your changes?

  9. anshulpatel25 commented on Sep 8, 2022

    @anshulpatel25
    ContributorAuthor

    Sure @bjonnh-work , I will do this over the weekend

  10. bjonnh-work commented on Sep 19, 2022

    @bjonnh-work
    Contributor

    Thank you @anshulpatel25!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions