GithubHelp home page GithubHelp logo

cameronxie / go-opa-reviewer Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 53 KB

OPA GitHub Pull Request Review Bot.

Makefile 6.70% Go 86.26% Dockerfile 4.65% Open Policy Agent 2.39%
aws-lambda github-app golang open-policy-agent pull-request-review

go-opa-reviewer's Introduction

Go OPA Reviewer

Test

This project demonstrates an approach for creating a GitHub App that leverages the Open Policy Agent (OPA) to perform queries on the modified files present in a Pull Request.

This project is built with Golang (v1.21) and hosted with AWS Lambda which fronted by AWS ALB. The project is using Lambda Layer to store the policy bundler, and use Secrets Manager to store GitHub App configurations and secrets.

Design

Go OPA Reviewer

  1. A Pull Request event is initiated on GitHub and delivery to the Application Load Balancer.
  2. The Application Load Balancer invoke the Reviewer Lambda function.
  3. The Reviewer Lambda function then retrieves the content of the modified files from GitHub and perform policy checks.
  4. The review results are posted back to the Pull Request page as comment.

Prerequisites

  • Register a GitHub App with following permissions and subscribing events, and update GITHUB_V3_API_URL, GITHUB_APP_INTEGRATION_ID, GITHUB_APP_WEBHOOK_SECRET and GITHUB_APP_PRIVATE_KEY in .env file. GITHUB_APP_PRIVATE_KEY value should be base64 encoded.
    • Repository Permissions:
      • Content: Read-only
      • Pull requests: Read and write
      • Metadata: Read-only
    • Subscribe to events:
      • Pull request
  • An AWS account which has sufficient permission to deploy VPC, ALB, Lambda and SecretsManager.
  • Docker and Docker Compose installed.

Folder Structure

.
├── Makefile
├── README.md
├── cmd
│   └── app.go               # Entry point to the Reviewer GitHub App.
├── docker
│   └── dev
├── docker-compose.yml
├── go.mod
├── go.sum
├── image
├── internal
│   ├── app                  # The main GitHub App package.
│   ├── presentation         # Handles the presentation of the review results. 
│   ├── prhandler            # Manages the handling of pull request events.
│   ├── reader               # Provides functionality for reading files.
│   ├── review               # Review service.
│   └── version              # Manages the project version.
├── pkg
│   └── reviewer             # Integrated with OPA SDK and handles the policy review.
├── policy                   # Contains Rego and Rego test files.
│   ├── main.rego
│   └── main_test.rego
├── stack                    # CloudFormation templates.
│   ├── github-app.yaml
│   └── secret.yaml
└── vendor

Deploy

  • This project utilizes Docker to manage the local development environment. Execute the make up command to start the development container.
  • Update the .env file as per your requirements.
  • From within the go_opa_reviewer_dev container, execute make deploy which will first initiate testings and linting for CloudFormation templates, Policy (Rego) files and the Lambda code, build policy bundle and lambda executable, and deploy to your aws account.
  • Once the deployment process is finished, retrieve the webhook URL from the CloudFormation output and update it on your GitHub App configuration page.

Test

Run the make test command in the go_opa_reviewer_dev container. This command will initiate testing and linting processes for CloudFormation files, Policy (Rego) files, and the Lambda code.

go-opa-reviewer's People

Contributors

cameronxie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.