From fd3acf3ccd95c3309fe091a8a6d4d146836a4235 Mon Sep 17 00:00:00 2001 From: David McKay Date: Wed, 2 Dec 2026 22:02:54 -0800 Subject: [PATCH 01/11] Cedar policy engine: shared contract in the API Boundaries move from CEL to Cedar. This is the API every slice of that move codes against, all additive: - Boundaries, BoundariesInput and BoundariesDraft gain an optional `rules` array: each rule with an id, its effect (forbid or permit), the language that decides it now, its Cedar, its CEL form, its name and description, the English it was written from and where that came from, and how it was moved from CEL (exact, model or none; converted or needs_rewrite; actions checked; mismatches; when). - A request with `rules` is authoritative. A request without it, as every released app sends, keeps today's meaning on the CEL view. - `deny`, `allow` and `labels` are deprecated, sunset 2027-12-02. - translateBoundary takes an optional `language` (cel when absent, as today) and answers with the language it wrote in. - A replay change names the deciding rule's id. Clients regenerated with `bun run api:generate`. --- api/openapi.yaml | 297 +++++++++- api/openapi/approvals.yaml | 328 ++++++++++- .../generated/boundaries/boundaries.msw.ts | 95 +++- .../api/generated/boundaries/boundaries.ts | 10 +- .../generated/boundaries/boundaries.zod.ts | 519 +++++++++++++++--- app/src/lib/api/generated/model/boundaries.ts | 20 +- .../api/generated/model/boundariesDraft.ts | 18 +- .../generated/model/boundariesDraftLabels.ts | 3 +- .../api/generated/model/boundariesInput.ts | 21 +- .../generated/model/boundariesInputLabels.ts | 3 +- .../api/generated/model/boundariesLabels.ts | 3 +- .../generated/model/boundaryReplayChange.ts | 5 + .../lib/api/generated/model/boundaryRule.ts | 42 ++ .../generated/model/boundaryRuleConversion.ts | 25 + .../api/generated/model/boundaryRuleEffect.ts | 14 + .../model/boundaryRuleEnglishSource.ts | 8 + .../api/generated/model/boundaryRuleInput.ts | 46 ++ .../generated/model/boundaryRuleLanguage.ts | 14 + .../model/boundaryRuleLanguageAnswer.ts | 8 + .../generated/model/boundaryTranslation.ts | 5 +- .../model/boundaryTranslationRequest.ts | 16 + app/src/lib/api/generated/model/index.ts | 8 + 22 files changed, 1393 insertions(+), 115 deletions(-) create mode 100644 app/src/lib/api/generated/model/boundaryRule.ts create mode 100644 app/src/lib/api/generated/model/boundaryRuleConversion.ts create mode 100644 app/src/lib/api/generated/model/boundaryRuleEffect.ts create mode 100644 app/src/lib/api/generated/model/boundaryRuleEnglishSource.ts create mode 100644 app/src/lib/api/generated/model/boundaryRuleInput.ts create mode 100644 app/src/lib/api/generated/model/boundaryRuleLanguage.ts create mode 100644 app/src/lib/api/generated/model/boundaryRuleLanguageAnswer.ts create mode 100644 app/src/lib/api/generated/model/boundaryTranslationRequest.ts diff --git a/api/openapi.yaml b/api/openapi.yaml index 99dc61c359..8927ce83af 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -16116,6 +16116,20 @@ paths: intent == "run_command" && initiator.kind != "person": name: No commands when nobody is watching description: Stops a Bot running a shell command in a run nobody started by hand. + cedarRules: + value: + mode: enforce + rules: + - id: rule_no_unattended_commands + effect: forbid + cedar: |- + forbid (principal, action == OpenBot::Action::"run_command", resource) + when { context.initiator.kind != "person" }; + name: No commands when nobody is watching + description: Stops a Bot running a shell command in a run nobody started by hand. + english: No shell commands when nobody is watching. + - effect: permit + cedar: permit (principal, action, resource); responses: '200': description: The boundaries, as saved. @@ -16170,11 +16184,15 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ChangeDescription' + $ref: '#/components/schemas/BoundaryTranslationRequest' examples: commands: value: text: No shell commands when nobody is watching. + cedar: + value: + text: No shell commands when nobody is watching. + language: cedar responses: '200': description: The proposed rule, and what it does. @@ -42840,6 +42858,115 @@ components: - enforce - dry-run description: enforce refuses what the rules refuse. dry-run records what they would have refused and lets it through, to try a rule before it stops anybody's work. + BoundaryRuleEffect: + type: string + enum: + - forbid + - permit + description: forbid refuses an action the rule matches, whatever any other rule says. permit allows an action it matches, unless a forbid rule matches it too. + BoundaryRuleLanguageAnswer: + type: string + x-extensible-enum: + - cel + - cedar + description: 'The language that decides a rule now: cedar, or cel for a rule OpenBot couldn''t yet move to Cedar with the same result.' + BoundaryRuleEnglishSource: + type: string + x-extensible-enum: + - authoring + - description + - reading + description: 'Where a rule''s English came from: authoring, the sentence an administrator wrote it from; description, its description; reading, OpenBot''s reading of the rule, for a rule typed by hand.' + BoundaryRuleConversion: + type: object + description: How a rule written in CEL was moved to Cedar, or why it wasn't. + required: + - tier + - status + - checked + - mismatches + - at + properties: + tier: + type: string + x-extensible-enum: + - exact + - model + - none + description: exact, translated rule for rule; model, written in Cedar by the deployment's model from the rule's English; none, no Cedar candidate could be written. + status: + type: string + x-extensible-enum: + - converted + - needs_rewrite + description: converted, the Cedar rule decided every action checked as the CEL rule did and now decides in its place; needs_rewrite, it didn't, or none could be written, so the CEL rule still decides and an administrator should rewrite it. + checked: + type: integer + minimum: 0 + description: How many actions, past and made up, both rules were asked about. + mismatches: + type: integer + minimum: 0 + description: How many of them the two rules decided differently. + at: + type: string + format: date-time + description: When the conversion ran. + BoundaryRule: + type: object + description: One rule, in the administrator's order. A rule is decided in Cedar when it has Cedar, and in CEL while it has none. + required: + - id + - effect + - language + - cedar + - cel + - name + - description + - english + - englishFrom + - conversion + properties: + id: + type: string + description: The rule's own id, which stays when its text changes. + effect: + $ref: '#/components/schemas/BoundaryRuleEffect' + language: + $ref: '#/components/schemas/BoundaryRuleLanguageAnswer' + cedar: + type: + - string + - 'null' + description: The rule as one Cedar policy. Null while the rule is still CEL. + cel: + type: + - string + - 'null' + description: 'The rule in CEL: the text it was written in, or the CEL form of a rule written in Cedar. Null when it has none, so a server older than the one that saved it doesn''t apply it.' + name: + type: + - string + - 'null' + description: + type: + - string + - 'null' + description: What the rule stops, in words. + english: + type: + - string + - 'null' + description: The English the rule was written from, when OpenBot has it. + englishFrom: + oneOf: + - $ref: '#/components/schemas/BoundaryRuleEnglishSource' + - type: 'null' + conversion: + description: How the rule was moved from CEL. Null for a rule written in Cedar. + oneOf: + - $ref: '#/components/schemas/BoundaryRuleConversion' + - type: 'null' BoundaryRuleLabel: type: object description: What a rule is called and what it stops, in words. Never evaluated. @@ -42853,7 +42980,7 @@ components: type: string Boundaries: type: object - description: 'What every Bot may do. Deny rules are read first: an action any of them is true for is refused, whatever an allow rule says. Then an action any allow rule is true for is permitted, and one that none is true for is refused.' + description: 'What every Bot may do. Forbid rules are read first: an action any of them matches is refused, whatever a permit rule says. Then an action any permit rule matches is allowed, and one that none matches is refused.' required: - mode - deny @@ -42862,21 +42989,73 @@ components: properties: mode: $ref: '#/components/schemas/BoundaryMode' + rules: + type: array + description: Every rule, forbid and permit, in the administrator's order. + items: + $ref: '#/components/schemas/BoundaryRule' deny: type: array - description: The deny rules, each a CEL expression. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Read `rules` instead. The forbid rules that have a CEL form, each a CEL expression. items: type: string allow: type: array - description: The allow rules, each a CEL expression. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Read `rules` instead. The permit rules that have a CEL form, each a CEL expression. items: type: string labels: type: object - description: Each rule's name and description, keyed by the rule's own text. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabel' + BoundaryRuleInput: + type: object + additionalProperties: false + description: One rule to save. Give its Cedar, or its CEL to have OpenBot move it to Cedar; a rule with neither is refused. + required: + - effect + properties: + id: + type: string + minLength: 1 + maxLength: 64 + description: The id of a rule being kept or changed. Leave it out for a new rule. + effect: + $ref: '#/components/schemas/BoundaryRuleEffect' + cedar: + type: string + minLength: 1 + description: The rule as one Cedar policy whose effect matches `effect`. It must be one OpenBot can check against its schema. + cel: + type: string + minLength: 1 + description: The rule in CEL, for a rule that has no Cedar yet. OpenBot moves it to Cedar when the result decides the same. + name: + type: string + minLength: 1 + maxLength: 80 + pattern: ^[^\x00]*[^\s\x00][^\x00]*$ + description: 1 to 80 characters once trimmed. + description: + type: string + maxLength: 300 + pattern: ^[^\x00]*$ + description: At most 300 characters once trimmed. + english: + type: string + maxLength: 1000 + pattern: ^[^\x00]*$ + description: The English the rule was written from. BoundaryRuleLabelInput: type: object additionalProperties: false @@ -42897,30 +43076,66 @@ components: BoundariesInput: type: object additionalProperties: false + description: The boundaries to save. With `rules`, the rules are exactly those, in that order, and `deny`, `allow` and `labels` are ignored. Without it, `deny` and `allow` replace the rules that have a CEL form, and a rule that has none is kept as it is. required: - mode properties: mode: $ref: '#/components/schemas/BoundaryMode' + rules: + type: array + description: Every rule, forbid and permit, in order. A rule added here must be one OpenBot can check. + items: + $ref: '#/components/schemas/BoundaryRuleInput' deny: type: array default: [] - description: The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Send `rules` instead. The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate. items: type: string allow: type: array default: [] - description: The allow rules, each a CEL expression. Empty permits nothing. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Send `rules` instead. The allow rules, each a CEL expression. Empty permits nothing. items: type: string labels: type: object - description: Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabelInput' authoring: $ref: '#/components/schemas/Authoring' + BoundaryRuleLanguage: + type: string + enum: + - cel + - cedar + description: The language a rule is written in. cedar is the language rules are written in from now on. cel is the language rules were written in before; a rule in it is still accepted, and is moved to Cedar when it is saved. + BoundaryTranslationRequest: + type: object + additionalProperties: false + required: + - text + properties: + text: + type: string + minLength: 1 + maxLength: 1000 + pattern: ^[^\x00]*[^\s\x00][^\x00]*$ + description: The change in a sentence or two, at most 1,000 characters once trimmed. + language: + $ref: '#/components/schemas/BoundaryRuleLanguage' + description: The language to write the rule in. Leave it out for cel, as before; send cedar for a rule in Cedar. BoundaryTranslation: type: object required: @@ -42931,9 +43146,12 @@ components: - compile - warning properties: + language: + $ref: '#/components/schemas/BoundaryRuleLanguageAnswer' + description: The language `rule` is written in. Absent means cel. rule: type: string - description: The rule the model wrote, as a CEL expression. + description: The rule the model wrote, in `language`. effect: type: string enum: @@ -42960,25 +43178,41 @@ components: BoundariesDraft: type: object additionalProperties: false - description: Boundaries to test, as a save would take them. + description: Boundaries to test, as a save would take them. With `rules`, the rules are those and `deny`, `allow` and `labels` are ignored. required: - mode properties: mode: $ref: '#/components/schemas/BoundaryMode' + rules: + type: array + description: Every rule to test, forbid and permit, in order. + items: + $ref: '#/components/schemas/BoundaryRuleInput' deny: type: array default: [] + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Send `rules` instead. The deny rules, each a CEL expression. items: type: string allow: type: array default: [] + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Send `rules` instead. The allow rules, each a CEL expression. items: type: string labels: type: object - description: Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + deprecated: true + x-deprecation-date: '2026-12-02' + x-sunset: '2027-12-02' + description: Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabelInput' BoundaryReplayRequest: @@ -43084,6 +43318,11 @@ components: - string - 'null' description: The rule that decides it. Null when no rule permits the action, so it is refused. + ruleId: + type: + - string + - 'null' + description: The id of the rule that decides it, as in `rules`. Null when no rule permits the action, or the rule has no id. reason: type: string BoundaryReplayReport: @@ -63573,9 +63812,42 @@ components: reason: The deal is worth more than $100,000. hadRequest: true BoundariesExample: - summary: One deny rule, and everything else allowed. + summary: One forbid rule, and everything else allowed. value: mode: enforce + rules: + - id: rule_no_unattended_commands + effect: forbid + language: cedar + cedar: |- + forbid (principal, action == OpenBot::Action::"run_command", resource) + when { context.initiator.kind != "person" }; + cel: intent == "run_command" && initiator.kind != "person" + name: No commands when nobody is watching + description: Stops a Bot running a shell command in a run nobody started by hand. + english: No shell commands when nobody is watching. + englishFrom: authoring + conversion: + tier: exact + status: converted + checked: 412 + mismatches: 0 + at: '2026-12-02T09:00:00.000Z' + - id: rule_everything_else + effect: permit + language: cedar + cedar: permit (principal, action, resource); + cel: 'true' + name: null + description: null + english: null + englishFrom: null + conversion: + tier: exact + status: converted + checked: 412 + mismatches: 0 + at: '2026-12-02T09:00:00.000Z' deny: - intent == "run_command" && initiator.kind != "person" allow: @@ -63617,6 +63889,7 @@ components: was: allowed would: refused rule: intent == "run_command" && initiator.kind != "person" + ruleId: rule_no_unattended_commands reason: A deny rule matched. WhatIfVocabularyExample: summary: One Bot, one person, one group and one app. diff --git a/api/openapi/approvals.yaml b/api/openapi/approvals.yaml index 5daac78fd9..63e0059af3 100644 --- a/api/openapi/approvals.yaml +++ b/api/openapi/approvals.yaml @@ -1813,6 +1813,20 @@ paths: intent == "run_command" && initiator.kind != "person": name: No commands when nobody is watching description: Stops a Bot running a shell command in a run nobody started by hand. + cedarRules: + value: + mode: enforce + rules: + - id: rule_no_unattended_commands + effect: forbid + cedar: |- + forbid (principal, action == OpenBot::Action::"run_command", resource) + when { context.initiator.kind != "person" }; + name: No commands when nobody is watching + description: Stops a Bot running a shell command in a run nobody started by hand. + english: No shell commands when nobody is watching. + - effect: permit + cedar: permit (principal, action, resource); responses: '200': description: The boundaries, as saved. @@ -1871,11 +1885,15 @@ paths: content: application/json: schema: - $ref: './common.yaml#/components/schemas/ChangeDescription' + $ref: '#/components/schemas/BoundaryTranslationRequest' examples: commands: value: text: No shell commands when nobody is watching. + cedar: + value: + text: No shell commands when nobody is watching. + language: cedar responses: '200': description: The proposed rule, and what it does. @@ -4057,95 +4075,330 @@ components: maxLength: 300 pattern: ^[^\x00]*$ description: At most 300 characters once trimmed. + BoundaryRuleEffect: + type: string + enum: [forbid, permit] + description: >- + forbid refuses an action the rule matches, whatever any other rule + says. permit allows an action it matches, unless a forbid rule + matches it too. + BoundaryRuleLanguage: + type: string + enum: [cel, cedar] + description: >- + The language a rule is written in. cedar is the language rules are + written in from now on. cel is the language rules were written in + before; a rule in it is still accepted, and is moved to Cedar when + it is saved. + BoundaryRuleLanguageAnswer: + type: string + x-extensible-enum: [cel, cedar] + description: >- + The language that decides a rule now: cedar, or cel for a rule + OpenBot couldn't yet move to Cedar with the same result. + BoundaryRuleEnglishSource: + type: string + x-extensible-enum: [authoring, description, reading] + description: >- + Where a rule's English came from: authoring, the sentence an + administrator wrote it from; description, its description; reading, + OpenBot's reading of the rule, for a rule typed by hand. + BoundaryRuleConversion: + type: object + description: >- + How a rule written in CEL was moved to Cedar, or why it wasn't. + required: [tier, status, checked, mismatches, at] + properties: + tier: + type: string + x-extensible-enum: [exact, model, none] + description: >- + exact, translated rule for rule; model, written in Cedar by the + deployment's model from the rule's English; none, no Cedar + candidate could be written. + status: + type: string + x-extensible-enum: [converted, needs_rewrite] + description: >- + converted, the Cedar rule decided every action checked as the + CEL rule did and now decides in its place; needs_rewrite, it + didn't, or none could be written, so the CEL rule still decides + and an administrator should rewrite it. + checked: + type: integer + minimum: 0 + description: How many actions, past and made up, both rules were asked about. + mismatches: + type: integer + minimum: 0 + description: How many of them the two rules decided differently. + at: + type: string + format: date-time + description: When the conversion ran. + BoundaryRule: + type: object + description: >- + One rule, in the administrator's order. A rule is decided in Cedar + when it has Cedar, and in CEL while it has none. + required: + - id + - effect + - language + - cedar + - cel + - name + - description + - english + - englishFrom + - conversion + properties: + id: + type: string + description: The rule's own id, which stays when its text changes. + effect: + $ref: '#/components/schemas/BoundaryRuleEffect' + language: + $ref: '#/components/schemas/BoundaryRuleLanguageAnswer' + cedar: + type: [string, 'null'] + description: The rule as one Cedar policy. Null while the rule is still CEL. + cel: + type: [string, 'null'] + description: >- + The rule in CEL: the text it was written in, or the CEL form of a + rule written in Cedar. Null when it has none, so a server older + than the one that saved it doesn't apply it. + name: + type: [string, 'null'] + description: + type: [string, 'null'] + description: What the rule stops, in words. + english: + type: [string, 'null'] + description: The English the rule was written from, when OpenBot has it. + englishFrom: + oneOf: + - $ref: '#/components/schemas/BoundaryRuleEnglishSource' + - type: 'null' + conversion: + description: How the rule was moved from CEL. Null for a rule written in Cedar. + oneOf: + - $ref: '#/components/schemas/BoundaryRuleConversion' + - type: 'null' + BoundaryRuleInput: + type: object + additionalProperties: false + description: >- + One rule to save. Give its Cedar, or its CEL to have OpenBot move it + to Cedar; a rule with neither is refused. + required: [effect] + properties: + id: + type: string + minLength: 1 + maxLength: 64 + description: The id of a rule being kept or changed. Leave it out for a new rule. + effect: + $ref: '#/components/schemas/BoundaryRuleEffect' + cedar: + type: string + minLength: 1 + description: >- + The rule as one Cedar policy whose effect matches `effect`. It must + be one OpenBot can check against its schema. + cel: + type: string + minLength: 1 + description: >- + The rule in CEL, for a rule that has no Cedar yet. OpenBot moves it + to Cedar when the result decides the same. + name: + type: string + minLength: 1 + maxLength: 80 + pattern: ^[^\x00]*[^\s\x00][^\x00]*$ + description: 1 to 80 characters once trimmed. + description: + type: string + maxLength: 300 + pattern: ^[^\x00]*$ + description: At most 300 characters once trimmed. + english: + type: string + maxLength: 1000 + pattern: ^[^\x00]*$ + description: The English the rule was written from. Boundaries: type: object description: >- - What every Bot may do. Deny rules are read first: an action any of - them is true for is refused, whatever an allow rule says. Then an - action any allow rule is true for is permitted, and one that none is - true for is refused. + What every Bot may do. Forbid rules are read first: an action any of + them matches is refused, whatever a permit rule says. Then an action + any permit rule matches is allowed, and one that none matches is + refused. required: [mode, deny, allow, labels] properties: mode: $ref: '#/components/schemas/BoundaryMode' + rules: + type: array + description: Every rule, forbid and permit, in the administrator's order. + items: + $ref: '#/components/schemas/BoundaryRule' deny: type: array - description: The deny rules, each a CEL expression. + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 + description: >- + Deprecated. Read `rules` instead. The forbid rules that have a CEL + form, each a CEL expression. items: type: string allow: type: array - description: The allow rules, each a CEL expression. + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 + description: >- + Deprecated. Read `rules` instead. The permit rules that have a CEL + form, each a CEL expression. items: type: string labels: type: object - description: Each rule's name and description, keyed by the rule's own text. + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 + description: >- + Deprecated. Read `rules` instead. Each CEL rule's name and + description, keyed by the rule's own text. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabel' BoundariesDraft: type: object additionalProperties: false - description: Boundaries to test, as a save would take them. + description: >- + Boundaries to test, as a save would take them. With `rules`, the + rules are those and `deny`, `allow` and `labels` are ignored. required: [mode] properties: mode: $ref: '#/components/schemas/BoundaryMode' + rules: + type: array + description: Every rule to test, forbid and permit, in order. + items: + $ref: '#/components/schemas/BoundaryRuleInput' deny: type: array default: [] + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 + description: Deprecated. Send `rules` instead. The deny rules, each a CEL expression. items: type: string allow: type: array default: [] + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 + description: Deprecated. Send `rules` instead. The allow rules, each a CEL expression. items: type: string labels: type: object + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 description: >- - Each rule's name and description, keyed by the rule's own text. A - label for a rule in neither list is dropped. + Deprecated. Send `rules` instead. Each rule's name and description, + keyed by the rule's own text. A label for a rule in neither list is + dropped. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabelInput' BoundariesInput: type: object additionalProperties: false + description: >- + The boundaries to save. With `rules`, the rules are exactly those, in + that order, and `deny`, `allow` and `labels` are ignored. Without it, + `deny` and `allow` replace the rules that have a CEL form, and a rule + that has none is kept as it is. required: [mode] properties: mode: $ref: '#/components/schemas/BoundaryMode' + rules: + type: array + description: >- + Every rule, forbid and permit, in order. A rule added here must be + one OpenBot can check. + items: + $ref: '#/components/schemas/BoundaryRuleInput' deny: type: array default: [] + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 description: >- - The deny rules, each a CEL expression. One added here must be one - OpenBot can evaluate. + Deprecated. Send `rules` instead. The deny rules, each a CEL + expression. One added here must be one OpenBot can evaluate. items: type: string allow: type: array default: [] + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 description: >- - The allow rules, each a CEL expression. Empty permits nothing. + Deprecated. Send `rules` instead. The allow rules, each a CEL + expression. Empty permits nothing. items: type: string labels: type: object + deprecated: true + x-deprecation-date: 2026-12-02 + x-sunset: 2027-12-02 description: >- - Each rule's name and description, keyed by the rule's own text. A - label for a rule in neither list is dropped. + Deprecated. Send `rules` instead. Each rule's name and description, + keyed by the rule's own text. A label for a rule in neither list is + dropped. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabelInput' authoring: $ref: './common.yaml#/components/schemas/Authoring' + BoundaryTranslationRequest: + type: object + additionalProperties: false + required: [text] + properties: + text: + type: string + minLength: 1 + maxLength: 1000 + pattern: ^[^\x00]*[^\s\x00][^\x00]*$ + description: The change in a sentence or two, at most 1,000 characters once trimmed. + language: + $ref: '#/components/schemas/BoundaryRuleLanguage' + description: >- + The language to write the rule in. Leave it out for cel, as + before; send cedar for a rule in Cedar. BoundaryTranslation: type: object required: [rule, effect, summary, explanation, compile, warning] properties: + language: + $ref: '#/components/schemas/BoundaryRuleLanguageAnswer' + description: The language `rule` is written in. Absent means cel. rule: type: string - description: The rule the model wrote, as a CEL expression. + description: The rule the model wrote, in `language`. effect: type: string enum: [deny, allow] @@ -4255,6 +4508,11 @@ components: description: >- The rule that decides it. Null when no rule permits the action, so it is refused. + ruleId: + type: [string, 'null'] + description: >- + The id of the rule that decides it, as in `rules`. Null when no rule + permits the action, or the rule has no id. reason: type: string BoundaryReplayReport: @@ -5910,9 +6168,42 @@ components: hadRequest: true BoundariesExample: - summary: One deny rule, and everything else allowed. + summary: One forbid rule, and everything else allowed. value: mode: enforce + rules: + - id: rule_no_unattended_commands + effect: forbid + language: cedar + cedar: |- + forbid (principal, action == OpenBot::Action::"run_command", resource) + when { context.initiator.kind != "person" }; + cel: intent == "run_command" && initiator.kind != "person" + name: No commands when nobody is watching + description: Stops a Bot running a shell command in a run nobody started by hand. + english: No shell commands when nobody is watching. + englishFrom: authoring + conversion: + tier: exact + status: converted + checked: 412 + mismatches: 0 + at: '2026-12-02T09:00:00.000Z' + - id: rule_everything_else + effect: permit + language: cedar + cedar: permit (principal, action, resource); + cel: 'true' + name: null + description: null + english: null + englishFrom: null + conversion: + tier: exact + status: converted + checked: 412 + mismatches: 0 + at: '2026-12-02T09:00:00.000Z' deny: - intent == "run_command" && initiator.kind != "person" allow: @@ -5956,6 +6247,7 @@ components: was: allowed would: refused rule: intent == "run_command" && initiator.kind != "person" + ruleId: rule_no_unattended_commands reason: A deny rule matched. WhatIfVocabularyExample: summary: One Bot, one person, one group and one app. diff --git a/app/src/lib/api/generated/boundaries/boundaries.msw.ts b/app/src/lib/api/generated/boundaries/boundaries.msw.ts index 615009d2e0..48c568a6a7 100644 --- a/app/src/lib/api/generated/boundaries/boundaries.msw.ts +++ b/app/src/lib/api/generated/boundaries/boundaries.msw.ts @@ -10,11 +10,51 @@ import type { BoundaryReplayReport, BoundaryReplayRequest, BoundaryTranslation, - ChangeDescription, + BoundaryTranslationRequest, } from "../model"; export const getGetBoundariesResponseMock = (): Boundaries => ({ mode: "enforce", + rules: [ + { + id: "rule_no_unattended_commands", + effect: "forbid", + language: "cedar", + cedar: + 'forbid (principal, action == OpenBot::Action::"run_command", resource)\nwhen { context.initiator.kind != "person" };', + cel: 'intent == "run_command" && initiator.kind != "person"', + name: "No commands when nobody is watching", + description: + "Stops a Bot running a shell command in a run nobody started by hand.", + english: "No shell commands when nobody is watching.", + englishFrom: "authoring", + conversion: { + tier: "exact", + status: "converted", + checked: 412, + mismatches: 0, + at: "2026-12-02T09:00:00.000Z", + }, + }, + { + id: "rule_everything_else", + effect: "permit", + language: "cedar", + cedar: "permit (principal, action, resource);", + cel: "true", + name: null, + description: null, + english: null, + englishFrom: null, + conversion: { + tier: "exact", + status: "converted", + checked: 412, + mismatches: 0, + at: "2026-12-02T09:00:00.000Z", + }, + }, + ], deny: ['intent == "run_command" && initiator.kind != "person"'], allow: ["true"], labels: { @@ -28,6 +68,46 @@ export const getGetBoundariesResponseMock = (): Boundaries => ({ export const getReplaceBoundariesResponseMock = (): Boundaries => ({ mode: "enforce", + rules: [ + { + id: "rule_no_unattended_commands", + effect: "forbid", + language: "cedar", + cedar: + 'forbid (principal, action == OpenBot::Action::"run_command", resource)\nwhen { context.initiator.kind != "person" };', + cel: 'intent == "run_command" && initiator.kind != "person"', + name: "No commands when nobody is watching", + description: + "Stops a Bot running a shell command in a run nobody started by hand.", + english: "No shell commands when nobody is watching.", + englishFrom: "authoring", + conversion: { + tier: "exact", + status: "converted", + checked: 412, + mismatches: 0, + at: "2026-12-02T09:00:00.000Z", + }, + }, + { + id: "rule_everything_else", + effect: "permit", + language: "cedar", + cedar: "permit (principal, action, resource);", + cel: "true", + name: null, + description: null, + english: null, + englishFrom: null, + conversion: { + tier: "exact", + status: "converted", + checked: 412, + mismatches: 0, + at: "2026-12-02T09:00:00.000Z", + }, + }, + ], deny: ['intent == "run_command" && initiator.kind != "person"'], allow: ["true"], labels: { @@ -69,6 +149,7 @@ export const getReplayBoundariesResponseMock = (): BoundaryReplayReport => ({ was: "allowed", would: "refused", rule: 'intent == "run_command" && initiator.kind != "person"', + ruleId: "rule_no_unattended_commands", reason: "A deny rule matched.", }, ], @@ -135,16 +216,22 @@ export const getTranslateBoundaryMockHandler = ( | BoundaryTranslation | (( info: Parameters< - HttpResponseResolver<{ organizationId: string }, ChangeDescription> + HttpResponseResolver< + { organizationId: string }, + BoundaryTranslationRequest + > >[0], ) => Promise | BoundaryTranslation), options?: RequestHandlerOptions, ) => { - return http.post<{ organizationId: string }, ChangeDescription>( + return http.post<{ organizationId: string }, BoundaryTranslationRequest>( "*/api/v2/organizations/:organizationId/boundaries/translate", async ( info: Parameters< - HttpResponseResolver<{ organizationId: string }, ChangeDescription> + HttpResponseResolver< + { organizationId: string }, + BoundaryTranslationRequest + > >[0], ) => { return HttpResponse.json( diff --git a/app/src/lib/api/generated/boundaries/boundaries.ts b/app/src/lib/api/generated/boundaries/boundaries.ts index bd3760e9c2..da30c8d430 100644 --- a/app/src/lib/api/generated/boundaries/boundaries.ts +++ b/app/src/lib/api/generated/boundaries/boundaries.ts @@ -25,7 +25,7 @@ import type { BoundaryReplayReport, BoundaryReplayRequest, BoundaryTranslation, - ChangeDescription, + BoundaryTranslationRequest, IdempotencyConflictResponse, InvalidRequestResponse, ModelFailedResponse, @@ -414,7 +414,7 @@ export const getTranslateBoundaryUrl = (organizationId: string) => { */ export const translateBoundary = async ( organizationId: string, - changeDescription: ChangeDescription, + boundaryTranslationRequest: BoundaryTranslationRequest, headers: TranslateBoundaryHeaders, options?: Parameters[1], ): Promise => { @@ -449,7 +449,7 @@ export const translateBoundary = async ( ...headers, ...getHeaders(options?.headers), }, - body: JSON.stringify(changeDescription), + body: JSON.stringify(boundaryTranslationRequest), }, ); }; @@ -508,7 +508,7 @@ export const getTranslateBoundaryMutationOptions = < export type TranslateBoundaryMutationResult = NonNullable< Awaited> >; -export type TranslateBoundaryMutationBody = ChangeDescription; +export type TranslateBoundaryMutationBody = BoundaryTranslationRequest; export type TranslateBoundaryMutationError = | InvalidRequestResponse | UnauthenticatedResponse @@ -522,7 +522,7 @@ export type TranslateBoundaryMutationError = | UnexpectedErrorResponse; export type TranslateBoundaryMutationVariables = { organizationId: string; - data: ChangeDescription; + data: BoundaryTranslationRequest; headers: TranslateBoundaryHeaders; }; diff --git a/app/src/lib/api/generated/boundaries/boundaries.zod.ts b/app/src/lib/api/generated/boundaries/boundaries.zod.ts index 05bab9c836..b95427d1b9 100644 --- a/app/src/lib/api/generated/boundaries/boundaries.zod.ts +++ b/app/src/lib/api/generated/boundaries/boundaries.zod.ts @@ -17,6 +17,10 @@ export const GetBoundariesParams = zod.object({ ), }); +export const getBoundariesResponseRulesItemConversionOneCheckedMin = 0; + +export const getBoundariesResponseRulesItemConversionOneMismatchesMin = 0; + export const GetBoundariesResponse = zod .object({ mode: zod @@ -24,12 +28,115 @@ export const GetBoundariesResponse = zod .describe( "enforce refuses what the rules refuse. dry-run records what they would have refused and lets it through, to try a rule before it stops anybody's work.", ), + rules: zod + .array( + zod + .object({ + id: zod + .string() + .describe( + "The rule's own id, which stays when its text changes.", + ), + effect: zod + .enum(["forbid", "permit"]) + .describe( + "forbid refuses an action the rule matches, whatever any other rule says. permit allows an action it matches, unless a forbid rule matches it too.", + ), + language: zod + .string() + .describe( + "The language that decides a rule now: cedar, or cel for a rule OpenBot couldn't yet move to Cedar with the same result.", + ), + cedar: zod + .string() + .nullable() + .describe( + "The rule as one Cedar policy. Null while the rule is still CEL.", + ), + cel: zod + .string() + .nullable() + .describe( + "The rule in CEL: the text it was written in, or the CEL form of a rule written in Cedar. Null when it has none, so a server older than the one that saved it doesn't apply it.", + ), + name: zod.string().nullable(), + description: zod + .string() + .nullable() + .describe("What the rule stops, in words."), + english: zod + .string() + .nullable() + .describe( + "The English the rule was written from, when OpenBot has it.", + ), + englishFrom: zod.union([ + zod + .string() + .describe( + "Where a rule's English came from: authoring, the sentence an administrator wrote it from; description, its description; reading, OpenBot's reading of the rule, for a rule typed by hand.", + ), + zod.null(), + ]), + conversion: zod + .union([ + zod + .object({ + tier: zod + .string() + .describe( + "exact, translated rule for rule; model, written in Cedar by the deployment's model from the rule's English; none, no Cedar candidate could be written.", + ), + status: zod + .string() + .describe( + "converted, the Cedar rule decided every action checked as the CEL rule did and now decides in its place; needs_rewrite, it didn't, or none could be written, so the CEL rule still decides and an administrator should rewrite it.", + ), + checked: zod + .int() + .min( + getBoundariesResponseRulesItemConversionOneCheckedMin, + ) + .describe( + "How many actions, past and made up, both rules were asked about.", + ), + mismatches: zod + .int() + .min( + getBoundariesResponseRulesItemConversionOneMismatchesMin, + ) + .describe( + "How many of them the two rules decided differently.", + ), + at: zod.iso + .datetime({ offset: true }) + .describe("When the conversion ran."), + }) + .describe( + "How a rule written in CEL was moved to Cedar, or why it wasn't.", + ), + zod.null(), + ]) + .describe( + "How the rule was moved from CEL. Null for a rule written in Cedar.", + ), + }) + .describe( + "One rule, in the administrator's order. A rule is decided in Cedar when it has Cedar, and in CEL while it has none.", + ), + ) + .optional() + .describe("Every rule, forbid and permit, in the administrator's order."), deny: zod .array(zod.string()) - .describe("The deny rules, each a CEL expression."), + .describe( + "Deprecated. Read `rules` instead. The forbid rules that have a CEL form, each a CEL expression.", + ), allow: zod .array(zod.string()) - .describe("The allow rules, each a CEL expression."), + .describe( + "Deprecated. Read `rules` instead. The permit rules that have a CEL form, each a CEL expression.", + ), labels: zod .record( zod.string(), @@ -43,11 +150,11 @@ export const GetBoundariesResponse = zod ), ) .describe( - "Each rule's name and description, keyed by the rule's own text.", + "Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text.", ), }) .describe( - "What every Bot may do. Deny rules are read first: an action any of them is true for is refused, whatever an allow rule says. Then an action any allow rule is true for is permitted, and one that none is true for is refused.", + "What every Bot may do. Forbid rules are read first: an action any of them matches is refused, whatever a permit rule says. Then an action any permit rule matches is allowed, and one that none matches is refused.", ); /** @@ -76,6 +183,23 @@ export const ReplaceBoundariesHeader = zod.object({ ), }); +export const replaceBoundariesBodyRulesItemIdMax = 64; + +export const replaceBoundariesBodyRulesItemNameMax = 80; + +export const replaceBoundariesBodyRulesItemNameRegExp = new RegExp( + "^[^\\x00]*[^\\s\\x00][^\\x00]*$", +); +export const replaceBoundariesBodyRulesItemDescriptionMax = 300; + +export const replaceBoundariesBodyRulesItemDescriptionRegExp = new RegExp( + "^[^\\x00]*$", +); +export const replaceBoundariesBodyRulesItemEnglishMax = 1000; + +export const replaceBoundariesBodyRulesItemEnglishRegExp = new RegExp( + "^[^\\x00]*$", +); export const replaceBoundariesBodyDenyDefault = []; export const replaceBoundariesBodyAllowDefault = []; export const replaceBoundariesBodyLabelsNameMax = 80; @@ -94,58 +218,127 @@ export const replaceBoundariesBodyAuthoringTextRegExp = new RegExp( "^[^\\x00]*[^\\s\\x00][^\\x00]*$", ); -export const ReplaceBoundariesBody = zod.object({ - mode: zod - .enum(["enforce", "dry-run"]) - .describe( - "enforce refuses what the rules refuse. dry-run records what they would have refused and lets it through, to try a rule before it stops anybody's work.", - ), - deny: zod - .array(zod.string()) - .default(replaceBoundariesBodyDenyDefault) - .describe( - "The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate.", - ), - allow: zod - .array(zod.string()) - .default(replaceBoundariesBodyAllowDefault) - .describe("The allow rules, each a CEL expression. Empty permits nothing."), - labels: zod - .record( - zod.string(), - zod.object({ - name: zod +export const ReplaceBoundariesBody = zod + .object({ + mode: zod + .enum(["enforce", "dry-run"]) + .describe( + "enforce refuses what the rules refuse. dry-run records what they would have refused and lets it through, to try a rule before it stops anybody's work.", + ), + rules: zod + .array( + zod + .object({ + id: zod + .string() + .min(1) + .max(replaceBoundariesBodyRulesItemIdMax) + .optional() + .describe( + "The id of a rule being kept or changed. Leave it out for a new rule.", + ), + effect: zod + .enum(["forbid", "permit"]) + .describe( + "forbid refuses an action the rule matches, whatever any other rule says. permit allows an action it matches, unless a forbid rule matches it too.", + ), + cedar: zod + .string() + .min(1) + .optional() + .describe( + "The rule as one Cedar policy whose effect matches `effect`. It must be one OpenBot can check against its schema.", + ), + cel: zod + .string() + .min(1) + .optional() + .describe( + "The rule in CEL, for a rule that has no Cedar yet. OpenBot moves it to Cedar when the result decides the same.", + ), + name: zod + .string() + .min(1) + .max(replaceBoundariesBodyRulesItemNameMax) + .regex(replaceBoundariesBodyRulesItemNameRegExp) + .optional() + .describe("1 to 80 characters once trimmed."), + description: zod + .string() + .max(replaceBoundariesBodyRulesItemDescriptionMax) + .regex(replaceBoundariesBodyRulesItemDescriptionRegExp) + .optional() + .describe("At most 300 characters once trimmed."), + english: zod + .string() + .max(replaceBoundariesBodyRulesItemEnglishMax) + .regex(replaceBoundariesBodyRulesItemEnglishRegExp) + .optional() + .describe("The English the rule was written from."), + }) + .describe( + "One rule to save. Give its Cedar, or its CEL to have OpenBot move it to Cedar; a rule with neither is refused.", + ), + ) + .optional() + .describe( + "Every rule, forbid and permit, in order. A rule added here must be one OpenBot can check.", + ), + deny: zod + .array(zod.string()) + .default(replaceBoundariesBodyDenyDefault) + .describe( + "Deprecated. Send `rules` instead. The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate.", + ), + allow: zod + .array(zod.string()) + .default(replaceBoundariesBodyAllowDefault) + .describe( + "Deprecated. Send `rules` instead. The allow rules, each a CEL expression. Empty permits nothing.", + ), + labels: zod + .record( + zod.string(), + zod.object({ + name: zod + .string() + .min(1) + .max(replaceBoundariesBodyLabelsNameMax) + .regex(replaceBoundariesBodyLabelsNameRegExp) + .describe("1 to 80 characters once trimmed."), + description: zod + .string() + .max(replaceBoundariesBodyLabelsDescriptionMax) + .regex(replaceBoundariesBodyLabelsDescriptionRegExp) + .optional() + .describe("At most 300 characters once trimmed."), + }), + ) + .optional() + .describe( + "Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped.", + ), + authoring: zod + .object({ + source: zod.literal("english"), + text: zod .string() .min(1) - .max(replaceBoundariesBodyLabelsNameMax) - .regex(replaceBoundariesBodyLabelsNameRegExp) - .describe("1 to 80 characters once trimmed."), - description: zod - .string() - .max(replaceBoundariesBodyLabelsDescriptionMax) - .regex(replaceBoundariesBodyLabelsDescriptionRegExp) - .optional() - .describe("At most 300 characters once trimmed."), - }), - ) - .optional() - .describe( - "Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped.", - ), - authoring: zod - .object({ - source: zod.literal("english"), - text: zod - .string() - .min(1) - .max(replaceBoundariesBodyAuthoringTextMax) - .regex(replaceBoundariesBodyAuthoringTextRegExp), - }) - .optional() - .describe( - "The sentence in English a change was written from, recorded with it.", - ), -}); + .max(replaceBoundariesBodyAuthoringTextMax) + .regex(replaceBoundariesBodyAuthoringTextRegExp), + }) + .optional() + .describe( + "The sentence in English a change was written from, recorded with it.", + ), + }) + .describe( + "The boundaries to save. With `rules`, the rules are exactly those, in that order, and `deny`, `allow` and `labels` are ignored. Without it, `deny` and `allow` replace the rules that have a CEL form, and a rule that has none is kept as it is.", + ); + +export const replaceBoundariesResponseRulesItemConversionOneCheckedMin = 0; + +export const replaceBoundariesResponseRulesItemConversionOneMismatchesMin = 0; export const ReplaceBoundariesResponse = zod .object({ @@ -154,12 +347,115 @@ export const ReplaceBoundariesResponse = zod .describe( "enforce refuses what the rules refuse. dry-run records what they would have refused and lets it through, to try a rule before it stops anybody's work.", ), + rules: zod + .array( + zod + .object({ + id: zod + .string() + .describe( + "The rule's own id, which stays when its text changes.", + ), + effect: zod + .enum(["forbid", "permit"]) + .describe( + "forbid refuses an action the rule matches, whatever any other rule says. permit allows an action it matches, unless a forbid rule matches it too.", + ), + language: zod + .string() + .describe( + "The language that decides a rule now: cedar, or cel for a rule OpenBot couldn't yet move to Cedar with the same result.", + ), + cedar: zod + .string() + .nullable() + .describe( + "The rule as one Cedar policy. Null while the rule is still CEL.", + ), + cel: zod + .string() + .nullable() + .describe( + "The rule in CEL: the text it was written in, or the CEL form of a rule written in Cedar. Null when it has none, so a server older than the one that saved it doesn't apply it.", + ), + name: zod.string().nullable(), + description: zod + .string() + .nullable() + .describe("What the rule stops, in words."), + english: zod + .string() + .nullable() + .describe( + "The English the rule was written from, when OpenBot has it.", + ), + englishFrom: zod.union([ + zod + .string() + .describe( + "Where a rule's English came from: authoring, the sentence an administrator wrote it from; description, its description; reading, OpenBot's reading of the rule, for a rule typed by hand.", + ), + zod.null(), + ]), + conversion: zod + .union([ + zod + .object({ + tier: zod + .string() + .describe( + "exact, translated rule for rule; model, written in Cedar by the deployment's model from the rule's English; none, no Cedar candidate could be written.", + ), + status: zod + .string() + .describe( + "converted, the Cedar rule decided every action checked as the CEL rule did and now decides in its place; needs_rewrite, it didn't, or none could be written, so the CEL rule still decides and an administrator should rewrite it.", + ), + checked: zod + .int() + .min( + replaceBoundariesResponseRulesItemConversionOneCheckedMin, + ) + .describe( + "How many actions, past and made up, both rules were asked about.", + ), + mismatches: zod + .int() + .min( + replaceBoundariesResponseRulesItemConversionOneMismatchesMin, + ) + .describe( + "How many of them the two rules decided differently.", + ), + at: zod.iso + .datetime({ offset: true }) + .describe("When the conversion ran."), + }) + .describe( + "How a rule written in CEL was moved to Cedar, or why it wasn't.", + ), + zod.null(), + ]) + .describe( + "How the rule was moved from CEL. Null for a rule written in Cedar.", + ), + }) + .describe( + "One rule, in the administrator's order. A rule is decided in Cedar when it has Cedar, and in CEL while it has none.", + ), + ) + .optional() + .describe("Every rule, forbid and permit, in the administrator's order."), deny: zod .array(zod.string()) - .describe("The deny rules, each a CEL expression."), + .describe( + "Deprecated. Read `rules` instead. The forbid rules that have a CEL form, each a CEL expression.", + ), allow: zod .array(zod.string()) - .describe("The allow rules, each a CEL expression."), + .describe( + "Deprecated. Read `rules` instead. The permit rules that have a CEL form, each a CEL expression.", + ), labels: zod .record( zod.string(), @@ -173,11 +469,11 @@ export const ReplaceBoundariesResponse = zod ), ) .describe( - "Each rule's name and description, keyed by the rule's own text.", + "Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text.", ), }) .describe( - "What every Bot may do. Deny rules are read first: an action any of them is true for is refused, whatever an allow rule says. Then an action any allow rule is true for is permitted, and one that none is true for is refused.", + "What every Bot may do. Forbid rules are read first: an action any of them matches is refused, whatever a permit rule says. Then an action any permit rule matches is allowed, and one that none matches is refused.", ); /** @@ -221,10 +517,20 @@ export const TranslateBoundaryBody = zod.object({ .describe( "The change in a sentence or two, at most 1,000 characters once trimmed.", ), + language: zod + .enum(["cel", "cedar"]) + .optional() + .describe( + "The language to write the rule in. Leave it out for cel, as before; send cedar for a rule in Cedar.", + ), }); export const TranslateBoundaryResponse = zod.object({ - rule: zod.string().describe("The rule the model wrote, as a CEL expression."), + language: zod + .string() + .optional() + .describe("The language `rule` is written in. Absent means cel."), + rule: zod.string().describe("The rule the model wrote, in `language`."), effect: zod .enum(["deny", "allow"]) .describe("Which list the rule belongs in."), @@ -283,6 +589,22 @@ export const ReplayBoundariesHeader = zod.object({ ), }); +export const replayBoundariesBodyBoundariesRulesItemIdMax = 64; + +export const replayBoundariesBodyBoundariesRulesItemNameMax = 80; + +export const replayBoundariesBodyBoundariesRulesItemNameRegExp = new RegExp( + "^[^\\x00]*[^\\s\\x00][^\\x00]*$", +); +export const replayBoundariesBodyBoundariesRulesItemDescriptionMax = 300; + +export const replayBoundariesBodyBoundariesRulesItemDescriptionRegExp = + new RegExp("^[^\\x00]*$"); +export const replayBoundariesBodyBoundariesRulesItemEnglishMax = 1000; + +export const replayBoundariesBodyBoundariesRulesItemEnglishRegExp = new RegExp( + "^[^\\x00]*$", +); export const replayBoundariesBodyBoundariesDenyDefault = []; export const replayBoundariesBodyBoundariesAllowDefault = []; export const replayBoundariesBodyBoundariesLabelsNameMax = 80; @@ -306,12 +628,75 @@ export const ReplayBoundariesBody = zod.object({ .describe( "enforce refuses what the rules refuse. dry-run records what they would have refused and lets it through, to try a rule before it stops anybody's work.", ), + rules: zod + .array( + zod + .object({ + id: zod + .string() + .min(1) + .max(replayBoundariesBodyBoundariesRulesItemIdMax) + .optional() + .describe( + "The id of a rule being kept or changed. Leave it out for a new rule.", + ), + effect: zod + .enum(["forbid", "permit"]) + .describe( + "forbid refuses an action the rule matches, whatever any other rule says. permit allows an action it matches, unless a forbid rule matches it too.", + ), + cedar: zod + .string() + .min(1) + .optional() + .describe( + "The rule as one Cedar policy whose effect matches `effect`. It must be one OpenBot can check against its schema.", + ), + cel: zod + .string() + .min(1) + .optional() + .describe( + "The rule in CEL, for a rule that has no Cedar yet. OpenBot moves it to Cedar when the result decides the same.", + ), + name: zod + .string() + .min(1) + .max(replayBoundariesBodyBoundariesRulesItemNameMax) + .regex(replayBoundariesBodyBoundariesRulesItemNameRegExp) + .optional() + .describe("1 to 80 characters once trimmed."), + description: zod + .string() + .max(replayBoundariesBodyBoundariesRulesItemDescriptionMax) + .regex(replayBoundariesBodyBoundariesRulesItemDescriptionRegExp) + .optional() + .describe("At most 300 characters once trimmed."), + english: zod + .string() + .max(replayBoundariesBodyBoundariesRulesItemEnglishMax) + .regex(replayBoundariesBodyBoundariesRulesItemEnglishRegExp) + .optional() + .describe("The English the rule was written from."), + }) + .describe( + "One rule to save. Give its Cedar, or its CEL to have OpenBot move it to Cedar; a rule with neither is refused.", + ), + ) + .optional() + .describe("Every rule to test, forbid and permit, in order."), deny: zod .array(zod.string()) - .default(replayBoundariesBodyBoundariesDenyDefault), + .default(replayBoundariesBodyBoundariesDenyDefault) + .describe( + "Deprecated. Send `rules` instead. The deny rules, each a CEL expression.", + ), allow: zod .array(zod.string()) - .default(replayBoundariesBodyBoundariesAllowDefault), + .default(replayBoundariesBodyBoundariesAllowDefault) + .describe( + "Deprecated. Send `rules` instead. The allow rules, each a CEL expression.", + ), labels: zod .record( zod.string(), @@ -332,10 +717,12 @@ export const ReplayBoundariesBody = zod.object({ ) .optional() .describe( - "Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped.", + "Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped.", ), }) - .describe("Boundaries to test, as a save would take them."), + .describe( + "Boundaries to test, as a save would take them. With `rules`, the rules are those and `deny`, `allow` and `labels` are ignored.", + ), limit: zod .int() .min(1) @@ -406,6 +793,12 @@ export const ReplayBoundariesResponse = zod.object({ .describe( "The rule that decides it. Null when no rule permits the action, so it is refused.", ), + ruleId: zod + .string() + .nullish() + .describe( + "The id of the rule that decides it, as in `rules`. Null when no rule permits the action, or the rule has no id.", + ), reason: zod.string(), }) .describe( diff --git a/app/src/lib/api/generated/model/boundaries.ts b/app/src/lib/api/generated/model/boundaries.ts index 2b6883b093..2bd77e94d8 100644 --- a/app/src/lib/api/generated/model/boundaries.ts +++ b/app/src/lib/api/generated/model/boundaries.ts @@ -3,16 +3,28 @@ */ import type { BoundariesLabels } from "./boundariesLabels"; import type { BoundaryMode } from "./boundaryMode"; +import type { BoundaryRule } from "./boundaryRule"; /** - * What every Bot may do. Deny rules are read first: an action any of them is true for is refused, whatever an allow rule says. Then an action any allow rule is true for is permitted, and one that none is true for is refused. + * What every Bot may do. Forbid rules are read first: an action any of them matches is refused, whatever a permit rule says. Then an action any permit rule matches is allowed, and one that none matches is refused. */ export interface Boundaries { mode: BoundaryMode; - /** The deny rules, each a CEL expression. */ + /** Every rule, forbid and permit, in the administrator's order. */ + rules?: BoundaryRule[]; + /** + * Deprecated. Read `rules` instead. The forbid rules that have a CEL form, each a CEL expression. + * @deprecated + */ deny: string[]; - /** The allow rules, each a CEL expression. */ + /** + * Deprecated. Read `rules` instead. The permit rules that have a CEL form, each a CEL expression. + * @deprecated + */ allow: string[]; - /** Each rule's name and description, keyed by the rule's own text. */ + /** + * Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text. + * @deprecated + */ labels: BoundariesLabels; } diff --git a/app/src/lib/api/generated/model/boundariesDraft.ts b/app/src/lib/api/generated/model/boundariesDraft.ts index 5aa832198b..69be0a4107 100644 --- a/app/src/lib/api/generated/model/boundariesDraft.ts +++ b/app/src/lib/api/generated/model/boundariesDraft.ts @@ -3,14 +3,28 @@ */ import type { BoundariesDraftLabels } from "./boundariesDraftLabels"; import type { BoundaryMode } from "./boundaryMode"; +import type { BoundaryRuleInput } from "./boundaryRuleInput"; /** - * Boundaries to test, as a save would take them. + * Boundaries to test, as a save would take them. With `rules`, the rules are those and `deny`, `allow` and `labels` are ignored. */ export interface BoundariesDraft { mode: BoundaryMode; + /** Every rule to test, forbid and permit, in order. */ + rules?: BoundaryRuleInput[]; + /** + * Deprecated. Send `rules` instead. The deny rules, each a CEL expression. + * @deprecated + */ deny?: string[]; + /** + * Deprecated. Send `rules` instead. The allow rules, each a CEL expression. + * @deprecated + */ allow?: string[]; - /** Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. */ + /** + * Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + * @deprecated + */ labels?: BoundariesDraftLabels; } diff --git a/app/src/lib/api/generated/model/boundariesDraftLabels.ts b/app/src/lib/api/generated/model/boundariesDraftLabels.ts index 3b9fc11a8a..b8e45d6355 100644 --- a/app/src/lib/api/generated/model/boundariesDraftLabels.ts +++ b/app/src/lib/api/generated/model/boundariesDraftLabels.ts @@ -4,6 +4,7 @@ import type { BoundaryRuleLabelInput } from "./boundaryRuleLabelInput"; /** - * Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + * Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + * @deprecated */ export type BoundariesDraftLabels = { [key: string]: BoundaryRuleLabelInput }; diff --git a/app/src/lib/api/generated/model/boundariesInput.ts b/app/src/lib/api/generated/model/boundariesInput.ts index f0a0a793e9..bde243d6d7 100644 --- a/app/src/lib/api/generated/model/boundariesInput.ts +++ b/app/src/lib/api/generated/model/boundariesInput.ts @@ -4,14 +4,29 @@ import type { Authoring } from "./authoring"; import type { BoundariesInputLabels } from "./boundariesInputLabels"; import type { BoundaryMode } from "./boundaryMode"; +import type { BoundaryRuleInput } from "./boundaryRuleInput"; +/** + * The boundaries to save. With `rules`, the rules are exactly those, in that order, and `deny`, `allow` and `labels` are ignored. Without it, `deny` and `allow` replace the rules that have a CEL form, and a rule that has none is kept as it is. + */ export interface BoundariesInput { mode: BoundaryMode; - /** The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate. */ + /** Every rule, forbid and permit, in order. A rule added here must be one OpenBot can check. */ + rules?: BoundaryRuleInput[]; + /** + * Deprecated. Send `rules` instead. The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate. + * @deprecated + */ deny?: string[]; - /** The allow rules, each a CEL expression. Empty permits nothing. */ + /** + * Deprecated. Send `rules` instead. The allow rules, each a CEL expression. Empty permits nothing. + * @deprecated + */ allow?: string[]; - /** Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. */ + /** + * Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + * @deprecated + */ labels?: BoundariesInputLabels; authoring?: Authoring; } diff --git a/app/src/lib/api/generated/model/boundariesInputLabels.ts b/app/src/lib/api/generated/model/boundariesInputLabels.ts index ee29bdd560..990f6fc050 100644 --- a/app/src/lib/api/generated/model/boundariesInputLabels.ts +++ b/app/src/lib/api/generated/model/boundariesInputLabels.ts @@ -4,6 +4,7 @@ import type { BoundaryRuleLabelInput } from "./boundaryRuleLabelInput"; /** - * Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + * Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. + * @deprecated */ export type BoundariesInputLabels = { [key: string]: BoundaryRuleLabelInput }; diff --git a/app/src/lib/api/generated/model/boundariesLabels.ts b/app/src/lib/api/generated/model/boundariesLabels.ts index f8ddc804dd..3f179e565d 100644 --- a/app/src/lib/api/generated/model/boundariesLabels.ts +++ b/app/src/lib/api/generated/model/boundariesLabels.ts @@ -4,6 +4,7 @@ import type { BoundaryRuleLabel } from "./boundaryRuleLabel"; /** - * Each rule's name and description, keyed by the rule's own text. + * Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text. + * @deprecated */ export type BoundariesLabels = { [key: string]: BoundaryRuleLabel }; diff --git a/app/src/lib/api/generated/model/boundaryReplayChange.ts b/app/src/lib/api/generated/model/boundaryReplayChange.ts index b58279e248..18c0e7848f 100644 --- a/app/src/lib/api/generated/model/boundaryReplayChange.ts +++ b/app/src/lib/api/generated/model/boundaryReplayChange.ts @@ -41,5 +41,10 @@ export interface BoundaryReplayChange { * @nullable */ rule: string | null; + /** + * The id of the rule that decides it, as in `rules`. Null when no rule permits the action, or the rule has no id. + * @nullable + */ + ruleId?: string | null; reason: string; } diff --git a/app/src/lib/api/generated/model/boundaryRule.ts b/app/src/lib/api/generated/model/boundaryRule.ts new file mode 100644 index 0000000000..05ccb4e3e1 --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRule.ts @@ -0,0 +1,42 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { BoundaryRuleConversion } from "./boundaryRuleConversion"; +import type { BoundaryRuleEffect } from "./boundaryRuleEffect"; +import type { BoundaryRuleEnglishSource } from "./boundaryRuleEnglishSource"; +import type { BoundaryRuleLanguageAnswer } from "./boundaryRuleLanguageAnswer"; + +/** + * One rule, in the administrator's order. A rule is decided in Cedar when it has Cedar, and in CEL while it has none. + */ +export interface BoundaryRule { + /** The rule's own id, which stays when its text changes. */ + id: string; + effect: BoundaryRuleEffect; + language: BoundaryRuleLanguageAnswer; + /** + * The rule as one Cedar policy. Null while the rule is still CEL. + * @nullable + */ + cedar: string | null; + /** + * The rule in CEL: the text it was written in, or the CEL form of a rule written in Cedar. Null when it has none, so a server older than the one that saved it doesn't apply it. + * @nullable + */ + cel: string | null; + /** @nullable */ + name: string | null; + /** + * What the rule stops, in words. + * @nullable + */ + description: string | null; + /** + * The English the rule was written from, when OpenBot has it. + * @nullable + */ + english: string | null; + englishFrom: BoundaryRuleEnglishSource | null; + /** How the rule was moved from CEL. Null for a rule written in Cedar. */ + conversion: BoundaryRuleConversion | null; +} diff --git a/app/src/lib/api/generated/model/boundaryRuleConversion.ts b/app/src/lib/api/generated/model/boundaryRuleConversion.ts new file mode 100644 index 0000000000..d62d4858ca --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRuleConversion.ts @@ -0,0 +1,25 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * How a rule written in CEL was moved to Cedar, or why it wasn't. + */ +export interface BoundaryRuleConversion { + /** exact, translated rule for rule; model, written in Cedar by the deployment's model from the rule's English; none, no Cedar candidate could be written. */ + tier: string; + /** converted, the Cedar rule decided every action checked as the CEL rule did and now decides in its place; needs_rewrite, it didn't, or none could be written, so the CEL rule still decides and an administrator should rewrite it. */ + status: string; + /** + * How many actions, past and made up, both rules were asked about. + * @minimum 0 + */ + checked: number; + /** + * How many of them the two rules decided differently. + * @minimum 0 + */ + mismatches: number; + /** When the conversion ran. */ + at: string; +} diff --git a/app/src/lib/api/generated/model/boundaryRuleEffect.ts b/app/src/lib/api/generated/model/boundaryRuleEffect.ts new file mode 100644 index 0000000000..19f41f6f29 --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRuleEffect.ts @@ -0,0 +1,14 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * forbid refuses an action the rule matches, whatever any other rule says. permit allows an action it matches, unless a forbid rule matches it too. + */ +export type BoundaryRuleEffect = + (typeof BoundaryRuleEffect)[keyof typeof BoundaryRuleEffect]; + +export const BoundaryRuleEffect = { + forbid: "forbid", + permit: "permit", +} as const; diff --git a/app/src/lib/api/generated/model/boundaryRuleEnglishSource.ts b/app/src/lib/api/generated/model/boundaryRuleEnglishSource.ts new file mode 100644 index 0000000000..f52d91030f --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRuleEnglishSource.ts @@ -0,0 +1,8 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * Where a rule's English came from: authoring, the sentence an administrator wrote it from; description, its description; reading, OpenBot's reading of the rule, for a rule typed by hand. + */ +export type BoundaryRuleEnglishSource = string; diff --git a/app/src/lib/api/generated/model/boundaryRuleInput.ts b/app/src/lib/api/generated/model/boundaryRuleInput.ts new file mode 100644 index 0000000000..71469c1b97 --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRuleInput.ts @@ -0,0 +1,46 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { BoundaryRuleEffect } from "./boundaryRuleEffect"; + +/** + * One rule to save. Give its Cedar, or its CEL to have OpenBot move it to Cedar; a rule with neither is refused. + */ +export interface BoundaryRuleInput { + /** + * The id of a rule being kept or changed. Leave it out for a new rule. + * @minLength 1 + * @maxLength 64 + */ + id?: string; + effect: BoundaryRuleEffect; + /** + * The rule as one Cedar policy whose effect matches `effect`. It must be one OpenBot can check against its schema. + * @minLength 1 + */ + cedar?: string; + /** + * The rule in CEL, for a rule that has no Cedar yet. OpenBot moves it to Cedar when the result decides the same. + * @minLength 1 + */ + cel?: string; + /** + * 1 to 80 characters once trimmed. + * @minLength 1 + * @maxLength 80 + * @pattern ^[^\x00]*[^\s\x00][^\x00]*$ + */ + name?: string; + /** + * At most 300 characters once trimmed. + * @maxLength 300 + * @pattern ^[^\x00]*$ + */ + description?: string; + /** + * The English the rule was written from. + * @maxLength 1000 + * @pattern ^[^\x00]*$ + */ + english?: string; +} diff --git a/app/src/lib/api/generated/model/boundaryRuleLanguage.ts b/app/src/lib/api/generated/model/boundaryRuleLanguage.ts new file mode 100644 index 0000000000..960b28f6ce --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRuleLanguage.ts @@ -0,0 +1,14 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * The language a rule is written in. cedar is the language rules are written in from now on. cel is the language rules were written in before; a rule in it is still accepted, and is moved to Cedar when it is saved. + */ +export type BoundaryRuleLanguage = + (typeof BoundaryRuleLanguage)[keyof typeof BoundaryRuleLanguage]; + +export const BoundaryRuleLanguage = { + cel: "cel", + cedar: "cedar", +} as const; diff --git a/app/src/lib/api/generated/model/boundaryRuleLanguageAnswer.ts b/app/src/lib/api/generated/model/boundaryRuleLanguageAnswer.ts new file mode 100644 index 0000000000..c25c06948d --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryRuleLanguageAnswer.ts @@ -0,0 +1,8 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * The language that decides a rule now: cedar, or cel for a rule OpenBot couldn't yet move to Cedar with the same result. + */ +export type BoundaryRuleLanguageAnswer = string; diff --git a/app/src/lib/api/generated/model/boundaryTranslation.ts b/app/src/lib/api/generated/model/boundaryTranslation.ts index 28dc955db8..df4d240eb3 100644 --- a/app/src/lib/api/generated/model/boundaryTranslation.ts +++ b/app/src/lib/api/generated/model/boundaryTranslation.ts @@ -1,11 +1,14 @@ /** * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. */ +import type { BoundaryRuleLanguageAnswer } from "./boundaryRuleLanguageAnswer"; import type { BoundaryTranslationEffect } from "./boundaryTranslationEffect"; import type { RuleCheck } from "./ruleCheck"; export interface BoundaryTranslation { - /** The rule the model wrote, as a CEL expression. */ + /** The language `rule` is written in. Absent means cel. */ + language?: BoundaryRuleLanguageAnswer; + /** The rule the model wrote, in `language`. */ rule: string; /** Which list the rule belongs in. */ effect: BoundaryTranslationEffect; diff --git a/app/src/lib/api/generated/model/boundaryTranslationRequest.ts b/app/src/lib/api/generated/model/boundaryTranslationRequest.ts new file mode 100644 index 0000000000..3f16f093cd --- /dev/null +++ b/app/src/lib/api/generated/model/boundaryTranslationRequest.ts @@ -0,0 +1,16 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { BoundaryRuleLanguage } from "./boundaryRuleLanguage"; + +export interface BoundaryTranslationRequest { + /** + * The change in a sentence or two, at most 1,000 characters once trimmed. + * @minLength 1 + * @maxLength 1000 + * @pattern ^[^\x00]*[^\s\x00][^\x00]*$ + */ + text: string; + /** The language to write the rule in. Leave it out for cel, as before; send cedar for a rule in Cedar. */ + language?: BoundaryRuleLanguage; +} diff --git a/app/src/lib/api/generated/model/index.ts b/app/src/lib/api/generated/model/index.ts index 06488a9515..d06b94e7e9 100644 --- a/app/src/lib/api/generated/model/index.ts +++ b/app/src/lib/api/generated/model/index.ts @@ -479,10 +479,18 @@ export * from "./boundaryReplayChangeWas"; export * from "./boundaryReplayChangeWould"; export * from "./boundaryReplayReport"; export * from "./boundaryReplayRequest"; +export * from "./boundaryRule"; +export * from "./boundaryRuleConversion"; +export * from "./boundaryRuleEffect"; +export * from "./boundaryRuleEnglishSource"; +export * from "./boundaryRuleInput"; export * from "./boundaryRuleLabel"; export * from "./boundaryRuleLabelInput"; +export * from "./boundaryRuleLanguage"; +export * from "./boundaryRuleLanguageAnswer"; export * from "./boundaryTranslation"; export * from "./boundaryTranslationEffect"; +export * from "./boundaryTranslationRequest"; export * from "./browserActivateTab"; export * from "./browserActivateTabAction"; export * from "./browserCloseTab"; From 4bea88b8880e652b0e2d79b77c8dd8c10b26c13f Mon Sep 17 00:00:00 2001 From: David McKay Date: Wed, 2 Dec 2026 22:06:52 -0800 Subject: [PATCH 02/11] Release policy: the database ends at 0216_action_policy_rules --- release-policy.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-policy.json b/release-policy.json index 77cdf66cf3..0a440d9310 100644 --- a/release-policy.json +++ b/release-policy.json @@ -27,7 +27,7 @@ "0082_routine_goal", "0077_channel_opening" ], - "to": "0215_windows_computer_machines", + "to": "0216_action_policy_rules", "rollbackCompatible": false }, "intelligenceCapabilities": [] From bb67e1498ac90423391b04f5250c324e9ff7faad Mon Sep 17 00:00:00 2001 From: David McKay Date: Wed, 2 Dec 2026 22:15:12 -0800 Subject: [PATCH 03/11] Boundaries deprecations: sunset 2028-01-03, at least 365 days from any day this can merge --- api/openapi.yaml | 36 ++++++++++++++++++------------------ api/openapi/approvals.yaml | 36 ++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/api/openapi.yaml b/api/openapi.yaml index 8927ce83af..0dcbdcfeee 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -42997,24 +42997,24 @@ components: deny: type: array deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Read `rules` instead. The forbid rules that have a CEL form, each a CEL expression. items: type: string allow: type: array deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Read `rules` instead. The permit rules that have a CEL form, each a CEL expression. items: type: string labels: type: object deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabel' @@ -43091,8 +43091,8 @@ components: type: array default: [] deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Send `rules` instead. The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate. items: type: string @@ -43100,16 +43100,16 @@ components: type: array default: [] deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Send `rules` instead. The allow rules, each a CEL expression. Empty permits nothing. items: type: string labels: type: object deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabelInput' @@ -43193,8 +43193,8 @@ components: type: array default: [] deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Send `rules` instead. The deny rules, each a CEL expression. items: type: string @@ -43202,16 +43202,16 @@ components: type: array default: [] deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Send `rules` instead. The allow rules, each a CEL expression. items: type: string labels: type: object deprecated: true - x-deprecation-date: '2026-12-02' - x-sunset: '2027-12-02' + x-deprecation-date: '2026-12-03' + x-sunset: '2028-01-03' description: Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is dropped. additionalProperties: $ref: '#/components/schemas/BoundaryRuleLabelInput' diff --git a/api/openapi/approvals.yaml b/api/openapi/approvals.yaml index 63e0059af3..1cf71e2ae8 100644 --- a/api/openapi/approvals.yaml +++ b/api/openapi/approvals.yaml @@ -4248,8 +4248,8 @@ components: deny: type: array deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Read `rules` instead. The forbid rules that have a CEL form, each a CEL expression. @@ -4258,8 +4258,8 @@ components: allow: type: array deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Read `rules` instead. The permit rules that have a CEL form, each a CEL expression. @@ -4268,8 +4268,8 @@ components: labels: type: object deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Read `rules` instead. Each CEL rule's name and description, keyed by the rule's own text. @@ -4294,8 +4294,8 @@ components: type: array default: [] deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: Deprecated. Send `rules` instead. The deny rules, each a CEL expression. items: type: string @@ -4303,16 +4303,16 @@ components: type: array default: [] deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: Deprecated. Send `rules` instead. The allow rules, each a CEL expression. items: type: string labels: type: object deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is @@ -4342,8 +4342,8 @@ components: type: array default: [] deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Send `rules` instead. The deny rules, each a CEL expression. One added here must be one OpenBot can evaluate. @@ -4353,8 +4353,8 @@ components: type: array default: [] deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Send `rules` instead. The allow rules, each a CEL expression. Empty permits nothing. @@ -4363,8 +4363,8 @@ components: labels: type: object deprecated: true - x-deprecation-date: 2026-12-02 - x-sunset: 2027-12-02 + x-deprecation-date: 2026-12-03 + x-sunset: 2028-01-03 description: >- Deprecated. Send `rules` instead. Each rule's name and description, keyed by the rule's own text. A label for a rule in neither list is From 226756c0e492bd3b265dba292c6fc6f587abefeb Mon Sep 17 00:00:00 2001 From: David McKay Date: Wed, 2 Dec 2026 22:52:39 -0800 Subject: [PATCH 04/11] Boundaries docs: rules in Cedar, CEL kept for 12 months The configuration and architecture docs described boundary rules as CEL. They now say what the server does once rules move to Cedar: - docs/architecture.md: rules are Cedar policies (the Bot the principal, the intent the action, the facts in context, text facts lowercased), checked against OpenBot's schema when saved; CEL rules keep applying as written until a Cedar rule is proven to decide the same; how the saved list keeps deny and allow as every rule's CEL form, so the previous release enforces the same rules during a rolling upgrade or after a rollback; LISTEN/NOTIFY as before. - docs/configuration.md and .env.example: AGENT_COMPUTER_POLICY takes a Cedar policy anywhere it takes CEL, and a Cedar rule that doesn't validate, or sits in the wrong list, stops the start. - README.md: the governance bullet says Cedar. --- .env.example | 6 +++++ README.md | 2 +- docs/architecture.md | 52 ++++++++++++++++++++++++++++++++++++------- docs/configuration.md | 2 +- 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index ecda6f0831..104ce23c3b 100644 --- a/.env.example +++ b/.env.example @@ -378,6 +378,12 @@ COMPUTER_TOKEN= # `enforce` blocks; `dry-run` decides and records but lets everything through, so a new rule can be # tried against real traffic before it starts refusing anybody's work. # +# A rule can also be a Cedar policy, which is how rules are written from now on: a `forbid` in +# `deny`, a `permit` in `allow`, the intent as the action and the attributes above in `context`, +# text other than ids lowercased. CEL rules like the one below keep working for 12 months. A Cedar +# rule that doesn't validate, or sits in the wrong list, stops the server starting. For example: +# "deny":["forbid (principal, action == OpenBot::Action::\"run_command\", resource) when { context.initiator.kind != \"person\" };"] +# # AGENT_COMPUTER_POLICY={"mode":"enforce","deny":["(intent == \"activate\" && contains(element.name, \"submit\")) || ((tool.name == \"computer_key\" || tool.name == \"computer_type\") && intent == \"activate\")"],"allow":["true"]} # How long one action waits for its element, in ms. Read by agent-computer, not the server. diff --git a/README.md b/README.md index 5c1098b0ee..6d6e523809 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,7 @@ Old addresses redirect to the pages above: - **A computer per person**: the supervisor gives each person their own container, with a folder and browser profile for each of their Bots. Tick Isolated on a Bot to give it a container of its own. Set `COMPUTER_RUNTIME=runsc` to run them under gVisor where the host supports it. - **A shell, not just a browser**: a Bot can run a command in its workspace, install what it needs, and process a file it saved. Through the same gate as everything else, so a rule can refuse a shell outright or refuse particular commands, and the command is on the record either way. The command inherits PATH, locale, terminal and proxy variables, not the rest of the deployment's environment. - **The gateway is the only way in**: it resolves the target from a server-held snapshot, evaluates the policy, writes the audit row, and only then calls the computer. There is no path that acts without the record existing first. -- **CEL policy, fail closed**: rules can inspect `tool.name`, `intent`, `bot.id`, `actor.id`, `page.url`, `page.host`, `element.*`, `key`, `command`, `file.*`, `mcp.*` and `initiator.*` (what started the run, so a rule can refuse a scheduled routine what it would allow a person). Deny is evaluated before allow, a missing policy permits nothing, and a broken rule refuses rather than opens. +- **Cedar policy, fail closed**: rules are [Cedar](https://docs.cedarpolicy.com/) policies, checked against OpenBot's schema when they are saved, and can inspect `tool.name`, `intent`, `bot.id`, `actor.id`, `page.url`, `page.host`, `element.*`, `key`, `command`, `file.*`, `mcp.*` and `initiator.*` (what started the run, so a rule can refuse a scheduled routine what it would allow a person). Forbid is evaluated before permit, a missing policy permits nothing, and a rule that can't be evaluated refuses rather than opens. Rules written in CEL keep working, and move to Cedar once a Cedar rule decides the same. - **Watch what it is doing**: the screen shows what a Bot is looking at, and the Activity list under it shows what it ran, read and saved in this conversation, with the output. A command line in the transcript opens to the same thing. A saved file shows its path and size, never its contents. - **Take the wheel**: a Bot that hits a login wall or a 2FA prompt asks for help. Control is handed over in the same panel and recorded as `computer.help_requested`, `computer.control_taken` and `computer.control_released`. While a person is driving, Bot actions are refused rather than queued. - **Secrets never enter the transcript**: the trail records that a secret was requested and how long it was, not what it said. diff --git a/docs/architecture.md b/docs/architecture.md index c2847054e9..9eac13890f 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -70,14 +70,50 @@ Policy rules can inspect: scheduled run, so this is the only field that can tell an unattended run from somebody typing. -Rules use CEL expressions plus case-insensitive `contains()` and `matches()`. -Deny rules are evaluated before allow rules. The policy engine fails closed: a -missing or empty policy permits nothing, a broken deny rule denies, and a broken -allow rule does not permit. OpenBot's shipped startup default is explicit: -`deny: []` and `allow: ["true"]`, unless `AGENT_COMPUTER_POLICY` or a saved -administrator policy replaces it. A malformed configured policy stops server -startup. A policy in `dry-run` mode decides and records every action but lets it -through. +Rules are written in [Cedar](https://docs.cedarpolicy.com/). Each rule is one +`forbid` or `permit` policy: the principal is the Bot (`OpenBot::Bot`), the action +is the intent (`OpenBot::Action::"activate"`, `"run_command"` and so on, `"other"` +for an action with none), the resource is the organization, and the facts above +are in `context` (`context.page.host`, `context.initiator.kind`). Every fact is +always present, so no rule needs `has`. Text facts other than ids are lowercased +before a rule reads them, so `context.element.name like "*submit*"` also matches +"SUBMIT", and a literal compared with one of them is written in lowercase. + +```cedar +forbid (principal, action == OpenBot::Action::"run_command", resource) +when { context.initiator.kind != "person" }; +``` + +A Cedar rule is checked when it is saved: exactly one policy, its effect the one it +is saved as, and valid in strict mode against OpenBot's schema, so it can't name a +fact OpenBot doesn't have. A rule that fails is refused with the reason, and nothing +is saved. + +Rules written before Cedar are CEL expressions plus case-insensitive `contains()` +and `matches()`. They keep applying exactly as written: OpenBot moves a CEL rule to +Cedar only once the Cedar rule has decided every past and generated action the same +way, and until then the CEL rule decides. Boundaries shows a rule still in CEL as +one to rewrite. CEL is still accepted, in a save and in `AGENT_COMPUTER_POLICY`, for +12 months. + +Forbid (deny) rules are evaluated before permit (allow) rules. The policy engine +fails closed: a missing or empty policy permits nothing, a forbid rule that can't +be evaluated denies, and a permit rule that can't be evaluated does not permit. +OpenBot's shipped startup default is explicit: `deny: []` and `allow: ["true"]`, +unless `AGENT_COMPUTER_POLICY` or a saved administrator policy replaces it. A +malformed configured policy, or a Cedar rule in it that doesn't validate, stops +server startup. A policy in `dry-run` mode decides and records every action but +lets it through. + +The saved boundary is one list of rules per organization, each with an id, its +Cedar, and its CEL form where it has one. Beside the list the server keeps writing +`deny` and `allow` with every rule's CEL form, so a server of the previous release +sharing the database during a rolling upgrade, or put back after one, enforces the +same rules it did. A rule written in Cedar with no exact CEL form is the one +exception: a server older than the release that saved it doesn't apply it. A save +from an app that sends only `deny` and `allow` changes the rules that have a CEL +form and keeps the others. Every server hears a change over `LISTEN`/`NOTIFY` and +reads the list again. The deployment's enterprise controls (Use Bots, cloud browser, computer and network use, the network policy, and the MCP allowlist) are asked before these rules, from a diff --git a/docs/configuration.md b/docs/configuration.md index 77dd74ab3a..a00ad3e2bf 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1270,7 +1270,7 @@ The chart sets the server's environment from them. You don't set these by hand: | `AGENT_COMPUTER_ALLOW_PRIVATE_HOSTS` | Local-only private-host browsing when `true`. A deployment running with `NODE_ENV=production` refuses to start while it is set. Cloud metadata addresses are refused either way. | | `AGENT_ENDPOINT_ALLOWED_HOSTS` | Private addresses an agent may be registered at, comma separated; unset (none) by default. Host, optionally with a port. Exact match; no wildcards. Never-allowed addresses cannot be named. An entry that is a URL or holds a `*` refuses to start. | | `OPENBOT_THIS_MACHINE_HOST` | For a server in a container on the person's own machine: the host name that container reaches the machine by. An agent registered at a loopback address (`localhost`, `127.x`, `[::1]`) is dialled through it; the address as typed is what is checked and stored. OpenBot Desktop sets `host.docker.internal`. Unset (the default) dials addresses as written. A value with a scheme, port or path refuses to start. | -| `AGENT_COMPUTER_POLICY` | JSON action policy: `{"mode":"enforce","deny":[...],"allow":[...]}`. `mode` is `enforce` or `dry-run`. Invalid JSON or an invalid policy refuses to start. | +| `AGENT_COMPUTER_POLICY` | JSON action policy: `{"mode":"enforce","deny":[...],"allow":[...]}`. `mode` is `enforce` or `dry-run`. Each rule is a Cedar policy (starting `forbid` in `deny`, `permit` in `allow`) or a CEL expression, accepted for 12 months; see [Browser action governance](architecture.md#browser-action-governance). Invalid JSON, an invalid policy, a Cedar rule that doesn't validate against OpenBot's schema, or a Cedar rule in the wrong list refuses to start. | | `COMPUTER_RUNTIME` | Set to `runsc` to run supervised computers under gVisor. | | `COMPUTER_SANDBOX` | Set to `on` to enable Chromium's own sandbox where the host permits user namespaces. Which way it went is printed at start-up. Compose's `agent-computer` service does not pass it from `.env`, and the supervisor does not forward it to the computers it creates: in Compose put it in `egress.env` (see below), which reaches the shared computer, and on Helm in `computers.extraEnv`. | From cf4968015006adb1a0ee3fe72972ea0974f8c005 Mon Sep 17 00:00:00 2001 From: David McKay Date: Wed, 2 Dec 2026 23:01:30 -0800 Subject: [PATCH 05/11] Boundaries and Activity on Cedar: rules in words, Rewrite this, conversion rows The Boundaries screens read and save the rule records (`rules`) instead of the CEL lists. Each rule shows its English first and its Cedar second, never its Cedar in the list. A rule OpenBot couldn't move to Cedar is marked "Rewrite this", and one press rewrites it from its English, replays it and saves it in Cedar under the same id. A moved rule says it was moved and checked. New rules and templates are written in Cedar, and a description is translated with `language: "cedar"`. Activity reads a `computer.policy_converted` row in words, with the old and new text stacked. A real-browser test covers the list, the rewrite, a moved rule, Add rule and Activity in Chromium and WebKit, light and dark, wide and phone. It also catches words running past their card, which the old two-column "What a rule can check" did at a phone's width with the Cedar names. --- .github/workflows/ci.yml | 1 + app/src/components/audit/audit-cells.tsx | 129 ++- .../components/boundaries/describe-rule.tsx | 4 +- app/src/lib/boundaries/rules.ts | 394 +++++-- app/src/lib/computers/mutations.ts | 11 +- app/src/lib/computers/policy-translate.ts | 14 +- app/src/lib/computers/queries.ts | 26 +- app/src/routes/_authed/admin/boundaries.tsx | 92 +- .../_authed/admin/boundaries_.$index.tsx | 213 +++- .../routes/_authed/admin/boundaries_.new.tsx | 86 +- app/tests/boundaries-describe.test.tsx | 285 +++++- app/tests/boundaries-pages.test.tsx | 271 ++++- app/tests/boundaries-screens-layout.test.tsx | 968 ++++++++++++++++++ app/tests/boundaries-screens.fixture.tsx | 89 ++ app/tests/composing-enter.test.tsx | 6 +- shared/audit-words.ts | 1 + 16 files changed, 2279 insertions(+), 311 deletions(-) create mode 100644 app/tests/boundaries-screens-layout.test.tsx create mode 100644 app/tests/boundaries-screens.fixture.tsx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cbb03dcbd..347f63f426 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -485,6 +485,7 @@ jobs: app/tests/audit-computer-limit-layout.test.tsx app/tests/bot-orb-one-color.test.tsx app/tests/bot-screen-record-layout.test.tsx + app/tests/boundaries-screens-layout.test.tsx app/tests/checkbox-contrast.test.tsx app/tests/compact-avatar-layout.test.tsx app/tests/composer-dictation-notice-layout.test.tsx diff --git a/app/src/components/audit/audit-cells.tsx b/app/src/components/audit/audit-cells.tsx index 542374ac02..fca979ed20 100644 --- a/app/src/components/audit/audit-cells.tsx +++ b/app/src/components/audit/audit-cells.tsx @@ -597,7 +597,15 @@ export function decisionText(event: AuditEvent, storedNames = true): string { : "Sent to the Bot it was meant for" : null; const legacy = legacyFolderAction(event); + // Nothing was refused either way: a rule moved, or a rule kept as it was for a person to rewrite. + const conversion = conversionOf(event); + const moved = conversion + ? conversion.converted + ? "Moved, and checked" + : "Still in the old rule language" + : null; return ( + moved ?? routed ?? approvalText(event) ?? (legacy?.outcome === "requested" ? "Asked for" : undefined) ?? @@ -758,6 +766,64 @@ function policyChangeLines(payload: Record): string[] { ]; } +/** + * A boundary rule moved to Cedar, or kept in CEL, as the conversion records it: one row per rule. + * Null for any other row. + */ +type PolicyConversion = { + name: string | null; + cel: string | null; + cedar: string | null; + english: string | null; + checked: number; + mismatches: number; + caseOnly: number; + converted: boolean; +}; + +function conversionOf(event: AuditEvent): PolicyConversion | null { + if (event.eventType !== "computer.policy_converted") return null; + const payload = event.payload ?? {}; + const text = (value: unknown) => + typeof value === "string" && value.trim() ? value : null; + const number = (value: unknown) => (typeof value === "number" ? value : 0); + return { + name: text(payload.name), + cel: text(payload.cel), + cedar: text(payload.cedar), + english: text(payload.english), + checked: number(payload.checked), + mismatches: number(payload.mismatches), + caseOnly: number(payload.caseOnly), + converted: payload.outcome === "converted", + }; +} + +/** + * What a move to the new rule language did, in words, one line each: which rule, how it was + * checked, and the sentence it was rewritten from. The rule's old and new text are drawn under them, + * stacked ({@link ConversionTexts}). + */ +function conversionLines(conversion: PolicyConversion): string[] { + const checked = conversion.checked.toLocaleString(); + return [ + ...(conversion.name ? [`Rule: ${conversion.name}`] : []), + conversion.converted + ? `It decided all ${checked} test actions as before.` + : conversion.cedar === null + ? "OpenBot couldn't write a new version, so the old rule still applies." + : conversion.mismatches > 0 + ? `The new version decided ${conversion.mismatches.toLocaleString()} of ${checked} test actions differently, so the old rule still applies.` + : "The new version didn't decide every test action as before, so the old rule still applies.", + ...(conversion.converted && conversion.caseOnly > 0 + ? [ + `Capital letters no longer matter, so it also stops ${conversion.caseOnly.toLocaleString()} test actions it let through before.`, + ] + : []), + ...(conversion.english ? [`Written from: “${conversion.english}”`] : []), + ]; +} + /** * Why a component was not shown, for a page anybody can open. The stored reason is the one the Bot * is given, which names the component and its data by their ids and sends the person to an admin. @@ -780,16 +846,24 @@ function decisionOf(event: AuditEvent): RecordedDecision { return (event.payload?.decision ?? {}) as RecordedDecision; } +/** The rule that allows whatever no other rule stops, in Cedar, with its spacing taken out. */ +const PERMIT_EVERYTHING = "permit(principal,action,resource);"; + /** - * The policy rule that decided a row, as its CEL, for Admin only. Undefined for the default `true` - * allow rule, which says nothing, and on a page anybody can open, where it is an admin's expression. + * The policy rule that decided a row, as its text (Cedar, or CEL for a rule not yet moved), for + * Admin only. Undefined for the default rule that allows everything else, which says nothing, and + * on a page anybody can open, where it is an admin's expression. */ function ruleExpression( event: AuditEvent, storedNames = true, ): string | undefined { const rule = decisionOf(event).rule; - return storedNames && typeof rule === "string" && rule && rule !== "true" + return storedNames && + typeof rule === "string" && + rule && + rule !== "true" && + rule.replace(/\s+/g, "") !== PERMIT_EVERYTHING ? rule : undefined; } @@ -815,7 +889,7 @@ function ruleNameLine(event: AuditEvent, storedNames: boolean): string | null { /** * Every reason line under the decision, in the order the cell draws them. Admin (`storedNames`) * reads each as recorded; a page anybody can open says a component's refusal in words and leaves - * out the policy rule that decided an action, which is an admin's expression. The rule's own CEL is + * out the policy rule that decided an action, which is an admin's expression. The rule's own text is * not one of these lines: the cell draws it last and clamped ({@link ruleExpression}). */ export function decisionDetails( @@ -906,10 +980,12 @@ export function decisionDetails( if (silence) lines.push(silence); if (event.eventType === "computer.policy_changed") lines.push(...policyChangeLines(payload)); + const conversion = conversionOf(event); + if (conversion) lines.push(...conversionLines(conversion)); /* * The rule that decided, by the name an admin gave it. A rule written from a sentence is a - * thousand characters of CEL, and printed whole as a reason line it made a Blocked row hundreds of - * pixels tall and named nothing. The expression is still drawn, clamped, under these lines. + * thousand characters of Cedar, and printed whole as a reason line it made a Blocked row hundreds + * of pixels tall and named nothing. The rule's text is still drawn, clamped, under these lines. */ const named = ruleNameLine(event, storedNames); if (named) lines.push(named); @@ -993,8 +1069,11 @@ export function searchTextOf( // Both ways a reason is said, as for the subject above. ...decisionDetails(event), ...decisionDetails(event, false), - // The rule's CEL, clamped on screen and found whole. + // The rule's text, clamped on screen and found whole. ruleExpression(event) ?? "", + // A rule moved to the new rule language, before and after, found the same way. + conversionOf(event)?.cel ?? "", + conversionOf(event)?.cedar ?? "", ] .join(" ") .toLowerCase(); @@ -1116,13 +1195,16 @@ export function DecisionCell({ }) { const outcome = outcomeOf(event); const expression = ruleExpression(event, storedNames); + const conversion = conversionOf(event); + // A rule left for a person to rewrite waits on them, so it is drawn as one. + const waiting = conversion !== null && !conversion.converted; return ( <> ))} {expression ? : null} + {conversion && storedNames ? ( + + ) : null} {event.eventType === "team.models_changed" ? ( ) : null} @@ -1244,7 +1329,33 @@ const DETAIL_LINE = "mt-0.5 max-w-[22rem] text-muted-foreground text-xs [overflow-wrap:anywhere]"; /** - * The rule's CEL, two lines at most until somebody asks for the rest. + * A moved rule's old text over its new one, each under a short label and clamped like any rule's + * text: stacked, never side by side, since the Decision column is narrow and a phone narrower. A + * rule kept in the old language shows the version OpenBot tried, when it wrote one. + */ +function ConversionTexts({ conversion }: { conversion: PolicyConversion }) { + return ( + <> + {conversion.cel ? ( + <> +
Before
+ + + ) : null} + {conversion.cedar ? ( + <> +
+ {conversion.converted ? "After" : "Tried"} +
+ + + ) : null} + + ); +} + +/** + * The rule's text, Cedar or CEL, two lines at most until somebody asks for the rest. * * A rule written from a sentence runs to a thousand characters, and drawn whole it made one Blocked * row taller than the window. Mono, like the other identifiers on a row, and muted, because the diff --git a/app/src/components/boundaries/describe-rule.tsx b/app/src/components/boundaries/describe-rule.tsx index 178aa4131c..0e13c5136d 100644 --- a/app/src/components/boundaries/describe-rule.tsx +++ b/app/src/components/boundaries/describe-rule.tsx @@ -99,8 +99,8 @@ export function DescribeField({ /** * "Describe the rule": a sentence in, a rule out, written by the deployment's own model. * - * It fills nothing in by itself. `onWritten` hands the rule to the screen, which puts it in the CEL - * field where the admin reads it, edits it if they want, and saves it themselves. A description that + * It fills nothing in by itself. `onWritten` hands the rule, in Cedar, to the screen, which puts it + * in the rule field where the admin reads it, edits it if they want, and saves it themselves. A description that * only grants permission comes back as an allow rule, which these screens cannot add, so it is * answered here and never handed on. */ diff --git a/app/src/lib/boundaries/rules.ts b/app/src/lib/boundaries/rules.ts index d08501af9d..c74a87f19f 100644 --- a/app/src/lib/boundaries/rules.ts +++ b/app/src/lib/boundaries/rules.ts @@ -1,135 +1,369 @@ -import type { ActionPolicy, RuleLabel } from "@/lib/computers/queries"; +import type { + Boundaries, + BoundariesDraft, + BoundariesInput, + BoundaryRule, + BoundaryRuleInput, +} from "@/lib/api/generated/model"; +import type { RuleLabel } from "@/lib/computers/queries"; /** - * A rule an administrator can start from, in words first and CEL underneath. + * A rule an administrator can start from, in words first and Cedar underneath. * * `cost` is what the rule also catches, or misses, that its name does not say. Each one is a real * edge of the rule as written, so it is shown before the rule is added rather than discovered from * the refusals it produces. */ export type RuleTemplate = RuleLabel & { + /** The rule in Cedar, which is what a template adds now. */ rule: string; cost: string; /** - * The rule's earlier text, still in force wherever it was added before it changed, and saved - * without a name of its own then. Read so that rule keeps the template's name. + * The rule's CEL texts, the last one first: what it added before rules were written in Cedar, and + * what it shipped with before that. A rule still stored as one of them keeps the template's name. */ - formerRules?: string[]; + formerRules: string[]; }; +/* + * Text is compared in lower case in Cedar: OpenBot lowercases what an action names (a button's + * label, a host, a command) before a rule reads it. So `like "*submit*"` also stops "Submit order", + * as `contains()` did, and every literal here is lower case. + */ export const RULE_TEMPLATES: RuleTemplate[] = [ { name: "Never submit a form", description: "Stops a Bot pressing a submit button, or Enter while typing.", - // The keypress clause is guarded by tool name so a click is only refused on a submit button. - // Both tools that can press Enter are named: `computer_type` takes a `submit` flag that presses - // it once the text is in, and a rule naming only `computer_key` left that door open. It asks for - // the activation the gateway reads from the key, not `key == "Enter"`, so Shift+Enter, `\n` and - // Space (which press a focused button) are refused as well. - rule: '(intent == "activate" && contains(element.name, "submit")) || ((tool.name == "computer_key" || tool.name == "computer_type") && intent == "activate")', + // The keypress clause names both tools that can press Enter: `computer_type` takes a `submit` + // flag that presses it once the text is in. It asks for the activation the gateway reads from + // the key, so Shift+Enter, `\n` and Space (which press a focused button) are refused as well. + rule: `forbid (principal, action == OpenBot::Action::"activate", resource) +when { + context.element.name like "*submit*" || + ["computer_key", "computer_type"].contains(context.tool.name) +};`, + formerRules: [ + '(intent == "activate" && contains(element.name, "submit")) || ((tool.name == "computer_key" || tool.name == "computer_type") && intent == "activate")', + ], cost: "Also stops the Bot pressing Enter or Space anywhere else. A form can submit from Enter in any field.", }, { name: "Never type into a password field", description: "Stops a Bot typing into a field labelled as a password.", - rule: 'intent == "type" && contains(element.name, "password")', + rule: `forbid (principal, action == OpenBot::Action::"type", resource) +when { context.element.name like "*password*" };`, + formerRules: ['intent == "type" && contains(element.name, "password")'], cost: "A password box with a different label isn't covered. The rule matches the label.", }, { name: "Stay off social media", description: "Stops a Bot opening Facebook or X.", - // Each site, or a name ending in a dot and the site. `contains(page.host, "x.com")` also stopped - // dropbox.com and netflix.com. The dot is `[.]` because cel-js keeps backslashes as written, so - // `\\.` would match a backslash and the rule would stop nothing. - rule: 'intent == "navigate" && (page.host == "facebook.com" || matches(page.host, "[.]facebook[.]com$") || page.host == "x.com" || matches(page.host, "[.]x[.]com$"))', + // Each site, or a name ending in a dot and the site: `like "*x.com"` would also stop dropbox.com. + rule: `forbid (principal, action == OpenBot::Action::"navigate", resource) +when { + context.page.host == "facebook.com" || + context.page.host like "*.facebook.com" || + context.page.host == "x.com" || + context.page.host like "*.x.com" +};`, formerRules: [ + 'intent == "navigate" && (page.host == "facebook.com" || matches(page.host, "[.]facebook[.]com$") || page.host == "x.com" || matches(page.host, "[.]x[.]com$"))', 'intent == "navigate" && (contains(page.host, "facebook.com") || contains(page.host, "x.com"))', ], cost: "Only these two sites. A link that redirects there from elsewhere is allowed.", }, ]; -/** The template a rule came from: its current text, or one it shipped with before. */ -function templateOf(rule: string): RuleTemplate | undefined { - return RULE_TEMPLATES.find( - (one) => one.rule === rule || one.formerRules?.includes(rule), +/** The rule that allows whatever no forbid rule stops: the default "Everything else". */ +export const PERMIT_EVERYTHING = "permit (principal, action, resource);"; + +/** A rule's text with its spacing taken out, so two spellings of one rule compare equal. */ +function squeezed(text: string): string { + return text.replace(/\s+/g, ""); +} + +/** Whether `text` is a Cedar policy rather than CEL: a Cedar policy opens with its effect. */ +export function isCedar(text: string): boolean { + return /^\s*(?:forbid|permit)\b/.test(text); +} + +/** The text that decides a rule now: its Cedar, or its CEL while it has none. */ +export function ruleText(rule: BoundaryRule): string { + return rule.cedar ?? rule.cel ?? ""; +} + +/** + * Every rule, forbid and permit, in the admin's order. + * + * A server from before Cedar answers only the CEL lists. Their rules are read as records with no id + * and no Cedar, so the screens still draw them; they are never marked to rewrite, since that server + * has nothing to move them to. + */ +export function rulesOf(policy: Boundaries): BoundaryRule[] { + if (policy.rules) return policy.rules; + // Read once per answer, so a rule is the same record wherever the screens look it up. + const read = legacyRules.get(policy); + if (read) return read; + const record = ( + effect: BoundaryRule["effect"], + cel: string, + ): BoundaryRule => ({ + id: "", + effect, + language: "cel", + cedar: null, + cel, + name: policy.labels?.[cel]?.name || null, + description: policy.labels?.[cel]?.description || null, + english: null, + englishFrom: null, + conversion: null, + }); + const rules = [ + ...policy.deny.map((cel) => record("forbid", cel)), + ...policy.allow.map((cel) => record("permit", cel)), + ]; + legacyRules.set(policy, rules); + return rules; +} + +/** The records read from an answer that had only the CEL lists, by that answer. */ +const legacyRules = new WeakMap(); + +/** The rules that stop something: the list on Boundaries. */ +export function forbidRules(policy: Boundaries): BoundaryRule[] { + return rulesOf(policy).filter((rule) => rule.effect === "forbid"); +} + +/** A rule OpenBot couldn't move to Cedar with the same result, which still decides in CEL. */ +export function needsRewrite(rule: BoundaryRule): boolean { + return rule.cedar === null && rule.conversion?.status === "needs_rewrite"; +} + +/** The address of a rule's own screen: its id, or its place in the list where it has none. */ +export function ruleKey(rule: BoundaryRule, index: number): string { + return rule.id || String(index); +} + +/** The rule a screen's address names: by its id, or by its place in the list. */ +export function ruleAt( + policy: Boundaries, + key: string, +): BoundaryRule | undefined { + const rules = forbidRules(policy); + return ( + rules.find((rule) => rule.id && rule.id === key) ?? + (/^\d+$/.test(key) ? rules[Number(key)] : undefined) + ); +} + +/** Whether a rule is written as `text`, in either language. */ +export function ruleIs(rule: BoundaryRule, text: string): boolean { + const wanted = squeezed(text); + return [rule.cedar, rule.cel].some( + (one) => one !== null && squeezed(one) === wanted, + ); +} + +/** The template a rule came from: its Cedar, or a CEL text it shipped with before. */ +function templateOf(rule: BoundaryRule): RuleTemplate | undefined { + return RULE_TEMPLATES.find((template) => + [template.rule, ...template.formerRules].some((text) => ruleIs(rule, text)), + ); +} + +/** Whether a template's rule is already one of the organization's. */ +export function hasTemplate(policy: Boundaries, template: RuleTemplate) { + return forbidRules(policy).some((rule) => templateOf(rule) === template); +} + +/** Whether a rule allows everything no forbid rule stops, in Cedar or in CEL. */ +export function permitsEverything(rule: BoundaryRule): boolean { + return ( + rule.effect === "permit" && + (ruleIs(rule, PERMIT_EVERYTHING) || + (rule.cedar === null && rule.cel?.trim() === "true")) + ); +} + +/** + * How a rule is shown: by its name, a template's name, or its English, never its Cedar. `code` is + * set only for a rule with no words at all, a CEL rule typed by hand on a server from before + * Cedar, which is told apart from the next by what it says. + */ +export function ruleLabel(rule: BoundaryRule): RuleLabel & { + code: string | null; +} { + if (rule.name) + return { + name: rule.name, + description: rule.description || rule.english || "", + code: null, + }; + const template = templateOf(rule); + if (template) + return { + name: template.name, + description: template.description, + code: null, + }; + if (rule.english) + return { + name: rule.english, + description: + rule.description && rule.description !== rule.english + ? rule.description + : "", + code: null, + }; + if (rule.description) + return { name: "Custom rule", description: rule.description, code: null }; + return { name: "Custom rule", description: "", code: ruleText(rule) }; +} + +/** + * A rule as a save sends it back: its id, its effect, the text that decides it, and its words. Its + * Cedar where it has some, otherwise its CEL. English that was OpenBot's own reading of the rule is + * not sent back as though an admin wrote it. + */ +export function ruleInputOf(rule: BoundaryRule): BoundaryRuleInput { + return { + ...(rule.id ? { id: rule.id } : {}), + effect: rule.effect, + ...(rule.cedar !== null + ? { cedar: rule.cedar } + : rule.cel !== null + ? { cel: rule.cel } + : {}), + ...(rule.name ? { name: rule.name } : {}), + ...(rule.description ? { description: rule.description } : {}), + ...(rule.english && + (rule.englishFrom === "authoring" || rule.englishFrom === null) + ? { english: rule.english } + : {}), + }; +} + +/** A new rule's text as a save sends it: Cedar, or CEL typed by hand, which OpenBot moves to Cedar. */ +export function textInput(text: string): { cedar: string } | { cel: string } { + return isCedar(text) ? { cedar: text } : { cel: text }; +} + +/** The whole boundary as a save sends it: the mode, and every rule as it is. */ +export function boundariesInput( + policy: Boundaries, + rules: BoundaryRuleInput[] = rulesOf(policy).map(ruleInputOf), +): BoundariesInput { + return { mode: policy.mode, rules }; +} + +/** + * The boundary with one rule rewritten in place, keeping its id, its position and its name. A rule + * shown by a template's name takes that name with it: edited, it no longer reads as the template. + * `english` is the sentence the new text was written from; without one, the rule keeps none. + */ +export function withRuleReplaced( + policy: Boundaries, + rule: BoundaryRule, + next: string, + english: string | null, +): BoundariesInput { + const template = rule.name ? undefined : templateOf(rule); + return boundariesInput( + policy, + rulesOf(policy).map((one) => { + if (one !== rule) return ruleInputOf(one); + const { + cedar: _cedar, + cel: _cel, + english: _english, + ...kept + } = ruleInputOf(one); + return { + ...kept, + ...(template + ? { name: template.name, description: template.description } + : {}), + ...textInput(next), + ...(english ? { english } : {}), + }; + }), ); } -/** What a rule can be written against, in the words an administrator would use. */ +/** The boundary without one rule. */ +export function withoutRule( + policy: Boundaries, + rule: BoundaryRule, +): BoundariesInput { + return boundariesInput( + policy, + rulesOf(policy) + .filter((one) => one !== rule) + .map(ruleInputOf), + ); +} + +/** The boundary with one rule added at the end of the list. */ +export function withRuleAdded( + policy: Boundaries, + added: BoundaryRuleInput, +): BoundariesInput { + return boundariesInput(policy, [...rulesOf(policy).map(ruleInputOf), added]); +} + +/** + * One rule on its own, with everything else allowed, as a replay tests it: what it would have + * stopped, and nothing a rule already in force stops. + */ +export function ruleOnItsOwn( + mode: Boundaries["mode"], + text: string, +): BoundariesDraft { + return { + mode, + rules: [ + { effect: "forbid", ...textInput(text) }, + { effect: "permit", cedar: PERMIT_EVERYTHING }, + ], + }; +} + +/** What a rule can be written against in Cedar, in the words an administrator would use. */ export const RULE_ATTRIBUTES: { name: string; meaning: string }[] = [ { - name: "tool.name", + name: "action", meaning: - "The action, such as computer_click, computer_type or computer_key.", + 'What the action is for, such as OpenBot::Action::"activate", "type", "navigate", "run_command" or "write_tool".', }, { - name: "intent", - meaning: "What the action is for: activate, type or navigate.", + name: "context.tool.name", + meaning: "The tool, such as computer_click, computer_type or computer_key.", }, - { name: "bot.id", meaning: "The Bot taking the action." }, - { name: "actor.id", meaning: "The person the Bot is acting for." }, { - name: "initiator.kind", + name: "principal", + meaning: 'The Bot taking the action: OpenBot::Bot::"".', + }, + { name: "context.actor.id", meaning: "The person the Bot is acting for." }, + { + name: "context.initiator.kind", meaning: - "What started the run: person, routine or handoff. A scheduled run acts as its owner, so actor.id alone can't tell you.", + "What started the run: person, routine or handoff. A scheduled run acts as its owner, so context.actor.id alone can't tell you.", }, - { name: "page.url, page.host", meaning: "The page the Bot is on." }, + { name: "context.page.url, .host", meaning: "The page the Bot is on." }, { - name: "element.name, element.role", + name: "context.element.name, .role", meaning: "The button, link or field being clicked or typed into.", }, - { name: "key", meaning: "The key pressed, such as Enter." }, - { name: "file", meaning: "The file being read or written." }, - { name: "command", meaning: "The command being run." }, + { name: "context.key", meaning: "The key pressed, such as enter." }, + { + name: "context.file.path, .name, .extension", + meaning: "The file being read or written.", + }, + { name: "context.command", meaning: "The command being run." }, { - name: "mcp.server, mcp.tool, mcp.effect", + name: "context.mcp.server, .tool, .effect", meaning: "For a connected app's tool: which app, which tool, and read or write.", }, ]; - -/** The name a rule is shown by: its label, a template's name if it is one, or plainly "Custom rule". */ -export function ruleLabel(policy: ActionPolicy, rule: string): RuleLabel { - const label = policy.labels?.[rule]; - if (label) return label; - const template = templateOf(rule); - if (template) - return { name: template.name, description: template.description }; - return { name: "Custom rule", description: "" }; -} - -/** - * The policy with one rule rewritten in place, keeping its position and taking its name with it. - * - * A template's rule has no stored label, only the template's own, so that one is stored under the - * new text: edited, it no longer matches the template, and would otherwise read as "Custom rule". - */ -export function withRuleReplaced( - policy: ActionPolicy, - rule: string, - next: string, -): ActionPolicy { - const { [rule]: own, ...labels } = policy.labels ?? {}; - const template = templateOf(rule); - const label = - own ?? - (template - ? { name: template.name, description: template.description } - : undefined); - return { - ...policy, - deny: policy.deny.map((one) => (one === rule ? next : one)), - labels: label ? { ...labels, [next]: label } : labels, - }; -} - -/** The policy without one rule, and without that rule's label. */ -export function withoutRule(policy: ActionPolicy, rule: string): ActionPolicy { - const { [rule]: _removed, ...labels } = policy.labels ?? {}; - return { - ...policy, - deny: policy.deny.filter((one) => one !== rule), - labels, - }; -} diff --git a/app/src/lib/computers/mutations.ts b/app/src/lib/computers/mutations.ts index 47b411be1b..368ff90a97 100644 --- a/app/src/lib/computers/mutations.ts +++ b/app/src/lib/computers/mutations.ts @@ -7,6 +7,7 @@ import { stopComputer, updateComputer, } from "@/lib/api/generated/computers/computers"; +import type { BoundariesInput } from "@/lib/api/generated/model"; import { idempotencyKey, organizationId } from "@/lib/api/request"; import { currentUserQueryOptions } from "@/lib/auth/queries"; import { clearActivity } from "./activity"; @@ -165,11 +166,15 @@ export function restoreSettled(queryClient: QueryClient, botId: string) { */ export type PolicyAuthoring = { source: "english"; text: string }; +/** + * What a save sends: the mode and every rule, in order, as records (`rules`). The CEL lists the API + * still takes from older apps are left out, so a rule that has no CEL form is never dropped. + */ +export type ActionPolicyInput = BoundariesInput; + export function saveActionPolicyMutationOptions(queryClient: QueryClient) { return mutationOptions({ - mutationFn: ( - next: ActionPolicy & { authoring?: PolicyAuthoring }, - ): Promise => + mutationFn: (next: ActionPolicyInput): Promise => replaceBoundaries( organizationId(), next, diff --git a/app/src/lib/computers/policy-translate.ts b/app/src/lib/computers/policy-translate.ts index 03d89598fa..cbd8241ee3 100644 --- a/app/src/lib/computers/policy-translate.ts +++ b/app/src/lib/computers/policy-translate.ts @@ -5,7 +5,7 @@ import { idempotencyKey, organizationId } from "@/lib/api/request"; export type RuleCompile = { ok: true } | { ok: false; error: string }; /** - * A boundary the deployment's model wrote from an admin's description. + * A boundary the deployment's model wrote from an admin's description, in Cedar. * * `explanation` is a second reading of `rule` by a call that never saw the description, so it says * what the rule does rather than what was asked for. Null when the rule does not compile. @@ -22,17 +22,21 @@ export type PolicyTranslation = { }; /** - * Description in, rule out. A plain function rather than a mutation: nothing is saved and nothing is - * cached. The server records the request on the trail; saving the rule is still the admin's own act. + * Description in, Cedar rule out. A plain function rather than a mutation: nothing is saved and + * nothing is cached. The server records the request on the trail; saving the rule is still the + * admin's own act. + * + * Asked for in Cedar, the language rules are written in now. A request without `language` still + * gets CEL, for the apps released before Cedar. */ export async function translatePolicyRule( text: string, ): Promise { const translation = await translateBoundary( organizationId(), - { text }, + { text, language: "cedar" }, { "Idempotency-Key": idempotencyKey() }, - { fallback: "Couldn't write the rule. Try again, or write it in CEL." }, + { fallback: "Couldn't write the rule. Try again, or write it yourself." }, ); // A rule that doesn't compile comes back with the compiler's words in `compile.error`. return translation as PolicyTranslation; diff --git a/app/src/lib/computers/queries.ts b/app/src/lib/computers/queries.ts index 4fb2737a1e..b1eec5c2f1 100644 --- a/app/src/lib/computers/queries.ts +++ b/app/src/lib/computers/queries.ts @@ -9,6 +9,8 @@ import { listComputers, } from "@/lib/api/generated/computers/computers"; import type { + Boundaries, + BoundariesDraft, ComputerRestore, WorkspaceSnapshot, WorkspaceSnapshots, @@ -60,15 +62,17 @@ export type ComputerFleet = { */ export type PolicyMode = "dry-run" | "enforce"; -/** The rules a Bot's actions are judged against. */ -export type ActionPolicy = { - mode: PolicyMode; - deny: string[]; - allow: string[]; - /** Each rule's name and what it stops, keyed by the rule's text. Display only. */ - labels?: Record; -}; +/** + * The rules a Bot's actions are judged against, as the API answers them: every rule in `rules`, in + * the admin's order, each decided in Cedar or, until OpenBot can move it, in CEL. The CEL lists + * beside them are the deprecated view older apps read; these screens read `rules`. + */ +export type ActionPolicy = Boundaries; + +/** Boundaries to test against recent actions, as a save would take them. */ +export type ActionPolicyDraft = BoundariesDraft; +/** How a rule is shown: its name, and what it stops. */ export type RuleLabel = { name: string; description: string }; /** @@ -95,7 +99,7 @@ export const computerKeys = { all: ["computers"] as const, fleet: () => ["computers", "fleet"] as const, policy: () => ["computers", "policy"] as const, - dryRun: (candidate: ActionPolicy) => + dryRun: (candidate: ActionPolicyDraft) => ["computers", "policy", "dry-run", candidate] as const, status: (botId: string) => ["computers", "status", botId] as const, /** `computer` absent is the caller's own computer for this Bot; an admin may name another. */ @@ -227,7 +231,7 @@ export type DryRunReport = { * the server's sentence saying why, and nothing is replayed. */ export async function dryRunActionPolicy( - candidate: ActionPolicy, + candidate: ActionPolicyDraft, ): Promise { // A test writes nothing, but it is a POST to the API, so it carries a key of its own. return replayBoundaries( @@ -245,7 +249,7 @@ export async function dryRunActionPolicy( * a rule already tried answers from the cache. A rule that doesn't compile is an answer, not a fault, * so it is not retried. */ -export function policyDryRunQueryOptions(candidate: ActionPolicy) { +export function policyDryRunQueryOptions(candidate: ActionPolicyDraft) { return queryOptions({ queryKey: computerKeys.dryRun(candidate), queryFn: (): Promise => dryRunActionPolicy(candidate), diff --git a/app/src/routes/_authed/admin/boundaries.tsx b/app/src/routes/_authed/admin/boundaries.tsx index 3d9496c567..94024052f3 100644 --- a/app/src/routes/_authed/admin/boundaries.tsx +++ b/app/src/routes/_authed/admin/boundaries.tsx @@ -9,6 +9,7 @@ import { PageShell, } from "@/components/layout/page-shell"; import { StaggerItem } from "@/components/layout/stagger"; +import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Item, @@ -19,7 +20,15 @@ import { } from "@/components/ui/item"; import { Separator } from "@/components/ui/separator"; import { Switch } from "@/components/ui/switch"; -import { ruleLabel } from "@/lib/boundaries/rules"; +import { + boundariesInput, + forbidRules, + needsRewrite, + permitsEverything, + ruleKey, + ruleLabel, + rulesOf, +} from "@/lib/boundaries/rules"; import { saveActionPolicyMutationOptions } from "@/lib/computers/mutations"; import { actionPolicyQueryOptions } from "@/lib/computers/queries"; import { failureSaid } from "@/lib/load-failure"; @@ -31,13 +40,22 @@ export const Route = createFileRoute("/_authed/admin/boundaries")({ const DESCRIPTION = "Define actions that Bots must never take. OpenBot checks these rules before a Bot acts on its computer or in a connected app."; +/** Under the list when some rules still use the old rule language: how many, and what to do. */ +function rewriteSaid(count: number): string { + return count === 1 + ? "1 rule uses the old rule language. Open it to rewrite it." + : `${count} rules use the old rule language. Open one to rewrite it.`; +} + /** * The deployment's boundaries, read as a list of things Bots may never do. * * It used to be one screen that was also the editor: the rule language explained in a paragraph of * attribute names, rules shown as raw CEL, and ready-made rules drawn as buttons. Nobody could tell - * from it what the page was for. Now each rule is a row with a name, adding one is its own screen - * (`boundaries_.new.tsx`) and a rule opens to what it has stopped (`boundaries_.$index.tsx`). + * from it what the page was for. Now each rule is a row in words (its name, or the English it was + * written from, never its Cedar), adding one is its own screen (`boundaries_.new.tsx`) and a rule + * opens to what it is made of and what it has stopped (`boundaries_.$index.tsx`). A rule OpenBot + * couldn't move to Cedar with the same result is marked on its row, so it is found from here. */ function BoundariesPage() { const queryClient = useQueryClient(); @@ -66,13 +84,19 @@ function BoundariesPage() { } const trial = policy.mode === "dry-run"; + const rules = forbidRules(policy); + const toRewrite = rules.filter(needsRewrite).length; + const permits = rulesOf(policy).filter((rule) => rule.effect === "permit"); const allowsEverythingElse = - policy.allow.length === 1 && policy.allow[0] === "true"; + permits.length === 1 && permits.every(permitsEverything); return ( - - {policy.deny.length === 0 ? ( + 0 ? rewriteSaid(toRewrite) : undefined} + title="Bots may never" + > + {rules.length === 0 ? ( ) : ( - {policy.deny.map((rule, index) => { - const label = ruleLabel(policy, rule); + {rules.map((rule, index) => { + const label = ruleLabel(rule); + const key = ruleKey(rule, index); return ( - + ( )} @@ -111,16 +136,21 @@ function BoundariesPage() { {label.name} {label.description ? ( {label.description} - ) : ( - // A rule nobody named is still told apart from the next by what it says. + ) : label.code ? ( + // A rule with no words at all is still told apart from the next by what it says. - {rule} + {label.code} - )} + ) : null} - + + {needsRewrite(rule) ? ( + Rewrite this + ) : null} + + - {index !== policy.deny.length - 1 && } + {index !== rules.length - 1 && } ); })} @@ -145,10 +175,12 @@ function BoundariesPage() { checked={trial} disabled={savePolicy.isPending} onCheckedChange={(checked) => - savePolicy.mutate({ - ...policy, - mode: checked ? "dry-run" : "enforce", - }) + savePolicy.mutate( + boundariesInput({ + ...policy, + mode: checked ? "dry-run" : "enforce", + }), + ) } /> @@ -169,21 +201,25 @@ function BoundariesPage() { {/* - * Read-only, and only interesting when it is not the default. Allow rules are checked after - * the list above and an empty list refuses everything, so a deployment that narrowed them - * in configuration needs to see that here rather than wonder why every action is refused. + * Read-only, and only interesting when it is not the default. Permit rules are checked + * after the list above and none refuses everything, so a deployment that narrowed them in + * configuration needs to see that here rather than wonder why every action is refused. + * Each is said in its words where it has some. */} Everything else - + {allowsEverythingElse ? "Allowed. A Bot can do anything no rule above stops, within its own permissions." - : policy.allow.length === 0 + : permits.length === 0 ? "Nothing else is allowed. Every action is refused." - : `Only what these allow: ${policy.allow.join(" · ")}`} + : `Only what these allow: ${permits + .map((rule) => { + const label = ruleLabel(rule); + return label.code ?? label.name; + }) + .join(" · ")}`} diff --git a/app/src/routes/_authed/admin/boundaries_.$index.tsx b/app/src/routes/_authed/admin/boundaries_.$index.tsx index 8a2ce38332..21fece618d 100644 --- a/app/src/routes/_authed/admin/boundaries_.$index.tsx +++ b/app/src/routes/_authed/admin/boundaries_.$index.tsx @@ -13,6 +13,7 @@ import { import { DryRunChanges } from "@/components/boundaries/dry-run-changes"; import { RulePreview } from "@/components/boundaries/rule-preview"; import { RuleReading } from "@/components/boundaries/rule-reading"; +import { IconAlertTriangle, IconCircleCheck } from "@/components/icons"; import { PageCard, PageSection, @@ -27,20 +28,33 @@ import { DialogHeader, DialogTitle, } from "@/components/ui/dialog"; -import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"; +import { + Field, + FieldDescription, + FieldGroup, + FieldLabel, +} from "@/components/ui/field"; import { Textarea } from "@/components/ui/textarea"; +import type { BoundaryRule } from "@/lib/api/generated/model"; import { + forbidRules, + needsRewrite, + ruleAt, + ruleIs, ruleLabel, + ruleOnItsOwn, + ruleText, withoutRule, withRuleReplaced, } from "@/lib/boundaries/rules"; import { saveActionPolicyMutationOptions } from "@/lib/computers/mutations"; +import { translatePolicyRule } from "@/lib/computers/policy-translate"; import { type ActionPolicy, actionPolicyQueryOptions, policyDryRunQueryOptions, } from "@/lib/computers/queries"; -import { type Failure, failureSaid } from "@/lib/load-failure"; +import { type Failure, failureOf, failureSaid } from "@/lib/load-failure"; /** How long the rule has to rest before it is replayed, as on Add rule. */ const PREVIEW_DELAY_MS = 400; @@ -55,16 +69,17 @@ const BACK = { }; /** - * One rule: what it is called, what it is made of, and what it has stopped lately. + * One rule: what it says in words, what it is made of, and what it has stopped lately. * - * Addressed by position because a rule has no id of its own, only its text. A position that no - * longer holds a rule, because it was removed elsewhere, says so rather than showing a neighbour. + * Addressed by the rule's id. A position in the list is still read, for a link made before rules had + * one. An address that no longer names a rule, because it was removed elsewhere, says so rather than + * showing a neighbour. */ function RulePage() { const { index } = Route.useParams(); const stored = useQuery(actionPolicyQueryOptions()); const policy = stored.data; - const rule = policy?.deny[Number(index)]; + const rule = policy ? ruleAt(policy, index) : undefined; if (!policy) { return ( @@ -86,16 +101,28 @@ function RulePage() { ); } - // Keyed by the rule, so a saved change starts the editor and its preview afresh from what is stored. - return ; + // Keyed by what decides the rule, so a saved change starts the editor and its preview afresh. + return ; } -function RuleDetail({ policy, rule }: { policy: ActionPolicy; rule: string }) { +function RuleDetail({ + policy, + rule, +}: { + policy: ActionPolicy; + rule: BoundaryRule; +}) { const navigate = Route.useNavigate(); const queryClient = useQueryClient(); const savePolicy = useMutation(saveActionPolicyMutationOptions(queryClient)); const [removing, setRemoving] = useState(false); - const label = ruleLabel(policy, rule); + const label = ruleLabel(rule); + const rewrite = needsRewrite(rule); + // The English is the first thing in the rule's card, so it isn't said under the title as well. + const description = + label.description && label.description !== rule.english + ? label.description + : undefined; /* * What this rule has stopped, read as the difference it makes: the policy without it, replayed @@ -110,11 +137,7 @@ function RuleDetail({ policy, rule }: { policy: ActionPolicy; rule: string }) { }); return ( - + {policy.mode === "dry-run" ? (

Trial mode is on, so this rule records matching actions without @@ -122,9 +145,19 @@ function RuleDetail({ policy, rule }: { policy: ActionPolicy; rule: string }) {

) : null} + {/* + * A rule OpenBot couldn't move to Cedar is this screen's whole point until it is rewritten, so + * the section that rewrites it takes the rule's place, under a title that says so. + */} @@ -206,55 +239,125 @@ function RuleDetail({ policy, rule }: { policy: ActionPolicy; rule: string }) { ); } +/** A count of actions in the reader's own figures: "1,204". */ +function count(value: number): string { + return value.toLocaleString(); +} + +/** + * How the rule came to Cedar, under its words: moved and checked, or why the new version wasn't + * taken. Nothing for a rule written in Cedar from the start. + */ +function ConversionLine({ rule }: { rule: BoundaryRule }) { + const conversion = rule.conversion; + if (!conversion) return null; + if (rule.cedar !== null && conversion.status === "converted") + return ( +

+ + + Moved from the old rule language and checked. It decided all{" "} + {count(conversion.checked)} test actions as before. + +

+ ); + if (needsRewrite(rule) && conversion.mismatches > 0) + return ( +

+ + + The new version OpenBot wrote decided {count(conversion.mismatches)}{" "} + of {count(conversion.checked)} test actions differently. + +

+ ); + return null; +} + /** - * The rule, editable in CEL or rewritten from a description, and saved only by Save rule. + * The rule, read in its English first and then as it is written, editable, rewritten from a + * description, and saved only by Save rule. * - * A changed rule is replayed on its own as it rests, as Add rule replays a new one, so what the new - * version would have stopped sits right above what the rule in force has stopped. Saved, it takes - * the old rule's place and name. + * A rule still in the old rule language is rewritten from its own English with one press: the + * deployment's model writes it in Cedar, it lands in the field like any edit, and it is replayed on + * its own as it rests, as Add rule replays a new one, so what the new version would have stopped + * sits right above what the rule in force has stopped. Saved, it takes the old rule's place, id and + * name. */ -function RuleEditor({ policy, rule }: { policy: ActionPolicy; rule: string }) { +function RuleEditor({ + policy, + rule, +}: { + policy: ActionPolicy; + rule: BoundaryRule; +}) { const queryClient = useQueryClient(); const savePolicy = useMutation(saveActionPolicyMutationOptions(queryClient)); - const [draft, setDraft] = useState(rule); + const current = ruleText(rule); + const [draft, setDraft] = useState(current); const [written, setWritten] = useState(null); + const [rewriting, setRewriting] = useState(false); // The error itself, not its words, so a hold is drawn calmly (lib/load-failure.tsx). const [problem, setProblem] = useState(null); + const rewrite = needsRewrite(rule); const trimmed = draft.trim(); - const changed = trimmed !== rule; - const duplicate = changed && policy.deny.includes(trimmed); + const changed = trimmed !== current.trim(); + const others = forbidRules(policy).filter((one) => one !== rule); + const duplicate = changed && others.some((one) => ruleIs(one, trimmed)); // The model's rule, unedited, that the compiler refused: its error is already under the rule. const broken = Boolean( written && !written.compile.ok && written.rule.trim() === trimmed, ); const ready = changed && Boolean(trimmed) && !duplicate && !broken; - const [settled, setSettled] = useState(rule); + const [settled, setSettled] = useState(current.trim()); useEffect(() => { const timer = setTimeout(() => setSettled(trimmed), PREVIEW_DELAY_MS); return () => clearTimeout(timer); }, [trimmed]); - const candidate: ActionPolicy | null = - settled && settled !== rule && !policy.deny.includes(settled) && !broken - ? { mode: policy.mode, deny: [settled], allow: ["true"] } + const candidate = + settled && + settled !== current.trim() && + !others.some((one) => ruleIs(one, settled)) && + !broken + ? ruleOnItsOwn(policy.mode, settled) : null; const preview = useQuery({ - ...policyDryRunQueryOptions( - candidate ?? { mode: "enforce", deny: [], allow: [] }, - ), + ...policyDryRunQueryOptions(candidate ?? { mode: "enforce", rules: [] }), enabled: candidate !== null, placeholderData: keepPreviousData, }); - /* The model's rule goes into the CEL field, where the preview picks it up as it would any edit. */ + /* The model's rule goes into the rule field, where the preview picks it up as it would any edit. */ const takeWritten = (next: WrittenRule) => { setWritten(next); setDraft(next.rule); }; + /** One press: the rule's own English to the model, in Cedar, into the field. */ + const rewriteFromEnglish = async () => { + if (!rule.english || rewriting) return; + setProblem(null); + setRewriting(true); + try { + const translation = await translatePolicyRule(rule.english); + // Read as granting permission, it can't stand in for a rule that stops something. + if (translation.effect === "allow") + setProblem({ + message: + "OpenBot read these words as something Bots may do, so it couldn't rewrite the rule from them. Change the rule below yourself.", + }); + else takeWritten({ ...translation, text: rule.english }); + } catch (thrown) { + setProblem(failureOf(thrown, String(thrown))); + } finally { + setRewriting(false); + } + }; + const reset = () => { - setDraft(rule); + setDraft(current); setWritten(null); setProblem(null); }; @@ -262,12 +365,13 @@ function RuleEditor({ policy, rule }: { policy: ActionPolicy; rule: string }) { const save = () => { if (!ready) return; setProblem(null); + // The sentence the new text was written from, while it is still what was written. + const english = + written && written.rule.trim() === trimmed ? written.text : null; savePolicy.mutate( { - ...withRuleReplaced(policy, rule, trimmed), - ...(written - ? { authoring: { source: "english" as const, text: written.text } } - : {}), + ...withRuleReplaced(policy, rule, trimmed, english), + ...(english ? { authoring: { source: "english", text: english } } : {}), }, { onError: (thrown: Error) => setProblem(thrown) }, ); @@ -297,7 +401,38 @@ function RuleEditor({ policy, rule }: { policy: ActionPolicy; rule: string }) { } > - + {rule.english ? ( + + In words +

{rule.english}

+ {rule.englishFrom === "reading" ? ( + + OpenBot's reading of the rule. + + ) : null} + + {rewrite ? ( +
+ +
+ ) : null} +
+ ) : ( + + )} + {/* With its English to rewrite from, the one press above is the way; a description is not asked for twice. */} + {rewrite && rule.english ? null : ( + + )} Rule