Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support http filter plugins (Open Policy Agent) #605

Open
2 tasks
baerwang opened this issue Jan 11, 2024 · 0 comments
Open
2 tasks

feature: support http filter plugins (Open Policy Agent) #605

baerwang opened this issue Jan 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@baerwang
Copy link
Member

baerwang commented Jan 11, 2024

What does pixiu need to do with OPA ?

It supports a variety of strategies, such as JWT, and the OPA module supports it comprehensively

PIxiu needs to be implemented in two ways (Choose one of the two)

  • depends on the OPA server
  • depends on the OPA rules

introduce

https://www.openpolicyagent.org/

Directions for use

start opa server

docker run -d --name opa -p 8181:8181 openpolicyagent/opa:latest run -s

Create opa pollicy

curl -X PUT '127.0.0.1:8181/v1/policies/example1' \
  -H 'Content-Type: text/plain' \
  -d 'package example1

import input.request

default allow = false

allow {
    # HTTP method must GET
    request.method == "GET"
}'

Query policy

curl -X POST '127.0.0.1:8181/v1/data/example1/allow' \
  -H 'Content-Type: application/json' \
  -d '{"input":{"request":{"method":"GET"}}}'

OPA rules

package main

import (
    "context"

    "github.com/open-policy-agent/opa/rego"
)

func main() {
    mod := `
    package test
    import future.keywords.if
    
    default allow := false
    
    allow if {
        input.x == 1
    }
    `

    pq, err := rego.New(
        rego.Query("data.test.allow"),
        rego.Module("test.rego", mod),
        rego.Input(map[string]interface{}{"x": 1})).PrepareForEval(context.Background())
    if err != nil {
        panic(err)
    }

    result, err := pq.Eval(context.Background())
    if err != nil {
        panic(err)
    }
    print(result.Allowed())
}
@baerwang baerwang added the enhancement New feature or request label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant