Generic inquiry tool to OPA server for CI process, such as GitHub Actions

opaq

opaq is a generic inquiry tool to OPA server. A major purpose of this tool is for inquiry in GitHub Actions.

Features

  • Data formatting: OPA server accepts only {"input": ...} schema and responds {"result": ...} schema. opaq changes input format and extracts result data before/after inquiry to OPA server.
  • Control exit code: --fail-defined and --fail-undefined options can change exit code to fail CI.
  • Inject metadata: --metadata (-m) can inject metadata to original input data for more sophisticated decision.

Usage

Installation with go command.

$ go install github.com/m-mizutani/opaq@latest

Or run command via docker image ghcr.io/m-mizutani/opaq:latest.

$ docker run ghcr.io/m-mizutani/opaq:latest -i result.json -u https://your-opa-server/v1/data/yourpolicy

Basic

$ opaq -i result.json -u https://your-opa-server/v1/data/yourpolicy
{
    "allow": true
}

GitHub Actions

E.g. querying a result of Trivy scan.

name: Vuln scan and inquiry to OPA server

on: [push]

jobs:
  scan:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout upstream repo
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
      - name: Run Trivy vulnerability scanner in repo mode
        uses: aquasecurity/trivy-action@master
        with:
          scan-type: fs
          format: json
          output: trivy-results.json
          list-all-pkgs: true
      - uses: docker://ghcr.io/m-mizutani/opaq:v0.1.0
        with:
          args: "-u https://your-opa-server/v1/data/trivy -i trivy-results.json -m repository=${{ github.repository }} -m ref=${{ github.ref_name }} --fail-defined"

Control exit code

opaq has two options for non-zero code exit to fail CI.

  • --fail-defined: Exits with non-zero exit code on undefined/empty result and errors
  • --fail-undefined: Exits with non-zero exit code on defined/non-empty result and errors
$ opaq -i result.json -u https://your-opa-server/v1/data/blue --fail-defined
{
    "allow": true
}
# Exit with non-zero code
$ opaq -i result.json -u https://your-opa-server/v1/data/orange --fail-defined
{}
# Normally exit

Inject metadata

In some cases, the structural data output for evaluation by OPA is not enough information for evaluation. For example, evaluation requires not only content of configuration file but also directory path and file name to check consistency. opaq allows to add metadata to original structure data.

$ opaq -i some/file.json -m "path=some/file.json" -u https://your-opa-server/v1/data/green

If original some/file.json is below,

{
    "config": {...}
}

-m option modifies data as following and send it to OPA server.

{
    "config": {...},
    "metadata": {
        "path": "some/file.json"
    }
}

Also, --metadata-field can change a field name of metadata. Default is metadata.

Other options

  • --input: Specify input file instead of STDIN
  • --format: Choose input format [json, yaml]
  • --data-field: Nest input data with a value of the option. If mydata is provided, {"user":"you"} will be modified to {"mydata":{"user":"you"}}
  • http-header: Add custom HTTP header(s). e.g. Authorization: Bearer XXXXX to pass authentication of OPA server

License

Apache License 2.0

Owner
Masayoshi Mizutani
Security + Software Engineer
Masayoshi Mizutani
Similar Resources

Example goreleaser + github actions config with keyless signing and SBOM generation

supply-chain-example GoReleaser + Go Mod proxying + Cosign keyless signing + Syft SBOM generation example. How it works GoReleaser manages the entire

Nov 15, 2022

Automatic sync from IMDb to Trakt (watchlist, lists, ratings and history) using GitHub actions

imdb-trakt-sync GoLang app that can sync IMDb and Trakt user data - watchlist, ratings and lists. For its data needs, the app is communicating with th

Jan 2, 2023

Sign Container Images with cosign and Verify signature by using Open Policy Agent (OPA)

 Sign Container Images with cosign and Verify signature by using Open Policy Agent (OPA)

Sign Container Images with cosign and Verify signature by using Open Policy Agent (OPA) In the beginning, I believe it is worth saying that this proje

Nov 30, 2022

runtime - an abstraction library on top of the Open Policy Agent (OPA)

runtime - an abstraction library on top of the Open Policy Agent (OPA) Introduction The "runtime" project is a library that sits on top of OPA. The go

Nov 7, 2022

A plugin for running Open Policy Agent (OPA) in AWS Lambda as a Lambda Extension.

opa-lambda-extension-plugin A custom plugin for running Open Policy Agent (OPA) in AWS Lambda as a Lambda Extension. To learn more about how Lambda Ex

Jan 2, 2023

🔮 ✈️ to integrate OPA Gatekeeper's new ExternalData feature with cosign to determine whether the images are valid by verifying their signatures

cosign-gatekeeper-provider To integrate OPA Gatekeeper's new ExternalData feature with cosign to determine whether the images are valid by verifying i

Dec 8, 2022

Cmsnr - cmsnr (pronounced "commissioner") is a lightweight framework for running OPA in a sidecar alongside your applications in Kubernetes.

cmsnr Description cmsnr (pronounced "commissioner") is a lightweight framework for running OPA in a sidecar alongside your applications in Kubernetes.

Jan 13, 2022

The Coherence command line interface (CLI) is a lightweight tool, in the tradition of tools such as kubectl

The Coherence command line interface (CLI) is a lightweight tool, in the tradition of tools such as kubectl

Coherence Command Line Interface (CLI) Contents Overview Why use the Coherence C

Dec 15, 2022

GitOops is a tool to help attackers and defenders identify lateral movement and privilege escalation paths in GitHub organizations by abusing CI/CD pipelines and GitHub access controls.

GitOops is a tool to help attackers and defenders identify lateral movement and privilege escalation paths in GitHub organizations by abusing CI/CD pipelines and GitHub access controls.

GitOops is a tool to help attackers and defenders identify lateral movement and privilege escalation paths in GitHub organizations by abusing CI/CD pipelines and GitHub access controls.

Jan 2, 2023
github-actions-merger is github actions that merges pull request with commit message including pull request labels.

github-actions-merger github-actions-merger is github actions that merges pull request with commit message including pull request labels. Usage Write

Dec 7, 2022
go-opa-validate is an open-source lib that evaluates OPA (open policy agent) policy against JSON or YAML data.
go-opa-validate is an open-source lib that evaluates OPA (open policy agent) policy against JSON or YAML data.

go-opa-validate go-opa-validate is an open-source lib that evaluates OPA (open policy agent) policy against JSON or YAML data. Installation Usage Cont

Nov 17, 2022
Provider-generic-workflows - A generic provider which uses argo workflows to define the backend actions.

provider-generic-workflows provider-generic-workflows is a generic provider which uses argo workflows for managing the external resource. This will re

Jan 1, 2022
A simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app to Docker Hub

go-pipeline-demo A repository containing a simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app t

Nov 17, 2021
Hexagonal architecture paradigms, such as dividing adapters into primary (driver) and secondary (driven)Hexagonal architecture paradigms, such as dividing adapters into primary (driver) and secondary (driven)

authorizer Architecture In this project, I tried to apply hexagonal architecture paradigms, such as dividing adapters into primary (driver) and second

Dec 7, 2021
Jan 4, 2022
toghsh translates github actions workflows to shell scripts

togsh - extracts shell commands from github actions workflows toghsh is a helper tool to translate github action workflows into equivalent shell scrip

Nov 16, 2021
CI/CD with Jenkins, GitHub Actions, Travis CI etc

CI/CD with Jenkins, GitHub Actions, Travis CI etc This is a simple repository built using Golang with the main purpose to try out different CI/CD tool

Nov 11, 2021
A reverse engineered github actions compatible self-hosted runner using nektos/act to execute your workflow steps

github-act-runner A reverse engineered github actions compatible self-hosted runner using nektos/act to execute your workflow steps. Unlike the offici

Dec 24, 2022
Gophercon lab "Get Go-ing with GitHub Actions"

GitHub Action Using Go This is a starting point for a GitHub Action based in Go. This repo provides all the structure needed to build a robust GitHub

Dec 8, 2021