6 Commits

Author SHA1 Message Date
Stephan Renatus cb54e9c14f runtime: rule labels metadata processing follow-ups (#8613)
 We now parse rego metadata annotations by default.

Rule annotations now support a `labels` field. During policy eval,
labels from all successfully evaluated rules are collected and included
in each decision log entry as a top-level `rule_labels` array. Each
element preserves the label map from one evaluated rule. Exact
duplicates are omitted.

```rego
# METADATA
# labels:
#   severity: low
#   team: platform
allow if input.role == "admin"
```

The resulting decision log entry will contain:

```json
{"rule_labels": [{"severity": "low", "team": "platform"}]}
```

---------

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-05-08 15:00:26 +00:00
Stephan Renatus 2cf57ca6d3 introduce rule IDs, include in decision logs and response payloads (#8606)
Rules can now be annotated with a metadata `id` field. When any
metadata `id` annotations are present in the rego (scope: rule), the IDs
of successfully evaluated rules are included in decision log events.
Additionally, the Data API supports a `?id` query parameter to
include evaluated rule IDs directly in the response payload.

```rego
# METADATA
# id: allow-admin
allow if input.role == "admin"
```

Modules containing `id` annotations will have metadata parsing enabled
automatically.

Fixes #2089

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-05-06 09:38:34 +02:00
Stephan Renatus a7b87cd127 cli: enable file_logger plugin
The plugin registration step was missing before, so the code, while in
the tree, was not active and the plugin couldn't be used.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-05-05 11:35:43 +02:00
Stephan Renatus 13e9488921 server+topdown+logs: feed arbitrary extra info from Data API to topdown and back (#8570)
Wrapping projects can now attach custom metadata to Data API requests
and have evaluation produce response metadata.

Introduce two distinct metadata paths:

  - Request (incoming) metadata: parsed from extra top-level keys in the request
body, made available to builtins via `BuiltinContext.RequestMetadata`.
    Logged in the decision log under `Custom["request_metadata"]`.

- Response (outgoing) metadata: a separate map (`BuiltinContext.ResponseMetadata`)
    that builtins can populate during evaluation. Only included in the
    API response and decision log (`Custom["response_metadata"]`)
    if non-empty.

In vanilla OPA, no builtins write response metadata, so responses are
unchanged. The request metadata map is only allocated when the request
carries extra fields; the outgoing map is one empty map per request.

To avoid conflicts with future OPA top-level keys, callers should use a
namespaced key: `{"input": {...}, "com.example.opa/md": {...}}`.

```mermaid
flowchart LR
    req["POST /v1/data\n{input, com.example.opa/md}"]
    parse["readInputPostV1"]
    eval["topdown eval"]
    resp["API response"]
    dl["decision log"]

    req --> parse
    parse -- "reqMetadata" --> eval
    parse -- "reqMetadata" --> dl
    eval -- "respMetadata\n(if non-empty)" --> resp
    eval -- "respMetadata\n(if non-empty)" --> dl
    eval -. "BuiltinContext\n.RequestMetadata\n.ResponseMetadata" .-> eval
```

---------

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-04-28 12:58:18 +00:00
Stephan Renatus b16fdc6137 e2e/cli: add test for debug print() logging (#8567)
* e2e/cli: add test for debug `print()` logging

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>

* ci: add *.txtar to "golang_change_suffixes"


This is so that e2e/cli testscript definitions cause CI runs.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>

---------

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-04-27 14:00:07 +00:00
Stephan Renatus 598e5cb439 e2e/cli: start CLI E2E tests (#8545)
Using the lovely testscript package with a couple of helpers.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-04-22 08:40:05 +00:00