From 2b66ef772b4dad305894c95f159ad1eff254a1e1 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:18:59 +0000 Subject: [PATCH 01/13] feat(connectors): check every connector call against OPA rules The broker now asks Open Policy Agent, embedded in the gateway, before it forwards a read, makes a write into a plan, or applies an approved plan. Rules are the .rego files in connectors.policy.rulesDir, read again every 10 seconds; a change that does not load keeps the last rules that did. - Rules return deny or require_approval sets of {title, description} from packages tapas.rules. or tapas.admin.. A deny answers the person with the descriptions; require_approval turns the call into a plan. - The input document follows the design discussion: checkpoint, phase, who, agent, where, what, findings (empty until detectors exist), and approval when an approved plan is applied. The agent that proposed a plan is stored with it and given to the rules again at apply. - Fails closed: no rules, rules that do not load (syntax, packages outside the namespace, deny not a partial set, no METADATA title and description, network or env built-ins), an evaluation error, a 2s timeout, or an answer of another shape all deny. A broker with no policy denies; the allow-all default is gone. - Each decision's effect, rule titles and rule revision go into the call's audit row. - connectors.enabled now needs connectors.policy.rulesDir. - Example rules (Greenhouse for recruiting only, approval for email sends and Frames writes) with Rego tests run by go test. - Adds github.com/open-policy-agent/opa v1.22.4; checks recorded in DEPENDENCIES.md. --- DEPENDENCIES.md | 11 + deploy/policy/examples/email.rego | 13 + deploy/policy/examples/email_test.rego | 25 + deploy/policy/examples/frames.rego | 23 + deploy/policy/examples/frames_test.rego | 40 ++ deploy/policy/examples/greenhouse.rego | 9 + deploy/policy/examples/greenhouse_test.rego | 29 ++ go.mod | 71 ++- go.sum | 185 ++++--- internal/cli/servercmd/gateway.go | 3 +- internal/cli/servercmd/local_build_test.go | 2 +- internal/cli/wiring/connectors_policy.go | 26 + .../cli/wiring/connectors_policy_local.go | 15 + internal/cli/wiring/connectors_policy_test.go | 41 ++ internal/cli/wiring/wiring.go | 9 +- internal/cli/wiring/wiring_test.go | 6 +- internal/config/config.go | 13 + internal/config/config_test.go | 12 +- internal/connectors/broker/action.go | 14 +- internal/connectors/broker/action_test.go | 80 ++- internal/connectors/broker/audit_test.go | 16 +- internal/connectors/broker/broker.go | 18 +- internal/connectors/broker/broker_test.go | 39 +- internal/connectors/broker/checkpolicy.go | 58 ++- internal/connectors/broker/propose.go | 10 +- internal/connectors/broker/record.go | 13 +- .../connectors/policy/opa/examples_test.go | 88 ++++ internal/connectors/policy/opa/opa.go | 417 ++++++++++++++++ internal/connectors/policy/opa/opa_test.go | 471 ++++++++++++++++++ internal/connectors/policy/policy.go | 89 +++- internal/connectors/policy/policy_test.go | 3 +- internal/gateway/apitest/fixture.go | 25 +- internal/gateway/connectors_policy_test.go | 170 +++++++ internal/gateway/mcp.go | 2 +- internal/gateway/server.go | 4 + 35 files changed, 1882 insertions(+), 168 deletions(-) create mode 100644 deploy/policy/examples/email.rego create mode 100644 deploy/policy/examples/email_test.rego create mode 100644 deploy/policy/examples/frames.rego create mode 100644 deploy/policy/examples/frames_test.rego create mode 100644 deploy/policy/examples/greenhouse.rego create mode 100644 deploy/policy/examples/greenhouse_test.rego create mode 100644 internal/cli/wiring/connectors_policy.go create mode 100644 internal/cli/wiring/connectors_policy_local.go create mode 100644 internal/cli/wiring/connectors_policy_test.go create mode 100644 internal/connectors/policy/opa/examples_test.go create mode 100644 internal/connectors/policy/opa/opa.go create mode 100644 internal/connectors/policy/opa/opa_test.go create mode 100644 internal/gateway/connectors_policy_test.go diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index edd6cc5b..dfda4400 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -373,6 +373,17 @@ Typo-squat check: each module path is the vendor's own (GitHub orgs anthropics, | github.com/modelcontextprotocol/go-sdk | v1.8.0 | 2026-09-04 (release page 2026-09-14) | modelcontextprotocol org (official Go SDK, maintained with Google: findleyr, jba); tag commit 3f3b699 matches proxy | clean | none | MCP server, Streamable HTTP, `auth.RequireBearerToken` and RFC 9728 metadata. Was already in the module graph at v1.3.1 (indirect); now direct. New indirect: segmentio/encoding v0.5.4 (2026-03), segmentio/asm v1.2.1 (2023-11), yosida95/uritemplate/v3 v3.0.2 (2022-04), each OSV clean | +### Connector policy: Open Policy Agent (checked 2026-12-01) + +Embedded in the gateway as a library (`internal/connectors/policy/opa`) to check every connector call against Rego rules. Only `v1/ast`, `v1/rego` and `v1/util` are imported; OPA's server, bundle downloader, plugins and telemetry are not compiled in. Not linked into a `javo local` build. + +| Dependency | Version | Released | Maintainers / source | OSV | Install scripts | Notes | +|---|---|---|---|---|---|---| +| github.com/open-policy-agent/opa | v1.22.4 | 2026-11-12 | open-policy-agent org (CNCF graduated, 12.5k stars, not archived); MAINTAINERS.md at the tag lists anderseknert, ashutosh-narkar, charlieegan3, srenatus, tsandall and others, unchanged in 90 days except a conftest maintainer added 2026-09-30; release commit by srenatus, release published by the project's release workflow; tag commit ba39415 matches the proxy origin | clean (`{}` for 1.22.4) | none | v1.23.0 is 5 days old, so v1.22.4 (19 days) is the newest release at least 14 days old. 1.22.x patch releases (11-05, 11-05, 11-10, 11-12) are fixes rebuilt for Go advisories, each with a GitHub release; no burst after inactivity. Built-ins that reach outside the gateway (`http.send`, `net.lookup_ip_addr`, `opa.runtime`) are refused when rules load | +| modules raised or added by it (indirect) | spf13/pflag v1.1.0, agnivade/levenshtein v1.2.2, decred/dcrd/dcrec/secp256k1/v4 v4.4.1, fsnotify v1.10.1, go-openapi/jsonpointer and jsonreference v1.0.1, go-openapi/swag/* v0.29.2, gobwas/glob v1.1.0, goccy/go-json v0.11.2, grpc-gateway/v2 v2.31.0, klauspost/compress v1.20.3, lestrrat-go/{blackmagic v1.0.4, dsig v1.4.0, dsig-secp256k1 v1.0.0, httpcc v1.0.1, httprc/v3 v3.0.6, jwx/v3 v3.4.0, option/v2 v2.0.0}, prometheus/client_golang v1.25.0, client_model v0.6.3, common v0.72.0, sirupsen/logrus v1.10.2, tetratelabs/wazero v1.12.0, valyala/fastjson v1.6.10, vektah/gqlparser/v2 v2.5.64, xeipuuv/gojsonpointer and gojsonreference (2019, 2018 pseudo-versions), yashtewari/glob-intersection v0.2.0, otel/proto/otlp v1.11.1, go.yaml.in/yaml/v3 v3.0.6, google.golang.org/grpc v1.85.0, gopkg.in/ini.v1 v1.67.3 | each 32 days old or more | OPA's requirements | clean (OSV batch query of each exact version: none) | none | none under 14 days old. Transitive: `govulncheck@v1.9.0 ./...` reports no vulnerability reached; the one module-level finding is GO-2026-5932 in golang.org/x/crypto v0.58.0, unchanged by this addition (see above) | + +Typo-squat check: `github.com/open-policy-agent/opa` is the module path the OPA documentation (openpolicyagent.org) names for Go integration. + #### Secret scanner: gitleaks with patched archive codecs (checked 2026-11-02) `internal/ai/redact` uses gitleaks' `detect` package (default rules) as a library to hide secrets in log lines before a bundle is sent to a model. diff --git a/deploy/policy/examples/email.rego b/deploy/policy/examples/email.rego new file mode 100644 index 00000000..bd6fd2d2 --- /dev/null +++ b/deploy/policy/examples/email.rego @@ -0,0 +1,13 @@ +package tapas.rules.email + +# send is the tools that send an email from a person's mailbox. +send := {"send_email", "send_message", "send_draft"} + +# METADATA +# title: Email sends need approval +# description: An email leaves the company in the person's name, so they approve each send in the browser first. +require_approval contains rego.metadata.rule() if { + input.where.connector == "gmail" + input.where.tool in send + not input.approval +} diff --git a/deploy/policy/examples/email_test.rego b/deploy/policy/examples/email_test.rego new file mode 100644 index 00000000..314acdb0 --- /dev/null +++ b/deploy/policy/examples/email_test.rego @@ -0,0 +1,25 @@ +package tapas.rules.email_test + +import data.tapas.rules.email + +send := { + "checkpoint": "tool_call", + "phase": "propose", + "who": {"person": "alice@example.com", "groups": []}, + "where": {"connector": "gmail", "tool": "send_email", "mode": "write"}, + "what": {"arguments": {"to": "bob@example.com", "subject": "Hi"}}, + "findings": [], +} + +test_a_send_needs_approval if { + some d in email.require_approval with input as send + d.title == "Email sends need approval" +} + +test_an_approved_send_goes_ahead if { + count(email.require_approval) == 0 with input as object.union(send, {"phase": "apply", "approval": {"plan": "p-1", "by": "alice@example.com"}}) +} + +test_reading_mail_needs_no_approval if { + count(email.require_approval) == 0 with input as object.union(send, {"where": {"connector": "gmail", "tool": "search", "mode": "read"}}) +} diff --git a/deploy/policy/examples/frames.rego b/deploy/policy/examples/frames.rego new file mode 100644 index 00000000..6b186281 --- /dev/null +++ b/deploy/policy/examples/frames.rego @@ -0,0 +1,23 @@ +package tapas.rules.frames + +# write is the Frames tools that change context the whole organisation +# reads. +write := {"create_frame", "update_frame"} + +# METADATA +# title: Frames changes need approval +# description: A Frame is shared context the whole organisation reads, so a person approves each change to one in the browser. +require_approval contains rego.metadata.rule() if { + input.where.connector == "frames" + input.where.tool in write + not input.approval +} + +# METADATA +# title: Frames changes are approved by their owner +# description: A change to a Frame is made only with the approval of the person it is made for. +deny contains rego.metadata.rule() if { + input.where.connector == "frames" + input.where.tool in write + input.approval.by != input.who.person +} diff --git a/deploy/policy/examples/frames_test.rego b/deploy/policy/examples/frames_test.rego new file mode 100644 index 00000000..a1797b61 --- /dev/null +++ b/deploy/policy/examples/frames_test.rego @@ -0,0 +1,40 @@ +package tapas.rules.frames_test + +import data.tapas.rules.frames + +update := { + "checkpoint": "tool_call", + "phase": "propose", + "who": {"person": "alice@example.com", "groups": []}, + "agent": {"name": "helper", "app": "helper-1", "token": "t-1", "client": "pi", "scheduled": false}, + "where": {"connector": "frames", "tool": "update_frame", "mode": "write"}, + "what": {"arguments": {"id": "f-1", "body": "Use the Oxford comma."}}, + "findings": [], +} + +approved(by) := object.union(update, {"phase": "apply", "approval": {"plan": "p-1", "by": by}}) + +test_a_change_needs_approval if { + count(frames.require_approval) == 1 with input as update + count(frames.deny) == 0 with input as update +} + +test_a_create_needs_approval if { + count(frames.require_approval) == 1 with input as object.union(update, {"where": {"connector": "frames", "tool": "create_frame", "mode": "write"}}) +} + +test_the_owners_approval_lets_it_through if { + count(frames.require_approval) == 0 with input as approved("alice@example.com") + count(frames.deny) == 0 with input as approved("alice@example.com") +} + +test_someone_elses_approval_is_denied if { + some d in frames.deny with input as approved("bob@example.com") + d.title == "Frames changes are approved by their owner" +} + +test_reads_pass if { + read := object.union(update, {"where": {"connector": "frames", "tool": "get_frame", "mode": "read"}}) + count(frames.require_approval) == 0 with input as read + count(frames.deny) == 0 with input as read +} diff --git a/deploy/policy/examples/greenhouse.rego b/deploy/policy/examples/greenhouse.rego new file mode 100644 index 00000000..3455a446 --- /dev/null +++ b/deploy/policy/examples/greenhouse.rego @@ -0,0 +1,9 @@ +package tapas.rules.greenhouse + +# METADATA +# title: Only recruiting uses Greenhouse +# description: Greenhouse holds candidates' personal data, so only people in the recruiting group may use it through an agent. +deny contains rego.metadata.rule() if { + input.where.connector == "greenhouse" + not "recruiting" in input.who.groups +} diff --git a/deploy/policy/examples/greenhouse_test.rego b/deploy/policy/examples/greenhouse_test.rego new file mode 100644 index 00000000..a9ea6d1a --- /dev/null +++ b/deploy/policy/examples/greenhouse_test.rego @@ -0,0 +1,29 @@ +package tapas.rules.greenhouse_test + +import data.tapas.rules.greenhouse + +call(groups) := { + "checkpoint": "tool_call", + "phase": "read", + "who": {"person": "alice@example.com", "groups": groups}, + "where": {"connector": "greenhouse", "tool": "list_candidates", "mode": "read"}, + "what": {"arguments": {}}, + "findings": [], +} + +test_recruiting_may_read if { + count(greenhouse.deny) == 0 with input as call(["recruiting"]) +} + +test_others_are_denied_with_a_reason if { + some d in greenhouse.deny with input as call(["sales"]) + d.title == "Only recruiting uses Greenhouse" +} + +test_no_groups_is_denied if { + count(greenhouse.deny) == 1 with input as call([]) +} + +test_other_connectors_are_not_affected if { + count(greenhouse.deny) == 0 with input as object.union(call([]), {"where": {"connector": "slack", "tool": "post", "mode": "write"}}) +} diff --git a/go.mod b/go.mod index 18efceb5..06f4026f 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,13 @@ require ( github.com/google/uuid v1.6.0 github.com/jackc/pgx/v5 v5.11.0 github.com/modelcontextprotocol/go-sdk v1.8.0 + github.com/open-policy-agent/opa v1.22.4 github.com/openai/openai-go/v3 v3.81.0 github.com/pressly/goose/v3 v3.29.0 github.com/robfig/cron/v3 v3.0.1 github.com/sony/gobreaker/v2 v2.4.0 github.com/spf13/cobra v1.10.2 - github.com/spf13/pflag v1.0.10 + github.com/spf13/pflag v1.1.0 github.com/tink-crypto/tink-go/v2 v2.9.0 github.com/zricethezav/gitleaks/v8 v8.30.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 @@ -63,6 +64,7 @@ require ( github.com/PagerDuty/go-pagerduty v1.8.0 // indirect github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20240116134246-a8cbe886bab0 // indirect github.com/STARRY-S/zip v0.2.1 // indirect + github.com/agnivade/levenshtein v1.2.2 // indirect github.com/andybalholm/brotli v1.2.7 // indirect github.com/aws/aws-sdk-go-v2 v1.47.1 // indirect github.com/aws/aws-sdk-go-v2/config v1.33.6 // indirect @@ -94,6 +96,7 @@ require ( github.com/clipperhouse/uax29/v2 v2.7.0 // indirect github.com/coder/websocket v1.8.15 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect github.com/dustin/go-humanize v1.1.0 // indirect github.com/emicklei/go-restful/v3 v3.13.0 // indirect @@ -101,24 +104,26 @@ require ( github.com/expr-lang/expr v1.17.8 // indirect github.com/fatih/semgroup v1.2.0 // indirect github.com/felixge/httpsnoop v1.1.0 // indirect - github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/fsnotify/fsnotify v1.10.1 // indirect github.com/fxamacker/cbor/v2 v2.9.2 // indirect github.com/gitleaks/go-gitdiff v0.9.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-openapi/jsonpointer v1.0.0 // indirect - github.com/go-openapi/jsonreference v1.0.0 // indirect - github.com/go-openapi/swag v0.28.0 // indirect - github.com/go-openapi/swag/cmdutils v0.28.0 // indirect - github.com/go-openapi/swag/conv v0.28.0 // indirect - github.com/go-openapi/swag/fileutils v0.28.0 // indirect - github.com/go-openapi/swag/jsonutils v0.28.0 // indirect - github.com/go-openapi/swag/loading v0.28.0 // indirect - github.com/go-openapi/swag/mangling v0.28.0 // indirect - github.com/go-openapi/swag/netutils v0.28.0 // indirect - github.com/go-openapi/swag/pools v0.28.0 // indirect - github.com/go-openapi/swag/stringutils v0.28.0 // indirect - github.com/go-openapi/swag/typeutils v0.28.0 // indirect - github.com/go-openapi/swag/yamlutils v0.28.0 // indirect + github.com/go-openapi/jsonpointer v1.0.1 // indirect + github.com/go-openapi/jsonreference v1.0.1 // indirect + github.com/go-openapi/swag v0.29.2 // indirect + github.com/go-openapi/swag/cmdutils v0.29.2 // indirect + github.com/go-openapi/swag/conv v0.29.2 // indirect + github.com/go-openapi/swag/fileutils v0.29.2 // indirect + github.com/go-openapi/swag/jsonutils v0.29.2 // indirect + github.com/go-openapi/swag/loading v0.29.2 // indirect + github.com/go-openapi/swag/mangling v0.29.2 // indirect + github.com/go-openapi/swag/netutils v0.29.2 // indirect + github.com/go-openapi/swag/pools v0.29.2 // indirect + github.com/go-openapi/swag/stringutils v0.29.2 // indirect + github.com/go-openapi/swag/typeutils v0.29.2 // indirect + github.com/go-openapi/swag/yamlutils v0.29.2 // indirect + github.com/gobwas/glob v1.1.0 // indirect + github.com/goccy/go-json v0.11.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.2 // indirect github.com/google/gnostic-models v0.7.0 // indirect github.com/google/go-github/v69 v69.2.0 // indirect @@ -128,7 +133,7 @@ require ( github.com/googleapis/gax-go/v2 v2.22.0 // indirect github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect github.com/gregdel/pushover v1.3.1 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.31.0 // indirect github.com/h2non/filetype v1.1.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -144,8 +149,15 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.3 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.20.2 // indirect + github.com/klauspost/compress v1.20.3 // indirect github.com/klauspost/pgzip v1.2.6 // indirect + github.com/lestrrat-go/blackmagic v1.0.4 // indirect + github.com/lestrrat-go/dsig v1.4.0 // indirect + github.com/lestrrat-go/dsig-secp256k1 v1.0.0 // indirect + github.com/lestrrat-go/httpcc v1.0.1 // indirect + github.com/lestrrat-go/httprc/v3 v3.0.6 // indirect + github.com/lestrrat-go/jwx/v3 v3.4.0 // indirect + github.com/lestrrat-go/option/v2 v2.0.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/magiconair/properties v1.8.9 // indirect github.com/mattn/go-colorable v0.1.15 // indirect @@ -171,9 +183,9 @@ require ( github.com/pierrec/lz4/v4 v4.1.33 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.24.0 // indirect - github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.70.0 // indirect + github.com/prometheus/client_golang v1.25.0 // indirect + github.com/prometheus/client_model v0.6.3 // indirect + github.com/prometheus/common v0.72.0 // indirect github.com/prometheus/procfs v0.22.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rs/zerolog v1.33.0 // indirect @@ -183,7 +195,7 @@ require ( github.com/segmentio/encoding v0.5.4 // indirect github.com/sethvargo/go-retry v0.5.0 // indirect github.com/shopspring/decimal v1.5.0 // indirect - github.com/sirupsen/logrus v1.9.4 // indirect + github.com/sirupsen/logrus v1.10.2 // indirect github.com/slack-go/slack v0.23.1 // indirect github.com/sorairolake/lzip-go v0.3.5 // indirect github.com/sourcegraph/conc v0.3.0 // indirect @@ -192,25 +204,30 @@ require ( github.com/spf13/viper v1.19.0 // indirect github.com/standard-webhooks/standard-webhooks/libraries v0.0.1 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/tetratelabs/wazero v1.9.0 // indirect + github.com/tetratelabs/wazero v1.12.0 // indirect github.com/therootcompany/xz v1.0.1 // indirect github.com/tidwall/gjson v1.19.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/sjson v1.2.5 // indirect github.com/ulikunitz/xz v0.5.17 // indirect + github.com/valyala/fastjson v1.6.10 // indirect + github.com/vektah/gqlparser/v2 v2.5.64 // indirect github.com/wasilibs/go-re2 v1.9.0 // indirect github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect github.com/x448/float16 v0.8.4 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/yashtewari/glob-intersection v0.2.0 // indirect github.com/yosida95/uritemplate/v3 v3.0.2 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 // indirect go.opentelemetry.io/otel/log v1.47.0 // indirect go.opentelemetry.io/otel/metric v1.47.0 // indirect - go.opentelemetry.io/proto/otlp v1.11.0 // indirect + go.opentelemetry.io/proto/otlp v1.11.1 // indirect go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.4 // indirect - go.yaml.in/yaml/v3 v3.0.5 // indirect + go.yaml.in/yaml/v3 v3.0.6 // indirect go.yaml.in/yaml/v4 v4.0.0-rc.2 // indirect go4.org v0.0.0-20230225012048-214862532bf5 // indirect golang.org/x/exp v0.0.0-20261011100332-faecfb24eb49 // indirect @@ -222,13 +239,13 @@ require ( google.golang.org/api v0.278.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8 // indirect - google.golang.org/grpc v1.84.0 // indirect + google.golang.org/grpc v1.85.0 // indirect google.golang.org/protobuf v1.36.12 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/ini.v1 v1.67.3 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.37.0 // indirect k8s.io/kube-openapi v0.0.0-20260721132016-d427ff9ee9ad // indirect diff --git a/go.sum b/go.sum index c8946a5d..0ae9d19d 100644 --- a/go.sum +++ b/go.sum @@ -47,11 +47,15 @@ github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20240116134246-a8cbe886bab0 h1:z github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20240116134246-a8cbe886bab0/go.mod h1:rjP7sIipbZcagro/6TCk6X0ZeFT2eyudH5+fve/cbBA= github.com/STARRY-S/zip v0.2.1 h1:pWBd4tuSGm3wtpoqRZZ2EAwOmcHK6XFf7bU9qcJXyFg= github.com/STARRY-S/zip v0.2.1/go.mod h1:xNvshLODWtC4EJ702g7cTYn13G53o1+X9BWnPFpcWV4= +github.com/agnivade/levenshtein v1.2.2 h1:fI8RgiztYX1Nn5pBHHqQ9EMCCklhrmXqPRIedFmx5M4= +github.com/agnivade/levenshtein v1.2.2/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU= github.com/andybalholm/brotli v1.2.7 h1:UgafRPGMam5ySHfRkhthMqOFA6IFoeF3D7mWIDLjG5A= github.com/andybalholm/brotli v1.2.7/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/anthropics/anthropic-sdk-go v1.82.0 h1:A82J+yHEMbQ3+7ObCagOX4tVm1uyBhELCHd2dDYZYuo= github.com/anthropics/anthropic-sdk-go v1.82.0/go.mod h1:GThfYqPJoaQ/6pmibCI98Cr4y5su2FXMUHn3NrSSnIc= github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/argoproj/notifications-engine v0.5.0 h1:ZSIY4wwWvudYhryUclPnvajzz+KvEgHI5J6sDwBLByU= github.com/argoproj/notifications-engine v0.5.0/go.mod h1:d1RazGXWvKRFv9//rg4MRRR7rbvbE7XLgTSMT5fITTE= github.com/aws/aws-sdk-go-v2 v1.47.1 h1:uOIZnp4PK3ZhKI0dNrJrhTEsLxbpXHTAJlwoS1pvAtw= @@ -137,6 +141,14 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= +github.com/dgraph-io/badger/v4 v4.9.6 h1:IQqMPVGLNCQr1b4Mu8lHkYm/xyqFRsyKaFEtyLi9CCQ= +github.com/dgraph-io/badger/v4 v4.9.6/go.mod h1:Xa9dAupjbwAacupWFCpa6YEn9E1PjBXkfZYr2I/8aWg= +github.com/dgraph-io/ristretto/v2 v2.2.0 h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM= +github.com/dgraph-io/ristretto/v2 v2.2.0/go.mod h1:RZrm63UmcBAaYWC1DotLYBmTvgkrs0+XhBd7Npn7/zI= +github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo= +github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= @@ -160,18 +172,22 @@ github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htX github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= -github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/fatih/semgroup v1.2.0 h1:h/OLXwEM+3NNyAdZEpMiH1OzfplU09i2qXPVThGZvyg= github.com/fatih/semgroup v1.2.0/go.mod h1:1KAD4iIYfXjE4U13B48VM4z9QUwV5Tt8O4rS879kgm8= github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= +github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= +github.com/foxcpp/go-mockdns v1.3.0 h1:p4PKLZnM1Ii78JzsxJxcYQ5sQT3lIdiPM/vT1SaL9S8= +github.com/foxcpp/go-mockdns v1.3.0/go.mod h1:IhLeSFGed3mJIAXPH2aiRQB+kqz7oqu8ld2qVbOu7Wk= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= -github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho= +github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo= github.com/fxamacker/cbor/v2 v2.9.2 h1:X4Ksno9+x3cz0TZv69ec1hxP/+tymuR8PXQJyDwfh78= github.com/fxamacker/cbor/v2 v2.9.2/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= github.com/gitleaks/go-gitdiff v0.9.1 h1:ni6z6/3i9ODT685OLCTf+s/ERlWUNWQF4x1pvoNICw0= @@ -189,40 +205,40 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= -github.com/go-openapi/jsonpointer v1.0.0 h1:kR9tHqY0CtZaOPVFm622dPVNhrvYpwr4uCxgL3h1H8s= -github.com/go-openapi/jsonpointer v1.0.0/go.mod h1:Z3rw7dWu1p9IgitXCFamSlA5lmDiklEB6vkaxcNZW5Y= -github.com/go-openapi/jsonreference v1.0.0 h1:jlmTr6torcd1YgDQvSfNmRtKzYDO4FGBkrAdlAVWnpY= -github.com/go-openapi/jsonreference v1.0.0/go.mod h1:jtwdyGbJk0Xhe5Y+rwtglQP6Sb1WZST4rT32LWB+sv0= -github.com/go-openapi/swag v0.28.0 h1:xkgbOSKj6DZziNpyqRRAOt3GJGtgjgsd2RoyT30VWuw= -github.com/go-openapi/swag v0.28.0/go.mod h1:4qYnT3Cqr1p1VknOdPo70evN4rgQnAg6jwApHyxSGIg= -github.com/go-openapi/swag/cmdutils v0.28.0 h1:7TOeNtkYru1SG8Y34tDh9WBbLsMqGnptuxWiHREPZ4Q= -github.com/go-openapi/swag/cmdutils v0.28.0/go.mod h1:Sm1MVFMkF6guJJ+pQqHnQA3N0j9qALV3NxzDSv6bETM= -github.com/go-openapi/swag/conv v0.28.0 h1:GtqqbyFe7vR5Y7ehxG9W6/OvrSFdf1OLeTGp40TqxH8= -github.com/go-openapi/swag/conv v0.28.0/go.mod h1:mbUE+mzctnhxi864m0Q07SpN8OowD9JhxmxuYvZZD/k= -github.com/go-openapi/swag/fileutils v0.28.0 h1:Z04XWQD7R8Eq+7GnOrjovBxPPmZzsS4gt2H2GPGIViU= -github.com/go-openapi/swag/fileutils v0.28.0/go.mod h1:VvJFZLTZS0AI854gEQz5tk7dBESdLjiNUMSZ/th2ry8= -github.com/go-openapi/swag/jsonutils v0.28.0 h1:YIch6FwO7RXzeAnbO8Tu7dWBZeUEH+4nA0HXltVTnv4= -github.com/go-openapi/swag/jsonutils v0.28.0/go.mod h1:CYM3WlTUcagR2ZoHdz54di/cbBqt82tuxuXgAjxw+mg= -github.com/go-openapi/swag/jsonutils/fixtures_test v0.28.0 h1:qV+VVUAx5Oro8WjVWpZeql7YReTKhT4smR4zhcOQZr0= -github.com/go-openapi/swag/jsonutils/fixtures_test v0.28.0/go.mod h1:mofwUWx70wvskwESqRJ//k/9kURmCgyJl5m5Ppoh5kY= -github.com/go-openapi/swag/loading v0.28.0 h1:td8QZdZC9MIYGGSnSPKShKiK22I2tU5UQvuUhIBPRLU= -github.com/go-openapi/swag/loading v0.28.0/go.mod h1:rXB0QiQX5mMveXEA7ouM4KiiM9jVJe4K6BVbwhD1M4k= -github.com/go-openapi/swag/mangling v0.28.0 h1:pH8eyeNO9SLYsTMWJrurnNfKmDa28XrlA+HePVD53VM= -github.com/go-openapi/swag/mangling v0.28.0/go.mod h1:jtBE2+V+3pILxOR7Vgce+Cwp6A2PgZbvVqfNntbVs0w= -github.com/go-openapi/swag/netutils v0.28.0 h1:YXN6TALEi2pzts8/8GNm6T61HTAZsieukGZidap989k= -github.com/go-openapi/swag/netutils v0.28.0/go.mod h1:J+WYyFMLtvtCGqa6jLv+YNUmIKI3ZRQRrvfNDMoQoEQ= -github.com/go-openapi/swag/pools v0.28.0 h1:HPMZWSAfce3rdVTFcjFiCIBtDg9h4x2QlRrHipwhxeU= -github.com/go-openapi/swag/pools v0.28.0/go.mod h1:kVQefhSK5RWuRe7BXsL8htgBPAMpN7HDGpGEknqugeE= -github.com/go-openapi/swag/stringutils v0.28.0 h1:ixsc9iYgDPubHL/8nSkbnryEHpD2VRlBMLKpQyPXcDU= -github.com/go-openapi/swag/stringutils v0.28.0/go.mod h1:lzRN95CxXmA03XcDWHLOb6nOMcxCqR5rGY0lOgsfRoM= -github.com/go-openapi/swag/typeutils v0.28.0 h1:nRBKSBXjDgf01VDPB3fWeD9nQuhCOVeIYAkUx2tbkyY= -github.com/go-openapi/swag/typeutils v0.28.0/go.mod h1:Srm0xFNRZ1Y+vCxJclo5qzx8aj+1pAKda/YfFPrG0dQ= -github.com/go-openapi/swag/yamlutils v0.28.0 h1:TV3JXH6DS46KUroDtMLAYHGkdWf5VDq3wVWFirmzROY= -github.com/go-openapi/swag/yamlutils v0.28.0/go.mod h1:x0q/yndZHEgk9Rx3DyDqzFUmHy55KTvIZldvF2dTJXs= -github.com/go-openapi/testify/enable/yaml/v2 v2.6.0 h1:gGHwAJ0R/5jU8BEGDbfRNR3hL68dAVi84WuOApp29B0= -github.com/go-openapi/testify/enable/yaml/v2 v2.6.0/go.mod h1:tY+St1SGq4NFl0QIqdTY4aEdbChAHxhyB77XQi9iJCo= -github.com/go-openapi/testify/v2 v2.6.0 h1:5PKH2HE7YJ/LuRPQGvSxBRlFXNQhSetBLlGAgUEu3ug= -github.com/go-openapi/testify/v2 v2.6.0/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw= +github.com/go-openapi/jsonpointer v1.0.1 h1:2KxywRmNwJkT/FMBa3iRNHEaAxSJvjqoufQZy3au1Mg= +github.com/go-openapi/jsonpointer v1.0.1/go.mod h1:wI7ZYsFmbIi9nBXOZqgDaS/bqOchRGZjqxFli7FBYxY= +github.com/go-openapi/jsonreference v1.0.1 h1:4zJ7AmYDKNmD3aSpfPnFNCFA5E80/xMHUNKgydaLh38= +github.com/go-openapi/jsonreference v1.0.1/go.mod h1:dYplQXa6p5lXprLcJ8LE2iU7vNpXsAHDQ5ZAgL+Qx3A= +github.com/go-openapi/swag v0.29.2 h1:9n8frkcsuQRA0INU31VbxNxt1zBaHxrHYGEf5BUjFi4= +github.com/go-openapi/swag v0.29.2/go.mod h1:RkCiX1gCVXWgLOavDXE3ALJrQ/VO2ziiIzOUs3z10xo= +github.com/go-openapi/swag/cmdutils v0.29.2 h1:cXEzX/nWCODon251f+1HgL75/R4XXML5IZxgLCWMoro= +github.com/go-openapi/swag/cmdutils v0.29.2/go.mod h1:XziaSVzYqkDvpWXzASfWajw2YvJrLscq610O2XiyqJw= +github.com/go-openapi/swag/conv v0.29.2 h1:8c9shoB8l0QRSR6ymq1llHdBWDqpIgJfjTGHx3Vuhm0= +github.com/go-openapi/swag/conv v0.29.2/go.mod h1:AZS0YigTNf8qNtD6WqJz/N4RUNmpr76SyjFGkq4+p6Q= +github.com/go-openapi/swag/fileutils v0.29.2 h1:mdUL+Vw5ah1fO1AvFCoHeIyv7YZsCz2MN3KNqd/lLVI= +github.com/go-openapi/swag/fileutils v0.29.2/go.mod h1:7QKmmodjAebaq61lGVJa8ldLdGeMF4DSgYv8tXOGGo0= +github.com/go-openapi/swag/jsonutils v0.29.2 h1:uZNSD2/rJDYAfvsLYkykTzXuyxM3QpDKV9jhRHrMu6k= +github.com/go-openapi/swag/jsonutils v0.29.2/go.mod h1:ONTdNvj3Y+IXRzfa17E+Rgt2ns/qiSOYjIo2K7v2yDs= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.29.2 h1:w+Fd6EBOMGlC74GYGHqCLGyb3Bpams8TtNrgM/SG4jo= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.29.2/go.mod h1:HC2egPORFzbj/gf05Zrfgz8Mgplx3oW7hgGi7pjZVhM= +github.com/go-openapi/swag/loading v0.29.2 h1:QU1ry24e6r6Shoxe380Nx0X5iKkpRO+hJffsyJ2dVlY= +github.com/go-openapi/swag/loading v0.29.2/go.mod h1:DqilDjuiJKETecsS4TRopWG1acUDsfqN39ZmQhPu6uI= +github.com/go-openapi/swag/mangling v0.29.2 h1:ltdo3K0tTP4P6zWhVVWDU9D37/YYBuMJRdZxiS2Dtog= +github.com/go-openapi/swag/mangling v0.29.2/go.mod h1:RjDi4TnItAenS3cgCXSpIl1kKbjG7il6pnmQVl/8bp8= +github.com/go-openapi/swag/netutils v0.29.2 h1:dBli6jyUa93sDS/XYWShJzf4+nnVfFKfvY9SLUaUzB8= +github.com/go-openapi/swag/netutils v0.29.2/go.mod h1:1pM6Xg/Um8E1eps3umWl8Hme3ByWXOtHsvFC0CULHUE= +github.com/go-openapi/swag/pools v0.29.2 h1:PlGoDRF8WtSyXkedZZkpW3f9wDhFf3u8KtaBcmgmh8c= +github.com/go-openapi/swag/pools v0.29.2/go.mod h1:V3lhxVT4qDYRqc2MRSSbLsTYIYV/2HlHafhyEkmzLIc= +github.com/go-openapi/swag/stringutils v0.29.2 h1:lcnBxwAaysT3bMUVBfn9V/PkfVqkurpqufKU6rTUMGk= +github.com/go-openapi/swag/stringutils v0.29.2/go.mod h1:i9cdh7sGaa0nm3CqIvH5IM5h2QClk1wns2ktKeILvRI= +github.com/go-openapi/swag/typeutils v0.29.2 h1:O7aVvkTs3pXwikgtrPLenigEMdQFgONKRooQA9pgf2I= +github.com/go-openapi/swag/typeutils v0.29.2/go.mod h1:7+GDG+uz9Ke+eVt4rClZg7wklSDp8hT/mKNh/pC26TE= +github.com/go-openapi/swag/yamlutils v0.29.2 h1:IFKFFeDnuIwzfsuWRQU+rI8iL3g4XyAYjV/RlnlxPLM= +github.com/go-openapi/swag/yamlutils v0.29.2/go.mod h1:7MGqtcrK73sxQ4ceiyIf8qiXS/s09JLMdR5esK5euYQ= +github.com/go-openapi/testify/enable/yaml/v2 v2.7.0 h1:wPW6YRgx3+SID1yUy/Xwa17L8kFEaEKod2VRbJDZNUs= +github.com/go-openapi/testify/enable/yaml/v2 v2.7.0/go.mod h1:mI1M88etYbc3PhgHsWQK2kwvNwW5aGFqMPbmib+SGIs= +github.com/go-openapi/testify/v2 v2.7.0 h1:bycOreEj6wfBvijg3YFogZ/sFjTCDmQnwSodSzHa3X8= +github.com/go-openapi/testify/v2 v2.7.0/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw= github.com/go-quicktest/qt v1.102.0 h1:HSQxCeh5YZH3EL3W39ixjtyaEhcWSXQHtHnMBzSs474= github.com/go-quicktest/qt v1.102.0/go.mod h1:p4lGIVX+8Wa6ZPNDvqcxq36XpUDLh42FLetFU7odllI= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= @@ -230,6 +246,10 @@ github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobwas/glob v1.1.0 h1:CS8tIr7+5fu50N+tKsQy3osOU5jmhjHv0/ildcKAn2Q= +github.com/gobwas/glob v1.1.0/go.mod h1:5OYLTTNYHcww+D/XwWAjGpmIE8sD41kWneKyzWkK7/k= +github.com/goccy/go-json v0.11.2 h1:jdZv93Tt4ioR8yW1CoNsvSxrcZlCXAUU1aZXN7gpXUA= +github.com/goccy/go-json v0.11.2/go.mod h1:3NdmfEkZlB7YI5UFw/qdFKq8XN1aiWR0YyRPWZNQltY= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -259,6 +279,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q= +github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -307,8 +329,8 @@ github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5T github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA= github.com/gregdel/pushover v1.3.1 h1:4bMLITOZ15+Zpi6qqoGqOPuVHCwSUvMCgVnN5Xhilfo= github.com/gregdel/pushover v1.3.1/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.31.0 h1:Bd7KaOxzULLxtZ/K5s1aLbWhR0+5RToO65TXHsf3bqQ= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.31.0/go.mod h1:nN7ts3dFXKtCZWc//yfkpcQNKJABg16/uDVAZpLDalo= github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -360,8 +382,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.20.2 h1:v5tiZvm1KGLyg5d5oXdXe3lsSPrbEUiKoXGia//I7Qo= -github.com/klauspost/compress v1.20.2/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= +github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4= +github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU= github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= @@ -375,6 +397,20 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/lestrrat-go/blackmagic v1.0.4 h1:IwQibdnf8l2KoO+qC3uT4OaTWsW7tuRQXy9TRN9QanA= +github.com/lestrrat-go/blackmagic v1.0.4/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw= +github.com/lestrrat-go/dsig v1.4.0 h1:g7LUjK8cT74A5DzBXJI5HzsJuLhoYN0Wzj4nuOMIrH8= +github.com/lestrrat-go/dsig v1.4.0/go.mod h1:I8Nddg/vN2cUl/h8N7SRRApLnNNeyZPIqLYpvpOtGGo= +github.com/lestrrat-go/dsig-secp256k1 v1.0.0 h1:JpDe4Aybfl0soBvoVwjqDbp+9S1Y2OM7gcrVVMFPOzY= +github.com/lestrrat-go/dsig-secp256k1 v1.0.0/go.mod h1:CxUgAhssb8FToqbL8NjSPoGQlnO4w3LG1P0qPWQm/NU= +github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= +github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= +github.com/lestrrat-go/httprc/v3 v3.0.6 h1:4FpLQ18KK/ypPbVU3NLWJNRvH3kcYiqKqWfKGqNWxxI= +github.com/lestrrat-go/httprc/v3 v3.0.6/go.mod h1:mSMtkZW92Z98M5YoNNztbRGxbXHql7tSitCvaxvo9l0= +github.com/lestrrat-go/jwx/v3 v3.4.0 h1:2YSO4sfAj+M90XUuEJZsMibRNpoh1KXP1iL+C/tFebg= +github.com/lestrrat-go/jwx/v3 v3.4.0/go.mod h1:jrZZIM3dgHB780ZrD/3H+ARR5ou4w3X3wFjWE+JWGMU= +github.com/lestrrat-go/option/v2 v2.0.0 h1:XxrcaJESE1fokHy3FpaQ/cXW8ZsIdWcdFzzLOcID3Ss= +github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0= @@ -401,6 +437,8 @@ github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6B github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg= github.com/mholt/archives v0.1.2 h1:UBSe5NfYKHI1sy+S5dJsEsG9jsKKk8NJA4HCC+xTI4A= github.com/mholt/archives v0.1.2/go.mod h1:D7QzTHgw3ctfS6wgOO9dN+MFgdZpbksGCxprUOwZWDs= +github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= +github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= github.com/minio/minlz v1.0.0 h1:Kj7aJZ1//LlTP1DM8Jm7lNKvvJS2m74gyyXXn3+uJWQ= github.com/minio/minlz v1.0.0/go.mod h1:qT0aEB35q79LLornSzeDH75LBf3aH1MV+jB5w9Wasec= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= @@ -446,6 +484,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.39.0 h1:y2ROC3hKFmQZJNFeGAMeHZKkjBL65mIZcvrLQBF9k6Q= github.com/onsi/gomega v1.39.0/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4= +github.com/open-policy-agent/opa v1.22.4 h1:/sKtqt7GVSvXQn1sML2PSzl8tD/mTHF2pzQC3x1CV8k= +github.com/open-policy-agent/opa v1.22.4/go.mod h1:1V4qD8pI14x77B4wUiAHBfoQLQypj03WcokRdY6zM80= github.com/openai/openai-go/v3 v3.81.0 h1:qWXDSLy7LWXGUvWMhKKs1ydrbImMDkgA7XSJv69tXYk= github.com/openai/openai-go/v3 v3.81.0/go.mod h1:i+lM+NFmWP+Yd+fYKEaPxUINBx+vZtRmY5gaszSfsiQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -466,13 +506,13 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pressly/goose/v3 v3.29.0 h1:dtEnBCT7CqkHIUCdgrXsrmeisaN8gFkRU4Y5OEwif4o= github.com/pressly/goose/v3 v3.29.0/go.mod h1:plA4aP4+u+Q3FMTgbFbhF8TuAWpAdfWpoFGkJsIFWh0= -github.com/prometheus/client_golang v1.24.0 h1:5XStIklKuAtJSNpdD3s8XJj/Yv78IQmE1kbNk87JrAI= -github.com/prometheus/client_golang v1.24.0/go.mod h1:QcsNdotprC2nS4BTM2ucbcqxd2CeXTEa9jW7zHO9iDE= +github.com/prometheus/client_golang v1.25.0 h1:cDtW1TcFsMi1RJc8khwCKB4VhzwV04aKqbYtNOXuiK0= +github.com/prometheus/client_golang v1.25.0/go.mod h1:j2X/4/kaQHLPnmyEU8zjmkndo1T317VpCIQEml8LTKk= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= -github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.70.0 h1:bcpru3tWPVnxGnETLgOV5jbp/JRXgYEyv65CuBLAMMI= -github.com/prometheus/common v0.70.0/go.mod h1:S/SFasQmgGiYH6C81LKCtYa8QACgthGg5zxL2udV7SY= +github.com/prometheus/client_model v0.6.3 h1:O0jaTVAYNxTHYInEPFJt5I3+sN8zqBtVMPTB1qyxiEo= +github.com/prometheus/client_model v0.6.3/go.mod h1:gpN5P9S7Rr6Yr92PiQ+Ixvhf6JZEkF1dnxsYL2aPBEM= +github.com/prometheus/common v0.72.0 h1:tAYsE+sPJxIncDAobm4H5aQjmox9ZxEIIqPbiffa8G4= +github.com/prometheus/common v0.72.0/go.mod h1:77NWqAQ2tXT7BIK40qjJdw5Acrsrg1TlHAnsQi3i6mk= github.com/prometheus/procfs v0.22.0 h1:6q9+/JL9IKAPbCmBrv9n5O5Ty3NKnciV5X7YGw0oics= github.com/prometheus/procfs v0.22.0/go.mod h1:CvmFr/GVhIjIvWJZW3tgkODBQMRIf0EyWMQLHCHab58= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= @@ -483,8 +523,8 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.15.0 h1:D0RCU5rMAp+SpgkiNdrjfJ+LX4J1M32V2NeCY7EJ6hc= -github.com/rogpeppe/go-internal v1.15.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs= +github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g= +github.com/rogpeppe/go-internal v1.16.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= @@ -503,8 +543,8 @@ github.com/sethvargo/go-retry v0.5.0/go.mod h1:tvsjdKG6xfiCx4LSiUZ06kcv38xvdVQwv github.com/shopspring/decimal v1.5.0 h1:HxSWk31RmJv0EyY4oLiGQB9u7WPludUwPBdvQZnYFPc= github.com/shopspring/decimal v1.5.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= -github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/sirupsen/logrus v1.10.2 h1:G2SED73/qrAu6YwbdxOD6peLkCBI3z7L+ykJFTXJBBo= +github.com/sirupsen/logrus v1.10.2/go.mod h1:SLEg8TqYulVKKfIGHldVp2K2aYz2DKSVBq4g/H5bR7Q= github.com/slack-go/slack v0.23.1 h1:ZS5B96wxxYQRwvJ3/vJFtqtUZi3tXhsZCyT44Nv7M80= github.com/slack-go/slack v0.23.1/go.mod h1:H0yR/YBuRJ39RkE+JpV/d/oEsbanzTRowR82bCN0cEs= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -526,8 +566,8 @@ github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= -github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.1.0 h1:6W6MbVUrnMb8PEhjkqwsVLY7ryuzRfFHF4mQd7L94ag= +github.com/spf13/pflag v1.1.0/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM= @@ -537,6 +577,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -547,12 +588,14 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= -github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= +github.com/tetratelabs/wazero v1.12.0 h1:DuWcpNu/FzgEXgGBDp8J1Spc+CWOvvtvVyjKlaZopYU= +github.com/tetratelabs/wazero v1.12.0/go.mod h1:LvKtzl2RqO4gyF27BiXU+nKAjcV8f38U+kP/q2vgxh0= github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw= github.com/therootcompany/xz v1.0.1/go.mod h1:3K3UH1yCKgBneZYhuQUvJ9HPD19UEXEI0BWbMn8qNMY= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= @@ -570,14 +613,24 @@ github.com/tink-crypto/tink-go/v2 v2.9.0/go.mod h1:aNXZeyxjQU9iqAeARRNmbESXUW6Ma github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.17 h1:flR0y/x1hgM8EGV1AW3Xll6T413G0glV8UfBwR617V4= github.com/ulikunitz/xz v0.5.17/go.mod h1:H9Rt/W6/Qj27PGauhQc6nfCDy7vHpzsOThBSaYDoEhw= +github.com/valyala/fastjson v1.6.10 h1:/yjJg8jaVQdYR3arGxPE2X5z89xrlhS0eGXdv+ADTh4= +github.com/valyala/fastjson v1.6.10/go.mod h1:e6FubmQouUNP73jtMLmcbxS6ydWIpOfhz34TSfO3JaE= +github.com/vektah/gqlparser/v2 v2.5.64 h1:N32yM6hQ6Kd5RdjCCEJsUrbCebVoA9yLLMOIa88Mkk0= +github.com/vektah/gqlparser/v2 v2.5.64/go.mod h1:nILRSUbsWDTuf8hSmAgFxuYh0SaMZdkvl6JSEbkJX8g= github.com/wasilibs/go-re2 v1.9.0 h1:kjAd8qbNvV4Ve2Uf+zrpTCrDHtqH4dlsRXktywo73JQ= github.com/wasilibs/go-re2 v1.9.0/go.mod h1:0sRtscWgpUdNA137bmr1IUgrRX0Su4dcn9AEe61y+yI= github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xyproto/randomstring v1.2.0 h1:y7PXAEBM3XlwJjPG2JQg4voxBYZ4+hPgRdGKCfU8wik= github.com/xyproto/randomstring v1.2.0/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= +github.com/yashtewari/glob-intersection v0.2.0 h1:8iuHdN88yYuCzCdjt0gDe+6bAhUwBeEWqThExu54RFg= +github.com/yashtewari/glob-intersection v0.2.0/go.mod h1:LK7pIC3piUjovexikBbJ26Yml7g8xa5bsjfx2v1fwok= github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4= github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -589,8 +642,8 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0 h1:oECp5f+hN7nkwjU/8BxQ/q23bGPb8FIrD839owX222E= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0/go.mod h1:DqEFwLumhzMBDQv9PcWbyoDxHI/4lAk6CM4nJBH39sc= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0 h1:B2h3uqicet1CT2N5TOFhS+Gq++9i0/CLmaxvhmhtP5s= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0/go.mod h1:dylvB+ZiiwMvsDij9O84Uy7SijLgHMX4mbkncds+4Sw= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 h1:LxwW/9ctSCv+QkE/cLR7M91ZIkXNMqJtEMi1vCw9U8s= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0/go.mod h1:tOsftB4SslBwwErVEPaenU2RpThXWPIU8DoJHEC4dyw= go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM= @@ -613,8 +666,8 @@ go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw= go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM= go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0= -go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk= -go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E= +go.opentelemetry.io/proto/otlp v1.11.1 h1:SCrPqH9NE5CmBrOqpjNCiT0X5mGwMyGERXdogfR7Yjw= +go.opentelemetry.io/proto/otlp v1.11.1/go.mod h1:wq8W4aSf6bOy8RZyESOeQFr9Pu7wydWX/TY4sgvrTPg= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -624,8 +677,8 @@ go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= -go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +go.yaml.in/yaml/v3 v3.0.6 h1:zcDfvjXEqTQmpjniUBLc91xYJMB2c4QOFxEF/LCEckM= +go.yaml.in/yaml/v3 v3.0.6/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= go.yaml.in/yaml/v4 v4.0.0-rc.2 h1:/FrI8D64VSr4HtGIlUtlFMGsm7H7pWTbj6vOLVZcA6s= go.yaml.in/yaml/v4 v4.0.0-rc.2/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= go4.org v0.0.0-20230225012048-214862532bf5 h1:nifaUDeh+rPaBCMPMQHZmvJf+QdpLFnuQPwx+LxVmtc= @@ -838,8 +891,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.84.0 h1:soMyaPJ8pAak5PIQ0DGBUir0XRo2fRoMqhNWMLlLxO0= -google.golang.org/grpc v1.84.0/go.mod h1:ljCht0DrxQrXBDRTZp52Qxh3Ffk8CdYm2sj4O2QN2C0= +google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw= +google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -862,8 +915,8 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AW gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.67.3 h1:iM9Lhz5MRSGhHVGGwCuzG9KO8PoirCXj/m/qTmOJJQw= +gopkg.in/ini.v1 v1.67.3/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/cli/servercmd/gateway.go b/internal/cli/servercmd/gateway.go index 229f8b22..f6747dbb 100644 --- a/internal/cli/servercmd/gateway.go +++ b/internal/cli/servercmd/gateway.go @@ -215,7 +215,7 @@ func (o *gatewayOptions) run(ctx context.Context, common *commonFlags, platform outageGrace = oidc.OutageGrace.Duration } fp := on.fingerprinter - conns, err := wiring.Connectors(platform.Connectors, db, sessionsKey, on.sessionsKeyLasting, platform.MCP.PublicURL) + conns, err := wiring.Connectors(ctx, platform.Connectors, db, sessionsKey, on.sessionsKeyLasting, platform.MCP.PublicURL) if err != nil { return err } @@ -302,6 +302,7 @@ func (o *gatewayOptions) run(ctx context.Context, common *commonFlags, platform MCP: platform.MCP, Connectors: conns.Registry, ConnectorTokens: connTokens, + ConnectorPolicy: conns.Policy, ConnectorVault: conns.Vault, ConnectorSignIn: conns.SignIn, ConnectorHTTP: httpx.Guard{PublicOnly: true, Internal: platform.Connectors.InternalHosts}.Client(), diff --git a/internal/cli/servercmd/local_build_test.go b/internal/cli/servercmd/local_build_test.go index 977439f7..11dd488b 100644 --- a/internal/cli/servercmd/local_build_test.go +++ b/internal/cli/servercmd/local_build_test.go @@ -107,7 +107,7 @@ func TestALocalBuildRefusesConnectors(t *testing.T) { if err != nil { t.Fatal(err) } - yaml = append(yaml, "connectors:\n enabled: true\nmcp:\n enabled: true\n publicURL: https://tapas.example.org\n"...) + yaml = append(yaml, "connectors:\n enabled: true\n policy:\n rulesDir: /etc/javo-policy\nmcp:\n enabled: true\n publicURL: https://tapas.example.org\n"...) if err := os.WriteFile(cfg, yaml, 0o600); err != nil { t.Fatal(err) } diff --git a/internal/cli/wiring/connectors_policy.go b/internal/cli/wiring/connectors_policy.go new file mode 100644 index 00000000..06e475eb --- /dev/null +++ b/internal/cli/wiring/connectors_policy.go @@ -0,0 +1,26 @@ +//go:build !local + +package wiring + +import ( + "context" + "time" + + "github.com/nebari-dev/javo/internal/config" + "github.com/nebari-dev/javo/internal/connectors/policy" + "github.com/nebari-dev/javo/internal/connectors/policy/opa" +) + +// policyReloadEvery is how often the rules directory is read for changes. +// A ConfigMap's mount changes about a minute after the ConfigMap does. +const policyReloadEvery = 10 * time.Second + +// connectorPolicy is OPA over the rules in c.RulesDir, loaded now and +// whenever they change until ctx ends. Rules that do not load deny every +// call (and are logged); a change that does not load keeps the last rules +// that did. +func connectorPolicy(ctx context.Context, c config.ConnectorPolicyCfg) policy.Checker { + e := opa.New(opa.Config{Dir: c.RulesDir}) + e.Start(ctx, policyReloadEvery) + return e +} diff --git a/internal/cli/wiring/connectors_policy_local.go b/internal/cli/wiring/connectors_policy_local.go new file mode 100644 index 00000000..aa006b66 --- /dev/null +++ b/internal/cli/wiring/connectors_policy_local.go @@ -0,0 +1,15 @@ +//go:build local + +package wiring + +import ( + "context" + + "github.com/nebari-dev/javo/internal/config" + "github.com/nebari-dev/javo/internal/connectors/policy" +) + +// connectorPolicy is none: a binary built with the tag local has no +// connectors (it refuses connectors.enabled before it gets here), so no +// policy engine is carried. +func connectorPolicy(context.Context, config.ConnectorPolicyCfg) policy.Checker { return nil } diff --git a/internal/cli/wiring/connectors_policy_test.go b/internal/cli/wiring/connectors_policy_test.go new file mode 100644 index 00000000..ece16baa --- /dev/null +++ b/internal/cli/wiring/connectors_policy_test.go @@ -0,0 +1,41 @@ +//go:build !local + +package wiring + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/nebari-dev/javo/internal/config" + "github.com/nebari-dev/javo/internal/connectors/policy" + "github.com/nebari-dev/javo/internal/secrets" + "github.com/nebari-dev/javo/internal/store/storetest" +) + +// With connectors on, calls are decided by the rules in the configured +// directory, loaded by the time the parts are built. +func TestConnectorCallsAreCheckedAgainstTheConfiguredRules(t *testing.T) { + db := storetest.New(t) + key, err := secrets.NewKey() + if err != nil { + t.Fatal(err) + } + dir := t.TempDir() + rules := "package tapas.rules.all\n\n# METADATA\n# title: Off\n# description: Connectors are off today.\ndeny contains rego.metadata.rule() if true\n" + if err := os.WriteFile(filepath.Join(dir, "all.rego"), []byte(rules), 0o600); err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + on := config.ConnectorsCfg{Enabled: true, Policy: config.ConnectorPolicyCfg{RulesDir: dir}} + p, err := Connectors(ctx, on, db, key, true, "") + if err != nil || p.Policy == nil { + t.Fatalf("parts %+v, %v", p, err) + } + d := policy.Evaluate(ctx, p.Policy, policy.Input{Where: policy.Where{Connector: "slack", Tool: "post"}}) + if d.Effect != policy.Deny || d.Reason != "Connectors are off today." { + t.Fatalf("decision %+v", d) + } +} diff --git a/internal/cli/wiring/wiring.go b/internal/cli/wiring/wiring.go index 2fc08aa8..530a432c 100644 --- a/internal/cli/wiring/wiring.go +++ b/internal/cli/wiring/wiring.go @@ -27,6 +27,7 @@ import ( "github.com/nebari-dev/javo/internal/backup/restic" "github.com/nebari-dev/javo/internal/buildinfo" "github.com/nebari-dev/javo/internal/config" + "github.com/nebari-dev/javo/internal/connectors/policy" connreg "github.com/nebari-dev/javo/internal/connectors/registry" "github.com/nebari-dev/javo/internal/connectors/vault" "github.com/nebari-dev/javo/internal/controller/jobs" @@ -238,6 +239,9 @@ type ConnectorParts struct { Registry *connreg.Registry Vault *vault.Vault SignIn gwconnectors.SignIn + // Policy decides every connector call by the rules in + // connectors.policy.rulesDir, kept loaded until ctx ends. + Policy policy.Checker } // Connectors builds the connector parts, sealed with the gateway's @@ -245,8 +249,8 @@ type ConnectorParts struct { // whether that key survives a restart (read from a Secret or a file): one // made at start would lose every stored client secret and token on the // next one, so connectors are refused with it. publicURL is the base of -// the OAuth redirect address. -func Connectors(c config.ConnectorsCfg, db *store.Store, seal tink.AEAD, lasting bool, publicURL string) (ConnectorParts, error) { +// the OAuth redirect address. The rules are watched until ctx ends. +func Connectors(ctx context.Context, c config.ConnectorsCfg, db *store.Store, seal tink.AEAD, lasting bool, publicURL string) (ConnectorParts, error) { if !c.Enabled { return ConnectorParts{}, nil } @@ -262,6 +266,7 @@ func Connectors(c config.ConnectorsCfg, db *store.Store, seal tink.AEAD, lasting p.SignIn, oauth = signIn(c, db, seal, clients, publicURL) p.Vault = vault.New(vault.Config{DB: db, Seal: seal, OAuth: oauth}) p.Registry = connreg.New(connreg.Config{DB: db, Seal: seal, InternalHosts: c.InternalHosts, Connections: p.Vault}) + p.Policy = connectorPolicy(ctx, c.Policy) return p, nil } diff --git a/internal/cli/wiring/wiring_test.go b/internal/cli/wiring/wiring_test.go index 3fc15d66..ef105822 100644 --- a/internal/cli/wiring/wiring_test.go +++ b/internal/cli/wiring/wiring_test.go @@ -270,14 +270,14 @@ func TestConnectorsNeedASessionsKeyThatSurvivesRestarts(t *testing.T) { if err != nil { t.Fatal(err) } - if p, err := Connectors(config.ConnectorsCfg{}, db, key, false, ""); p.Registry != nil || p.Vault != nil || err != nil { + if p, err := Connectors(context.Background(), config.ConnectorsCfg{}, db, key, false, ""); p.Registry != nil || p.Vault != nil || p.Policy != nil || err != nil { t.Fatalf("off: %+v, %v", p, err) } on := config.ConnectorsCfg{Enabled: true} - if p, err := Connectors(on, db, key, false, ""); p.Registry != nil || err == nil || !strings.Contains(err.Error(), "--sessions-key-secret") { + if p, err := Connectors(context.Background(), on, db, key, false, ""); p.Registry != nil || err == nil || !strings.Contains(err.Error(), "--sessions-key-secret") { t.Fatalf("with a key made at start: %+v, %v", p, err) } - if p, err := Connectors(on, db, key, true, ""); p.Registry == nil || p.Vault == nil || err != nil { + if p, err := Connectors(context.Background(), on, db, key, true, ""); p.Registry == nil || p.Vault == nil || err != nil { t.Fatalf("with a lasting key: %+v, %v", p, err) } } diff --git a/internal/config/config.go b/internal/config/config.go index 21c1aab4..2d39705a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -360,6 +360,16 @@ type ConnectorsCfg struct { // reached at over plain http and at a private address: in-cluster MCP // servers. Every other connector address must be https and public. InternalHosts []string `json:"internalHosts,omitempty"` + // Policy is the rules every connector call is checked against. + Policy ConnectorPolicyCfg `json:"policy"` +} + +// ConnectorPolicyCfg says where the connector policy's rules are. +type ConnectorPolicyCfg struct { + // RulesDir is an absolute directory of Rego files (a ConfigMap mount in + // the chart), read again when it changes. Required with connectors on: + // with no rules loaded every connector call is denied. + RulesDir string `json:"rulesDir,omitempty"` } // AgentsCfg configures coding-agent apps (templates of category agents). @@ -964,6 +974,9 @@ func (p Platform) Validate() error { if p.Connectors.Enabled && !p.MCP.Enabled { bad("connectors", "enabled needs mcp.enabled: agents reach connectors only through the MCP endpoint") } + if p.Connectors.Enabled && !filepath.IsAbs(p.Connectors.Policy.RulesDir) { + bad("connectors.policy.rulesDir", "%q is not an absolute directory: connectors need the rules every call is checked against", p.Connectors.Policy.RulesDir) + } for i, h := range p.Connectors.InternalHosts { if h == "" || strings.ContainsAny(h, ":/@?# \t") { bad(fmt.Sprintf("connectors.internalHosts[%d]", i), "%q is not a host name such as mcp-slack.tapas.svc (no scheme, port or path)", h) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index cc709f6b..3e59fd87 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -715,11 +715,11 @@ func TestConnectorsAreOffByDefaultAndNeedAPublicURLAndMCP(t *testing.T) { if p.Connectors.Enabled || len(p.Connectors.InternalHosts) != 0 { t.Fatalf("connectors = %+v", p.Connectors) } - p, err = load(t, "auth:\n local:\n enabled: true\nurls:\n uiHost: tapas.example.org\nmcp:\n enabled: true\nconnectors:\n enabled: true\n internalHosts: [mcp-slack.tapas.svc]\n") + p, err = load(t, "auth:\n local:\n enabled: true\nurls:\n uiHost: tapas.example.org\nmcp:\n enabled: true\nconnectors:\n enabled: true\n internalHosts: [mcp-slack.tapas.svc]\n policy:\n rulesDir: /etc/javo-policy\n") if err != nil { t.Fatal(err) } - if !p.Connectors.Enabled || p.Connectors.InternalHosts[0] != "mcp-slack.tapas.svc" { + if !p.Connectors.Enabled || p.Connectors.InternalHosts[0] != "mcp-slack.tapas.svc" || p.Connectors.Policy.RulesDir != "/etc/javo-policy" { t.Fatalf("connectors = %+v", p.Connectors) } // The OAuth redirect address is built from the public URL, never from a @@ -731,6 +731,14 @@ func TestConnectorsAreOffByDefaultAndNeedAPublicURLAndMCP(t *testing.T) { if _, err := load(t, "auth:\n local:\n enabled: true\nurls:\n uiHost: tapas.example.org\nconnectors:\n enabled: true\n"); err == nil || !strings.Contains(err.Error(), "mcp.enabled") { t.Fatalf("connectors without the MCP endpoint: %v", err) } + // Every connector call is checked against the rules: there are none to + // check against without a directory to read them from. + base := "auth:\n local:\n enabled: true\nurls:\n uiHost: tapas.example.org\nmcp:\n enabled: true\nconnectors:\n enabled: true\n" + for _, policy := range []string{"", " policy:\n rulesDir: relative/rules\n"} { + if _, err := load(t, base+policy); err == nil || !strings.Contains(err.Error(), "connectors.policy.rulesDir") { + t.Errorf("connectors with policy %q: %v", policy, err) + } + } for _, host := range []string{`""`, "http://mcp.tapas.svc", "mcp.tapas.svc:8080", "mcp.tapas.svc/mcp", `"two words"`} { _, err := load(t, "auth:\n local:\n enabled: true\nconnectors:\n internalHosts: ["+host+"]\n") if err == nil || !strings.Contains(err.Error(), "connectors.internalHosts") { diff --git a/internal/connectors/broker/action.go b/internal/connectors/broker/action.go index 524a76c3..2a0b726b 100644 --- a/internal/connectors/broker/action.go +++ b/internal/connectors/broker/action.go @@ -27,6 +27,11 @@ const ( urlParam = "url" ) +// agentParam is the proposal's parameter that records the agent that +// proposed the call (policy.Agent as JSON), so the policy is told of it +// again when the owner's approval applies the call. +const agentParam = "agent" + // Action is the connector-call catalog action (D18): planning a write // repeats the call's checks and asks the policy, and applying an approved // one checks again and forwards exactly the stored arguments once. @@ -72,17 +77,18 @@ func (a *CallAction) Plan(ctx context.Context, p actions.Proposal) (actions.Plan } } if r, ok := ctx.Value(planReportKey{}).(*planReport); ok { - r.outcome, r.policy = c.outcome, c.policy + r.outcome, r.decision = c.outcome, c.decision } if res != nil { return actions.Planned{}, refusal(c, res) } var args bytes.Buffer - _ = json.Compact(&args, c.args) // checked by resolve + _ = json.Compact(&args, c.args) // checked by resolve + agent, _ := json.Marshal(agentOf(c.caller)) // strings and a bool: cannot fail return actions.Planned{ Proposal: actions.Proposal{ Action: actions.ConnectorCall, Target: p.Target, Owner: c.caller.Principal.ID, - Params: map[string]string{argumentsParam: args.String(), connectorParam: c.conn.ID, urlParam: c.conn.URL}, + Params: map[string]string{argumentsParam: args.String(), connectorParam: c.conn.ID, urlParam: c.conn.URL, agentParam: string(agent)}, }, TargetName: c.conn.Name, Summary: c.conn.Name + ": " + c.tool, Changes: changes, Destructive: destructive(c.mode, c.listed), @@ -119,7 +125,7 @@ func (a *CallAction) Apply(ctx context.Context, p actions.Proposal) error { func (a *CallAction) newCall(ctx context.Context, ph phase, p actions.Proposal) *call { return &call{ phase: ph, caller: a.callerOf(ctx), name: p.Target, args: json.RawMessage(p.Params[argumentsParam]), started: a.b.c.Now(), - approved: approvedConnector{ID: p.Params[connectorParam], URL: p.Params[urlParam]}, + approved: approvedConnector{ID: p.Params[connectorParam], URL: p.Params[urlParam]}, proposer: p.Params[agentParam], } } diff --git a/internal/connectors/broker/action_test.go b/internal/connectors/broker/action_test.go index ea0d9022..037dde36 100644 --- a/internal/connectors/broker/action_test.go +++ b/internal/connectors/broker/action_test.go @@ -6,6 +6,7 @@ import ( "errors" "net/http" "strings" + "sync" "testing" "time" @@ -114,7 +115,7 @@ func TestPlanningRepeatsTheCallsChecks(t *testing.T) { } }) } - if seen.Phase != policy.PhasePropose || !seen.Write || seen.Tool != "post" { + if seen.Phase != policy.PhasePropose || seen.Where.Mode != "write" || seen.Where.Tool != "post" || seen.Approval != nil { t.Fatalf("policy saw %+v", seen) } } @@ -143,6 +144,83 @@ func TestApplyingSendsTheStoredArgumentsOnce(t *testing.T) { } } +// recording allows every call and keeps what it was asked. +type recording struct { + mu sync.Mutex + seen []policy.Input +} + +func (r *recording) Check(_ context.Context, in policy.Input) (policy.Decision, error) { + r.mu.Lock() + defer r.mu.Unlock() + r.seen = append(r.seen, in) + return policy.Decision{Effect: policy.Allow, Rules: []string{}, Revision: "rev-1"}, nil +} + +// Applying asks the policy as the plan's owner with the approval, and names +// the agent that proposed the call, as stored with the plan: an agent the +// rules deny cannot get a call made by having it approved. +func TestApplyingTellsThePolicyWhoProposedAndThatItIsApproved(t *testing.T) { + t.Parallel() + r := &recording{} + f := newFixture(t, options{policy: r}) + agent := writer() + agent.Token.App = &token.App{Namespace: "ns", Name: "helper-1", Short: "helper"} + agent.AgentApp, agent.Agent = true, "helper" + pl, err := as(f, agent).Plan(ctx, proposal(`{"text":"hello"}`)) + if err != nil { + t.Fatal(err) + } + if err := as(f, owner()).Apply(ctx, pl.Proposal); err != nil { + t.Fatal(err) + } + if len(r.seen) != 2 { + t.Fatalf("asked %d times: %+v", len(r.seen), r.seen) + } + planned, applied := r.seen[0], r.seen[1] + wantAgent := policy.Agent{Name: "helper", App: "helper-1", Token: "t-1", Client: "claude-code"} + if planned.Phase != policy.PhasePropose || planned.Agent != wantAgent || planned.Approval != nil { + t.Fatalf("planning saw %+v", planned) + } + if applied.Phase != policy.PhaseApply || applied.Agent != wantAgent || applied.Approval == nil || applied.Approval.By != "alice" || + applied.Who.Person != "alice" || string(applied.What.Arguments) != `{"text":"hello"}` || applied.Where != planned.Where { + t.Fatalf("applying saw %+v (approval %+v)", applied, applied.Approval) + } + // The agent cannot choose what the apply is told: the param is the + // planner's, whatever the proposal carried. + p := proposal(`{}`) + p.Params["agent"] = `{"name":"someone-else"}` + pl, err = as(f, agent).Plan(ctx, p) + if err != nil { + t.Fatal(err) + } + if err := as(f, owner()).Apply(ctx, pl.Proposal); err != nil { + t.Fatal(err) + } + if got := r.seen[len(r.seen)-1].Agent; got != wantAgent { + t.Fatalf("applying saw agent %+v", got) + } +} + +// A plan whose record of the proposing agent cannot be read is not made: +// the policy could not be told who asked for it. +func TestApplyingAnUnreadableProposerDenies(t *testing.T) { + t.Parallel() + f := newFixture(t, options{}) + pl, err := as(f, writer()).Plan(ctx, proposal(`{}`)) + if err != nil { + t.Fatal(err) + } + pl.Params["agent"] = "{not json" + if err := as(f, owner()).Apply(ctx, pl.Proposal); err == nil || len(f.fake.Calls()) != 0 { + t.Fatalf("applied: %v, calls %v", err, f.fake.Calls()) + } + var d map[string]any + if rows := callRows(t, f.db); len(rows) != 1 || json.Unmarshal(rows[0].Detail, &d) != nil || d["outcome"] != "denied_policy" || rows[0].Allowed { + t.Fatalf("rows %+v", rows) + } +} + // Anything that changed since the plan was made stops it before the // connector: the plan fails with the reason. func TestApplyingChecksAgain(t *testing.T) { diff --git a/internal/connectors/broker/audit_test.go b/internal/connectors/broker/audit_test.go index 2786ffff..3815b0f1 100644 --- a/internal/connectors/broker/audit_test.go +++ b/internal/connectors/broker/audit_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "maps" + "reflect" "strings" "testing" "time" @@ -101,6 +102,14 @@ func TestEachOutcomeWritesOneRow(t *testing.T) { detail: map[string]any{"tool": "echo", "outcome": "denied_token", "agent": "helper-1"}}, {name: "denied_authz", caller: bob, tool: "fake__echo", args: `{}`, allowed: false, detail: map[string]any{"tool": "echo", "outcome": "denied_authz"}}, + {name: "rules and revision", o: options{policy: decided{policy.Decision{Effect: policy.Allow, Rules: []string{}, Revision: "rev-1"}}}, caller: alice(), tool: "fake__echo", args: `{}`, allowed: true, + detail: map[string]any{"tool": "echo", "mode": "read", "outcome": "ok", "policy": "allow", "policyRevision": "rev-1"}}, + {name: "denying rules", o: options{policy: decided{policy.Decision{Effect: policy.Deny, Reason: "No.", Rules: []string{"A", "B"}, Revision: "rev-2"}}}, caller: alice(), tool: "fake__echo", args: `{}`, allowed: false, + detail: map[string]any{"tool": "echo", "mode": "read", "outcome": "denied_policy", "policy": "deny", "policyRules": []any{"A", "B"}, "policyRevision": "rev-2"}}, + {name: "rules asking approval of a plan", o: options{policy: decided{policy.Decision{Effect: policy.RequireApproval, Rules: []string{"Held"}, Revision: "rev-3"}}}, caller: proposing(writer()), tool: "fake__post", args: `{}`, allowed: true, + detail: map[string]any{"tool": "post", "mode": "write", "outcome": "proposed", "policy": "require_approval", "policyRules": []any{"Held"}, "policyRevision": "rev-3", "plan": plans.StoredID("h-1")}}, + {name: "rules denying a plan", o: options{policy: decided{policy.Decision{Effect: policy.Deny, Reason: "No.", Rules: []string{"Never"}, Revision: "rev-4"}}}, caller: proposing(writer()), tool: "fake__post", args: `{}`, allowed: false, + detail: map[string]any{"tool": "post", "mode": "write", "outcome": "denied_policy", "policy": "deny", "policyRules": []any{"Never"}, "policyRevision": "rev-4"}}, {name: "denied_policy", o: options{policy: denyAll{&seen}}, caller: alice(), tool: "fake__echo", args: `{}`, allowed: false, detail: map[string]any{"tool": "echo", "mode": "read", "outcome": "denied_policy", "policy": "deny"}}, {name: "not_connected", o: options{tokens: connectorstest.StaticToken("")}, caller: alice(), tool: "fake__echo", args: `{}`, allowed: true, @@ -142,13 +151,18 @@ func TestEachOutcomeWritesOneRow(t *testing.T) { if err := json.Unmarshal(r.Detail, &got); err != nil { t.Fatal(err) } - if !maps.Equal(got, want) { + if !reflect.DeepEqual(got, want) { t.Errorf("detail\n got %v\nwant %v", got, want) } }) } } +// decided answers d to every call. +type decided struct{ d policy.Decision } + +func (c decided) Check(context.Context, policy.Input) (policy.Decision, error) { return c.d, nil } + // Listing tools records nothing. func TestListingWritesNoRow(t *testing.T) { t.Parallel() diff --git a/internal/connectors/broker/broker.go b/internal/connectors/broker/broker.go index 2ee9adb9..291b5974 100644 --- a/internal/connectors/broker/broker.go +++ b/internal/connectors/broker/broker.go @@ -43,7 +43,7 @@ type Config struct { // Audit records one row per tool call (D19); a call whose row cannot be // written answers an error. Required: without it every call fails. Audit Auditor - // Policy is asked before a call goes ahead; nil allows all. + // Policy is asked before a call goes ahead; nil denies every call. Policy policy.Checker // PublicURL is where people reach Tapas, for the page they connect // accounts at. @@ -60,9 +60,6 @@ type Broker struct { // New returns a Broker over c. func New(c Config) *Broker { - if c.Policy == nil { - c.Policy = policy.AllowAll{} - } if c.Now == nil { c.Now = time.Now } @@ -81,11 +78,11 @@ type call struct { conn connectors.Connector mode connectors.ToolMode bearer string - // outcome is how the call ended, and policy the policy's effect (empty - // when it was not asked), for the audit row. - outcome string - policy policy.Effect - started time.Time + // outcome is how the call ended, and decision the policy's (its effect + // empty when it was not asked), for the audit row. + outcome string + decision policy.Decision + started time.Time // phase is what the steps run for: an agent's call, planning a write, // or applying an approved one. phase phase @@ -96,6 +93,9 @@ type call struct { // approved is the connector an approved plan was asked for; applying // refuses any other one. approved approvedConnector + // proposer is the agent that proposed an approved plan, as JSON + // (policy.Agent), for the policy's input when it is applied. + proposer string } // approvedConnector pins a plan to a connector by id and address. diff --git a/internal/connectors/broker/broker_test.go b/internal/connectors/broker/broker_test.go index 7dc84711..437cdaad 100644 --- a/internal/connectors/broker/broker_test.go +++ b/internal/connectors/broker/broker_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "net/http" + "reflect" "strings" "sync" "testing" @@ -76,6 +77,9 @@ func newFixture(t *testing.T, o options) *fixture { if o.audit == nil { o.audit = db.Audit() } + if o.policy == nil { + o.policy = allowAll{} + } b := broker.New(broker.Config{ Connectors: reg, Forwarder: o.forwarder, Tokens: o.tokens, Policy: o.policy, Audit: o.audit, PublicURL: "https://tapas.example.org", Now: o.now, @@ -326,6 +330,27 @@ func TestNotConnectedShowsNoToolsAndSaysWhereToConnect(t *testing.T) { } } +// allowAll allows every call: the fixture's policy unless a test sets one. +type allowAll struct{} + +func (allowAll) Check(context.Context, policy.Input) (policy.Decision, error) { + return policy.Decision{Effect: policy.Allow}, nil +} + +// A broker given no policy denies every call: there is no allow-all +// default. +func TestNoPolicyDeniesEveryCall(t *testing.T) { + t.Parallel() + f := newFixture(t, options{}) + b := broker.New(broker.Config{ + Connectors: f.reg, Forwarder: &client.Client{HTTP: &http.Client{}}, Tokens: connectorstest.StaticToken(bearer), Audit: f.db.Audit(), + }) + res, _ := b.Call(ctx, alice(), "fake__echo", json.RawMessage(`{}`)) + if !res.IsError || !strings.Contains(text(t, res), "policy") || len(f.fake.Calls()) != 0 { + t.Fatalf("no policy: %+v, calls %v", res, f.fake.Calls()) + } +} + type denyAll struct{ seen *policy.Input } func (d denyAll) Check(_ context.Context, in policy.Input) (policy.Decision, error) { @@ -347,9 +372,15 @@ func TestPolicyIsAskedBeforeARead(t *testing.T) { if !res.IsError || !strings.Contains(text(t, res), "Reads of fake are off today") || len(f.fake.Calls()) != 0 { t.Fatalf("denied read %+v", res) } - if seen.Phase != policy.PhaseRead || seen.Person != "alice" || seen.Connector != "fake" || seen.Tool != "echo" || - seen.TokenID != "t-1" || string(seen.Arguments) != `{"text":"hello"}` || seen.Write { - t.Fatalf("policy saw %+v", seen) + want := policy.Input{ + Checkpoint: policy.CheckpointToolCall, Phase: policy.PhaseRead, + Who: policy.Who{Person: "alice", Groups: []string{"sales"}}, + Agent: policy.Agent{Token: "t-1", Client: "claude-code"}, + Where: policy.Where{Connector: "fake", Tool: "echo", Mode: "read"}, + What: policy.What{Arguments: json.RawMessage(`{"text":"hello"}`)}, + } + if !reflect.DeepEqual(seen, want) { + t.Fatalf("policy saw\n %+v\nwant %+v", seen, want) } f = newFixture(t, options{policy: failing{}}) if res := call(t, f, alice(), "fake__echo", `{}`); !res.IsError || len(f.fake.Calls()) != 0 { @@ -414,7 +445,7 @@ func TestATimeoutIsAToolError(t *testing.T) { } b := broker.New(broker.Config{ Connectors: reg, Forwarder: &client.Client{HTTP: &http.Client{}, CallTimeout: 100e6}, Tokens: connectorstest.StaticToken(bearer), - Audit: db.Audit(), + Audit: db.Audit(), Policy: allowAll{}, }) fake.Hang(true) res, _ := b.Call(ctx, alice(), "fake__echo", json.RawMessage(`{}`)) diff --git a/internal/connectors/broker/checkpolicy.go b/internal/connectors/broker/checkpolicy.go index 1cc26a60..354836fc 100644 --- a/internal/connectors/broker/checkpolicy.go +++ b/internal/connectors/broker/checkpolicy.go @@ -2,6 +2,7 @@ package broker import ( "context" + "encoding/json" "strings" sdk "github.com/modelcontextprotocol/go-sdk/mcp" @@ -11,22 +12,23 @@ import ( "github.com/nebari-dev/javo/internal/reasons" ) -// checkPolicy asks the policy hook about a call. An agent's read is asked -// in the read phase, and require_approval makes it a write; an agent's -// write is asked when it is planned. A plan may be made when the policy -// allows it or asks for approval; an approved plan is applied only when -// the policy allows it then. A deny ends the call with the policy's -// reason. +// checkPolicy asks the policy about a call. An agent's read is asked in +// the read phase, and require_approval makes it a write; an agent's write +// is asked when it is planned. A plan may be made when the policy allows +// it or asks for approval; an approved plan is applied only when the +// policy allows it then, told of the approval. A deny ends the call with +// the policy's reason. func (b *Broker) checkPolicy(ctx context.Context, c *call) *sdk.CallToolResult { - ph := map[phase]policy.Phase{phaseCall: policy.PhaseRead, phasePlan: policy.PhasePropose, phaseApply: policy.PhaseApply}[c.phase] if c.phase == phaseCall && c.mode != connectors.ToolRead { return nil } - d := policy.Evaluate(ctx, b.c.Policy, policy.Input{ - Phase: ph, Person: c.caller.Principal.ID, Groups: c.caller.Principal.Groups, Agent: c.caller.Agent, - TokenID: c.caller.Token.ID, Connector: c.conn.Slug, Tool: c.tool, Write: c.mode == connectors.ToolWrite, Arguments: c.args, - }) - c.policy = d.Effect + in, ok := c.policyInput() + if !ok { + c.decision = policy.Decision{Effect: policy.Deny} + return errorResult(c, outcomeDeniedPolicy, serverError) + } + d := policy.Evaluate(ctx, b.c.Policy, in) + c.decision = d switch { case d.Effect == policy.Allow: return nil @@ -40,3 +42,35 @@ func (b *Broker) checkPolicy(ctx context.Context, c *call) *sdk.CallToolResult { } return errorResult(c, outcomeDeniedPolicy, reasons.Msg(reasons.MsgConnectorDeniedByPolicy, strings.TrimRight(d.Reason, "."))) } + +// policyInput is c as the policy sees it; false when an approved call's +// record of who proposed it cannot be read. +func (c *call) policyInput() (policy.Input, bool) { + in := policy.Input{ + Checkpoint: policy.CheckpointToolCall, + Phase: map[phase]policy.Phase{phaseCall: policy.PhaseRead, phasePlan: policy.PhasePropose, phaseApply: policy.PhaseApply}[c.phase], + Who: policy.Who{Person: c.caller.Principal.ID, Groups: c.caller.Principal.Groups}, + Agent: agentOf(c.caller), + Where: policy.Where{Connector: c.conn.Slug, Tool: c.tool, Mode: string(c.mode)}, + What: policy.What{Arguments: c.args}, + } + if c.phase == phaseApply { + // The owner approves in the browser: the agent is the one that + // proposed the call, as recorded when it was planned. + in.Agent = policy.Agent{} + if c.proposer != "" && json.Unmarshal([]byte(c.proposer), &in.Agent) != nil { + return policy.Input{}, false + } + in.Approval = &policy.Approval{Plan: c.plan, By: c.caller.Principal.ID} + } + return in, true +} + +// agentOf is what made a call for caller. +func agentOf(caller connectors.Caller) policy.Agent { + a := policy.Agent{Name: caller.Agent, Token: caller.Token.ID, Client: caller.Client, Scheduled: caller.Token.Job != ""} + if app := caller.Token.App; app != nil { + a.App = app.Name + } + return a +} diff --git a/internal/connectors/broker/propose.go b/internal/connectors/broker/propose.go index ba26d8c4..ece84cd2 100644 --- a/internal/connectors/broker/propose.go +++ b/internal/connectors/broker/propose.go @@ -37,8 +37,8 @@ func (b *Broker) propose(ctx context.Context, c *call) *sdk.CallToolResult { p, err := c.caller.Propose(context.WithValue(ctx, planReportKey{}, planned), actions.Proposal{ Action: actions.ConnectorCall, Target: c.name, Params: map[string]string{argumentsParam: string(c.args)}, }) - if planned.policy != "" { - c.policy = planned.policy + if planned.decision.Effect != "" { + c.decision = planned.decision } var refused *connectors.ProposalRefused switch { @@ -59,10 +59,10 @@ func (b *Broker) propose(ctx context.Context, c *call) *sdk.CallToolResult { } // planReport is how planning a call proposed by propose ended: its outcome -// when the checks refused it, and the policy's effect when it was asked. +// when the checks refused it, and the policy's decision when it was asked. type planReport struct { - outcome string - policy policy.Effect + outcome string + decision policy.Decision } type planReportKey struct{} diff --git a/internal/connectors/broker/record.go b/internal/connectors/broker/record.go index 4a94218f..d92285cb 100644 --- a/internal/connectors/broker/record.go +++ b/internal/connectors/broker/record.go @@ -49,9 +49,13 @@ type callDetail struct { Client string `json:"client"` // Plan is the plan a write became. Plan string `json:"plan,omitempty"` - // Policy is the policy's effect; "" when it was not asked. - Policy string `json:"policy"` - Ms int64 `json:"ms"` + // Policy is the policy's effect; "" when it was not asked. PolicyRules + // are the titles of the rules that decided it, and PolicyRevision the + // rule set's revision. + Policy string `json:"policy"` + PolicyRules []string `json:"policyRules,omitempty"` + PolicyRevision string `json:"policyRevision,omitempty"` + Ms int64 `json:"ms"` } // record writes the call's audit row once its outcome is known and returns @@ -86,7 +90,8 @@ func auditRow(c *call, now time.Time) store.AuditEvent { who, via := store.ActorStrings(model.Actor{Person: c.caller.Principal.ID, Token: c.caller.Token.ID}) d := callDetail{ Tool: c.tool, Mode: string(c.mode), Outcome: c.outcome, Client: c.caller.Client, - Plan: c.plan, Policy: string(c.policy), Ms: now.Sub(c.started).Milliseconds(), + Plan: c.plan, Policy: string(c.decision.Effect), PolicyRules: c.decision.Rules, PolicyRevision: c.decision.Revision, + Ms: now.Sub(c.started).Milliseconds(), } if app := c.caller.Token.App; app != nil { d.Agent = app.Name diff --git a/internal/connectors/policy/opa/examples_test.go b/internal/connectors/policy/opa/examples_test.go new file mode 100644 index 00000000..a98e22b2 --- /dev/null +++ b/internal/connectors/policy/opa/examples_test.go @@ -0,0 +1,88 @@ +package opa_test + +import ( + "encoding/json" + "testing" + + "github.com/open-policy-agent/opa/v1/storage/inmem" + "github.com/open-policy-agent/opa/v1/tester" + + "github.com/nebari-dev/javo/internal/connectors/policy" + "github.com/nebari-dev/javo/internal/connectors/policy/opa" +) + +// examples are the example rules shipped with Tapas, with their tests. +const examples = "../../../../deploy/policy/examples" + +// The examples' own Rego tests pass, as `opa test deploy/policy/examples` +// would run them. +func TestTheExamplesRegoTestsPass(t *testing.T) { + t.Parallel() + modules, store, err := tester.Load([]string{examples}, nil) + if err != nil { + t.Fatal(err) + } + if store == nil { + store = inmem.New() + } + txn, err := store.NewTransaction(ctx) + if err != nil { + t.Fatal(err) + } + defer store.Abort(ctx, txn) + ch, err := tester.NewRunner().SetStore(store).SetModules(modules).RaiseBuiltinErrors(true).RunTests(ctx, txn) + if err != nil { + t.Fatal(err) + } + n := 0 + for r := range ch { + n++ + if r.Fail || r.Error != nil || r.Skip { + t.Errorf("%s.%s: fail=%v skip=%v err=%v", r.Package, r.Name, r.Fail, r.Skip, r.Error) + } + } + if n < 10 { + t.Fatalf("ran %d tests", n) + } +} + +// The examples load as Tapas loads rules, and decide calls as their +// descriptions say. +func TestTheExamplesDecideCalls(t *testing.T) { + t.Parallel() + e := opa.New(opa.Config{Dir: examples}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + in := func(groups []string, connector, tool string) policy.Input { + return policy.Input{ + Checkpoint: policy.CheckpointToolCall, Phase: policy.PhasePropose, + Who: policy.Who{Person: "alice@example.com", Groups: groups}, + Where: policy.Where{Connector: connector, Tool: tool, Mode: "write"}, + What: policy.What{Arguments: json.RawMessage(`{}`)}, + } + } + approved := func(i policy.Input, by string) policy.Input { + i.Phase, i.Approval = policy.PhaseApply, &policy.Approval{Plan: "p-1", By: by} + return i + } + for _, tc := range []struct { + name string + in policy.Input + want policy.Effect + }{ + {"greenhouse for sales", in([]string{"sales"}, "greenhouse", "list_candidates"), policy.Deny}, + {"greenhouse for recruiting", in([]string{"recruiting"}, "greenhouse", "list_candidates"), policy.Allow}, + {"an email send", in(nil, "gmail", "send_email"), policy.RequireApproval}, + {"an approved email send", approved(in(nil, "gmail", "send_email"), "alice@example.com"), policy.Allow}, + {"a Frames update", in(nil, "frames", "update_frame"), policy.RequireApproval}, + {"a Frames create approved by its owner", approved(in(nil, "frames", "create_frame"), "alice@example.com"), policy.Allow}, + {"a Frames update approved by another", approved(in(nil, "frames", "update_frame"), "bob@example.com"), policy.Deny}, + {"a Frames read", in(nil, "frames", "get_frame"), policy.Allow}, + {"anything else", in(nil, "slack", "post"), policy.Allow}, + } { + if d := check(t, e, tc.in); d.Effect != tc.want || (d.Effect != policy.Allow && d.Reason == "") { + t.Errorf("%s: %+v, want %s", tc.name, d, tc.want) + } + } +} diff --git a/internal/connectors/policy/opa/opa.go b/internal/connectors/policy/opa/opa.go new file mode 100644 index 00000000..37a6bd94 --- /dev/null +++ b/internal/connectors/policy/opa/opa.go @@ -0,0 +1,417 @@ +// Package opa checks connector calls against an organisation's rules, +// written in Rego and evaluated by Open Policy Agent embedded in the +// gateway. The rules are the .rego files of one directory (a ConfigMap +// mount in a cluster), read again when they change, so they can change +// without a release. +// +// The contract with the rules: +// +// - Rules live in packages tapas.rules. (from git) or +// tapas.admin. (kept for rules edited in Tapas later); shared +// helpers in tapas.lib or below it. Any other package is refused. +// - A rule set is the partial sets deny and require_approval of those +// packages. Each carries a METADATA title and description; each +// element is an object with a non-empty string title and description, +// usually rego.metadata.rule(). +// - Any deny denies, with the descriptions as the reason; else any +// require_approval asks for approval; else the call is allowed. +// +// It fails closed: no rules, rules that do not load, an evaluation error or +// timeout, or an answer of any other shape is an error, which the policy +// package turns into a deny. A reload that fails keeps the rules that last +// loaded. Each decision is made by one rule set and names its revision. +package opa + +import ( + "bytes" + "context" + "crypto/sha256" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "log/slog" + "os" + "path/filepath" + "slices" + "strings" + "sync" + "sync/atomic" + "time" + + "github.com/open-policy-agent/opa/v1/ast" + "github.com/open-policy-agent/opa/v1/rego" + "github.com/open-policy-agent/opa/v1/util" + + "github.com/nebari-dev/javo/internal/connectors/policy" +) + +// DefaultTimeout bounds one evaluation. +const DefaultTimeout = 2 * time.Second + +// Config sets up an Engine. +type Config struct { + // Dir holds the rules: its .rego files, not in subdirectories, except + // those ending in _test.rego. + Dir string + // Timeout bounds one evaluation; 0 is DefaultTimeout. + Timeout time.Duration +} + +// Engine is a policy.Checker over the rules in a directory. +type Engine struct { + dir string + timeout time.Duration + // reload serialises Reload; cur is read without it. + reload sync.Mutex + cur atomic.Pointer[ruleSet] +} + +// ruleSet is one loaded set of rules: decisions read it whole. +type ruleSet struct { + query rego.PreparedEvalQuery + revision string +} + +var _ policy.Checker = (*Engine)(nil) + +// New is an Engine with no rules loaded: it denies until Reload or Start +// loads some. +func New(c Config) *Engine { + if c.Timeout <= 0 { + c.Timeout = DefaultTimeout + } + return &Engine{dir: c.Dir, timeout: c.Timeout} +} + +// Revision is the loaded rule set's revision, "" when none is loaded. +func (e *Engine) Revision() string { + if rs := e.cur.Load(); rs != nil { + return rs.revision + } + return "" +} + +// Start loads the rules, then, until ctx ends, reads the directory again +// every interval and loads what changed. It returns once the first load +// is done; a failed load is logged, and the rules that last loaded stay +// (none at first, so every call is denied). +func (e *Engine) Start(ctx context.Context, every time.Duration) { + e.reloadLogged(ctx) + go func() { + t := time.NewTicker(every) + defer t.Stop() + for { + select { + case <-ctx.Done(): + return + case <-t.C: + e.reloadLogged(ctx) + } + } + }() +} + +func (e *Engine) reloadLogged(ctx context.Context) { + if err := e.load(ctx); err != nil && !errors.Is(err, errUnchanged) { + slog.Error("connector policy rules not loaded; the last rules that loaded stay", "dir", e.dir, "revision", e.Revision(), "err", err) + } +} + +// errUnchanged is a reload that found the rules as they were loaded. +var errUnchanged = errors.New("rules unchanged") + +// Reload reads the rules and, when they changed and load, puts them in +// place of the old ones. On an error the old ones stay. Rules unchanged +// since the last load answer nil. +func (e *Engine) Reload(ctx context.Context) error { + err := e.load(ctx) + if errors.Is(err, errUnchanged) { + return nil + } + return err +} + +func (e *Engine) load(ctx context.Context) error { + e.reload.Lock() + defer e.reload.Unlock() + files, err := readRules(e.dir) + if err != nil { + return err + } + rev := revision(files) + if cur := e.cur.Load(); cur != nil && cur.revision == rev { + return errUnchanged + } + q, err := compile(ctx, files) + if err != nil { + return err + } + e.cur.Store(&ruleSet{query: q, revision: rev}) + slog.Info("connector policy rules loaded", "dir", e.dir, "revision", rev, "files", len(files)) + return nil +} + +// ruleFile is one rule file's name and content. +type ruleFile struct { + name string + src []byte +} + +// readRules reads dir's rule files, sorted by name. A file that is +// missing, empty of rules, or unreadable is an error. +func readRules(dir string) ([]ruleFile, error) { + if dir == "" { + return nil, errors.New("no rules directory is configured") + } + entries, err := os.ReadDir(dir) + if err != nil { + return nil, fmt.Errorf("read the rules directory: %w", err) + } + var out []ruleFile + for _, ent := range entries { + name := ent.Name() + // A ConfigMap volume keeps its files in dot directories and links + // them at the top: the links are read, the dot entries not. + if strings.HasPrefix(name, ".") || !strings.HasSuffix(name, ".rego") || strings.HasSuffix(name, "_test.rego") { + continue + } + path := filepath.Join(dir, name) + if st, err := os.Stat(path); err == nil && !st.Mode().IsRegular() { + continue + } + src, err := os.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("read %s: %w", name, err) + } + out = append(out, ruleFile{name: name, src: src}) + } + if len(out) == 0 { + return nil, fmt.Errorf("no .rego files in %s", dir) + } + return out, nil +} + +// revision names a rule set by its files' names and contents. +func revision(files []ruleFile) string { + h := sha256.New() + for _, f := range files { + fmt.Fprintf(h, "%d:%s%d:", len(f.name), f.name, len(f.src)) + h.Write(f.src) + } + return hex.EncodeToString(h.Sum(nil))[:12] +} + +// Effects, as the rules name them. +const ( + ruleDeny = "deny" + ruleApproval = "require_approval" +) + +// query collects every deny and require_approval of the rules' packages +// whole, so a value of the wrong shape is seen, not skipped. +const query = `out := [[ns, pkg, name, value] | + some ns in ["rules", "admin"] + some name in ["deny", "require_approval"] + value := data.tapas[ns][pkg][name] +]` + +// capabilities are this OPA's built-in functions less those that reach +// outside the gateway: the network and the process's environment. +var capabilities = sync.OnceValue(func() *ast.Capabilities { + c := ast.CapabilitiesForThisVersion() + refused := map[string]bool{"http.send": true, "net.lookup_ip_addr": true, "opa.runtime": true} + c.Builtins = slices.DeleteFunc(slices.Clone(c.Builtins), func(b *ast.Builtin) bool { return refused[b.Name] }) + return c +}) + +// compile parses, checks and prepares files as one rule set. +func compile(ctx context.Context, files []ruleFile) (rego.PreparedEvalQuery, error) { + modules := map[string]*ast.Module{} + for _, f := range files { + m, err := ast.ParseModuleWithOpts(f.name, string(f.src), ast.ParserOptions{ProcessAnnotation: true, RegoVersion: ast.RegoV1}) + if err != nil { + return rego.PreparedEvalQuery{}, err + } + if err := checkModule(f.name, m); err != nil { + return rego.PreparedEvalQuery{}, err + } + modules[f.name] = m + } + c := ast.NewCompiler().WithCapabilities(capabilities()).WithStrict(true) + if c.Compile(modules); c.Failed() { + return rego.PreparedEvalQuery{}, c.Errors + } + return rego.New( + rego.Query(query), rego.Compiler(c), rego.StrictBuiltinErrors(true), rego.SetRegoVersion(ast.RegoV1), + ).PrepareForEval(ctx) +} + +// checkModule refuses a module outside the rules' packages, and a deny or +// require_approval rule that is not a partial set with a title and +// description or that sits where it would not be collected. +func checkModule(name string, m *ast.Module) error { + path := m.Package.Path + if len(path) < 3 || !path[1].Equal(ast.StringTerm("tapas")) { + return fmt.Errorf("%s: package %v is not under tapas.rules, tapas.admin or tapas.lib", name, m.Package.Path) + } + section := path[2].Value + collected := len(path) == 4 && (section.Compare(ast.String("rules")) == 0 || section.Compare(ast.String("admin")) == 0) + if !collected && section.Compare(ast.String("lib")) != 0 { + return fmt.Errorf("%s: package %v is not tapas.rules., tapas.admin. or under tapas.lib", name, m.Package.Path) + } + for _, r := range m.Rules { + rule := r.Head.Name.String() + if len(r.Head.Ref()) > 0 { + rule = r.Head.Ref()[0].Value.(ast.Var).String() + } + if rule != ruleDeny && rule != ruleApproval { + continue + } + at := fmt.Sprintf("%s:%d", name, r.Location.Row) + switch { + case !collected: + return fmt.Errorf("%s: %s is collected only in tapas.rules. or tapas.admin.", at, rule) + case len(r.Head.Ref()) != 1 || r.Head.RuleKind() != ast.MultiValue || r.Default: + return fmt.Errorf("%s: %s must be a partial set: %s contains ... if { ... }", at, rule, rule) + case !described(r): + return fmt.Errorf("%s: %s needs a METADATA title and description", at, rule) + } + } + return nil +} + +// described reports whether r carries a title and a description. +func described(r *ast.Rule) bool { + for _, a := range r.Annotations { + if a.Scope == "rule" && a.Title != "" && a.Description != "" { + return true + } + } + return false +} + +// Check decides in with the rules loaded now, in at most the timeout. +func (e *Engine) Check(ctx context.Context, in policy.Input) (policy.Decision, error) { + rs := e.cur.Load() + if rs == nil { + return policy.Decision{}, errors.New("no connector policy rules are loaded") + } + doc, err := inputValue(in) + if err != nil { + return policy.Decision{}, err + } + ctx, cancel := context.WithTimeout(ctx, e.timeout) + defer cancel() + rs2, err := rs.query.Eval(ctx, rego.EvalParsedInput(doc)) + if err != nil { + return policy.Decision{}, fmt.Errorf("evaluate the rules (revision %s): %w", rs.revision, err) + } + d, err := decide(rs2) + if err != nil { + return policy.Decision{}, fmt.Errorf("rules revision %s: %w", rs.revision, err) + } + d.Revision = rs.revision + return d, nil +} + +// inputValue is in as Rego reads it, numbers kept exact. +func inputValue(in policy.Input) (ast.Value, error) { + if in.Findings == nil { + in.Findings = []policy.Finding{} + } + if in.Who.Groups == nil { + in.Who.Groups = []string{} + } + if len(bytes.TrimSpace(in.What.Arguments)) == 0 { + in.What.Arguments = json.RawMessage(`{}`) + } + raw, err := json.Marshal(in) + if err != nil { + return nil, fmt.Errorf("encode the policy input: %w", err) + } + var doc any + if err := util.UnmarshalJSON(raw, &doc); err != nil { + return nil, fmt.Errorf("decode the policy input: %w", err) + } + return ast.InterfaceToValue(doc) +} + +// decide reads the query's one answer: deny beats require_approval, which +// beats allow. Any answer of another shape is an error. +func decide(rs rego.ResultSet) (policy.Decision, error) { + if len(rs) != 1 { + return policy.Decision{}, fmt.Errorf("%d answers, want 1", len(rs)) + } + out, ok := rs[0].Bindings["out"].([]any) + if !ok { + return policy.Decision{}, errors.New("no answer") + } + var deny, ask []rule + for _, row := range out { + r, _ := row.([]any) + if len(r) != 4 { + return policy.Decision{}, errors.New("an answer of the wrong shape") + } + ns, pkg, name := r[0], r[1], r[2] + rules, err := rulesOf(r[3]) + if err != nil { + return policy.Decision{}, fmt.Errorf("tapas.%v.%v.%v: %w", ns, pkg, name, err) + } + if name == ruleDeny { + deny = append(deny, rules...) + } else { + ask = append(ask, rules...) + } + } + byTitle := func(a, b rule) int { return strings.Compare(a.title, b.title) } + slices.SortFunc(deny, byTitle) + slices.SortFunc(ask, byTitle) + switch { + case len(deny) > 0: + return policy.Decision{Effect: policy.Deny, Reason: reasonOf(deny), Rules: titles(deny)}, nil + case len(ask) > 0: + return policy.Decision{Effect: policy.RequireApproval, Reason: reasonOf(ask), Rules: titles(ask)}, nil + } + return policy.Decision{Effect: policy.Allow}, nil +} + +// rule is one rule that fired. +type rule struct{ title, description string } + +// rulesOf reads a deny or require_approval set: objects with a non-empty +// string title and description. +func rulesOf(v any) ([]rule, error) { + elems, ok := v.([]any) + if !ok { + return nil, errors.New("not a set") + } + out := make([]rule, 0, len(elems)) + for _, el := range elems { + obj, _ := el.(map[string]any) + title, _ := obj["title"].(string) + desc, _ := obj["description"].(string) + if strings.TrimSpace(title) == "" || strings.TrimSpace(desc) == "" { + return nil, errors.New("an element without a title and description (use rego.metadata.rule())") + } + out = append(out, rule{title: title, description: desc}) + } + return out, nil +} + +// reasonOf is the rules' descriptions as one sentence, joined by "; ". +func reasonOf(rules []rule) string { + parts := make([]string, len(rules)) + for i, r := range rules { + parts[i] = strings.TrimRight(strings.TrimSpace(r.description), ".") + } + return strings.Join(parts, "; ") + "." +} + +func titles(rules []rule) []string { + out := make([]string, len(rules)) + for i, r := range rules { + out[i] = r.title + } + return out +} diff --git a/internal/connectors/policy/opa/opa_test.go b/internal/connectors/policy/opa/opa_test.go new file mode 100644 index 00000000..b24414fd --- /dev/null +++ b/internal/connectors/policy/opa/opa_test.go @@ -0,0 +1,471 @@ +package opa_test + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "strings" + "sync" + "testing" + "time" + + "github.com/nebari-dev/javo/internal/connectors/policy" + "github.com/nebari-dev/javo/internal/connectors/policy/opa" +) + +var ctx = context.Background() + +// recruitingOnly denies Greenhouse to anyone outside recruiting. +const recruitingOnly = `package tapas.rules.greenhouse + +# METADATA +# title: Only recruiting uses Greenhouse +# description: Greenhouse holds candidates' data, so only the recruiting group may use it. +deny contains rego.metadata.rule() if { + input.where.connector == "greenhouse" + not "recruiting" in input.who.groups +} +` + +// emailApproval holds every email send for approval until it is approved. +const emailApproval = `package tapas.rules.email + +# METADATA +# title: Email sends need approval +# description: An email leaves the company, so a person approves each send. +require_approval contains rego.metadata.rule() if { + input.where.connector == "gmail" + input.where.tool == "send_email" + not input.approval +} +` + +// write puts files (name to content) in a fresh directory. +func write(t *testing.T, files map[string]string) string { + t.Helper() + dir := t.TempDir() + put(t, dir, files) + return dir +} + +func put(t *testing.T, dir string, files map[string]string) { + t.Helper() + for name, src := range files { + if err := os.WriteFile(filepath.Join(dir, name), []byte(src), 0o600); err != nil { + t.Fatal(err) + } + } +} + +func input(person string, groups []string, connector, tool string) policy.Input { + return policy.Input{ + Checkpoint: policy.CheckpointToolCall, Phase: policy.PhaseRead, + Who: policy.Who{Person: person, Groups: groups}, + Where: policy.Where{Connector: connector, Tool: tool, Mode: "read"}, + What: policy.What{Arguments: json.RawMessage(`{}`)}, + } +} + +func check(t *testing.T, e *opa.Engine, in policy.Input) policy.Decision { + t.Helper() + d, err := e.Check(ctx, in) + if err != nil { + t.Fatalf("check: %v", err) + } + return d +} + +func loaded(t *testing.T, files map[string]string) *opa.Engine { + t.Helper() + e := opa.New(opa.Config{Dir: write(t, files)}) + if err := e.Reload(ctx); err != nil { + t.Fatalf("load: %v", err) + } + return e +} + +func TestADenyRuleDeniesWithItsDescription(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{"greenhouse.rego": recruitingOnly}) + d := check(t, e, input("alice", []string{"sales"}, "greenhouse", "list_candidates")) + if d.Effect != policy.Deny || d.Reason != "Greenhouse holds candidates' data, so only the recruiting group may use it." { + t.Fatalf("decision %+v", d) + } + if len(d.Rules) != 1 || d.Rules[0] != "Only recruiting uses Greenhouse" || d.Revision == "" || d.Revision != e.Revision() { + t.Fatalf("decision %+v, revision %q", d, e.Revision()) + } + if d := check(t, e, input("bob", []string{"recruiting"}, "greenhouse", "list_candidates")); d.Effect != policy.Allow || len(d.Rules) != 0 { + t.Fatalf("recruiting: %+v", d) + } +} + +func TestARuleCanRequireApprovalUntilTheCallIsApproved(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{"email.rego": emailApproval}) + in := input("alice", nil, "gmail", "send_email") + if d := check(t, e, in); d.Effect != policy.RequireApproval || d.Rules[0] != "Email sends need approval" { + t.Fatalf("decision %+v", d) + } + in.Phase, in.Approval = policy.PhaseApply, &policy.Approval{Plan: "p-1", By: "alice"} + if d := check(t, e, in); d.Effect != policy.Allow { + t.Fatalf("approved: %+v", d) + } +} + +// A deny beats a rule asking for approval, and every rule that denied is +// named. +func TestDenyWinsAndNamesEveryRule(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{"email.rego": emailApproval, "noemail.rego": `package tapas.rules.noemail + +# METADATA +# title: No email from agents +# description: Agents may not send email. +deny contains rego.metadata.rule() if input.where.connector == "gmail" + +# METADATA +# title: Not on this tool +# description: send_email is off. +deny contains rego.metadata.rule() if input.where.tool == "send_email" +`}) + d := check(t, e, input("alice", nil, "gmail", "send_email")) + if d.Effect != policy.Deny || d.Reason != "Agents may not send email; send_email is off." || + strings.Join(d.Rules, ",") != "No email from agents,Not on this tool" { + t.Fatalf("decision %+v", d) + } +} + +// Rules see every part of the input document, arguments with their numbers +// exact. +func TestRulesSeeTheWholeInput(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{"all.rego": `package tapas.rules.all + +# METADATA +# title: Exact +# description: Everything matched. +deny contains rego.metadata.rule() if { + input.checkpoint == "tool_call" + input.phase == "propose" + input.who.person == "alice" + input.who.groups == ["recruiting"] + input.agent == {"name": "helper", "app": "helper-1", "token": "t-1", "client": "claude-code", "scheduled": false} + input.where == {"connector": "slack", "tool": "post", "mode": "write"} + input.what.arguments.big == 12345678901234567890 + input.what.arguments.text == "hi" + input.findings == [] + not input.approval +} +`}) + in := policy.Input{ + Checkpoint: policy.CheckpointToolCall, Phase: policy.PhasePropose, + Who: policy.Who{Person: "alice", Groups: []string{"recruiting"}}, + Agent: policy.Agent{Name: "helper", App: "helper-1", Token: "t-1", Client: "claude-code"}, + Where: policy.Where{Connector: "slack", Tool: "post", Mode: "write"}, + What: policy.What{Arguments: json.RawMessage(`{"big":12345678901234567890,"text":"hi"}`)}, + } + if d := check(t, e, in); d.Effect != policy.Deny { + t.Fatalf("decision %+v", d) + } +} + +// Rules under tapas.admin count as well, and a shared library is usable. +func TestAdminRulesAndALibraryCount(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{ + "lib.rego": "package tapas.lib.groups\n\nmember(g) if g in input.who.groups\n", + "admin.rego": `package tapas.admin.ui + +import data.tapas.lib.groups + +# METADATA +# title: Contractors stay out of Slack +# description: Contractors may not use Slack. +deny contains rego.metadata.rule() if { + input.where.connector == "slack" + groups.member("contractors") +} +`}) + if d := check(t, e, input("alice", []string{"contractors"}, "slack", "post")); d.Effect != policy.Deny { + t.Fatalf("decision %+v", d) + } +} + +// failsClosed asserts e refuses to decide: an error, never an allow. +func failsClosed(t *testing.T, e *opa.Engine, in policy.Input) { + t.Helper() + d, err := e.Check(ctx, in) + if err == nil { + t.Fatalf("decided %+v", d) + } + if p := policy.Evaluate(ctx, e, in); p.Effect != policy.Deny || p.Reason == "" { + t.Fatalf("evaluated %+v", p) + } +} + +func TestNoRulesDeniesEverything(t *testing.T) { + t.Parallel() + for name, dir := range map[string]string{ + "missing directory": filepath.Join(t.TempDir(), "nope"), + "empty directory": t.TempDir(), + "only tests": write(t, map[string]string{"x_test.rego": "package tapas.rules.x_test\n"}), + "not set": "", + } { + t.Run(name, func(t *testing.T) { + e := opa.New(opa.Config{Dir: dir}) + if err := e.Reload(ctx); err == nil { + t.Fatal("loaded nothing without an error") + } + failsClosed(t, e, input("alice", nil, "slack", "post")) + }) + } +} + +// Each of these rule sets is refused when loaded, so nothing is decided by +// it. +func TestRulesThatCannotBeLoaded(t *testing.T) { + t.Parallel() + meta := "# METADATA\n# title: T\n# description: D.\n" + for name, src := range map[string]string{ + "syntax error": "package tapas.rules.x\n\ndeny contains if {", + "outside tapas": "package other\n\nx := 1\n", + "nested rules package": "package tapas.rules.a.b\n\n" + meta + "deny contains rego.metadata.rule() if true\n", + "tapas root": "package tapas\n\nx := 1\n", + "deny in the library": "package tapas.lib\n\n" + meta + "deny contains rego.metadata.rule() if true\n", + "deny as a boolean": "package tapas.rules.x\n\n" + meta + "deny if true\n", + "deny as a value": "package tapas.rules.x\n\n" + meta + "deny := {rego.metadata.rule()}\n", + "deny without a title": "package tapas.rules.x\n\n# METADATA\n# description: D.\ndeny contains rego.metadata.rule() if true\n", + "approval without detail": "package tapas.rules.x\n\n# METADATA\n# title: T\nrequire_approval contains rego.metadata.rule() if true\n", + "http.send": "package tapas.rules.x\n\nx := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", + "net.lookup_ip_addr": "package tapas.rules.x\n\nx := net.lookup_ip_addr(\"example.com\")\n", + "opa.runtime": "package tapas.rules.x\n\nx := opa.runtime()\n", + "unknown function": "package tapas.rules.x\n\nx := nope(1)\n", + } { + t.Run(name, func(t *testing.T) { + e := opa.New(opa.Config{Dir: write(t, map[string]string{"x.rego": src})}) + if err := e.Reload(ctx); err == nil { + t.Fatal("loaded") + } + failsClosed(t, e, input("alice", nil, "slack", "post")) + }) + } +} + +// An answer Tapas cannot read is not a decision. +func TestMalformedAnswersDeny(t *testing.T) { + t.Parallel() + for name, body := range map[string]string{ + "a string": `deny contains "no" if true`, + "no description": `deny contains {"title": "T"} if true`, + "empty title": `deny contains {"title": "", "description": "D."} if true`, + "a number as title": `deny contains {"title": 1, "description": "D."} if true`, + "approval as string": `require_approval contains "please" if true`, + } { + t.Run(name, func(t *testing.T) { + src := "package tapas.rules.x\n\n# METADATA\n# title: T\n# description: D.\n" + body + "\n" + failsClosed(t, loaded(t, map[string]string{"x.rego": src}), input("alice", nil, "slack", "post")) + }) + } +} + +// A rule whose evaluation fails, at run time, denies. +func TestAnEvaluationErrorDenies(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{"x.rego": `package tapas.rules.x + +# METADATA +# title: T +# description: D. +deny contains rego.metadata.rule() if to_number(input.what.arguments.n) > 1 +`}) + in := input("alice", nil, "slack", "post") + in.What.Arguments = json.RawMessage(`{"n":"not a number"}`) + failsClosed(t, e, in) + in.What.Arguments = json.RawMessage(`{"n":"0"}`) + if d := check(t, e, in); d.Effect != policy.Allow { + t.Fatalf("decision %+v", d) + } +} + +func TestASlowEvaluationTimesOutAndDenies(t *testing.T) { + t.Parallel() + e := opa.New(opa.Config{Timeout: 20 * time.Millisecond, Dir: write(t, map[string]string{"slow.rego": `package tapas.rules.slow + +# METADATA +# title: T +# description: D. +deny contains rego.metadata.rule() if { + count([1 | some i in numbers.range(1, 4000); some j in numbers.range(1, 4000)]) < 0 +} +`})}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + start := time.Now() + failsClosed(t, e, input("alice", nil, "slack", "post")) + if _, err := e.Check(ctx, input("alice", nil, "slack", "post")); !strings.Contains(err.Error(), "cancel") { + t.Fatalf("not a timeout: %v", err) + } + if took := time.Since(start); took > 5*time.Second { + t.Fatalf("took %v", took) + } +} + +// A reload that fails keeps the rules that last loaded; a good one replaces +// them; files that did not change are not loaded again. +func TestAFailedReloadKeepsTheLastGoodRules(t *testing.T) { + t.Parallel() + dir := write(t, map[string]string{"greenhouse.rego": recruitingOnly}) + e := opa.New(opa.Config{Dir: dir}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + good := e.Revision() + in := input("alice", []string{"sales"}, "greenhouse", "list_candidates") + + put(t, dir, map[string]string{"greenhouse.rego": "package tapas.rules.greenhouse\n\ndeny contains if {"}) + if err := e.Reload(ctx); err == nil { + t.Fatal("a broken file loaded") + } + if d := check(t, e, in); d.Effect != policy.Deny || d.Revision != good || e.Revision() != good { + t.Fatalf("after a broken reload %+v", d) + } + + if err := os.Remove(filepath.Join(dir, "greenhouse.rego")); err != nil { + t.Fatal(err) + } + if err := e.Reload(ctx); err == nil { + t.Fatal("an empty directory loaded") + } + if d := check(t, e, in); d.Effect != policy.Deny || d.Revision != good { + t.Fatalf("after emptying %+v", d) + } + + put(t, dir, map[string]string{"email.rego": emailApproval}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + if d := check(t, e, in); d.Effect != policy.Allow || d.Revision == good || d.Revision != e.Revision() { + t.Fatalf("after a good reload %+v", d) + } + again := e.Revision() + if err := e.Reload(ctx); err != nil || e.Revision() != again { + t.Fatalf("unchanged reload: %v, %q", err, e.Revision()) + } +} + +// A Kubernetes ConfigMap volume holds its files twice, under a timestamped +// directory and through ..data, with the names linked at the top. Each rule +// is loaded once, and test files are skipped. +func TestAConfigMapMountLoadsEachRuleOnce(t *testing.T) { + t.Parallel() + dir := t.TempDir() + ts := filepath.Join(dir, "..2026_12_01_10_00_00.000000001") + if err := os.Mkdir(ts, 0o700); err != nil { + t.Fatal(err) + } + put(t, ts, map[string]string{"greenhouse.rego": recruitingOnly, "greenhouse_test.rego": "package tapas.rules.greenhouse_test\n\nbroken {"}) + if err := os.Symlink(filepath.Base(ts), filepath.Join(dir, "..data")); err != nil { + t.Fatal(err) + } + for _, f := range []string{"greenhouse.rego", "greenhouse_test.rego"} { + if err := os.Symlink(filepath.Join("..data", f), filepath.Join(dir, f)); err != nil { + t.Fatal(err) + } + } + e := opa.New(opa.Config{Dir: dir}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + if d := check(t, e, input("alice", nil, "greenhouse", "x")); d.Effect != policy.Deny || len(d.Rules) != 1 { + t.Fatalf("decision %+v", d) + } +} + +// Start loads the rules before it returns, then picks up a change to the +// directory without a restart. +func TestStartLoadsThenReloadsAChangedDirectory(t *testing.T) { + t.Parallel() + dir := write(t, map[string]string{"email.rego": emailApproval}) + e := opa.New(opa.Config{Dir: dir}) + wctx, cancel := context.WithCancel(ctx) + defer cancel() + e.Start(wctx, 5*time.Millisecond) + in := input("alice", []string{"sales"}, "greenhouse", "x") + if d := check(t, e, in); d.Effect != policy.Allow { + t.Fatalf("after start %+v", d) + } + put(t, dir, map[string]string{"greenhouse.rego": recruitingOnly}) + waitFor(t, func() bool { d, err := e.Check(ctx, in); return err == nil && d.Effect == policy.Deny }) +} + +func waitFor(t *testing.T, ok func() bool) { + t.Helper() + deadline := time.Now().Add(10 * time.Second) + for !ok() { + if time.Now().After(deadline) { + t.Fatal("timed out") + } + time.Sleep(2 * time.Millisecond) + } +} + +// Decisions made while the rules are reloaded each come from one whole rule +// set: the revision a decision names is the one whose rules made it. +func TestDecisionsDuringAReloadUseOneRuleSet(t *testing.T) { + t.Parallel() + a := map[string]string{"r.rego": strings.Replace(recruitingOnly, "Only recruiting uses Greenhouse", "A", 1)} + b := map[string]string{"r.rego": `package tapas.rules.greenhouse + +# METADATA +# title: B +# description: Held. +require_approval contains rego.metadata.rule() if input.where.connector == "greenhouse" +`} + dir := write(t, a) + e := opa.New(opa.Config{Dir: dir}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + revA := e.Revision() + put(t, dir, b) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + revB := e.Revision() + in := input("alice", nil, "greenhouse", "x") + + stop := make(chan struct{}) + var wg sync.WaitGroup + wg.Go(func() { + for i := 0; ; i++ { + select { + case <-stop: + return + default: + } + put(t, dir, map[bool]map[string]string{true: a, false: b}[i%2 == 0]) + _ = e.Reload(ctx) + } + }) + var checkers sync.WaitGroup + for range 8 { + checkers.Go(func() { + for range 200 { + d, err := e.Check(ctx, in) + switch { + case err != nil: + t.Errorf("check: %v", err) + case d.Revision == revA && d.Effect == policy.Deny && len(d.Rules) == 1 && d.Rules[0] == "A": + case d.Revision == revB && d.Effect == policy.RequireApproval && len(d.Rules) == 1 && d.Rules[0] == "B": + default: + t.Errorf("mixed decision %+v", d) + } + } + }) + } + checkers.Wait() + close(stop) + wg.Wait() +} diff --git a/internal/connectors/policy/policy.go b/internal/connectors/policy/policy.go index b1ce9681..c52d9e91 100644 --- a/internal/connectors/policy/policy.go +++ b/internal/connectors/policy/policy.go @@ -26,24 +26,78 @@ const ( RequireApproval Effect = "require_approval" ) -// Input is one tool call as the checker sees it. Identity comes from the -// verified Tapas token, never from the call's arguments. +// CheckpointToolCall is the checkpoint of a connector tool call. +const CheckpointToolCall = "tool_call" + +// Input is the document the rules see for one check, the same shape at +// every checkpoint (who, which agent, where, what, findings). Identity comes +// from the verified Tapas token, never from the call's arguments; the rules +// read it as JSON, by the tags below. type Input struct { - Phase Phase - Person string - Groups []string - Agent string - TokenID string - Connector string - Tool string - Write bool - Arguments json.RawMessage + Checkpoint string `json:"checkpoint"` + Phase Phase `json:"phase"` + Who Who `json:"who"` + Agent Agent `json:"agent"` + Where Where `json:"where"` + What What `json:"what"` + // Findings are what detectors spotted in What. No detector runs yet, so + // it is always empty; rules may already match on it. + Findings []Finding `json:"findings"` + // Approval is the approved plan being applied: set in PhaseApply only. + Approval *Approval `json:"approval,omitempty"` +} + +// Who is the person an agent acts for, and their groups. +type Who struct { + Person string `json:"person"` + Groups []string `json:"groups"` +} + +// Agent is what made the call: the coding agent app (empty for a personal +// token), the token, and what the MCP client calls itself (display only, +// the client chooses it). Scheduled is true for a job's token. +type Agent struct { + Name string `json:"name"` + App string `json:"app"` + Token string `json:"token"` + Client string `json:"client"` + Scheduled bool `json:"scheduled"` +} + +// Where is the connector, its tool, and the tool's mode ("read" or "write") +// as the admin set it. +type Where struct { + Connector string `json:"connector"` + Tool string `json:"tool"` + Mode string `json:"mode"` +} + +// What is the content of the call: its arguments, a JSON object. +type What struct { + Arguments json.RawMessage `json:"arguments"` +} + +// Finding is one thing a detector spotted: which detector, and where in +// the input (a JSON path). +type Finding struct { + Detector string `json:"detector"` + Path string `json:"path"` +} + +// Approval is the plan whose apply is being checked, and who approved it. +type Approval struct { + Plan string `json:"plan"` + By string `json:"by"` } -// Decision is a checker's answer. Reason is shown to the agent on a deny. +// Decision is a checker's answer. Reason is shown to the person on a deny. +// Rules are the titles of the rules that decided it, and Revision the rule +// set's, for the audit log. type Decision struct { - Effect Effect - Reason string + Effect Effect + Reason string + Rules []string + Revision string } // Checker decides whether a tool call may go ahead. @@ -51,13 +105,6 @@ type Checker interface { Check(ctx context.Context, in Input) (Decision, error) } -// AllowAll allows every call: the default when no policy is configured. -type AllowAll struct{} - -func (AllowAll) Check(context.Context, Input) (Decision, error) { - return Decision{Effect: Allow}, nil -} - // Evaluate asks c about in and fails closed: a nil checker, an error or an // unknown effect denies. A deny always carries a reason. The error's text is // not passed on, as it may hold what the checker saw. diff --git a/internal/connectors/policy/policy_test.go b/internal/connectors/policy/policy_test.go index 61ac8023..e0c62c9c 100644 --- a/internal/connectors/policy/policy_test.go +++ b/internal/connectors/policy/policy_test.go @@ -26,7 +26,6 @@ func TestEvaluate(t *testing.T) { reason string // empty: any non-empty reason }{ {"allow passes", fixed{d: policy.Decision{Effect: policy.Allow}}, policy.Allow, "-"}, - {"allow everything", policy.AllowAll{}, policy.Allow, "-"}, {"approval passes through", fixed{d: policy.Decision{Effect: policy.RequireApproval, Reason: "writes need a look"}}, policy.RequireApproval, "writes need a look"}, {"deny keeps its reason", fixed{d: policy.Decision{Effect: policy.Deny, Reason: "not on weekends"}}, policy.Deny, "not on weekends"}, {"deny without a reason gets one", fixed{d: policy.Decision{Effect: policy.Deny}}, policy.Deny, ""}, @@ -36,7 +35,7 @@ func TestEvaluate(t *testing.T) { {"nil checker denies", nil, policy.Deny, ""}, } { t.Run(tc.name, func(t *testing.T) { - d := policy.Evaluate(context.Background(), tc.c, policy.Input{Phase: policy.PhaseRead, Connector: "slack", Tool: "post_message"}) + d := policy.Evaluate(context.Background(), tc.c, policy.Input{Phase: policy.PhaseRead, Where: policy.Where{Connector: "slack", Tool: "post_message"}}) if d.Effect != tc.effect { t.Fatalf("effect %q, want %q", d.Effect, tc.effect) } diff --git a/internal/gateway/apitest/fixture.go b/internal/gateway/apitest/fixture.go index e5223969..2b45d4e9 100644 --- a/internal/gateway/apitest/fixture.go +++ b/internal/gateway/apitest/fixture.go @@ -13,6 +13,8 @@ import ( "net/http" "net/http/httptest" "net/netip" + "os" + "path/filepath" "strings" "sync" "testing" @@ -40,6 +42,8 @@ import ( "github.com/nebari-dev/javo/internal/config" "github.com/nebari-dev/javo/internal/connectors" "github.com/nebari-dev/javo/internal/connectors/oauth" + connpolicy "github.com/nebari-dev/javo/internal/connectors/policy" + "github.com/nebari-dev/javo/internal/connectors/policy/opa" connreg "github.com/nebari-dev/javo/internal/connectors/registry" "github.com/nebari-dev/javo/internal/connectors/vault" "github.com/nebari-dev/javo/internal/core/registry" @@ -89,6 +93,9 @@ type Fixture struct { Connectors *connreg.Registry // Vault is the connected accounts, with Options.Connectors. Vault *vault.Vault + // ConnectorPolicy decides connector calls by the rules in + // Options.ConnectorRules, with Options.Connectors. + ConnectorPolicy *opa.Engine // Revalidator is the gateway's, for a proxy mounted on it. Revalidator *authn.Revalidator secure bool @@ -180,6 +187,9 @@ type Options struct { ConnectorInternalHosts []string ConnectorTokens connectors.TokenSource ConnectorHTTP *http.Client + // ConnectorRules is the directory of the rules connector calls are + // checked against, loaded once; "" is rules that deny nothing. + ConnectorRules string // AgentModel serves the coding agents' model endpoint. AgentModel *agentproxy.Proxy // Agent is the admin's agent model and template. @@ -309,6 +319,8 @@ func New(t *testing.T, o Options, objs ...any) *Fixture { var conns *connreg.Registry var vlt *vault.Vault var signIn *oauth.Service + var connPolicy *opa.Engine + var checker connpolicy.Checker // nil, not a nil *opa.Engine, while off if o.Connectors { key, err := secrets.NewKey() if err != nil { @@ -331,6 +343,15 @@ func New(t *testing.T, o Options, objs ...any) *Fixture { if o.ConnectorTokens == nil { o.ConnectorTokens = vlt } + if o.ConnectorRules == "" { + o.ConnectorRules = t.TempDir() + if err := os.WriteFile(filepath.Join(o.ConnectorRules, "none.rego"), []byte("package tapas.rules.none\n"), 0o600); err != nil { + t.Fatal(err) + } + } + connPolicy = opa.New(opa.Config{Dir: o.ConnectorRules}) + _ = connPolicy.Reload(context.Background()) // rules that do not load deny: some tests mean that + checker = connPolicy } rv := authn.NewRevalidator(providers, sessions, people, 0, o.Now) var exp exposure.Backend = exposurepath.New(o.Urls) @@ -362,9 +383,9 @@ func New(t *testing.T, o Options, objs ...any) *Fixture { NetworkPolicy: policy, Engines: o.Engines, ContainerImages: o.Images, Ready: o.Ready, PreviewsEnabled: o.Previews, Thumbnails: o.Thumbnails, PreviewsMaxPerApp: o.PreviewsMax, CodeHosts: o.CodeHosts, Backups: o.Backups, Environments: o.Environments, PublicHost: o.PublicHost, PixiImage: o.PixiImage, LockAgents: o.LockAgents, TrustedAgents: !o.NoTrustedAgents, DeviceLoginOff: o.NoDeviceLogin, Connectors: conns, - ConnectorTokens: o.ConnectorTokens, ConnectorHTTP: o.ConnectorHTTP, ConnectorVault: vlt, ConnectorSignIn: signInOf(signIn), + ConnectorTokens: o.ConnectorTokens, ConnectorPolicy: checker, ConnectorHTTP: o.ConnectorHTTP, ConnectorVault: vlt, ConnectorSignIn: signInOf(signIn), }) - return &Fixture{AI: live, Connectors: conns, Vault: vlt, T: t, Client: c, Db: db, People: people, Store: sessions, Tokens: tokens, Srv: srv, Revalidator: rv, secure: o.Urls.SecureCookies(o.Secure)} + return &Fixture{AI: live, Connectors: conns, Vault: vlt, ConnectorPolicy: connPolicy, T: t, Client: c, Db: db, People: people, Store: sessions, Tokens: tokens, Srv: srv, Revalidator: rv, secure: o.Urls.SecureCookies(o.Secure)} } // signInOf keeps a nil sign-in a nil interface. diff --git a/internal/gateway/connectors_policy_test.go b/internal/gateway/connectors_policy_test.go new file mode 100644 index 00000000..9e6cbafc --- /dev/null +++ b/internal/gateway/connectors_policy_test.go @@ -0,0 +1,170 @@ +//go:build !local + +package gateway_test + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/nebari-dev/javo/internal/connectors" + "github.com/nebari-dev/javo/internal/connectors/connectorstest" + "github.com/nebari-dev/javo/internal/connectors/registry" + "github.com/nebari-dev/javo/internal/gateway/apitest" + "github.com/nebari-dev/javo/internal/model" + "github.com/nebari-dev/javo/internal/plans" +) + +// fakeRules deny echoing a secret and hold echoing "hold" for approval. +const fakeRules = `package tapas.rules.fake + +# METADATA +# title: No secrets +# description: Text marked secret stays inside the company. +deny contains rego.metadata.rule() if input.what.arguments.text == "secret" + +# METADATA +# title: Holds are approved +# description: A held echo needs its owner's approval. +require_approval contains rego.metadata.rule() if { + input.where.tool == "echo" + input.what.arguments.text == "hold" + not input.approval +} +` + +// newPolicyFixture is a gateway with the fake connector for everyone and +// the rules files in a directory of their own, loaded once. +func newPolicyFixture(t *testing.T, files map[string]string) (*mcpFixture, *connectorstest.Connector, string) { + t.Helper() + dir := t.TempDir() + for name, src := range files { + if err := os.WriteFile(filepath.Join(dir, name), []byte(src), 0o600); err != nil { + t.Fatal(err) + } + } + fake := connectorstest.NewConnector(t, "tok-fake") + af := apitest.New(t, apitest.Options{ + Mcp: true, Connectors: true, ConnectorInternalHosts: []string{"127.0.0.1"}, ConnectorRules: dir, + ConnectorTokens: connectorstest.StaticToken("tok-fake"), ConnectorHTTP: &http.Client{}, PublicURL: "https://tapas.example.org", + }) + s := httptest.NewServer(af.Srv) + t.Cleanup(s.Close) + f := &mcpFixture{Fixture: af, url: s.URL, alice: af.LoginAlice()} + if _, err := f.Connectors.Create(context.Background(), model.Actor{Person: "admin"}, registry.Input{ + Slug: "fake", Name: "Fake", URL: fake.URL, Enabled: true, + AllowedGroups: []string{"*"}, ToolModes: map[string]connectors.ToolMode{"echo": connectors.ToolRead}, + }); err != nil { + t.Fatal(err) + } + return f, fake, dir +} + +// lastCall is the newest connector.call row's detail. +func lastCall(t *testing.T, f *mcpFixture) map[string]any { + t.Helper() + all, err := f.Db.Audit().List(context.Background(), 1000) + if err != nil { + t.Fatal(err) + } + for _, r := range all { + if r.Action == "connector.call" { + var d map[string]any + if err := json.Unmarshal(r.Detail, &d); err != nil { + t.Fatal(err) + } + return d + } + } + t.Fatal("no connector.call row") + return nil +} + +// Through /mcp: a call the rules allow is made, one they deny never +// reaches the connector and the agent is told why, and one they hold +// becomes a plan that is made once its owner approves it. Each decision is +// in the audit log with the rules and their revision. +func TestRulesDecideConnectorCallsThroughMCP(t *testing.T) { + t.Parallel() + f, fake, _ := newPolicyFixture(t, map[string]string{"fake.rego": fakeRules}) + rev := f.ConnectorPolicy.Revision() + cs := f.connect(t, f.NewToken(f.alice, `{"name":"agent","scope":"propose"}`).Token) + + res, text := callTool(t, cs, "fake__echo", map[string]any{"text": "hi"}) + if res.IsError || text != `{"text":"hi"}` { + t.Fatalf("allowed: %v %q", res.IsError, text) + } + if d := lastCall(t, f); d["outcome"] != "ok" || d["policy"] != "allow" || d["policyRevision"] != rev { + t.Fatalf("allowed row %v", d) + } + + res, text = callTool(t, cs, "fake__echo", map[string]any{"text": "secret"}) + if !res.IsError || text != "Not allowed by the platform's policy: Text marked secret stays inside the company." { + t.Fatalf("denied: %v %q", res.IsError, text) + } + if n := len(fake.Calls()); n != 1 { + t.Fatalf("a denied call reached the connector: %d calls", n) + } + if d := lastCall(t, f); d["outcome"] != "denied_policy" || d["policy"] != "deny" || d["policyRevision"] != rev || + !jsonEqual(d["policyRules"], []string{"No secrets"}) { + t.Fatalf("denied row %v", d) + } + + res, text = callTool(t, cs, "fake__echo", map[string]any{"text": "hold"}) + var held struct{ PlanID, State string } + if res.IsError || json.Unmarshal([]byte(text), &held) != nil || held.State != "awaiting_approval" { + t.Fatalf("held: %v %q", res.IsError, text) + } + if n := len(fake.Calls()); n != 1 { + t.Fatalf("a held call reached the connector: %d calls", n) + } + if d := lastCall(t, f); d["outcome"] != "proposed" || d["policy"] != "require_approval" || !jsonEqual(d["policyRules"], []string{"Holds are approved"}) { + t.Fatalf("held row %v", d) + } + w := f.Do("POST", "/api/plans/"+held.PlanID+"/approve", "", f.alice) + if w.Code != http.StatusOK || apitest.Decode[apitest.PlanJSON](t, w).State != plans.Applied { + t.Fatalf("approve: %d %s", w.Code, w.Body) + } + calls := fake.Calls() + if len(calls) != 2 || calls[1].Tool != "echo" || string(calls[1].Arguments) != `{"text":"hold"}` { + t.Fatalf("calls %+v", calls) + } + if d := lastCall(t, f); d["outcome"] != "ok" || d["policy"] != "allow" || d["plan"] != plans.StoredID(held.PlanID) { + t.Fatalf("applied row %v", d) + } +} + +// Rules that do not load deny every call, with a reason; a broken change +// to good rules keeps them. +func TestBrokenRulesFailClosed(t *testing.T) { + t.Parallel() + f, fake, _ := newPolicyFixture(t, map[string]string{"fake.rego": "package tapas.rules.fake\n\ndeny contains if {"}) + cs := f.connect(t, f.NewToken(f.alice, `{"name":"agent","scope":"propose"}`).Token) + res, text := callTool(t, cs, "fake__echo", map[string]any{"text": "hi"}) + if !res.IsError || !strings.Contains(text, "policy") || len(fake.Calls()) != 0 { + t.Fatalf("broken rules: %v %q, calls %v", res.IsError, text, fake.Calls()) + } + if d := lastCall(t, f); d["outcome"] != "denied_policy" || d["policy"] != "deny" { + t.Fatalf("row %v", d) + } + + g, gfake, dir := newPolicyFixture(t, map[string]string{"fake.rego": fakeRules}) + if err := os.WriteFile(filepath.Join(dir, "fake.rego"), []byte("package tapas.rules.fake\n\nbroken {"), 0o600); err != nil { + t.Fatal(err) + } + if err := g.ConnectorPolicy.Reload(context.Background()); err == nil { + t.Fatal("broken rules loaded") + } + gcs := g.connect(t, g.NewToken(g.alice, `{"name":"agent","scope":"propose"}`).Token) + if res, text := callTool(t, gcs, "fake__echo", map[string]any{"text": "secret"}); !res.IsError || !strings.Contains(text, "stays inside") { + t.Fatalf("after a broken reload: %v %q", res.IsError, text) + } + if res, _ := callTool(t, gcs, "fake__echo", map[string]any{"text": "hi"}); res.IsError || len(gfake.Calls()) != 1 { + t.Fatalf("after a broken reload an allowed call failed: calls %v", gfake.Calls()) + } +} diff --git a/internal/gateway/mcp.go b/internal/gateway/mcp.go index 44c9457d..758f6018 100644 --- a/internal/gateway/mcp.go +++ b/internal/gateway/mcp.go @@ -82,7 +82,7 @@ func newConnectorBroker(cfg Config) connectorBroker { return nil } return broker.New(broker.Config{ - Connectors: cfg.Connectors, Forwarder: &client.Client{HTTP: connectorHTTP(cfg)}, Tokens: cfg.ConnectorTokens, Audit: cfg.Store.Audit(), + Connectors: cfg.Connectors, Forwarder: &client.Client{HTTP: connectorHTTP(cfg)}, Tokens: cfg.ConnectorTokens, Audit: cfg.Store.Audit(), Policy: cfg.ConnectorPolicy, PublicURL: cfg.MCP.PublicURL, Now: cfg.Now, }) } diff --git a/internal/gateway/server.go b/internal/gateway/server.go index 5d827bad..d38b9610 100644 --- a/internal/gateway/server.go +++ b/internal/gateway/server.go @@ -25,6 +25,7 @@ import ( "github.com/nebari-dev/javo/internal/capacity" "github.com/nebari-dev/javo/internal/config" "github.com/nebari-dev/javo/internal/connectors" + "github.com/nebari-dev/javo/internal/connectors/policy" connreg "github.com/nebari-dev/javo/internal/connectors/registry" "github.com/nebari-dev/javo/internal/connectors/vault" ctrljobs "github.com/nebari-dev/javo/internal/controller/jobs" @@ -208,6 +209,9 @@ type Config struct { // ConnectorTokens gives connector calls their bearer; nil means nobody // is connected, so no connector tool is offered. ConnectorTokens connectors.TokenSource + // ConnectorPolicy is the rules every connector call is checked against; + // nil denies every connector call. + ConnectorPolicy policy.Checker // ConnectorVault is the connected accounts (the same vault as // ConnectorTokens in production); nil while connectors are off. ConnectorVault *vault.Vault From ba78d1dbdbb515c7c847bd6cec9efd32a15e3597 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:23:07 +0000 Subject: [PATCH 02/13] fix(connectors): keep the client's own name out of the policy input What an MCP client calls itself is chosen by the client, and is empty when a call is planned through the plans API, so a rule resting on it could be fooled or miss. The startup log now says every connector call is denied when no rules have loaded yet, instead of naming last rules that never existed. --- deploy/policy/examples/frames_test.rego | 2 +- internal/connectors/broker/action_test.go | 2 +- internal/connectors/broker/broker_test.go | 2 +- internal/connectors/broker/checkpolicy.go | 2 +- internal/connectors/policy/opa/opa.go | 7 ++++++- internal/connectors/policy/opa/opa_test.go | 4 ++-- internal/connectors/policy/policy.go | 8 ++++---- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/deploy/policy/examples/frames_test.rego b/deploy/policy/examples/frames_test.rego index a1797b61..a1268396 100644 --- a/deploy/policy/examples/frames_test.rego +++ b/deploy/policy/examples/frames_test.rego @@ -6,7 +6,7 @@ update := { "checkpoint": "tool_call", "phase": "propose", "who": {"person": "alice@example.com", "groups": []}, - "agent": {"name": "helper", "app": "helper-1", "token": "t-1", "client": "pi", "scheduled": false}, + "agent": {"name": "helper", "app": "helper-1", "token": "t-1", "scheduled": false}, "where": {"connector": "frames", "tool": "update_frame", "mode": "write"}, "what": {"arguments": {"id": "f-1", "body": "Use the Oxford comma."}}, "findings": [], diff --git a/internal/connectors/broker/action_test.go b/internal/connectors/broker/action_test.go index 037dde36..e9417662 100644 --- a/internal/connectors/broker/action_test.go +++ b/internal/connectors/broker/action_test.go @@ -178,7 +178,7 @@ func TestApplyingTellsThePolicyWhoProposedAndThatItIsApproved(t *testing.T) { t.Fatalf("asked %d times: %+v", len(r.seen), r.seen) } planned, applied := r.seen[0], r.seen[1] - wantAgent := policy.Agent{Name: "helper", App: "helper-1", Token: "t-1", Client: "claude-code"} + wantAgent := policy.Agent{Name: "helper", App: "helper-1", Token: "t-1"} if planned.Phase != policy.PhasePropose || planned.Agent != wantAgent || planned.Approval != nil { t.Fatalf("planning saw %+v", planned) } diff --git a/internal/connectors/broker/broker_test.go b/internal/connectors/broker/broker_test.go index 437cdaad..20ef19a6 100644 --- a/internal/connectors/broker/broker_test.go +++ b/internal/connectors/broker/broker_test.go @@ -375,7 +375,7 @@ func TestPolicyIsAskedBeforeARead(t *testing.T) { want := policy.Input{ Checkpoint: policy.CheckpointToolCall, Phase: policy.PhaseRead, Who: policy.Who{Person: "alice", Groups: []string{"sales"}}, - Agent: policy.Agent{Token: "t-1", Client: "claude-code"}, + Agent: policy.Agent{Token: "t-1"}, // not the client's own name for itself: it chooses it Where: policy.Where{Connector: "fake", Tool: "echo", Mode: "read"}, What: policy.What{Arguments: json.RawMessage(`{"text":"hello"}`)}, } diff --git a/internal/connectors/broker/checkpolicy.go b/internal/connectors/broker/checkpolicy.go index 354836fc..8cec1d92 100644 --- a/internal/connectors/broker/checkpolicy.go +++ b/internal/connectors/broker/checkpolicy.go @@ -68,7 +68,7 @@ func (c *call) policyInput() (policy.Input, bool) { // agentOf is what made a call for caller. func agentOf(caller connectors.Caller) policy.Agent { - a := policy.Agent{Name: caller.Agent, Token: caller.Token.ID, Client: caller.Client, Scheduled: caller.Token.Job != ""} + a := policy.Agent{Name: caller.Agent, Token: caller.Token.ID, Scheduled: caller.Token.Job != ""} if app := caller.Token.App; app != nil { a.App = app.Name } diff --git a/internal/connectors/policy/opa/opa.go b/internal/connectors/policy/opa/opa.go index 37a6bd94..b583dfbe 100644 --- a/internal/connectors/policy/opa/opa.go +++ b/internal/connectors/policy/opa/opa.go @@ -113,7 +113,12 @@ func (e *Engine) Start(ctx context.Context, every time.Duration) { } func (e *Engine) reloadLogged(ctx context.Context) { - if err := e.load(ctx); err != nil && !errors.Is(err, errUnchanged) { + err := e.load(ctx) + switch { + case err == nil || errors.Is(err, errUnchanged): + case e.Revision() == "": + slog.Error("connector policy rules not loaded; every connector call is denied until they load", "dir", e.dir, "err", err) + default: slog.Error("connector policy rules not loaded; the last rules that loaded stay", "dir", e.dir, "revision", e.Revision(), "err", err) } } diff --git a/internal/connectors/policy/opa/opa_test.go b/internal/connectors/policy/opa/opa_test.go index b24414fd..bdef5ce3 100644 --- a/internal/connectors/policy/opa/opa_test.go +++ b/internal/connectors/policy/opa/opa_test.go @@ -150,7 +150,7 @@ deny contains rego.metadata.rule() if { input.phase == "propose" input.who.person == "alice" input.who.groups == ["recruiting"] - input.agent == {"name": "helper", "app": "helper-1", "token": "t-1", "client": "claude-code", "scheduled": false} + input.agent == {"name": "helper", "app": "helper-1", "token": "t-1", "scheduled": false} input.where == {"connector": "slack", "tool": "post", "mode": "write"} input.what.arguments.big == 12345678901234567890 input.what.arguments.text == "hi" @@ -161,7 +161,7 @@ deny contains rego.metadata.rule() if { in := policy.Input{ Checkpoint: policy.CheckpointToolCall, Phase: policy.PhasePropose, Who: policy.Who{Person: "alice", Groups: []string{"recruiting"}}, - Agent: policy.Agent{Name: "helper", App: "helper-1", Token: "t-1", Client: "claude-code"}, + Agent: policy.Agent{Name: "helper", App: "helper-1", Token: "t-1"}, Where: policy.Where{Connector: "slack", Tool: "post", Mode: "write"}, What: policy.What{Arguments: json.RawMessage(`{"big":12345678901234567890,"text":"hi"}`)}, } diff --git a/internal/connectors/policy/policy.go b/internal/connectors/policy/policy.go index c52d9e91..0725fab9 100644 --- a/internal/connectors/policy/policy.go +++ b/internal/connectors/policy/policy.go @@ -53,14 +53,14 @@ type Who struct { Groups []string `json:"groups"` } -// Agent is what made the call: the coding agent app (empty for a personal -// token), the token, and what the MCP client calls itself (display only, -// the client chooses it). Scheduled is true for a job's token. +// Agent is what made the call: the coding agent app's short and object +// names (empty for a personal token) and the token. Scheduled is true for +// a job's token. What the MCP client calls itself is left out: the client +// chooses it, so no rule may rest on it. type Agent struct { Name string `json:"name"` App string `json:"app"` Token string `json:"token"` - Client string `json:"client"` Scheduled bool `json:"scheduled"` } From b17d899c5f3045abd58839ac5a651c2ff8581e41 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:21:55 +0000 Subject: [PATCH 03/13] feat(helm): mount connector policy rules With config.connectors.enabled the gateway needs a directory of Rego rules. connectorPolicy.configMap names an existing ConfigMap (such as one synced from a GitOps repository); connectorPolicy.rules renders the files into javo-connector-policy. The chart mounts the ConfigMap whole, read-only, at /etc/javo-policy (no subPath, so the mount updates and the gateway reloads the rules) and sets connectors.policy.rulesDir there unless it is set. It refuses to render with connectors on and neither or both set. With connectors off nothing is added. --- deploy/helm/javo/templates/_helpers.tpl | 38 +++++ deploy/helm/javo/templates/config.yaml | 8 +- .../helm/javo/templates/connector-policy.yaml | 16 ++ deploy/helm/javo/templates/gateway.yaml | 6 + deploy/helm/javo/templates/server.yaml | 6 + deploy/helm/javo/values.yaml | 16 ++ test/helm/connectorpolicy_test.go | 142 ++++++++++++++++++ 7 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 deploy/helm/javo/templates/connector-policy.yaml create mode 100644 test/helm/connectorpolicy_test.go diff --git a/deploy/helm/javo/templates/_helpers.tpl b/deploy/helm/javo/templates/_helpers.tpl index b59e97c7..07d2b081 100644 --- a/deploy/helm/javo/templates/_helpers.tpl +++ b/deploy/helm/javo/templates/_helpers.tpl @@ -497,3 +497,41 @@ imagePullSecrets: configMap: {name: javo-branding} {{- end -}} {{- end -}} + +{{/* Where the gateway reads the connector policy's rules. */}} +{{- define "javo.connectorPolicyDir" -}} +/etc/javo-policy +{{- end -}} + +{{/* The ConfigMap of connector policy rules the gateway mounts; empty with +connectors off. With connectors on, fails unless exactly one of +connectorPolicy.configMap and connectorPolicy.rules is set. */}} +{{- define "javo.connectorPolicyConfigMap" -}} +{{- $p := .Values.connectorPolicy -}} +{{- if (default (dict) .Values.config.connectors).enabled -}} +{{- if and $p.configMap $p.rules -}} +{{- fail "connectorPolicy: set configMap or rules, not both" -}} +{{- else if $p.configMap -}} +{{ $p.configMap }} +{{- else if $p.rules -}} +javo-connector-policy +{{- else -}} +{{- fail "config.connectors.enabled needs connector policy rules: set connectorPolicy.configMap or connectorPolicy.rules (without rules every connector call would be denied)" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* A whole-directory mount, never subPath: a subPath mount does not update, +and the gateway reads the rules again when the mount changes. */}} +{{- define "javo.connectorPolicyMount" -}} +{{- if include "javo.connectorPolicyConfigMap" . -}} +- {name: connector-policy, mountPath: {{ include "javo.connectorPolicyDir" . }}, readOnly: true} +{{- end -}} +{{- end -}} + +{{- define "javo.connectorPolicyVolume" -}} +{{- with include "javo.connectorPolicyConfigMap" . -}} +- name: connector-policy + configMap: {name: {{ . }}} +{{- end -}} +{{- end -}} diff --git a/deploy/helm/javo/templates/config.yaml b/deploy/helm/javo/templates/config.yaml index 9ad36208..901bdcbd 100644 --- a/deploy/helm/javo/templates/config.yaml +++ b/deploy/helm/javo/templates/config.yaml @@ -4,7 +4,8 @@ containerImages from the top-level containerImages values, branding from the top-level branding values, source.cloneImage and source.previews from the top-level source values, auth.oidc.clientSecretFile defaults to the file mounted from -gateway.oidcClientSecret, and urls.uiHost defaults to the ingress host. +gateway.oidcClientSecret, connectors.policy.rulesDir defaults to the rules +mounted from connectorPolicy, and urls.uiHost defaults to the ingress host. urls.uiHost, urls.appsHost, auth.oidc.issuer and auth.oidc.clientID are rendered as templates. */ -}} {{- $cfg := deepCopy .Values.config -}} @@ -12,6 +13,11 @@ rendered as templates. */ -}} {{- $_ := set $cfg "source" (dict "cloneImage" .Values.source.cloneImage "gitConfig" .Values.source.gitConfig "previews" .Values.source.previews) -}} {{- $_ := set $cfg "branding" (include "javo.brandingConfig" . | fromJson) -}} {{- $_ := set $cfg "namespaces" (merge (dict "shared" .Values.workspaceNamespace) (default (dict) $cfg.namespaces)) -}} +{{- if include "javo.connectorPolicyConfigMap" . -}} +{{- $policy := default (dict) $cfg.connectors.policy -}} +{{- if not $policy.rulesDir }}{{ $_ := set $policy "rulesDir" (include "javo.connectorPolicyDir" .) }}{{ end -}} +{{- $_ := set $cfg.connectors "policy" $policy -}} +{{- end -}} {{- $oidc := (default (dict) $cfg.auth).oidc -}} {{- if $oidc -}} {{- range $k := list "issuer" "clientID" -}} diff --git a/deploy/helm/javo/templates/connector-policy.yaml b/deploy/helm/javo/templates/connector-policy.yaml new file mode 100644 index 00000000..266930ec --- /dev/null +++ b/deploy/helm/javo/templates/connector-policy.yaml @@ -0,0 +1,16 @@ +{{- /* +The connector policy's rules given inline (connectorPolicy.rules). The gateway +mounts them, whole, at javo.connectorPolicyDir and reads them again when the +mount changes, so editing them needs no restart. +*/ -}} +{{- if and (include "javo.connectorPolicyConfigMap" .) .Values.connectorPolicy.rules }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: javo-connector-policy + namespace: {{ .Release.Namespace }} + labels: + {{- include "javo.labels" . | nindent 4 }} +data: + {{- toYaml .Values.connectorPolicy.rules | nindent 2 }} +{{- end }} diff --git a/deploy/helm/javo/templates/gateway.yaml b/deploy/helm/javo/templates/gateway.yaml index 96da36e4..a46ec589 100644 --- a/deploy/helm/javo/templates/gateway.yaml +++ b/deploy/helm/javo/templates/gateway.yaml @@ -71,6 +71,9 @@ spec: {{- with include "javo.brandingMount" . }} {{- . | nindent 12 }} {{- end }} + {{- with include "javo.connectorPolicyMount" . }} + {{- . | nindent 12 }} + {{- end }} {{- with include "javo.bucketMounts" . }} {{- . | nindent 12 }} {{- end }} @@ -93,6 +96,9 @@ spec: {{- with include "javo.brandingVolume" . }} {{- . | nindent 8 }} {{- end }} + {{- with include "javo.connectorPolicyVolume" . }} + {{- . | nindent 8 }} + {{- end }} {{- with include "javo.bucketVolumes" . }} {{- . | nindent 8 }} {{- end }} diff --git a/deploy/helm/javo/templates/server.yaml b/deploy/helm/javo/templates/server.yaml index ea077820..5778b566 100644 --- a/deploy/helm/javo/templates/server.yaml +++ b/deploy/helm/javo/templates/server.yaml @@ -112,6 +112,9 @@ spec: {{- with include "javo.brandingMount" . }} {{- . | nindent 12 }} {{- end }} + {{- with include "javo.connectorPolicyMount" . }} + {{- . | nindent 12 }} + {{- end }} {{- with include "javo.bucketMounts" . }} {{- . | nindent 12 }} {{- end }} @@ -137,6 +140,9 @@ spec: {{- with include "javo.brandingVolume" . }} {{- . | nindent 8 }} {{- end }} + {{- with include "javo.connectorPolicyVolume" . }} + {{- . | nindent 8 }} + {{- end }} {{- with include "javo.bucketVolumes" . }} {{- . | nindent 8 }} {{- end }} diff --git a/deploy/helm/javo/values.yaml b/deploy/helm/javo/values.yaml index d657f843..d10cad72 100644 --- a/deploy/helm/javo/values.yaml +++ b/deploy/helm/javo/values.yaml @@ -469,6 +469,22 @@ branding: dark: {url: "", svg: "", base64: ""} favicon: {url: "", svg: "", base64: ""} +# The Rego rules every connector call is checked against (see +# site/src/content/docs/admin/connector-policy.md). Needed with +# config.connectors.enabled: set exactly one of configMap and rules, or the +# chart refuses to render (without rules every connector call would be +# denied). Both are ignored with connectors off. The gateway mounts the +# ConfigMap whole at /etc/javo-policy (config.connectors.policy.rulesDir, +# unless you set that) and reads it again every 10 seconds, so a change to +# the rules needs no restart. +connectorPolicy: + # An existing ConfigMap in the release namespace whose keys are .rego + # files, such as one ArgoCD syncs from a GitOps repository. + configMap: "" + # File name to Rego source, rendered into ConfigMap javo-connector-policy, + # e.g. --set-file 'connectorPolicy.rules.greenhouse\.rego=greenhouse.rego'. + rules: {} + # Platform config, rendered into ConfigMap javo-config and read by both the # controller and the gateway (see internal/config for every key). # namespaces.shared is taken from workspaceNamespace above. diff --git a/test/helm/connectorpolicy_test.go b/test/helm/connectorpolicy_test.go new file mode 100644 index 00000000..8a60abd4 --- /dev/null +++ b/test/helm/connectorpolicy_test.go @@ -0,0 +1,142 @@ +package helm + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" + + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + + "github.com/nebari-dev/javo/internal/connectors/policy/opa" +) + +// connectorsOn turns connectors on, with the UI host their OAuth redirect +// address is built from. +var connectorsOn = []string{"--set", "config.connectors.enabled=true", "--set", "ingress.host=tapas.example.com"} + +var examples = filepath.Join("..", "..", "deploy", "policy", "examples") + +// policyVolume returns the gateway's volume mounted at /etc/javo-policy and +// whether the gateway mounts one there (whole, not a subPath). +func policyVolume(t *testing.T, d appsv1.Deployment) (corev1.Volume, bool) { + t.Helper() + for _, c := range d.Spec.Template.Spec.Containers { + for _, m := range c.VolumeMounts { + if m.MountPath != "/etc/javo-policy" { + continue + } + if m.SubPath != "" || !m.ReadOnly { + t.Fatalf("%s mounts the rules with subPath %q, readOnly %v", d.Name, m.SubPath, m.ReadOnly) + } + for _, v := range d.Spec.Template.Spec.Volumes { + if v.Name == m.Name { + return v, true + } + } + t.Fatalf("%s mounts volume %s, which it does not have", d.Name, m.Name) + } + } + return corev1.Volume{}, false +} + +func TestInlineConnectorRulesAreMountedWhereTheConfigSays(t *testing.T) { + t.Parallel() + for _, engine := range engines { + out, err := render(t, append(append(engineArgs(engine), connectorsOn...), + "--set-file", `connectorPolicy.rules.greenhouse\.rego=`+filepath.Join(examples, "greenhouse.rego"), + "--set-file", `connectorPolicy.rules.email\.rego=`+filepath.Join(examples, "email.rego"))...) + if err != nil { + t.Fatalf("%s render: %v\n%s", engine, err, out) + } + if dir := loadedConfig(t, out).Connectors.Policy.RulesDir; dir != "/etc/javo-policy" { + t.Fatalf("%s: rulesDir = %q", engine, dir) + } + var cm corev1.ConfigMap + if !object(t, out, "ConfigMap", "javo-connector-policy", &cm) { + t.Fatalf("%s: no ConfigMap javo-connector-policy", engine) + } + v, ok := policyVolume(t, deploymentOf(t, out, engine, "gateway")) + if !ok || v.ConfigMap == nil || v.ConfigMap.Name != "javo-connector-policy" || len(v.ConfigMap.Items) != 0 { + t.Fatalf("%s: rules volume = %+v (mounted %v)", engine, v, ok) + } + + // The rendered files are the rules, and they load. + local := t.TempDir() + for name, src := range cm.Data { + if err := os.WriteFile(filepath.Join(local, name), []byte(src), 0o600); err != nil { + t.Fatal(err) + } + } + if len(cm.Data) != 2 { + t.Fatalf("%s: ConfigMap keys = %v", engine, cm.Data) + } + if err := opa.New(opa.Config{Dir: local}).Reload(context.Background()); err != nil { + t.Fatalf("%s: the gateway would refuse the rendered rules: %v", engine, err) + } + } +} + +func TestConnectorRulesFromAnExistingConfigMap(t *testing.T) { + t.Parallel() + out, err := render(t, append(connectorsOn, "--set", "connectorPolicy.configMap=tapas-rules")...) + if err != nil { + t.Fatalf("render: %v\n%s", err, out) + } + if dir := loadedConfig(t, out).Connectors.Policy.RulesDir; dir != "/etc/javo-policy" { + t.Fatalf("rulesDir = %q", dir) + } + if object(t, out, "ConfigMap", "javo-connector-policy", &corev1.ConfigMap{}) { + t.Fatal("a ConfigMap javo-connector-policy beside the existing one") + } + v, ok := policyVolume(t, deploymentOf(t, out, "sqlite", "gateway")) + if !ok || v.ConfigMap == nil || v.ConfigMap.Name != "tapas-rules" { + t.Fatalf("rules volume = %+v (mounted %v)", v, ok) + } +} + +func TestAnExplicitRulesDirIsKept(t *testing.T) { + t.Parallel() + out, err := render(t, append(connectorsOn, "--set", "connectorPolicy.configMap=tapas-rules", + "--set", "config.connectors.policy.rulesDir=/srv/rules")...) + if err != nil { + t.Fatalf("render: %v\n%s", err, out) + } + if dir := loadedConfig(t, out).Connectors.Policy.RulesDir; dir != "/srv/rules" { + t.Fatalf("rulesDir = %q", dir) + } +} + +func TestConnectorsNeedOneSourceOfRules(t *testing.T) { + t.Parallel() + out, err := render(t, connectorsOn...) + if err == nil || !strings.Contains(out, "every connector call would be denied") { + t.Fatalf("connectors without rules: err %v\n%s", err, out) + } + out, err = render(t, append(connectorsOn, "--set", "connectorPolicy.configMap=tapas-rules", + "--set", `connectorPolicy.rules.a\.rego=package tapas.rules.a`)...) + if err == nil || !strings.Contains(out, "not both") { + t.Fatalf("connectors with both sources: err %v\n%s", err, out) + } +} + +func TestConnectorsOffRenderNoRules(t *testing.T) { + t.Parallel() + for _, engine := range engines { + out, err := render(t, append(engineArgs(engine), "--set", "connectorPolicy.configMap=tapas-rules")...) + if err != nil { + t.Fatalf("%s render: %v\n%s", engine, err, out) + } + if object(t, out, "ConfigMap", "javo-connector-policy", &corev1.ConfigMap{}) { + t.Fatalf("%s: a ConfigMap javo-connector-policy with connectors off", engine) + } + if _, ok := policyVolume(t, deploymentOf(t, out, engine, "gateway")); ok { + t.Fatalf("%s: rules mounted with connectors off", engine) + } + if dir := loadedConfig(t, out).Connectors.Policy.RulesDir; dir != "" { + t.Fatalf("%s: rulesDir = %q with connectors off", engine, dir) + } + } +} From 3a74c438d25c2f28d91e4f14a921b59874f178eb Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:23:30 +0000 Subject: [PATCH 04/13] docs: writing, testing and loading connector policy rules A Connector policy page for admins: when calls are checked, the input document, the rule contract with worked examples, testing with opa test, loading through the chart's connectorPolicy values, what fails closed and what the audit log records. Connectors and the Helm values reference link to it and name connectors.policy.rulesDir. --- .../content/docs/admin/connector-policy.md | 195 ++++++++++++++++++ site/src/content/docs/admin/connectors.md | 4 + .../content/docs/reference/helm-values.mdx | 2 + 3 files changed, 201 insertions(+) create mode 100644 site/src/content/docs/admin/connector-policy.md diff --git a/site/src/content/docs/admin/connector-policy.md b/site/src/content/docs/admin/connector-policy.md new file mode 100644 index 00000000..0dbdba77 --- /dev/null +++ b/site/src/content/docs/admin/connector-policy.md @@ -0,0 +1,195 @@ +--- +title: Connector policy +description: Your organisation's own rules, written in Rego, that every connector call is checked against before it reaches the vendor. +sidebar: + order: 10.7 +--- + +Every call an agent makes through a [connector](/admin/connectors/) is checked against your organisation's rules before Tapas forwards it. The rules are [Rego](https://www.openpolicyagent.org/docs/policy-language) files, evaluated by Open Policy Agent (OPA) inside the gateway. With connectors on, the gateway needs rules: with none loaded, every connector call is denied. + +OPA is enforcement; Frames are context and never carry a rule that must hold. + +## When a call is checked + +| When | Phase | What happens next | +|---|---|---| +| An agent calls a **read** tool | `read` | Checked before the call is forwarded to the vendor. | +| An agent calls a **write** tool | `propose` | Checked when the write is made into a plan the person approves in the browser. | +| The person approves the plan | `apply` | Checked again, with `input.approval` set, before the write is forwarded. | + +Each check has one of three outcomes: + +- **allow**: the call goes ahead. +- **deny**: the call stops, and the agent is told why, with the description of every rule that denied it: "Not allowed by the platform's policy: ...". A deny wins over everything else. +- **require_approval**: the call is held for its owner's approval in the browser. A read is turned into a plan, like a write. A write becomes a plan anyway. At `apply` the plan has already been approved, so a rule that still asks for approval denies the call: write such rules so they stop asking once the plan is approved (see below). + +## What the rules see + +Each check gives the rules one input document, the same shape at every phase. Who the person is comes from their verified Tapas token, never from what the agent sent. + +```json +{ + "checkpoint": "tool_call", + "phase": "apply", + "who": { + "person": "alice@example.com", + "groups": ["recruiting"] + }, + "agent": { + "name": "helper", + "app": "helper-1", + "token": "t-1", + "client": "claude-code", + "scheduled": false + }, + "where": { + "connector": "gmail", + "tool": "send_email", + "mode": "write" + }, + "what": { + "arguments": {"to": "bob@example.com", "subject": "Interview on Friday"} + }, + "findings": [], + "approval": { + "plan": "p-1", + "by": "alice@example.com" + } +} +``` + +| Field | What it is | +|---|---| +| `checkpoint` | Always `tool_call` for now. | +| `phase` | `read`, `propose` or `apply` (see above). | +| `who.person`, `who.groups` | The person the agent acts for, and their groups. | +| `agent.name` | The short name of the coding agent app that made the call; empty for a personal token. | +| `agent.app` | The name of the app the token belongs to; empty for a personal token. | +| `agent.token` | The id of the token that made the call. | +| `agent.client` | What the MCP client calls itself. The client chooses it, so use it for display, never to decide. | +| `agent.scheduled` | `true` when a scheduled job's token made the call. | +| `where.connector`, `where.tool` | The connector's short name and the tool called. | +| `where.mode` | `read` or `write`, as the admin marked the tool. | +| `what.arguments` | The tool's arguments, a JSON object. | +| `findings` | What detectors spotted in the arguments. No detector exists yet, so it is always empty; rules may already match on it. | +| `approval` | Only at `apply`: the approved plan and who approved it. Absent in the other phases. | + +At `apply` the person approves in the browser, but `agent` is still the agent that proposed the plan, as recorded when it was proposed. + +## Writing rules + +The contract: + +- Rules live in packages `tapas.rules.`, such as `tapas.rules.email`. `tapas.admin.` is kept for rules edited in Tapas later. Shared helpers go in `tapas.lib` or a package below it, such as `tapas.lib.groups`; they cannot hold `deny` or `require_approval`. Any other package is refused. +- A rule is a partial set named `deny` or `require_approval`: `deny contains ... if { ... }`. +- Each such rule carries a `METADATA` comment with a `title` and a `description`. The description is the sentence the person sees when the rule fires, and the title goes into the audit log. +- Each element of the set is an object with a non-empty `title` and `description`. Use `rego.metadata.rule()`, which is the rule's own METADATA. + +A worked example: only the recruiting group may use the Greenhouse connector. + +```text +package tapas.rules.greenhouse + +# METADATA +# title: Only recruiting uses Greenhouse +# description: Greenhouse holds candidates' personal data, so only people in the recruiting group may use it through an agent. +deny contains rego.metadata.rule() if { + input.where.connector == "greenhouse" + not "recruiting" in input.who.groups +} +``` + +When `bob@example.com`, who is in `sales`, asks his agent to list candidates, the call stops with "Not allowed by the platform's policy: Greenhouse holds candidates' personal data, so only people in the recruiting group may use it through an agent." People in `recruiting` are not affected, and nor are other connectors. + +### Approval only until approved + +A `require_approval` rule fires at every phase it matches, including `apply`, where it would deny the approved call. Add `not input.approval` so it asks only before approval: + +```text +package tapas.rules.email + +send := {"send_email", "send_message", "send_draft"} + +# METADATA +# title: Email sends need approval +# description: An email leaves the company in the person's name, so they approve each send in the browser first. +require_approval contains rego.metadata.rule() if { + input.where.connector == "gmail" + input.where.tool in send + not input.approval +} +``` + +At `apply` you can also check the approval itself, such as `input.approval.by == input.who.person`. + +## Testing rules + +Test the rules with the OPA CLI, pinned to the version Tapas embeds, **v1.22.4**, so both read the rules the same way. Put tests in files ending in `_test.rego` next to the rules: Tapas skips those files when it loads the rules. + +```sh +opa test -v path/to/rules/ +``` + +`deploy/policy/examples/` in the Tapas repository has example rules (Greenhouse for recruiting only, approval for email sends, approval for Frames changes by their owner) with their tests, a good start for your own. + +## Loading the rules + +Tapas reads the `.rego` files at the top of `connectors.policy.rulesDir`, an absolute directory; subdirectories, files starting with a dot and `_test.rego` files are skipped. With the Helm chart, give the rules in one of two ways (exactly one, or the chart refuses to render): + +**Inline**, in your values. The chart puts them in the ConfigMap `javo-connector-policy`: + +```yaml +config: + connectors: + enabled: true +connectorPolicy: + rules: + greenhouse.rego: | + package tapas.rules.greenhouse + ... +``` + +or from files: `--set-file 'connectorPolicy.rules.greenhouse\.rego=greenhouse.rego'`. + +**From a ConfigMap you manage**, such as one ArgoCD syncs from a GitOps repository of rules, in the release's namespace: + +```yaml +config: + connectors: + enabled: true +connectorPolicy: + configMap: tapas-connector-rules +``` + +Either way the gateway mounts the ConfigMap at `/etc/javo-policy`, and the chart sets `connectors.policy.rulesDir` to it unless you set it yourself. + +Changing the rules needs no restart. Kubernetes updates the mounted files about a minute after the ConfigMap changes, and the gateway reads the directory every 10 seconds and loads what changed. A change that does not load (a syntax error, a rule breaking the contract) is logged with the reason, and the last rules that loaded stay in force. Each loaded rule set has a revision, a short hash of its files' names and contents, which the log names when rules load and each decision records. + +## Fail closed + +Every one of these denies the call: + +- No rules have loaded since the gateway started: the directory is missing, unreadable or has no `.rego` files, or the first rules do not load. +- Evaluating the rules fails, or takes more than 2 seconds. +- A `deny` or `require_approval` element has no title or description, or the rules give an answer of any other shape. +- `require_approval` at `apply` (see above). +- The record of which agent proposed a plan cannot be read when it is applied. + +Rules are refused when they load (and the last good ones stay) when: + +- a file does not parse; +- a package is outside `tapas.rules.`, `tapas.admin.` and `tapas.lib`; +- a `deny` or `require_approval` rule has no METADATA title and description, is not a partial set (`contains`), is a `default` rule, or sits in `tapas.lib`; +- a rule uses a built-in that reaches outside the gateway: `http.send`, `net.lookup_ip_addr` or `opa.runtime` (the network and the gateway's environment). + +## Where decisions are recorded + +Each connector call's row in the audit log carries the decision, next to the tool, the outcome and the agent: + +| Field | What it is | +|---|---| +| `policy` | `allow`, `deny` or `require_approval`; empty when the policy was not asked. | +| `policyRules` | The titles of the rules that decided it. | +| `policyRevision` | The revision of the rules that decided it. | + +A denied call's outcome is `denied_policy`. The arguments are never recorded. diff --git a/site/src/content/docs/admin/connectors.md b/site/src/content/docs/admin/connectors.md index e7ab8029..51fd26af 100644 --- a/site/src/content/docs/admin/connectors.md +++ b/site/src/content/docs/admin/connectors.md @@ -16,8 +16,12 @@ mcp: enabled: true connectors: enabled: true + policy: + rulesDir: /etc/javo-policy ``` +Every connector call is checked against your organisation's rules, the `.rego` files in `policy.rulesDir` (an absolute directory, required with connectors on; the Helm chart mounts the rules there and sets it for you). Without rules every call is denied. See [Connector policy](/admin/connector-policy/) for writing, testing and loading them. + Connectors need the gateway's sessions key to survive restarts (`--sessions-key-secret`, which the chart sets): the OAuth client secrets and people's tokens are encrypted with it. The gateway refuses to start with connectors on and a key made at start. ## Add a connector diff --git a/site/src/content/docs/reference/helm-values.mdx b/site/src/content/docs/reference/helm-values.mdx index 587e52ed..3ac2a8e4 100644 --- a/site/src/content/docs/reference/helm-values.mdx +++ b/site/src/content/docs/reference/helm-values.mdx @@ -23,6 +23,8 @@ These are the chart's default values, read from `deploy/helm/javo/values.yaml` w | `database.backup`, `backupTarget` | [Backups and restore](/admin/backups/) | | `secrets` | [Secrets and keys](/admin/secrets-and-keys/) | | `config.ai`, `ai`, `config.mcp` | [AI](/admin/ai/) | +| `config.connectors` | [Connectors](/admin/connectors/) | +| `connectorPolicy` | [Connector policy](/admin/connector-policy/) | | `config.nebi`, `config.environments` | [Nebi environments](/admin/nebi/) | | `config.memory` | [Memory](/admin/memory/) | | `config.thumbnails` | [App thumbnails](/admin/thumbnails/) | From 298c86d5debe62e95a48d73f09590a8c365087ba Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:34:46 +0000 Subject: [PATCH 05/13] fix(connectors): refuse rules that would quietly not apply or reach out - A deny or require_approval nested in another name (x.deny) loaded and was never read; it is now refused. - Rules are type-checked against the input document, so a misspelt or removed input field is refused instead of never firing, and a rule set with no deny or require_approval rule at all does not load. - json.match_schema and json.verify_schema fetch a schema's $ref by URL or file path; both are refused, and no built-in may reach a host. - The rules are read from the directory a ConfigMap's ..data names, so an update never loads old and new files mixed. - A failed policy check is logged with the connector, tool and rules' revision. Files that failed to load are logged once, not recompiled every 10 seconds. --- internal/connectors/policy/opa/opa.go | 132 +++++++++++++++++---- internal/connectors/policy/opa/opa_test.go | 61 ++++++++-- internal/connectors/policy/policy.go | 5 + internal/gateway/apitest/fixture.go | 12 +- 4 files changed, 174 insertions(+), 36 deletions(-) diff --git a/internal/connectors/policy/opa/opa.go b/internal/connectors/policy/opa/opa.go index b583dfbe..95302ac4 100644 --- a/internal/connectors/policy/opa/opa.go +++ b/internal/connectors/policy/opa/opa.go @@ -62,9 +62,13 @@ type Config struct { type Engine struct { dir string timeout time.Duration - // reload serialises Reload; cur is read without it. + // reload serialises Reload and guards failed; cur is read without it. reload sync.Mutex cur atomic.Pointer[ruleSet] + // failed is the revision that last failed to load and why, so the same + // broken files are not compiled and logged again on every read. + failed string + failedErr error } // ruleSet is one loaded set of rules: decisions read it whole. @@ -114,8 +118,9 @@ func (e *Engine) Start(ctx context.Context, every time.Duration) { func (e *Engine) reloadLogged(ctx context.Context) { err := e.load(ctx) + var again *stillBroken switch { - case err == nil || errors.Is(err, errUnchanged): + case err == nil || errors.Is(err, errUnchanged) || errors.As(err, &again): case e.Revision() == "": slog.Error("connector policy rules not loaded; every connector call is denied until they load", "dir", e.dir, "err", err) default: @@ -126,6 +131,13 @@ func (e *Engine) reloadLogged(ctx context.Context) { // errUnchanged is a reload that found the rules as they were loaded. var errUnchanged = errors.New("rules unchanged") +// stillBroken is a reload that found the files that last failed to load, +// unchanged: the same error, already logged. +type stillBroken struct{ err error } + +func (e *stillBroken) Error() string { return e.err.Error() } +func (e *stillBroken) Unwrap() error { return e.err } + // Reload reads the rules and, when they changed and load, puts them in // place of the old ones. On an error the old ones stay. Rules unchanged // since the last load answer nil. @@ -148,10 +160,15 @@ func (e *Engine) load(ctx context.Context) error { if cur := e.cur.Load(); cur != nil && cur.revision == rev { return errUnchanged } + if rev == e.failed { + return &stillBroken{e.failedErr} + } q, err := compile(ctx, files) if err != nil { + e.failed, e.failedErr = rev, err return err } + e.failed, e.failedErr = "", nil e.cur.Store(&ruleSet{query: q, revision: rev}) slog.Info("connector policy rules loaded", "dir", e.dir, "revision", rev, "files", len(files)) return nil @@ -165,10 +182,19 @@ type ruleFile struct { // readRules reads dir's rule files, sorted by name. A file that is // missing, empty of rules, or unreadable is an error. +// +// A ConfigMap volume keeps each version of its files in a dot directory, +// points ..data at the current one, and links each name at the top to +// ..data. On an update ..data moves first and the top-level links follow, +// so the files are read from the directory ..data names, resolved once: +// one whole version, never old and new files mixed. func readRules(dir string) ([]ruleFile, error) { if dir == "" { return nil, errors.New("no rules directory is configured") } + if version, err := filepath.EvalSymlinks(filepath.Join(dir, "..data")); err == nil { + dir = version + } entries, err := os.ReadDir(dir) if err != nil { return nil, fmt.Errorf("read the rules directory: %w", err) @@ -176,8 +202,6 @@ func readRules(dir string) ([]ruleFile, error) { var out []ruleFile for _, ent := range entries { name := ent.Name() - // A ConfigMap volume keeps its files in dot directories and links - // them at the top: the links are read, the dot entries not. if strings.HasPrefix(name, ".") || !strings.HasSuffix(name, ".rego") || strings.HasSuffix(name, "_test.rego") { continue } @@ -222,68 +246,132 @@ const query = `out := [[ns, pkg, name, value] | ]` // capabilities are this OPA's built-in functions less those that reach -// outside the gateway: the network and the process's environment. +// outside the gateway: the network, local files (JSON schemas fetch their +// $ref by URL or file path) and the process's environment. No host is +// allowed to any built-in that would honour AllowNet. var capabilities = sync.OnceValue(func() *ast.Capabilities { c := ast.CapabilitiesForThisVersion() - refused := map[string]bool{"http.send": true, "net.lookup_ip_addr": true, "opa.runtime": true} + refused := map[string]bool{ + "http.send": true, "net.lookup_ip_addr": true, "opa.runtime": true, + "json.match_schema": true, "json.verify_schema": true, + } c.Builtins = slices.DeleteFunc(slices.Clone(c.Builtins), func(b *ast.Builtin) bool { return refused[b.Name] }) + c.AllowNet = []string{} return c }) +// inputSchema is the shape of policy.Input, so a rule that reads a field +// the input does not have (a misspelling, or a field that was removed) is +// refused when it loads instead of never firing. Arguments are free. +const inputSchema = `{ + "type": "object", "additionalProperties": false, + "properties": { + "checkpoint": {"type": "string"}, + "phase": {"type": "string"}, + "who": {"type": "object", "additionalProperties": false, "properties": { + "person": {"type": "string"}, "groups": {"type": "array", "items": {"type": "string"}}}}, + "agent": {"type": "object", "additionalProperties": false, "properties": { + "name": {"type": "string"}, "app": {"type": "string"}, "token": {"type": "string"}, "scheduled": {"type": "boolean"}}}, + "where": {"type": "object", "additionalProperties": false, "properties": { + "connector": {"type": "string"}, "tool": {"type": "string"}, "mode": {"type": "string"}}}, + "what": {"type": "object", "additionalProperties": false, "properties": { + "arguments": {"type": "object", "additionalProperties": true}}}, + "findings": {"type": "array", "items": {"type": "object", "additionalProperties": false, "properties": { + "detector": {"type": "string"}, "path": {"type": "string"}}}}, + "approval": {"type": "object", "additionalProperties": false, "properties": { + "plan": {"type": "string"}, "by": {"type": "string"}}} + } +}` + +var schemas = sync.OnceValue(func() *ast.SchemaSet { + var schema any + if err := util.UnmarshalJSON([]byte(inputSchema), &schema); err != nil { + panic(err) // a constant + } + ss := ast.NewSchemaSet() + ss.Put(ast.SchemaRootRef, schema) + return ss +}) + // compile parses, checks and prepares files as one rule set. func compile(ctx context.Context, files []ruleFile) (rego.PreparedEvalQuery, error) { modules := map[string]*ast.Module{} + effects := 0 for _, f := range files { m, err := ast.ParseModuleWithOpts(f.name, string(f.src), ast.ParserOptions{ProcessAnnotation: true, RegoVersion: ast.RegoV1}) if err != nil { return rego.PreparedEvalQuery{}, err } - if err := checkModule(f.name, m); err != nil { + n, err := checkModule(f.name, m) + if err != nil { return rego.PreparedEvalQuery{}, err } + effects += n modules[f.name] = m } - c := ast.NewCompiler().WithCapabilities(capabilities()).WithStrict(true) + if effects == 0 { + return rego.PreparedEvalQuery{}, errors.New("no deny or require_approval rule: rules that decide nothing are taken for rules that did not load") + } + c := ast.NewCompiler().WithCapabilities(capabilities()).WithStrict(true).WithSchemas(schemas()) if c.Compile(modules); c.Failed() { return rego.PreparedEvalQuery{}, c.Errors } return rego.New( - rego.Query(query), rego.Compiler(c), rego.StrictBuiltinErrors(true), rego.SetRegoVersion(ast.RegoV1), + rego.Query(query), rego.Compiler(c), rego.Capabilities(capabilities()), rego.StrictBuiltinErrors(true), rego.SetRegoVersion(ast.RegoV1), ).PrepareForEval(ctx) } // checkModule refuses a module outside the rules' packages, and a deny or // require_approval rule that is not a partial set with a title and -// description or that sits where it would not be collected. -func checkModule(name string, m *ast.Module) error { +// description or that sits where it would not be collected (another +// package, or deeper in a name such as x.deny). It answers how many such +// rules m has. +func checkModule(name string, m *ast.Module) (int, error) { path := m.Package.Path if len(path) < 3 || !path[1].Equal(ast.StringTerm("tapas")) { - return fmt.Errorf("%s: package %v is not under tapas.rules, tapas.admin or tapas.lib", name, m.Package.Path) + return 0, fmt.Errorf("%s: package %v is not under tapas.rules, tapas.admin or tapas.lib", name, m.Package.Path) } section := path[2].Value collected := len(path) == 4 && (section.Compare(ast.String("rules")) == 0 || section.Compare(ast.String("admin")) == 0) if !collected && section.Compare(ast.String("lib")) != 0 { - return fmt.Errorf("%s: package %v is not tapas.rules., tapas.admin. or under tapas.lib", name, m.Package.Path) + return 0, fmt.Errorf("%s: package %v is not tapas.rules., tapas.admin. or under tapas.lib", name, m.Package.Path) } + n := 0 for _, r := range m.Rules { - rule := r.Head.Name.String() - if len(r.Head.Ref()) > 0 { - rule = r.Head.Ref()[0].Value.(ast.Var).String() - } - if rule != ruleDeny && rule != ruleApproval { + rule, ok := effectIn(r.Head.Ref()) + if !ok { continue } + n++ at := fmt.Sprintf("%s:%d", name, r.Location.Row) switch { case !collected: - return fmt.Errorf("%s: %s is collected only in tapas.rules. or tapas.admin.", at, rule) + return 0, fmt.Errorf("%s: %s is collected only in tapas.rules. or tapas.admin.", at, rule) case len(r.Head.Ref()) != 1 || r.Head.RuleKind() != ast.MultiValue || r.Default: - return fmt.Errorf("%s: %s must be a partial set: %s contains ... if { ... }", at, rule, rule) + return 0, fmt.Errorf("%s: %s must be a partial set named %s itself: %s contains ... if { ... }", at, rule, rule, rule) case !described(r): - return fmt.Errorf("%s: %s needs a METADATA title and description", at, rule) + return 0, fmt.Errorf("%s: %s needs a METADATA title and description", at, rule) } } - return nil + return n, nil +} + +// effectIn is the effect a rule head names anywhere in its reference +// (deny, x.deny, deny.x), and whether it names one. +func effectIn(ref ast.Ref) (string, bool) { + for _, t := range ref { + var name string + switch v := t.Value.(type) { + case ast.Var: + name = string(v) + case ast.String: + name = string(v) + } + if name == ruleDeny || name == ruleApproval { + return name, true + } + } + return "", false } // described reports whether r carries a title and a description. diff --git a/internal/connectors/policy/opa/opa_test.go b/internal/connectors/policy/opa/opa_test.go index bdef5ce3..a31bb151 100644 --- a/internal/connectors/policy/opa/opa_test.go +++ b/internal/connectors/policy/opa/opa_test.go @@ -228,19 +228,27 @@ func TestRulesThatCannotBeLoaded(t *testing.T) { t.Parallel() meta := "# METADATA\n# title: T\n# description: D.\n" for name, src := range map[string]string{ - "syntax error": "package tapas.rules.x\n\ndeny contains if {", - "outside tapas": "package other\n\nx := 1\n", - "nested rules package": "package tapas.rules.a.b\n\n" + meta + "deny contains rego.metadata.rule() if true\n", - "tapas root": "package tapas\n\nx := 1\n", - "deny in the library": "package tapas.lib\n\n" + meta + "deny contains rego.metadata.rule() if true\n", - "deny as a boolean": "package tapas.rules.x\n\n" + meta + "deny if true\n", - "deny as a value": "package tapas.rules.x\n\n" + meta + "deny := {rego.metadata.rule()}\n", - "deny without a title": "package tapas.rules.x\n\n# METADATA\n# description: D.\ndeny contains rego.metadata.rule() if true\n", - "approval without detail": "package tapas.rules.x\n\n# METADATA\n# title: T\nrequire_approval contains rego.metadata.rule() if true\n", - "http.send": "package tapas.rules.x\n\nx := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", - "net.lookup_ip_addr": "package tapas.rules.x\n\nx := net.lookup_ip_addr(\"example.com\")\n", - "opa.runtime": "package tapas.rules.x\n\nx := opa.runtime()\n", - "unknown function": "package tapas.rules.x\n\nx := nope(1)\n", + "syntax error": "package tapas.rules.x\n\ndeny contains if {", + "outside tapas": "package other\n\nx := 1\n", + "nested rules package": "package tapas.rules.a.b\n\n" + meta + "deny contains rego.metadata.rule() if true\n", + "tapas root": "package tapas\n\nx := 1\n", + "deny in the library": "package tapas.lib\n\n" + meta + "deny contains rego.metadata.rule() if true\n", + "deny as a boolean": "package tapas.rules.x\n\n" + meta + "deny if true\n", + "deny as a value": "package tapas.rules.x\n\n" + meta + "deny := {rego.metadata.rule()}\n", + "deny without a title": "package tapas.rules.x\n\n# METADATA\n# description: D.\ndeny contains rego.metadata.rule() if true\n", + "approval without detail": "package tapas.rules.x\n\n# METADATA\n# title: T\nrequire_approval contains rego.metadata.rule() if true\n", + "deny under another name": "package tapas.rules.x\n\n" + meta + "y.deny contains rego.metadata.rule() if true\n", + "approval under a name": "package tapas.rules.x\n\n" + meta + "y.require_approval contains rego.metadata.rule() if true\n", + "deny deeper in the lib": "package tapas.lib\n\n" + meta + "x.deny contains rego.metadata.rule() if true\n", + "json schema by URL": "package tapas.rules.x\n\nx := json.match_schema({}, {\"$ref\": \"http://127.0.0.1:1/s.json\"})\n", + "json schema from a file": "package tapas.rules.x\n\nx := json.verify_schema({\"$ref\": \"file:///etc/passwd\"})\n", + "a misspelt input field": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.where.conector == \"slack\"\n", + "a field not in the input": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.agent.client == \"x\"\n", + "no deny or approval rule": "package tapas.rules.x\n\nsend := {\"send_email\"}\n", + "http.send": "package tapas.rules.x\n\nx := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", + "net.lookup_ip_addr": "package tapas.rules.x\n\nx := net.lookup_ip_addr(\"example.com\")\n", + "opa.runtime": "package tapas.rules.x\n\nx := opa.runtime()\n", + "unknown function": "package tapas.rules.x\n\nx := nope(1)\n", } { t.Run(name, func(t *testing.T) { e := opa.New(opa.Config{Dir: write(t, map[string]string{"x.rego": src})}) @@ -383,6 +391,33 @@ func TestAConfigMapMountLoadsEachRuleOnce(t *testing.T) { } } +// During a ConfigMap update the kubelet points ..data at the new files +// before it adds the top-level links of new ones: the rules are read from +// ..data, one whole version, never a mix. +func TestAConfigMapIsReadFromOneVersion(t *testing.T) { + t.Parallel() + dir := t.TempDir() + ts := filepath.Join(dir, "..2026_12_01_11_00_00.000000002") + if err := os.Mkdir(ts, 0o700); err != nil { + t.Fatal(err) + } + // The deny rule moved from a.rego to b.rego; b.rego's link is not there yet. + put(t, ts, map[string]string{"a.rego": emailApproval, "b.rego": recruitingOnly}) + if err := os.Symlink(filepath.Base(ts), filepath.Join(dir, "..data")); err != nil { + t.Fatal(err) + } + if err := os.Symlink(filepath.Join("..data", "a.rego"), filepath.Join(dir, "a.rego")); err != nil { + t.Fatal(err) + } + e := opa.New(opa.Config{Dir: dir}) + if err := e.Reload(ctx); err != nil { + t.Fatal(err) + } + if d := check(t, e, input("alice", nil, "greenhouse", "x")); d.Effect != policy.Deny { + t.Fatalf("decision %+v", d) + } +} + // Start loads the rules before it returns, then picks up a change to the // directory without a restart. func TestStartLoadsThenReloadsAChangedDirectory(t *testing.T) { diff --git a/internal/connectors/policy/policy.go b/internal/connectors/policy/policy.go index 0725fab9..6be6aa5f 100644 --- a/internal/connectors/policy/policy.go +++ b/internal/connectors/policy/policy.go @@ -6,6 +6,7 @@ package policy import ( "context" "encoding/json" + "log/slog" ) // Phase is the point of a call the check is for. @@ -115,6 +116,10 @@ func Evaluate(ctx context.Context, c Checker, in Input) Decision { d, err := c.Check(ctx, in) switch { case err != nil: + // Logged here, with what was asked of whom but not the arguments, + // so an admin can tell a broken rule from a rule that denied. + slog.Error("connector policy check failed; the call is denied", "phase", in.Phase, "person", in.Who.Person, + "connector", in.Where.Connector, "tool", in.Where.Tool, "err", err) return Decision{Effect: Deny, Reason: "The policy check failed."} case d.Effect == Deny && d.Reason == "": d.Reason = "Denied by policy." diff --git a/internal/gateway/apitest/fixture.go b/internal/gateway/apitest/fixture.go index 2b45d4e9..529a2de5 100644 --- a/internal/gateway/apitest/fixture.go +++ b/internal/gateway/apitest/fixture.go @@ -101,6 +101,16 @@ type Fixture struct { secure bool } +// noneRules are connector policy rules that deny nothing: rules that +// decide nothing at all do not load. +const noneRules = `package tapas.rules.none + +# METADATA +# title: Nothing +# description: Never fires. +deny contains rego.metadata.rule() if input.where.connector == "no connector has this name" +` + // Options change how New builds the gateway; the zero value is a gateway // with local sign-in, the shared namespace and default roles. type Options struct { @@ -345,7 +355,7 @@ func New(t *testing.T, o Options, objs ...any) *Fixture { } if o.ConnectorRules == "" { o.ConnectorRules = t.TempDir() - if err := os.WriteFile(filepath.Join(o.ConnectorRules, "none.rego"), []byte("package tapas.rules.none\n"), 0o600); err != nil { + if err := os.WriteFile(filepath.Join(o.ConnectorRules, "none.rego"), []byte(noneRules), 0o600); err != nil { t.Fatal(err) } } From e577fb23c7b933a6971fe6ae1c8a06e470ccd6dd Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:34:46 +0000 Subject: [PATCH 06/13] fix(connectors): audit plans made through the API and keep a held read's decision - A connector call planned through POST /api/plans, not through /mcp, now writes its audit row with the policy's decision, allowed or denied; without the row no plan is made. - A read the rules held for approval keeps that decision in its row, unless planning denied it. - A plan with no record of the agent that proposed it (one made before that record was kept) is denied when applied. --- internal/connectors/broker/action.go | 8 +++ internal/connectors/broker/action_test.go | 67 +++++++++++++++++++---- internal/connectors/broker/audit_test.go | 12 ++++ internal/connectors/broker/checkpolicy.go | 7 ++- internal/connectors/broker/propose.go | 4 +- 5 files changed, 82 insertions(+), 16 deletions(-) diff --git a/internal/connectors/broker/action.go b/internal/connectors/broker/action.go index 2a0b726b..9f23fa4b 100644 --- a/internal/connectors/broker/action.go +++ b/internal/connectors/broker/action.go @@ -76,8 +76,16 @@ func (a *CallAction) Plan(ctx context.Context, p actions.Proposal) (actions.Plan res = errorResult(c, outcomeToolError, reasons.Msg(reasons.MsgConnectorArgumentsInvalid)) } } + if res == nil { + c.outcome = outcomeProposed + } if r, ok := ctx.Value(planReportKey{}).(*planReport); ok { r.outcome, r.decision = c.outcome, c.decision + } else if err := a.b.appendRow(ctx, c); err != nil { + // Asked through the plans API, not through /mcp (where propose + // writes the row): this is the decision's only record, so no plan + // is made without it. + return actions.Planned{}, &Refusal{Kind: RefusedUnavailable, Message: serverError} } if res != nil { return actions.Planned{}, refusal(c, res) diff --git a/internal/connectors/broker/action_test.go b/internal/connectors/broker/action_test.go index e9417662..b329b2ad 100644 --- a/internal/connectors/broker/action_test.go +++ b/internal/connectors/broker/action_test.go @@ -20,6 +20,7 @@ import ( "github.com/nebari-dev/javo/internal/connectors/policy" "github.com/nebari-dev/javo/internal/connectors/registry" "github.com/nebari-dev/javo/internal/reasons" + "github.com/nebari-dev/javo/internal/store" ) // as is the connector-call action acting for c. @@ -136,11 +137,11 @@ func TestApplyingSendsTheStoredArgumentsOnce(t *testing.T) { if len(calls) != 1 || calls[0].Tool != "post" || calls[0].Bearer != bearer || string(calls[0].Arguments) != pl.Params["arguments"] { t.Fatalf("calls %+v", calls) } - rows := callRows(t, f.db) + r := planThenApply(t, f.db) var d map[string]any - if len(rows) != 1 || json.Unmarshal(rows[0].Detail, &d) != nil || d["outcome"] != "ok" || d["mode"] != "write" || d["policy"] != "allow" || - rows[0].Actor != "alice" || !rows[0].Allowed { - t.Fatalf("rows %+v", rows) + if json.Unmarshal(r.Detail, &d) != nil || d["outcome"] != "ok" || d["mode"] != "write" || d["policy"] != "allow" || + r.Actor != "alice" || !r.Allowed { + t.Fatalf("row %+v", r) } } @@ -211,14 +212,56 @@ func TestApplyingAnUnreadableProposerDenies(t *testing.T) { if err != nil { t.Fatal(err) } - pl.Params["agent"] = "{not json" - if err := as(f, owner()).Apply(ctx, pl.Proposal); err == nil || len(f.fake.Calls()) != 0 { - t.Fatalf("applied: %v, calls %v", err, f.fake.Calls()) + for _, agent := range []string{"{not json", ""} { + pl.Params["agent"] = agent + if err := as(f, owner()).Apply(ctx, pl.Proposal); err == nil || len(f.fake.Calls()) != 0 { + t.Fatalf("agent %q applied: %v, calls %v", agent, err, f.fake.Calls()) + } + var d map[string]any + if r := callRows(t, f.db)[0]; json.Unmarshal(r.Detail, &d) != nil || d["outcome"] != "denied_policy" || r.Allowed { + t.Fatalf("agent %q row %+v", agent, r) + } } +} + +// planThenApply is the row of an apply, the newest of exactly two: the +// plan's row, then the apply's. +func planThenApply(t *testing.T, db *store.Store) store.AuditEvent { + t.Helper() + rows := callRows(t, db) var d map[string]any - if rows := callRows(t, f.db); len(rows) != 1 || json.Unmarshal(rows[0].Detail, &d) != nil || d["outcome"] != "denied_policy" || rows[0].Allowed { + if len(rows) != 2 || json.Unmarshal(rows[1].Detail, &d) != nil || d["outcome"] != "proposed" { t.Fatalf("rows %+v", rows) } + return rows[0] +} + +// A plan asked for through the API, not through /mcp, is audited with the +// policy's decision too: allowed or denied. +func TestPlanningThroughTheAPIIsAudited(t *testing.T) { + t.Parallel() + for _, tc := range []struct { + name string + policy policy.Checker + outcome string + effect string + allowed bool + }{ + {"allowed", decided{policy.Decision{Effect: policy.Allow, Revision: "rev-1"}}, "proposed", "allow", true}, + {"held", decided{policy.Decision{Effect: policy.RequireApproval, Rules: []string{"Held"}, Revision: "rev-1"}}, "proposed", "require_approval", true}, + {"denied", decided{policy.Decision{Effect: policy.Deny, Reason: "No.", Rules: []string{"Never"}, Revision: "rev-1"}}, "denied_policy", "deny", false}, + } { + t.Run(tc.name, func(t *testing.T) { + f := newFixture(t, options{policy: tc.policy}) + _, _ = as(f, writer()).Plan(ctx, proposal(`{}`)) + rows := callRows(t, f.db) + var d map[string]any + if len(rows) != 1 || json.Unmarshal(rows[0].Detail, &d) != nil || d["outcome"] != tc.outcome || d["policy"] != tc.effect || + d["policyRevision"] != "rev-1" || rows[0].Allowed != tc.allowed || rows[0].Actor != "alice" { + t.Fatalf("rows %+v", rows) + } + }) + } } // Anything that changed since the plan was made stops it before the @@ -287,8 +330,8 @@ func TestApplyingChecksAgain(t *testing.T) { t.Fatalf("applied: %v, calls %v", err, f.fake.Calls()) } var d map[string]any - if rows := callRows(t, f.db); len(rows) != 1 || json.Unmarshal(rows[0].Detail, &d) != nil || d["outcome"] != "denied_policy" { - t.Fatalf("rows %+v", rows) + if r := planThenApply(t, f.db); json.Unmarshal(r.Detail, &d) != nil || d["outcome"] != "denied_policy" { + t.Fatalf("row %+v", r) } }) t.Run("approval is not enough", func(t *testing.T) { @@ -356,8 +399,8 @@ func TestAnApprovedCallWithNoAnswerMayHaveActed(t *testing.T) { t.Fatalf("applied: %v", err) } var d map[string]any - if rows := callRows(t, f.db); len(rows) != 1 || json.Unmarshal(rows[0].Detail, &d) != nil || d["outcome"] != tc.outcome { - t.Fatalf("rows %+v", rows) + if r := planThenApply(t, f.db); json.Unmarshal(r.Detail, &d) != nil || d["outcome"] != tc.outcome { + t.Fatalf("row %+v", r) } }) } diff --git a/internal/connectors/broker/audit_test.go b/internal/connectors/broker/audit_test.go index 3815b0f1..4c0d4dfc 100644 --- a/internal/connectors/broker/audit_test.go +++ b/internal/connectors/broker/audit_test.go @@ -110,6 +110,8 @@ func TestEachOutcomeWritesOneRow(t *testing.T) { detail: map[string]any{"tool": "post", "mode": "write", "outcome": "proposed", "policy": "require_approval", "policyRules": []any{"Held"}, "policyRevision": "rev-3", "plan": plans.StoredID("h-1")}}, {name: "rules denying a plan", o: options{policy: decided{policy.Decision{Effect: policy.Deny, Reason: "No.", Rules: []string{"Never"}, Revision: "rev-4"}}}, caller: proposing(writer()), tool: "fake__post", args: `{}`, allowed: false, detail: map[string]any{"tool": "post", "mode": "write", "outcome": "denied_policy", "policy": "deny", "policyRules": []any{"Never"}, "policyRevision": "rev-4"}}, + {name: "read held for approval", o: options{policy: decidedAt{policy.PhaseRead: {Effect: policy.RequireApproval, Rules: []string{"Held reads"}, Revision: "rev-5"}}}, caller: proposing(writer()), tool: "fake__echo", args: `{}`, allowed: true, + detail: map[string]any{"tool": "echo", "mode": "write", "outcome": "proposed", "policy": "require_approval", "policyRules": []any{"Held reads"}, "policyRevision": "rev-5", "plan": plans.StoredID("h-1")}}, {name: "denied_policy", o: options{policy: denyAll{&seen}}, caller: alice(), tool: "fake__echo", args: `{}`, allowed: false, detail: map[string]any{"tool": "echo", "mode": "read", "outcome": "denied_policy", "policy": "deny"}}, {name: "not_connected", o: options{tokens: connectorstest.StaticToken("")}, caller: alice(), tool: "fake__echo", args: `{}`, allowed: true, @@ -163,6 +165,16 @@ type decided struct{ d policy.Decision } func (c decided) Check(context.Context, policy.Input) (policy.Decision, error) { return c.d, nil } +// decidedAt answers the decision of a call's phase, and allow in the others. +type decidedAt map[policy.Phase]policy.Decision + +func (c decidedAt) Check(_ context.Context, in policy.Input) (policy.Decision, error) { + if d, ok := c[in.Phase]; ok { + return d, nil + } + return policy.Decision{Effect: policy.Allow}, nil +} + // Listing tools records nothing. func TestListingWritesNoRow(t *testing.T) { t.Parallel() diff --git a/internal/connectors/broker/checkpolicy.go b/internal/connectors/broker/checkpolicy.go index 8cec1d92..7d9d6f68 100644 --- a/internal/connectors/broker/checkpolicy.go +++ b/internal/connectors/broker/checkpolicy.go @@ -44,7 +44,7 @@ func (b *Broker) checkPolicy(ctx context.Context, c *call) *sdk.CallToolResult { } // policyInput is c as the policy sees it; false when an approved call's -// record of who proposed it cannot be read. +// record of who proposed it is missing or cannot be read. func (c *call) policyInput() (policy.Input, bool) { in := policy.Input{ Checkpoint: policy.CheckpointToolCall, @@ -56,9 +56,10 @@ func (c *call) policyInput() (policy.Input, bool) { } if c.phase == phaseApply { // The owner approves in the browser: the agent is the one that - // proposed the call, as recorded when it was planned. + // proposed the call, as recorded when it was planned. A plan with + // no such record (made before it was kept) is not applied. in.Agent = policy.Agent{} - if c.proposer != "" && json.Unmarshal([]byte(c.proposer), &in.Agent) != nil { + if json.Unmarshal([]byte(c.proposer), &in.Agent) != nil { return policy.Input{}, false } in.Approval = &policy.Approval{Plan: c.plan, By: c.caller.Principal.ID} diff --git a/internal/connectors/broker/propose.go b/internal/connectors/broker/propose.go index ece84cd2..f8b59974 100644 --- a/internal/connectors/broker/propose.go +++ b/internal/connectors/broker/propose.go @@ -37,7 +37,9 @@ func (b *Broker) propose(ctx context.Context, c *call) *sdk.CallToolResult { p, err := c.caller.Propose(context.WithValue(ctx, planReportKey{}, planned), actions.Proposal{ Action: actions.ConnectorCall, Target: c.name, Params: map[string]string{argumentsParam: string(c.args)}, }) - if planned.decision.Effect != "" { + // The read phase's decision stays when it is what made the call a + // plan, unless planning denied it. + if c.decision.Effect == "" || planned.decision.Effect == policy.Deny { c.decision = planned.decision } var refused *connectors.ProposalRefused From 6c12190ad733ef1baafe83b03829bd32f7624db1 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:34:46 +0000 Subject: [PATCH 07/13] fix(helm,docs): mount rules at rulesDir and match the docs to the checks - The chart mounts the rules at config.connectors.policy.rulesDir when it is set, so the gateway reads them where they are. - The Frames example drops a deny that could never fire: Tapas applies a plan only for the person who approved it. - The docs drop agent.client, add opa check --strict, say agent.name and agent.app are chosen by the app's owner, and list every case now refused at load. --- deploy/helm/javo/templates/_helpers.tpl | 6 +++-- deploy/policy/examples/frames.rego | 9 ------- deploy/policy/examples/frames_test.rego | 10 +------- .../connectors/policy/opa/examples_test.go | 1 - .../content/docs/admin/connector-policy.md | 25 ++++++++++++------- test/helm/connectorpolicy_test.go | 18 +++++++++++-- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/deploy/helm/javo/templates/_helpers.tpl b/deploy/helm/javo/templates/_helpers.tpl index 07d2b081..6e4f8ead 100644 --- a/deploy/helm/javo/templates/_helpers.tpl +++ b/deploy/helm/javo/templates/_helpers.tpl @@ -498,9 +498,11 @@ imagePullSecrets: {{- end -}} {{- end -}} -{{/* Where the gateway reads the connector policy's rules. */}} +{{/* Where the gateway reads the connector policy's rules, and so where +they are mounted: config.connectors.policy.rulesDir, by default +/etc/javo-policy. */}} {{- define "javo.connectorPolicyDir" -}} -/etc/javo-policy +{{- (default (dict) (default (dict) .Values.config.connectors).policy).rulesDir | default "/etc/javo-policy" -}} {{- end -}} {{/* The ConfigMap of connector policy rules the gateway mounts; empty with diff --git a/deploy/policy/examples/frames.rego b/deploy/policy/examples/frames.rego index 6b186281..6282d701 100644 --- a/deploy/policy/examples/frames.rego +++ b/deploy/policy/examples/frames.rego @@ -12,12 +12,3 @@ require_approval contains rego.metadata.rule() if { input.where.tool in write not input.approval } - -# METADATA -# title: Frames changes are approved by their owner -# description: A change to a Frame is made only with the approval of the person it is made for. -deny contains rego.metadata.rule() if { - input.where.connector == "frames" - input.where.tool in write - input.approval.by != input.who.person -} diff --git a/deploy/policy/examples/frames_test.rego b/deploy/policy/examples/frames_test.rego index a1268396..dda308fe 100644 --- a/deploy/policy/examples/frames_test.rego +++ b/deploy/policy/examples/frames_test.rego @@ -16,25 +16,17 @@ approved(by) := object.union(update, {"phase": "apply", "approval": {"plan": "p- test_a_change_needs_approval if { count(frames.require_approval) == 1 with input as update - count(frames.deny) == 0 with input as update } test_a_create_needs_approval if { count(frames.require_approval) == 1 with input as object.union(update, {"where": {"connector": "frames", "tool": "create_frame", "mode": "write"}}) } -test_the_owners_approval_lets_it_through if { +test_an_approved_change_goes_ahead if { count(frames.require_approval) == 0 with input as approved("alice@example.com") - count(frames.deny) == 0 with input as approved("alice@example.com") -} - -test_someone_elses_approval_is_denied if { - some d in frames.deny with input as approved("bob@example.com") - d.title == "Frames changes are approved by their owner" } test_reads_pass if { read := object.union(update, {"where": {"connector": "frames", "tool": "get_frame", "mode": "read"}}) count(frames.require_approval) == 0 with input as read - count(frames.deny) == 0 with input as read } diff --git a/internal/connectors/policy/opa/examples_test.go b/internal/connectors/policy/opa/examples_test.go index a98e22b2..d9d00d07 100644 --- a/internal/connectors/policy/opa/examples_test.go +++ b/internal/connectors/policy/opa/examples_test.go @@ -77,7 +77,6 @@ func TestTheExamplesDecideCalls(t *testing.T) { {"an approved email send", approved(in(nil, "gmail", "send_email"), "alice@example.com"), policy.Allow}, {"a Frames update", in(nil, "frames", "update_frame"), policy.RequireApproval}, {"a Frames create approved by its owner", approved(in(nil, "frames", "create_frame"), "alice@example.com"), policy.Allow}, - {"a Frames update approved by another", approved(in(nil, "frames", "update_frame"), "bob@example.com"), policy.Deny}, {"a Frames read", in(nil, "frames", "get_frame"), policy.Allow}, {"anything else", in(nil, "slack", "post"), policy.Allow}, } { diff --git a/site/src/content/docs/admin/connector-policy.md b/site/src/content/docs/admin/connector-policy.md index 0dbdba77..f3b94e3f 100644 --- a/site/src/content/docs/admin/connector-policy.md +++ b/site/src/content/docs/admin/connector-policy.md @@ -39,7 +39,6 @@ Each check gives the rules one input document, the same shape at every phase. Wh "name": "helper", "app": "helper-1", "token": "t-1", - "client": "claude-code", "scheduled": false }, "where": { @@ -63,10 +62,9 @@ Each check gives the rules one input document, the same shape at every phase. Wh | `checkpoint` | Always `tool_call` for now. | | `phase` | `read`, `propose` or `apply` (see above). | | `who.person`, `who.groups` | The person the agent acts for, and their groups. | -| `agent.name` | The short name of the coding agent app that made the call; empty for a personal token. | -| `agent.app` | The name of the app the token belongs to; empty for a personal token. | +| `agent.name` | The short name of the coding agent app that made the call; empty for a personal token. Its owner chooses it, so a rule that names a kind of agent by it can be sidestepped by renaming the app. | +| `agent.app` | The name of the app the token belongs to; empty for a personal token. Chosen by its owner too. | | `agent.token` | The id of the token that made the call. | -| `agent.client` | What the MCP client calls itself. The client chooses it, so use it for display, never to decide. | | `agent.scheduled` | `true` when a scheduled job's token made the call. | | `where.connector`, `where.tool` | The connector's short name and the tool called. | | `where.mode` | `read` or `write`, as the admin marked the tool. | @@ -120,17 +118,20 @@ require_approval contains rego.metadata.rule() if { } ``` -At `apply` you can also check the approval itself, such as `input.approval.by == input.who.person`. +Tapas applies a plan only for the person it was proposed for, after they approve it in the browser, so `input.approval.by` is always `input.who.person`. ## Testing rules Test the rules with the OPA CLI, pinned to the version Tapas embeds, **v1.22.4**, so both read the rules the same way. Put tests in files ending in `_test.rego` next to the rules: Tapas skips those files when it loads the rules. ```sh +opa check --strict path/to/rules/ opa test -v path/to/rules/ ``` -`deploy/policy/examples/` in the Tapas repository has example rules (Greenhouse for recruiting only, approval for email sends, approval for Frames changes by their owner) with their tests, a good start for your own. +Tapas compiles rules in strict mode (an unused variable or import is an error), so run `opa check --strict` as well: `opa test` alone passes rules Tapas refuses. Tapas also checks every `input.` path a rule reads against the input document above, and refuses a rule that reads a field the input does not have, such as a misspelt `input.where.conector`. + +`deploy/policy/examples/` in the Tapas repository has example rules (Greenhouse for recruiting only, approval for email sends, approval for Frames changes) with their tests, a good start for your own. ## Loading the rules @@ -170,17 +171,23 @@ Changing the rules needs no restart. Kubernetes updates the mounted files about Every one of these denies the call: - No rules have loaded since the gateway started: the directory is missing, unreadable or has no `.rego` files, or the first rules do not load. +- The policy check fails for any reason. The gateway logs why, with the connector, the tool and the rules' revision (never the arguments). - Evaluating the rules fails, or takes more than 2 seconds. - A `deny` or `require_approval` element has no title or description, or the rules give an answer of any other shape. - `require_approval` at `apply` (see above). -- The record of which agent proposed a plan cannot be read when it is applied. +- The record of which agent proposed a plan is missing or cannot be read when it is applied (a plan proposed before an upgrade that added it, for example). Rules are refused when they load (and the last good ones stay) when: - a file does not parse; - a package is outside `tapas.rules.`, `tapas.admin.` and `tapas.lib`; -- a `deny` or `require_approval` rule has no METADATA title and description, is not a partial set (`contains`), is a `default` rule, or sits in `tapas.lib`; -- a rule uses a built-in that reaches outside the gateway: `http.send`, `net.lookup_ip_addr` or `opa.runtime` (the network and the gateway's environment). +- a `deny` or `require_approval` rule has no METADATA title and description, is not a partial set (`contains`), is a `default` rule, sits in `tapas.lib`, or is nested in another name (`x.deny`), where it would never be read; +- no file has a `deny` or `require_approval` rule at all: rules that can decide nothing are taken for rules that did not load; +- a rule reads an `input.` field the input document does not have; +- a rule is not valid in strict mode; +- a rule uses a built-in that reaches outside the gateway: `http.send`, `net.lookup_ip_addr`, `opa.runtime`, `json.match_schema` or `json.verify_schema` (the network, local files through a schema's `$ref`, and the gateway's environment). + +A set of files that failed to load is logged once; it is not loaded again until the files change. ## Where decisions are recorded diff --git a/test/helm/connectorpolicy_test.go b/test/helm/connectorpolicy_test.go index 8a60abd4..5c1f0eec 100644 --- a/test/helm/connectorpolicy_test.go +++ b/test/helm/connectorpolicy_test.go @@ -22,10 +22,16 @@ var examples = filepath.Join("..", "..", "deploy", "policy", "examples") // policyVolume returns the gateway's volume mounted at /etc/javo-policy and // whether the gateway mounts one there (whole, not a subPath). func policyVolume(t *testing.T, d appsv1.Deployment) (corev1.Volume, bool) { + t.Helper() + return policyVolumeAt(t, d, "/etc/javo-policy") +} + +// policyVolumeAt is policyVolume at dir. +func policyVolumeAt(t *testing.T, d appsv1.Deployment, dir string) (corev1.Volume, bool) { t.Helper() for _, c := range d.Spec.Template.Spec.Containers { for _, m := range c.VolumeMounts { - if m.MountPath != "/etc/javo-policy" { + if m.MountPath != dir { continue } if m.SubPath != "" || !m.ReadOnly { @@ -97,7 +103,7 @@ func TestConnectorRulesFromAnExistingConfigMap(t *testing.T) { } } -func TestAnExplicitRulesDirIsKept(t *testing.T) { +func TestAnExplicitRulesDirIsWhereTheRulesAreMounted(t *testing.T) { t.Parallel() out, err := render(t, append(connectorsOn, "--set", "connectorPolicy.configMap=tapas-rules", "--set", "config.connectors.policy.rulesDir=/srv/rules")...) @@ -107,6 +113,14 @@ func TestAnExplicitRulesDirIsKept(t *testing.T) { if dir := loadedConfig(t, out).Connectors.Policy.RulesDir; dir != "/srv/rules" { t.Fatalf("rulesDir = %q", dir) } + // The rules are mounted where the gateway reads them, not elsewhere. + d := deploymentOf(t, out, "sqlite", "gateway") + if v, ok := policyVolumeAt(t, d, "/srv/rules"); !ok || v.ConfigMap == nil || v.ConfigMap.Name != "tapas-rules" { + t.Fatalf("rules volume at /srv/rules = %+v (mounted %v)", v, ok) + } + if _, ok := policyVolume(t, d); ok { + t.Fatal("rules also mounted at /etc/javo-policy") + } } func TestConnectorsNeedOneSourceOfRules(t *testing.T) { From a79c784e63005835bed098ca62747cbdc3144ace Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 12:39:15 +0000 Subject: [PATCH 08/13] fix(connectors): refuse computed rule names and keep argument values out of logs - A rule in tapas.rules or tapas.admin whose name is computed (y[k]) could be deny without being read where deny is; such names are now refused when the rules load. - A failed evaluation is described by OPA's error code and the rule's file and line, not OPA's message, which can quote an argument's value into the gateway log. - A load cut short by its context does not mark the files as broken. - Test: a plan whose audit row cannot be written is not made. --- internal/connectors/broker/action_test.go | 10 ++++ internal/connectors/policy/opa/opa.go | 28 +++++++++- internal/connectors/policy/opa/opa_test.go | 62 ++++++++++++++-------- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/internal/connectors/broker/action_test.go b/internal/connectors/broker/action_test.go index b329b2ad..9bbeb9f2 100644 --- a/internal/connectors/broker/action_test.go +++ b/internal/connectors/broker/action_test.go @@ -224,6 +224,16 @@ func TestApplyingAnUnreadableProposerDenies(t *testing.T) { } } +// A plan asked for through the API whose audit row cannot be written is +// not made: the row is the decision's only record. +func TestPlanningWithoutAnAuditRowIsRefused(t *testing.T) { + t.Parallel() + f := newFixture(t, options{audit: brokenAudit{}}) + if _, err := as(f, writer()).Plan(ctx, proposal(`{}`)); kind(t, err) != broker.RefusedUnavailable { + t.Fatalf("planned: %v", err) + } +} + // planThenApply is the row of an apply, the newest of exactly two: the // plan's row, then the apply's. func planThenApply(t *testing.T, db *store.Store) store.AuditEvent { diff --git a/internal/connectors/policy/opa/opa.go b/internal/connectors/policy/opa/opa.go index 95302ac4..e473dfe4 100644 --- a/internal/connectors/policy/opa/opa.go +++ b/internal/connectors/policy/opa/opa.go @@ -41,6 +41,7 @@ import ( "github.com/open-policy-agent/opa/v1/ast" "github.com/open-policy-agent/opa/v1/rego" + "github.com/open-policy-agent/opa/v1/topdown" "github.com/open-policy-agent/opa/v1/util" "github.com/nebari-dev/javo/internal/connectors/policy" @@ -165,7 +166,9 @@ func (e *Engine) load(ctx context.Context) error { } q, err := compile(ctx, files) if err != nil { - e.failed, e.failedErr = rev, err + if ctx.Err() == nil { // the files' fault, not a load cut short + e.failed, e.failedErr = rev, err + } return err } e.failed, e.failedErr = "", nil @@ -338,6 +341,11 @@ func checkModule(name string, m *ast.Module) (int, error) { } n := 0 for _, r := range m.Rules { + // A name computed at run time (y[k]) could be deny without being + // read where deny is: in the rules' packages names are fixed. + if collected && !r.Head.Ref().IsGround() { + return 0, fmt.Errorf("%s:%d: %v: a rule's name may not be computed in tapas.rules or tapas.admin", name, r.Location.Row, r.Head.Ref()) + } rule, ok := effectIn(r.Head.Ref()) if !ok { continue @@ -398,7 +406,7 @@ func (e *Engine) Check(ctx context.Context, in policy.Input) (policy.Decision, e defer cancel() rs2, err := rs.query.Eval(ctx, rego.EvalParsedInput(doc)) if err != nil { - return policy.Decision{}, fmt.Errorf("evaluate the rules (revision %s): %w", rs.revision, err) + return policy.Decision{}, fmt.Errorf("evaluate the rules (revision %s): %s", rs.revision, evalFailure(err)) } d, err := decide(rs2) if err != nil { @@ -408,6 +416,22 @@ func (e *Engine) Check(ctx context.Context, in policy.Input) (policy.Decision, e return d, nil } +// evalFailure says what went wrong evaluating, by its kind and where in +// the rules, never by OPA's own message, which can quote values the rules +// read (an argument a built-in could not parse, say). +func evalFailure(err error) string { + var te *topdown.Error + switch { + case errors.As(err, &te) && te.Location != nil: + return fmt.Sprintf("%s at %s:%d", te.Code, te.Location.File, te.Location.Row) + case errors.As(err, &te): + return te.Code + case errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled): + return "cancelled: " + err.Error() + } + return fmt.Sprintf("%T", err) +} + // inputValue is in as Rego reads it, numbers kept exact. func inputValue(in policy.Input) (ast.Value, error) { if in.Findings == nil { diff --git a/internal/connectors/policy/opa/opa_test.go b/internal/connectors/policy/opa/opa_test.go index a31bb151..ed4ebc32 100644 --- a/internal/connectors/policy/opa/opa_test.go +++ b/internal/connectors/policy/opa/opa_test.go @@ -228,27 +228,28 @@ func TestRulesThatCannotBeLoaded(t *testing.T) { t.Parallel() meta := "# METADATA\n# title: T\n# description: D.\n" for name, src := range map[string]string{ - "syntax error": "package tapas.rules.x\n\ndeny contains if {", - "outside tapas": "package other\n\nx := 1\n", - "nested rules package": "package tapas.rules.a.b\n\n" + meta + "deny contains rego.metadata.rule() if true\n", - "tapas root": "package tapas\n\nx := 1\n", - "deny in the library": "package tapas.lib\n\n" + meta + "deny contains rego.metadata.rule() if true\n", - "deny as a boolean": "package tapas.rules.x\n\n" + meta + "deny if true\n", - "deny as a value": "package tapas.rules.x\n\n" + meta + "deny := {rego.metadata.rule()}\n", - "deny without a title": "package tapas.rules.x\n\n# METADATA\n# description: D.\ndeny contains rego.metadata.rule() if true\n", - "approval without detail": "package tapas.rules.x\n\n# METADATA\n# title: T\nrequire_approval contains rego.metadata.rule() if true\n", - "deny under another name": "package tapas.rules.x\n\n" + meta + "y.deny contains rego.metadata.rule() if true\n", - "approval under a name": "package tapas.rules.x\n\n" + meta + "y.require_approval contains rego.metadata.rule() if true\n", - "deny deeper in the lib": "package tapas.lib\n\n" + meta + "x.deny contains rego.metadata.rule() if true\n", - "json schema by URL": "package tapas.rules.x\n\nx := json.match_schema({}, {\"$ref\": \"http://127.0.0.1:1/s.json\"})\n", - "json schema from a file": "package tapas.rules.x\n\nx := json.verify_schema({\"$ref\": \"file:///etc/passwd\"})\n", - "a misspelt input field": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.where.conector == \"slack\"\n", - "a field not in the input": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.agent.client == \"x\"\n", - "no deny or approval rule": "package tapas.rules.x\n\nsend := {\"send_email\"}\n", - "http.send": "package tapas.rules.x\n\nx := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", - "net.lookup_ip_addr": "package tapas.rules.x\n\nx := net.lookup_ip_addr(\"example.com\")\n", - "opa.runtime": "package tapas.rules.x\n\nx := opa.runtime()\n", - "unknown function": "package tapas.rules.x\n\nx := nope(1)\n", + "syntax error": "package tapas.rules.x\n\ndeny contains if {", + "outside tapas": "package other\n\nx := 1\n", + "nested rules package": "package tapas.rules.a.b\n\n" + meta + "deny contains rego.metadata.rule() if true\n", + "tapas root": "package tapas\n\nx := 1\n", + "deny in the library": "package tapas.lib\n\n" + meta + "deny contains rego.metadata.rule() if true\n", + "deny as a boolean": "package tapas.rules.x\n\n" + meta + "deny if true\n", + "deny as a value": "package tapas.rules.x\n\n" + meta + "deny := {rego.metadata.rule()}\n", + "deny without a title": "package tapas.rules.x\n\n# METADATA\n# description: D.\ndeny contains rego.metadata.rule() if true\n", + "approval without detail": "package tapas.rules.x\n\n# METADATA\n# title: T\nrequire_approval contains rego.metadata.rule() if true\n", + "deny under another name": "package tapas.rules.x\n\n" + meta + "y.deny contains rego.metadata.rule() if true\n", + "approval under a name": "package tapas.rules.x\n\n" + meta + "y.require_approval contains rego.metadata.rule() if true\n", + "deny deeper in the lib": "package tapas.lib\n\n" + meta + "x.deny contains rego.metadata.rule() if true\n", + "json schema by URL": "package tapas.rules.x\n\nx := json.match_schema({}, {\"$ref\": \"http://127.0.0.1:1/s.json\"})\n", + "json schema from a file": "package tapas.rules.x\n\nx := json.verify_schema({\"$ref\": \"file:///etc/passwd\"})\n", + "a misspelt input field": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.where.conector == \"slack\"\n", + "a field not in the input": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.agent.client == \"x\"\n", + "no deny or approval rule": "package tapas.rules.x\n\nsend := {\"send_email\"}\n", + "deny under a computed name": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if false\n\n" + meta + "y[k] contains rego.metadata.rule() if { k := \"deny\"; input.where.connector == \"slack\" }\n", + "http.send": "package tapas.rules.x\n\nx := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", + "net.lookup_ip_addr": "package tapas.rules.x\n\nx := net.lookup_ip_addr(\"example.com\")\n", + "opa.runtime": "package tapas.rules.x\n\nx := opa.runtime()\n", + "unknown function": "package tapas.rules.x\n\nx := nope(1)\n", } { t.Run(name, func(t *testing.T) { e := opa.New(opa.Config{Dir: write(t, map[string]string{"x.rego": src})}) @@ -296,6 +297,25 @@ deny contains rego.metadata.rule() if to_number(input.what.arguments.n) > 1 } } +// What a rule saw, such as an argument's value, is not in the error a +// failed check gives (which is logged). +func TestAFailedCheckDoesNotCarryTheArguments(t *testing.T) { + t.Parallel() + e := loaded(t, map[string]string{"x.rego": `package tapas.rules.x + +# METADATA +# title: T +# description: D. +deny contains rego.metadata.rule() if to_number(input.what.arguments.n) > 1 +`}) + in := input("alice", nil, "slack", "post") + in.What.Arguments = json.RawMessage(`{"n":"SECRET-ARG-123"}`) + _, err := e.Check(ctx, in) + if err == nil || strings.Contains(err.Error(), "SECRET") || !strings.Contains(err.Error(), "x.rego") { + t.Fatalf("error %v", err) + } +} + func TestASlowEvaluationTimesOutAndDenies(t *testing.T) { t.Parallel() e := opa.New(opa.Config{Timeout: 20 * time.Millisecond, Dir: write(t, map[string]string{"slow.rego": `package tapas.rules.slow From fa3a9e9a9acd119ca846353e7397ae2a4e3b8a7a Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 13:07:24 +0000 Subject: [PATCH 09/13] test(localbuild): fail when a local build imports the policy engine The local build leaves Open Policy Agent out; nothing checked that cut, so an import from a file both builds compile would have gone unnoticed. --- test/localbuild/localbuild_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/localbuild/localbuild_test.go b/test/localbuild/localbuild_test.go index e9b85c75..4b8ea274 100644 --- a/test/localbuild/localbuild_test.go +++ b/test/localbuild/localbuild_test.go @@ -3,8 +3,9 @@ // Package localbuild checks what a javo built with the tag local // (make local) leaves out, so that it stays small: the Kubernetes client // and what runs Tapas on a cluster, the model providers' clients, the -// secret scanner, the failure-notice engine, the MCP endpoint, the OpenID -// Connect client and the Postgres driver. Each is in files the tag leaves +// secret scanner, the failure-notice engine, the MCP endpoint, the +// connector policy engine (Open Policy Agent), the OpenID Connect client +// and the Postgres driver. Each is in files the tag leaves // out, or in a package only such files import, so none is imported at // all. That cut does not fail a build when it is undone: an import in a // file both builds compile only makes the binary larger. The default @@ -74,6 +75,9 @@ var notImported = []leftOut{ {path: javo + "connectors/client"}, {path: javo + "connectors/oauth"}, {path: "github.com/modelcontextprotocol/go-sdk"}, + // The connector policy engine, Open Policy Agent. + {path: javo + "connectors/policy/opa"}, + {path: "github.com/open-policy-agent/opa"}, {path: javo + "features/authoidc"}, {path: "github.com/coreos/go-oidc"}, {path: "github.com/go-jose/go-jose"}, From 83b860b7163519cb3408f19abc6553969ced04a9 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 13:07:48 +0000 Subject: [PATCH 10/13] docs: match connector docs to the policy checks - Rules are mounted at connectors.policy.rulesDir, which the chart sets to /etc/javo-policy unless it is set. - Reads no longer run straight away: the policy can deny them or hold them for approval, and the person sees the policy's reason. - Rules only take access away; Tapas's own access check runs first. - Computed rule names are listed among what is refused at load. - The architecture page names the policy check; DEPENDENCIES lists v1/topdown and the refused JSON schema built-ins. --- DEPENDENCIES.md | 4 ++-- site/src/content/docs/admin/connector-policy.md | 5 ++++- site/src/content/docs/admin/connectors.md | 2 +- site/src/content/docs/architecture/index.md | 2 +- site/src/content/docs/using/ask-ai.md | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index dfda4400..1ea3a915 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -375,11 +375,11 @@ Typo-squat check: each module path is the vendor's own (GitHub orgs anthropics, ### Connector policy: Open Policy Agent (checked 2026-12-01) -Embedded in the gateway as a library (`internal/connectors/policy/opa`) to check every connector call against Rego rules. Only `v1/ast`, `v1/rego` and `v1/util` are imported; OPA's server, bundle downloader, plugins and telemetry are not compiled in. Not linked into a `javo local` build. +Embedded in the gateway as a library (`internal/connectors/policy/opa`) to check every connector call against Rego rules. Only `v1/ast`, `v1/rego`, `v1/topdown` (its error type, to log a failed evaluation by code and place) and `v1/util` are imported; OPA's server, bundle downloader, plugins and telemetry are not compiled in. Not linked into a `javo local` build. | Dependency | Version | Released | Maintainers / source | OSV | Install scripts | Notes | |---|---|---|---|---|---|---| -| github.com/open-policy-agent/opa | v1.22.4 | 2026-11-12 | open-policy-agent org (CNCF graduated, 12.5k stars, not archived); MAINTAINERS.md at the tag lists anderseknert, ashutosh-narkar, charlieegan3, srenatus, tsandall and others, unchanged in 90 days except a conftest maintainer added 2026-09-30; release commit by srenatus, release published by the project's release workflow; tag commit ba39415 matches the proxy origin | clean (`{}` for 1.22.4) | none | v1.23.0 is 5 days old, so v1.22.4 (19 days) is the newest release at least 14 days old. 1.22.x patch releases (11-05, 11-05, 11-10, 11-12) are fixes rebuilt for Go advisories, each with a GitHub release; no burst after inactivity. Built-ins that reach outside the gateway (`http.send`, `net.lookup_ip_addr`, `opa.runtime`) are refused when rules load | +| github.com/open-policy-agent/opa | v1.22.4 | 2026-11-12 | open-policy-agent org (CNCF graduated, 12.5k stars, not archived); MAINTAINERS.md at the tag lists anderseknert, ashutosh-narkar, charlieegan3, srenatus, tsandall and others, unchanged in 90 days except a conftest maintainer added 2026-09-30; release commit by srenatus, release published by the project's release workflow; tag commit ba39415 matches the proxy origin | clean (`{}` for 1.22.4) | none | v1.23.0 is 5 days old, so v1.22.4 (19 days) is the newest release at least 14 days old. 1.22.x patch releases (11-05, 11-05, 11-10, 11-12) are fixes rebuilt for Go advisories, each with a GitHub release; no burst after inactivity. Built-ins that reach outside the gateway (`http.send`, `net.lookup_ip_addr`, `opa.runtime`, and `json.match_schema` and `json.verify_schema`, which fetch a schema's `$ref` by URL or file path) are refused when rules load | | modules raised or added by it (indirect) | spf13/pflag v1.1.0, agnivade/levenshtein v1.2.2, decred/dcrd/dcrec/secp256k1/v4 v4.4.1, fsnotify v1.10.1, go-openapi/jsonpointer and jsonreference v1.0.1, go-openapi/swag/* v0.29.2, gobwas/glob v1.1.0, goccy/go-json v0.11.2, grpc-gateway/v2 v2.31.0, klauspost/compress v1.20.3, lestrrat-go/{blackmagic v1.0.4, dsig v1.4.0, dsig-secp256k1 v1.0.0, httpcc v1.0.1, httprc/v3 v3.0.6, jwx/v3 v3.4.0, option/v2 v2.0.0}, prometheus/client_golang v1.25.0, client_model v0.6.3, common v0.72.0, sirupsen/logrus v1.10.2, tetratelabs/wazero v1.12.0, valyala/fastjson v1.6.10, vektah/gqlparser/v2 v2.5.64, xeipuuv/gojsonpointer and gojsonreference (2019, 2018 pseudo-versions), yashtewari/glob-intersection v0.2.0, otel/proto/otlp v1.11.1, go.yaml.in/yaml/v3 v3.0.6, google.golang.org/grpc v1.85.0, gopkg.in/ini.v1 v1.67.3 | each 32 days old or more | OPA's requirements | clean (OSV batch query of each exact version: none) | none | none under 14 days old. Transitive: `govulncheck@v1.9.0 ./...` reports no vulnerability reached; the one module-level finding is GO-2026-5932 in golang.org/x/crypto v0.58.0, unchanged by this addition (see above) | Typo-squat check: `github.com/open-policy-agent/opa` is the module path the OPA documentation (openpolicyagent.org) names for Go integration. diff --git a/site/src/content/docs/admin/connector-policy.md b/site/src/content/docs/admin/connector-policy.md index f3b94e3f..a327ee8c 100644 --- a/site/src/content/docs/admin/connector-policy.md +++ b/site/src/content/docs/admin/connector-policy.md @@ -7,6 +7,8 @@ sidebar: Every call an agent makes through a [connector](/admin/connectors/) is checked against your organisation's rules before Tapas forwards it. The rules are [Rego](https://www.openpolicyagent.org/docs/policy-language) files, evaluated by Open Policy Agent (OPA) inside the gateway. With connectors on, the gateway needs rules: with none loaded, every connector call is denied. +Rules can only take access away. Tapas's own access check (the connector is on, the person is in one of its allowed groups, the tool is not off) runs first, and a call it refuses never reaches the rules. So an `allow` means "no rule objects", not "this person may". + OPA is enforcement; Frames are context and never carry a rule that must hold. ## When a call is checked @@ -162,7 +164,7 @@ connectorPolicy: configMap: tapas-connector-rules ``` -Either way the gateway mounts the ConfigMap at `/etc/javo-policy`, and the chart sets `connectors.policy.rulesDir` to it unless you set it yourself. +Either way the gateway mounts the ConfigMap at `connectors.policy.rulesDir`, which the chart sets to `/etc/javo-policy` unless you set it yourself. Changing the rules needs no restart. Kubernetes updates the mounted files about a minute after the ConfigMap changes, and the gateway reads the directory every 10 seconds and loads what changed. A change that does not load (a syntax error, a rule breaking the contract) is logged with the reason, and the last rules that loaded stay in force. Each loaded rule set has a revision, a short hash of its files' names and contents, which the log names when rules load and each decision records. @@ -182,6 +184,7 @@ Rules are refused when they load (and the last good ones stay) when: - a file does not parse; - a package is outside `tapas.rules.`, `tapas.admin.` and `tapas.lib`; - a `deny` or `require_approval` rule has no METADATA title and description, is not a partial set (`contains`), is a `default` rule, sits in `tapas.lib`, or is nested in another name (`x.deny`), where it would never be read; +- a rule in `tapas.rules.` or `tapas.admin.` has a name computed when it runs (`y[k]`), which could make a `deny` that is never read; - no file has a `deny` or `require_approval` rule at all: rules that can decide nothing are taken for rules that did not load; - a rule reads an `input.` field the input document does not have; - a rule is not valid in strict mode; diff --git a/site/src/content/docs/admin/connectors.md b/site/src/content/docs/admin/connectors.md index 51fd26af..2b00cc8f 100644 --- a/site/src/content/docs/admin/connectors.md +++ b/site/src/content/docs/admin/connectors.md @@ -32,7 +32,7 @@ Connectors need the gateway's sessions key to survive restarts (`--sessions-key- 2. At the vendor, create an OAuth app and give it the **redirect address** the form shows. Each connector has its own address, `https:///settings/connections/callback/`; the vendor must have it exactly. 3. Paste the OAuth client id and secret. The secret is never shown again; leave the field empty to keep it. Some servers (such as Notion's) register a client themselves: leave both empty. 4. Choose the **allowed groups**. `*` means every member; an empty list means nobody. Being a platform admin does not let you use a connector. -5. Mark each tool **read**, **write** or **off**. Reads run straight away; writes (and any tool not marked) become a request the person approves in the browser; off tools are not offered. **Refresh tools** reads the server's current list, signed in with your own account, so connect yours first. +5. Mark each tool **read**, **write** or **off**. Reads run once the [connector policy](/admin/connector-policy/) allows them (its rules can also deny a read or hold it for approval); writes (and any tool not marked) become a request the person approves in the browser; off tools are not offered. **Refresh tools** reads the server's current list, signed in with your own account, so connect yours first. Every person connects their own account in **Settings, Connected accounts**, and their agents act as them at the vendor. There is no account an admin connects for everyone. diff --git a/site/src/content/docs/architecture/index.md b/site/src/content/docs/architecture/index.md index 7ac7b9b0..276baad8 100644 --- a/site/src/content/docs/architecture/index.md +++ b/site/src/content/docs/architecture/index.md @@ -32,7 +32,7 @@ Solid arrows are always there; dotted ones only when that feature is on. - **Nebi** (optional): where people keep shared pixi environments. - **S3 bucket** (optional): where backups go, as restic repositories. - **mem0** (optional): the mem0 pack, which keeps memory for people's agents. The gateway reads its key and talks to it over the cluster network. -- **Connectors** (optional): vendors' MCP servers (Slack, GitHub and others) and their OAuth authorization servers, or MCP servers inside the cluster. The gateway signs each person in to them, keeps their tokens and forwards their agents' tool calls. See [Connectors](/admin/connectors/). +- **Connectors** (optional): vendors' MCP servers (Slack, GitHub and others) and their OAuth authorization servers, or MCP servers inside the cluster. The gateway signs each person in to them, keeps their tokens and forwards their agents' tool calls. Each call is first checked against Rego rules read from a mounted directory (a ConfigMap in the chart) and reloaded when it changes; see [Connector policy](/admin/connector-policy/). - **AI model** (optional): an OpenAI-compatible server or Anthropic, for Ask AI. - **Git hosts**: apps can run from a repository; GitHub pull requests can get preview apps. diff --git a/site/src/content/docs/using/ask-ai.md b/site/src/content/docs/using/ask-ai.md index e89c2ea3..00eb1675 100644 --- a/site/src/content/docs/using/ask-ai.md +++ b/site/src/content/docs/using/ask-ai.md @@ -32,4 +32,4 @@ An agent can read what you can read through API routes that answer JSON. Streams ### Connector tools -When your admin has added connectors (such as Slack or GitHub) and you have connected your account to one, the agent also sees that connector's tools, named `__` (for example `slack__post_message`). Tools your admin marked as reads run straight away. Every other tool only **proposes** the call: the agent gets a link, and the call waits as a plan showing each value it will send, exactly as it will be sent. When you approve it in the browser, Tapas checks again that the connector is still on, that you may still use it and that the tool is still offered, then sends that stored call once, with your own connected account. A second approval is refused as already done; a rejected or expired plan never reaches the connector. If the connector answers with an error, the plan shows as failed; the connector's own message is not stored. The agent sees whether the plan was applied or failed, not what the connector answered. Each proposal and each call is recorded in the audit log, without the values sent. +When your admin has added connectors (such as Slack or GitHub) and you have connected your account to one, the agent also sees that connector's tools, named `__` (for example `slack__post_message`). Tools your admin marked as reads run at once unless your organisation's [connector policy](/admin/connector-policy/) says otherwise: a call its rules deny is not made, and the agent gets "Not allowed by the platform's policy:" followed by the rule's reason; a read its rules hold for approval is proposed like a write below. Every other tool only **proposes** the call: the agent gets a link, and the call waits as a plan showing each value it will send, exactly as it will be sent. When you approve it in the browser, Tapas checks again that the connector is still on, that you may still use it, that the tool is still offered and that the policy still allows it, then sends that stored call once, with your own connected account. A second approval is refused as already done; a rejected or expired plan never reaches the connector. If the connector answers with an error, the plan shows as failed; the connector's own message is not stored. The agent sees whether the plan was applied or failed, not what the connector answered. Each proposal and each call is recorded in the audit log, without the values sent. From a26b45571901ad29d6792d6bd6bcb4ba178cec4f Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 13:08:05 +0000 Subject: [PATCH 11/13] test(connectors): refuse network built-ins in rule sets that otherwise load The built-in cases had no deny rule, so they were refused for that and passed even with every built-in allowed. Each now carries a valid rule set, so only the built-in can refuse it. --- internal/connectors/policy/opa/opa_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/connectors/policy/opa/opa_test.go b/internal/connectors/policy/opa/opa_test.go index ed4ebc32..27824f4f 100644 --- a/internal/connectors/policy/opa/opa_test.go +++ b/internal/connectors/policy/opa/opa_test.go @@ -227,6 +227,9 @@ func TestNoRulesDeniesEverything(t *testing.T) { func TestRulesThatCannotBeLoaded(t *testing.T) { t.Parallel() meta := "# METADATA\n# title: T\n# description: D.\n" + // valid is a rule set that loads but for what each case adds, so the + // case is refused for that and nothing else. + valid := "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if false\n\n" for name, src := range map[string]string{ "syntax error": "package tapas.rules.x\n\ndeny contains if {", "outside tapas": "package other\n\nx := 1\n", @@ -240,16 +243,16 @@ func TestRulesThatCannotBeLoaded(t *testing.T) { "deny under another name": "package tapas.rules.x\n\n" + meta + "y.deny contains rego.metadata.rule() if true\n", "approval under a name": "package tapas.rules.x\n\n" + meta + "y.require_approval contains rego.metadata.rule() if true\n", "deny deeper in the lib": "package tapas.lib\n\n" + meta + "x.deny contains rego.metadata.rule() if true\n", - "json schema by URL": "package tapas.rules.x\n\nx := json.match_schema({}, {\"$ref\": \"http://127.0.0.1:1/s.json\"})\n", - "json schema from a file": "package tapas.rules.x\n\nx := json.verify_schema({\"$ref\": \"file:///etc/passwd\"})\n", + "json schema by URL": valid + "x := json.match_schema({}, {\"$ref\": \"http://127.0.0.1:1/s.json\"})\n", + "json schema from a file": valid + "x := json.verify_schema({\"$ref\": \"file:///etc/passwd\"})\n", "a misspelt input field": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.where.conector == \"slack\"\n", "a field not in the input": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if input.agent.client == \"x\"\n", "no deny or approval rule": "package tapas.rules.x\n\nsend := {\"send_email\"}\n", "deny under a computed name": "package tapas.rules.x\n\n" + meta + "deny contains rego.metadata.rule() if false\n\n" + meta + "y[k] contains rego.metadata.rule() if { k := \"deny\"; input.where.connector == \"slack\" }\n", - "http.send": "package tapas.rules.x\n\nx := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", - "net.lookup_ip_addr": "package tapas.rules.x\n\nx := net.lookup_ip_addr(\"example.com\")\n", - "opa.runtime": "package tapas.rules.x\n\nx := opa.runtime()\n", - "unknown function": "package tapas.rules.x\n\nx := nope(1)\n", + "http.send": valid + "x := http.send({\"method\": \"get\", \"url\": \"https://example.com\"})\n", + "net.lookup_ip_addr": valid + "x := net.lookup_ip_addr(\"example.com\")\n", + "opa.runtime": valid + "x := opa.runtime()\n", + "unknown function": valid + "x := nope(1)\n", } { t.Run(name, func(t *testing.T) { e := opa.New(opa.Config{Dir: write(t, map[string]string{"x.rego": src})}) From d02e250a64e170a0c282440110fd6c8bfe8eca81 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 13:08:40 +0000 Subject: [PATCH 12/13] test(connectors): tie the rules' input schema to policy.Input The schema rules are type-checked against is written out by hand. A test now compares its fields with those of a fully set policy.Input, so a field added to one side only fails. --- internal/connectors/policy/opa/schema_test.go | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 internal/connectors/policy/opa/schema_test.go diff --git a/internal/connectors/policy/opa/schema_test.go b/internal/connectors/policy/opa/schema_test.go new file mode 100644 index 00000000..241e8d16 --- /dev/null +++ b/internal/connectors/policy/opa/schema_test.go @@ -0,0 +1,106 @@ +package opa + +import ( + "encoding/json" + "reflect" + "slices" + "testing" + + "github.com/nebari-dev/javo/internal/connectors/policy" +) + +// full is a policy.Input with every field set, nested ones too. +var full = policy.Input{ + Checkpoint: policy.CheckpointToolCall, Phase: policy.PhaseApply, + Who: policy.Who{Person: "alice", Groups: []string{"recruiting"}}, + Agent: policy.Agent{Name: "helper", App: "helper-1", Token: "t-1", Scheduled: true}, + Where: policy.Where{Connector: "slack", Tool: "post", Mode: "write"}, + What: policy.What{Arguments: json.RawMessage(`{"text":"hi"}`)}, + Findings: []policy.Finding{{Detector: "ssn", Path: "what.arguments.text"}}, + Approval: &policy.Approval{Plan: "p-1", By: "alice"}, +} + +// inputSchema, which rules are checked against, has exactly the fields of +// policy.Input as the rules receive it: a field on one side only would +// refuse good rules, or let a rule read a field that never comes. +func TestTheInputSchemaMatchesTheInput(t *testing.T) { + if !allSet(reflect.ValueOf(full)) { + t.Fatal("full leaves a field of policy.Input unset: set it") + } + raw, err := json.Marshal(full) + if err != nil { + t.Fatal(err) + } + var doc any + if err := json.Unmarshal(raw, &doc); err != nil { + t.Fatal(err) + } + var schema map[string]any + if err := json.Unmarshal([]byte(inputSchema), &schema); err != nil { + t.Fatal(err) + } + got, want := schemaPaths(schema, ""), docPaths(doc, "") + if !slices.Equal(got, want) { + t.Fatalf("schema fields\n %v\ninput fields\n %v", got, want) + } +} + +// allSet reports whether every field of v, a struct, and of the structs +// it holds is set. +func allSet(v reflect.Value) bool { + switch v.Kind() { + case reflect.Pointer: + return !v.IsNil() && allSet(v.Elem()) + case reflect.Struct: + for i := range v.NumField() { + if !allSet(v.Field(i)) { + return false + } + } + return true + case reflect.Slice: + return v.Len() > 0 && (v.Type().Elem().Kind() != reflect.Struct || allSet(v.Index(0))) + } + return !v.IsZero() +} + +// schemaPaths are the dotted paths of the properties schema declares, not +// below what.arguments (free); an array's items count as its path. +func schemaPaths(schema map[string]any, at string) []string { + var out []string + props, _ := schema["properties"].(map[string]any) + for name, sub := range props { + p := at + name + out = append(out, p) + s, _ := sub.(map[string]any) + if items, ok := s["items"].(map[string]any); ok { + s = items + } + if p != "what.arguments" { + out = append(out, schemaPaths(s, p+".")...) + } + } + slices.Sort(out) + return out +} + +// docPaths are the dotted paths of doc's object keys, in the same way. +func docPaths(doc any, at string) []string { + var out []string + switch d := doc.(type) { + case map[string]any: + for name, sub := range d { + p := at + name + out = append(out, p) + if p != "what.arguments" { + out = append(out, docPaths(sub, p+".")...) + } + } + case []any: + if len(d) > 0 { + out = append(out, docPaths(d[0], at)...) + } + } + slices.Sort(out) + return out +} From 235ab5b8f0e983aea539fbd24ae1bae2d99f283a Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 1 Dec 2026 13:09:00 +0000 Subject: [PATCH 13/13] fix(connectors): drop agent.scheduled from the policy input A job's token is refused before the policy is asked, so the field was always false; a rule resting on it could never fire. A rule that reads it is now refused when it loads. --- deploy/policy/examples/frames_test.rego | 2 +- internal/connectors/broker/checkpolicy.go | 2 +- internal/connectors/policy/opa/opa.go | 2 +- internal/connectors/policy/opa/opa_test.go | 2 +- internal/connectors/policy/opa/schema_test.go | 2 +- internal/connectors/policy/policy.go | 14 +++++++------- site/src/content/docs/admin/connector-policy.md | 4 +--- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/deploy/policy/examples/frames_test.rego b/deploy/policy/examples/frames_test.rego index dda308fe..b0327a79 100644 --- a/deploy/policy/examples/frames_test.rego +++ b/deploy/policy/examples/frames_test.rego @@ -6,7 +6,7 @@ update := { "checkpoint": "tool_call", "phase": "propose", "who": {"person": "alice@example.com", "groups": []}, - "agent": {"name": "helper", "app": "helper-1", "token": "t-1", "scheduled": false}, + "agent": {"name": "helper", "app": "helper-1", "token": "t-1"}, "where": {"connector": "frames", "tool": "update_frame", "mode": "write"}, "what": {"arguments": {"id": "f-1", "body": "Use the Oxford comma."}}, "findings": [], diff --git a/internal/connectors/broker/checkpolicy.go b/internal/connectors/broker/checkpolicy.go index 7d9d6f68..b6120e37 100644 --- a/internal/connectors/broker/checkpolicy.go +++ b/internal/connectors/broker/checkpolicy.go @@ -69,7 +69,7 @@ func (c *call) policyInput() (policy.Input, bool) { // agentOf is what made a call for caller. func agentOf(caller connectors.Caller) policy.Agent { - a := policy.Agent{Name: caller.Agent, Token: caller.Token.ID, Scheduled: caller.Token.Job != ""} + a := policy.Agent{Name: caller.Agent, Token: caller.Token.ID} if app := caller.Token.App; app != nil { a.App = app.Name } diff --git a/internal/connectors/policy/opa/opa.go b/internal/connectors/policy/opa/opa.go index e473dfe4..a77986dd 100644 --- a/internal/connectors/policy/opa/opa.go +++ b/internal/connectors/policy/opa/opa.go @@ -274,7 +274,7 @@ const inputSchema = `{ "who": {"type": "object", "additionalProperties": false, "properties": { "person": {"type": "string"}, "groups": {"type": "array", "items": {"type": "string"}}}}, "agent": {"type": "object", "additionalProperties": false, "properties": { - "name": {"type": "string"}, "app": {"type": "string"}, "token": {"type": "string"}, "scheduled": {"type": "boolean"}}}, + "name": {"type": "string"}, "app": {"type": "string"}, "token": {"type": "string"}}}, "where": {"type": "object", "additionalProperties": false, "properties": { "connector": {"type": "string"}, "tool": {"type": "string"}, "mode": {"type": "string"}}}, "what": {"type": "object", "additionalProperties": false, "properties": { diff --git a/internal/connectors/policy/opa/opa_test.go b/internal/connectors/policy/opa/opa_test.go index 27824f4f..0b3b2a8d 100644 --- a/internal/connectors/policy/opa/opa_test.go +++ b/internal/connectors/policy/opa/opa_test.go @@ -150,7 +150,7 @@ deny contains rego.metadata.rule() if { input.phase == "propose" input.who.person == "alice" input.who.groups == ["recruiting"] - input.agent == {"name": "helper", "app": "helper-1", "token": "t-1", "scheduled": false} + input.agent == {"name": "helper", "app": "helper-1", "token": "t-1"} input.where == {"connector": "slack", "tool": "post", "mode": "write"} input.what.arguments.big == 12345678901234567890 input.what.arguments.text == "hi" diff --git a/internal/connectors/policy/opa/schema_test.go b/internal/connectors/policy/opa/schema_test.go index 241e8d16..a5c04dab 100644 --- a/internal/connectors/policy/opa/schema_test.go +++ b/internal/connectors/policy/opa/schema_test.go @@ -13,7 +13,7 @@ import ( var full = policy.Input{ Checkpoint: policy.CheckpointToolCall, Phase: policy.PhaseApply, Who: policy.Who{Person: "alice", Groups: []string{"recruiting"}}, - Agent: policy.Agent{Name: "helper", App: "helper-1", Token: "t-1", Scheduled: true}, + Agent: policy.Agent{Name: "helper", App: "helper-1", Token: "t-1"}, Where: policy.Where{Connector: "slack", Tool: "post", Mode: "write"}, What: policy.What{Arguments: json.RawMessage(`{"text":"hi"}`)}, Findings: []policy.Finding{{Detector: "ssn", Path: "what.arguments.text"}}, diff --git a/internal/connectors/policy/policy.go b/internal/connectors/policy/policy.go index 6be6aa5f..71b2f56f 100644 --- a/internal/connectors/policy/policy.go +++ b/internal/connectors/policy/policy.go @@ -55,14 +55,14 @@ type Who struct { } // Agent is what made the call: the coding agent app's short and object -// names (empty for a personal token) and the token. Scheduled is true for -// a job's token. What the MCP client calls itself is left out: the client -// chooses it, so no rule may rest on it. +// names (empty for a personal token) and the token. What the MCP client +// calls itself is left out: the client chooses it, so no rule may rest on +// it. A job's token never reaches the policy (connectors refuse it), so +// there is no field for one. type Agent struct { - Name string `json:"name"` - App string `json:"app"` - Token string `json:"token"` - Scheduled bool `json:"scheduled"` + Name string `json:"name"` + App string `json:"app"` + Token string `json:"token"` } // Where is the connector, its tool, and the tool's mode ("read" or "write") diff --git a/site/src/content/docs/admin/connector-policy.md b/site/src/content/docs/admin/connector-policy.md index a327ee8c..c4151f89 100644 --- a/site/src/content/docs/admin/connector-policy.md +++ b/site/src/content/docs/admin/connector-policy.md @@ -40,8 +40,7 @@ Each check gives the rules one input document, the same shape at every phase. Wh "agent": { "name": "helper", "app": "helper-1", - "token": "t-1", - "scheduled": false + "token": "t-1" }, "where": { "connector": "gmail", @@ -67,7 +66,6 @@ Each check gives the rules one input document, the same shape at every phase. Wh | `agent.name` | The short name of the coding agent app that made the call; empty for a personal token. Its owner chooses it, so a rule that names a kind of agent by it can be sidestepped by renaming the app. | | `agent.app` | The name of the app the token belongs to; empty for a personal token. Chosen by its owner too. | | `agent.token` | The id of the token that made the call. | -| `agent.scheduled` | `true` when a scheduled job's token made the call. | | `where.connector`, `where.tool` | The connector's short name and the tool called. | | `where.mode` | `read` or `write`, as the admin marked the tool. | | `what.arguments` | The tool's arguments, a JSON object. |