Giter VIP home page Giter VIP logo

opa-cdk-workflow's Introduction

OPA CDK Workflow

This repository defines a simple application (API service) that uses Envoy and OPA to authorize traffic.

Getting Started

Bootstrap the project. This will install the AWS CDK and bootstrap the stack.

make bootstrap

Next, deploy the stack.

make deploy

The application being deployed in this example is a simple HTTP service that will respond to a request to /echo by replying with any data passed (via the request's POST body).

Using the DNS name output from the deploy step above, we should be able to assert that some requests succeed, while others fail.

curl -v http://<LB dns name>/echo
< HTTP/1.1 200 OK


curl -d "hello" -v http://<LB dns name>/echo
< HTTP/1.1 403 Forbidden

As shown above, the policy is configured to allow GET requests to /echo, but not POST requests to /echo. We can modify the policy in this repository to correct that.

Policy Modification

In this case, we want to allow POST for the /echo path. Find this test:

test_post_echo_denied {
    not allow with input as {
        "attributes": {
            "request": {
                "http": {
                    "method": "POST",
                    "path": "/echo"
                }
            }
        }
    }
}

And change it to:

test_post_echo_allowed {
    allow with input as {
        "attributes": {
            "request": {
                "http": {
                    "method": "POST",
                    "path": "/echo"
                }
            }
        }
    }
}

Execute the test suite and notice the test fails:

make test

Now adjust the rules defined in policy.rego to make the test pass. When you're ready to deploy these changes, run deploy again.

make deploy

This will deploy the updated policy bundle, which the API service's OPA container will pick up within 20 seconds and begin enforcing. It will not redeploy the service.

The POST request to /echo should now work.

curl -d "hello" -v http://<LB dns name>/echo
< HTTP/1.1 200 OK
hello

Cleanup

Tear it all down.

make destroy

opa-cdk-workflow's People

Contributors

bcelenza 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.