Files
backstage/plugins/events-backend-module-github
Patrick Jungermann 0f46ec304c feat(events/github): add signature verification
Add `createGithubSignatureValidator(config)` which can be used
to create a validator used at an ingress for topic `github`.

On top, there is a new `githubWebhookEventsModule` for the new backend plugin API
which auto-registers the `HttpPostIngress` for topic `github` incl. the validator.

Relates-to: PR #13931
Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
2022-11-24 21:57:12 +01:00
..
2022-11-22 15:40:52 +00:00

events-backend-module-github

Welcome to the events-backend-module-github backend plugin!

This plugin is a module for the events-backend backend plugin and extends it with an GithubEventRouter.

The event router will subscribe to the topic github and route the events to more concrete topics based on the value of the provided x-github-event metadata field.

Examples:

x-github-event topic
pull_request github.pull_request
push github.push
repository github.repository

Please find all possible webhook event types at the official documentation.

Installation

Install the events-backend plugin.

Install this module:

# From your Backstage root directory
yarn add --cwd packages/backend @backstage/plugin-events-backend-module-github

Add the event router to the EventsBackend:

+const githubEventRouter = new GithubEventRouter();

 EventsBackend
+  .addPublishers(githubEventRouter)
+  .addSubscribers(githubEventRouter);
// [...]

Signature Validator

Add the signature validator for the topic github:

// at packages/backend/src/plugins/events.ts
+ import { createGithubSignatureValidator } from '@backstage/plugin-events-backend-module-github';
// [...]
   const http = HttpPostIngressEventPublisher.fromConfig({
     config: env.config,
     ingresses: {
+       github: {
+         validator: createGithubSignatureValidator(env.config),
+       },
     },
     logger: env.logger,
  });

Additionally, you need to add the configuration:

events:
  modules:
    github:
      webhookSecret: your-secret-token

Configuration at GitHub: https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks