Skip to content

Commit b23661a

Browse files
committed
chore: readme and opa diagram
1 parent 8be604f commit b23661a

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ metadata:
113113
114114
The following section describes how to use this plugin with Open Policy Agent (OPA)
115115
116+
![OPA diagram](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/team-carepay/traefik-jwt-plugin/main/opa.puml)
117+
116118
### OPA input payload
117119
118120
The plugin will translate the HTTP request (including headers and parameters) and forwards the payload as JSON to OPA.
@@ -180,28 +182,27 @@ and that the user has the required claims in the token.
180182

181183
The policy below shows an simplified example:
182184

183-
```config
185+
```rego
184186
package example
185187
186-
default allow = false
188+
import future.keywords.in
189+
import future.keywords.if
187190
188-
allow {
189-
input.method = "GET"
190-
input.path[0] = "public"
191-
}
191+
default allow := false
192192
193-
allow {
194-
input.method = "GET"
195-
input.path = [ "secure", i ]
196-
has_token([ "123", "456"])
193+
allow if {
194+
input.method == "GET"
195+
input.path[0] == "public"
197196
}
198197
199-
has_token(tokens) {
200-
input.path[1] = tokens[i]
198+
allow if {
199+
input.method == "GET"
200+
input.path[0] == "secure"
201+
input.path[1] in {"123", "456"}
201202
}
202203
```
203204

204-
In the above example, requesting `/public/anything` or `/secure/123` is allowed,
205+
In the above example, requesting `/public/anything` or `/secure/123` or `/secure/456` is allowed,
205206
however requesting `/secure/xxx` would be rejected and results in a 403 Forbidden.
206207

207208
## License

opa.puml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@startuml
2+
actor User
3+
component "Load Balancer" as lb
4+
component "Trefik with\ntraefik-jwt-plugin" as t
5+
component "OPA" as opa
6+
component "Microservice" as ms
7+
User -right-> lb
8+
User <-right- lb
9+
lb -right-> t
10+
lb <-right- t
11+
t -down-> opa
12+
t <-down- opa
13+
t -right-> ms
14+
t <-right- ms
15+
@enduml

0 commit comments

Comments
 (0)