Skip to content

Commit 2b58f31

Browse files
committed
docs: update opa middleware docs
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 5eda469 commit 2b58f31

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

cmd/finch-daemon/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func defineDockerConfig(uid int) error {
298298
})
299299
}
300300

301-
// checkRegoFileValidity verifies that the given rego file exists and has the right file extension
301+
// checkRegoFileValidity verifies that the given rego file exists and has the right file extension.
302302
func checkRegoFileValidity(filePath string) error {
303303
if _, err := os.Stat(filePath); os.IsNotExist(err) {
304304
return fmt.Errorf("provided Rego file path does not exist: %s", filePath)

docs/opa-middleware.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Applying OPA authz policies
2+
3+
This guide provides instructions for setting up [OPA](https://github.com/open-policy-agent/opa) authz policies with the finch-daemon. Authz policies allow users to allowlist or deny certain resources based on policy rules.
4+
5+
## What Is OPA Authz implementation
6+
Open Policy Agent (OPA) is an open-source, general-purpose policy engine that enables unified, context-aware policy enforcement across the entire stack. OPA provides a high-level declarative language, Rego, for specifying policy as code and simple APIs to offload policy decision-making from your software.
7+
8+
In the current implementation, users can use OPA Rego policies to filter API requests at the Daemon level. It's important to note that the current implementation only supports allowlisting of requests. This means you can specify which requests should be allowed, and all others will be denied by default.
9+
10+
## Setting up a policy
11+
12+
Use the [sample rego](../sample.rego) policy template to build your policy rules.
13+
14+
The package name must be `finch.authz`, the daemon middleware will look for the result of the `allow` key on each API call to determine wether to allow/deny the request.
15+
An approved request will go through without any events, a rejected request will fail with status code 403
16+
17+
Example:
18+
19+
The following policy blocks all API requests made to the daemon.
20+
```
21+
package finch.authz
22+
23+
default allow = false
24+
25+
```
26+
`allow` can be modified based on the business requirements for example we can prevent users from creating new containers by preventing them from accessing the create API
27+
28+
```
29+
allow if {
30+
not (input.Method == "POST" and input.Path == "/v1.43/containers/create")
31+
}
32+
```
33+
Use the [Rego playground](https://play.openpolicyagent.org/) to fine tune your rego policies
34+
35+
## Enable OPA Middleware
36+
37+
Once you are ready with your policy document, use the `--enable-opa` flag to tell the finch-daemon to enable the OPA middleware. The daemon will then look for the policy document provided by the `--rego-file` flag.
38+
39+
Note: The `--rego-file` flag is required when `--enable-opa` is set.
40+
41+
Example:
42+
`sudo bin/finch-daemon --debug --socket-owner $UID --socket-addr /run/finch-test.sock --pidfile /run/finch-test.pid --enable-opa --rego-file /<path-to>/finch-daemon/sample.rego &`

0 commit comments

Comments
 (0)