Skip to content

Commit 4a8148e

Browse files
committed
chore: add experimental documentation
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 160ae7c commit 4a8148e

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
- name: Set Rego file path
111111
run: echo "REGO_FILE_PATH=${{ github.workspace }}/docs/sample-rego-policies/example.rego" >> $GITHUB_ENV
112112
- name: Start finch-daemon with opa Authz
113-
run: sudo bin/finch-daemon --debug --enable-opa-middleware --rego-file ${{ github.workspace }}/docs/sample-rego-policies/example.rego --skip-rego-perm-check --socket-owner $UID --socket-addr /run/finch.sock --pidfile /run/finch.pid &
113+
run: sudo bin/finch-daemon --debug --experimental --rego-file ${{ github.workspace }}/docs/sample-rego-policies/example.rego --skip-rego-perm-check --socket-owner $UID --socket-addr /run/finch.sock --pidfile /run/finch.pid &
114114
- name: Run opa e2e tests
115115
run: sudo -E make test-e2e-opa
116116
- name: Clean up Daemon socket

api/router/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func VersionMiddleware(next http.Handler) http.Handler {
111111
}
112112

113113
// CreateRegoMiddleware dynamically parses the rego file at the path specified in options
114-
// and allows or denies the request based on the policy.
114+
// and return a function that allows or denies the request based on the policy.
115115
// Will return a nil function and an error if the given file path is blank or invalid.
116116
func CreateRegoMiddleware(regoFilePath string, logger *flog.Logrus) (func(next http.Handler) http.Handler, error) {
117117
if regoFilePath == "" {

cmd/finch-daemon/main.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ const (
4343
)
4444

4545
type DaemonOptions struct {
46-
debug bool
47-
socketAddr string
48-
socketOwner int
49-
debugAddress string
50-
configPath string
51-
pidFile string
52-
regoFilePath string
53-
enableOPAMiddleware bool
54-
skipRegoPermCheck bool
46+
debug bool
47+
socketAddr string
48+
socketOwner int
49+
debugAddress string
50+
configPath string
51+
pidFile string
52+
regoFilePath string
53+
enableExperimental bool
54+
skipRegoPermCheck bool
5555
}
5656

5757
var options = new(DaemonOptions)
@@ -71,8 +71,8 @@ func main() {
7171
rootCmd.Flags().StringVar(&options.configPath, "config-file", defaultConfigPath, "Daemon Config Path")
7272
rootCmd.Flags().StringVar(&options.pidFile, "pidfile", defaultPidFile, "pid file location")
7373
rootCmd.Flags().StringVar(&options.regoFilePath, "rego-file", "", "Rego Policy Path")
74-
rootCmd.Flags().BoolVar(&options.enableOPAMiddleware, "enable-opa-middleware", false, "turn on OPA middleware for allowlisting")
7574
rootCmd.Flags().BoolVar(&options.skipRegoPermCheck, "skip-rego-perm-check", false, "skip the rego file permission check (allows permissions more permissive than 0600)")
75+
rootCmd.Flags().BoolVar(&options.enableExperimental, "experimental", false, "enable experimental features")
7676

7777
if err := rootCmd.Execute(); err != nil {
7878
log.Printf("got error: %v", err)
@@ -223,11 +223,18 @@ func newRouter(options *DaemonOptions, logger *flog.Logrus) (http.Handler, error
223223
}
224224

225225
var regoFilePath string
226-
if options.enableOPAMiddleware {
226+
227+
if options.regoFilePath != "" {
228+
if !options.enableExperimental {
229+
return nil, fmt.Errorf("rego file provided without experimental flag - OPA middleware is an experimental feature, please enable it with '--experimental' flag")
230+
}
227231
regoFilePath, err = checkRegoFileValidity(options, logger)
228232
if err != nil {
229233
return nil, err
230234
}
235+
} else if options.enableExperimental {
236+
// Only experimental flag set
237+
logger.Info("experimental features enabled but no rego file provided - skipping OPA policy evaluation")
231238
}
232239

233240
opts := createRouterOptions(conf, clientWrapper, ncWrapper, logger, regoFilePath)

docs/opa-middleware.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
# Applying OPA authz policies
1+
# OPA Authorization Middleware (Experimental)
22

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.
3+
> ⚠️ **Experimental Feature**: The OPA authorization middleware is being introduced as an experimental feature.
4+
5+
This guide provides instructions for setting up [OPA](https://github.com/open-policy-agent/opa) authorization policies with the finch-daemon. These policies allow users to allowlist or deny certain resources based on policy rules.
6+
7+
## Experimental Status
8+
9+
This feature is being released as experimental because:
10+
- Integration patterns and best practices are still being established
11+
- Performance characteristics are being evaluated
12+
13+
As an experimental feature:
14+
- Breaking changes may occur in any release
15+
- Long-term backward compatibility is not guaranteed
16+
- Documentation and examples may evolve substantially
17+
- Production use is not recommended at this stage
418

519
## What Is OPA Authz implementation
620
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.
@@ -34,24 +48,26 @@ Use the [Rego playground](https://play.openpolicyagent.org/) to fine tune your r
3448

3549
## Enable OPA Middleware
3650

37-
Once you are ready with your policy document, use the `--enable-opa-middleware` 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.
51+
Once you are ready with your policy document, use the `--experimental` flag to enable experimental features including OPA middleware. The daemon will then look for the policy document provided by the `--rego-file` flag.
3852

39-
Note: The `--rego-file` flag is required when `--enable-opa-middleware` is set.
53+
Note: Since OPA middleware is an experimental feature, the `--experimental` flag is required when using `--rego-file`.
4054

4155
The daemon enforces strict permissions (0600 or more restrictive) on the Rego policy file to prevent unauthorized modifications. You can bypass this check using the `--skip-rego-perm-check` flag.
4256

4357
Examples:
4458

4559
Standard secure usage:
4660
```bash
47-
sudo bin/finch-daemon --debug --socket-owner $UID --socket-addr /run/finch-test.sock --pidfile /run/finch-test.pid --enable-opa-middleware --rego-file /path/to/policy.rego
61+
sudo bin/finch-daemon --debug --socket-owner $UID --socket-addr /run/finch-test.sock --pidfile /run/finch-test.pid --experimental --rego-file /path/to/policy.rego
4862
```
4963

5064
With permission check bypassed:
5165
```bash
52-
sudo bin/finch-daemon --debug --socket-owner $UID --socket-addr /run/finch-test.sock --pidfile /run/finch-test.pid --enable-opa-middleware --rego-file /path/to/policy.rego --skip-rego-perm-check
66+
sudo bin/finch-daemon --debug --socket-owner $UID --socket-addr /run/finch-test.sock --pidfile /run/finch-test.pid --experimental --rego-file /path/to/policy.rego --skip-rego-perm-check
5367
```
5468

69+
Note: If you enable experimental features with `--experimental` but don't provide a `--rego-file`, the daemon will run without OPA policy evaluation.
70+
5571

5672
# Best practices for secure rego policies
5773

docs/sample-rego-policies/example.rego

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# This is an experimental preview policy example.
2+
# As this feature is under active development:
3+
# - Breaking changes may occur without notice
4+
# - Production use is not recommended
5+
16
package finch.authz
27

38
import future.keywords.if

e2e/tests/opa_middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func OpaMiddlewareTest(opt *option.Option) {
126126
"--socket-addr", "/run/test.sock",
127127
"--pidfile", "/run/test.pid",
128128
"--rego-file", regoPath,
129-
"--enable-opa-middleware")
129+
"--experimental")
130130
err = cmd.Run()
131131

132132
// Should fail due to permissions
@@ -137,7 +137,7 @@ func OpaMiddlewareTest(opt *option.Option) {
137137
"--socket-addr", "/run/test.sock",
138138
"--pidfile", "/run/test.pid",
139139
"--rego-file", regoPath,
140-
"--enable-opa-middleware",
140+
"--experimental",
141141
"--skip-rego-perm-check")
142142

143143
// Start the process in background

0 commit comments

Comments
 (0)