Skip to content

feat(policy): safedep policy, project, endpoint and audit commands - #67

Merged
abhisek merged 17 commits into
mainfrom
claude/pensive-sagan-3x8any
Nov 5, 2026
Merged

abhisek merged 17 commits into
mainfrom
claude/pensive-sagan-3x8any

Conversation

@abhisek

@abhisek abhisek commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR adds the CLI of the cloud policy MVP:

  • safedep/control-tower#1590: the safedep policy command tree.
  • safedep/control-tower#1591: project, endpoint and audit commands.
  • safedep/control-tower#1636: safedep policy decision list, the decision log. This came from feat(policy): safedep policy decision list #69, which is closed so that this PR holds all the MVP commands.

The commands follow the CLI walkthrough and the parent spec in control-tower (docs/specs/2026-10-28-cloud-policy-management-design.md, Design 6 and 8), and the server spec docs/specs/2026-10-30-policy-server-design.md. Every command is tested against fakes and mocks of the API contract from safedep/api#253, safedep/api#254 and safedep/api#260.

Commands

Tree Commands
policy show, get [--revision N], edit [-m TITLE] [--override NAME]
policy change list, show, edit, sync, delete, publish [--yes], and create --from-revision N for a rollback
policy revision list, show
policy rule create (--block | --trust), list, show, update, delete, with a bulk block from a file
policy decision list [--since] [--until] [--tool] [--outcome] [--revision] [--rule] [--override] [--path] [--package] [--project] [--endpoint]
project list [--selector], show, label set | delete, policy show
endpoint list gets --applied-revision '<N', --selector and a POLICY column. New: label set | delete and policy show
audit event list [--since] [--until] [--action] [--resource KIND[/ID]] [--actor]

The tree has 24 new doc pages in docs/cmd/.

Behaviour worth a look

  • policy edit:
    • It writes the policy as YAML from the descriptor, so a new contract field needs only an SDK bump.
    • The id of each policy override is in the document, so a rename keeps it. The CLI warns before a save that removes an override. It refuses an id that is not in the opened policy.
    • It refuses to open a policy that holds fields this CLI does not know, because a save would drop them.
    • An edit that changes nothing saves nothing, by proto.Equal.
  • change publish previews first. It shows the change direction and every warning, stops on a stale change with the sync hint, and asks for confirmation for a change that loosens (--yes with no TTY).
  • rule create:
    • A trust entry selects one package. Only a block can use a /* or .* prefix.
    • --scope all expands to every trust scope that the SDK knows.
    • A wide pkg:<type>/* block warns. A trust expiry over 90 days is refused before the request.
  • decision list:
    • Each row shows when, the tool, the package, the outcome, the rule or path that decided, the revision (with the default policy revision when the default policy decided), and where:
      • for pmg, the hostname and the user, plus the CI repository, the Kubernetes workload or the agent;
      • for a pull request check, repo#number and the link.
    • --override takes a name or an id. The id of a deleted override goes to the server as it is.
    • --package takes a PURL with no version. The CLI keeps the name as each ecosystem stores it.
    • The CLI checks the filter lengths locally.
    • JSON output has every field of the contract.
  • Text from the server is escaped on the terminal. This covers labels from endpoints, reasons, descriptions and decision fields. JSON output stays raw.
  • Errors map to useful messages with usefulerror.ReasonOf from dry. Examples: a stale change, an etag mismatch, a Member who cannot change the policy, a missing revision, and a server that does not have the decision log yet.
  • --since and --until share one check in internal/duration for audit event list and decision list.

Differences from the walkthrough

These are left out on purpose:

  • Delivery, project and notice rows in policy show; policy status; field list|show; publish -f; endpoint policy list; step-up lines.
    • The contract has no data for them yet, or they belong to M2 and M3.
  • "Seen on N endpoints" before rule create, and HITS columns.
    • The contract carries no such counts outside a change preview.
  • Field titles such as "Scan gate · Fail on" in change show.
    • The command shows contract paths, because the titles need GetPolicyCatalog. A later change can add policy field show from that RPC.
  • decision list takes project and endpoint ids, not names.

Review

Fable review agents checked both parts of the work three ways: adversarial, functional against the walkthrough and the spec, and clean code.

  • The policy tree: the review found a rename that lost an override id, an edit that dropped unknown fields, a publish with no preview, and server strings printed unescaped. A commit fixes all of them.
  • The decision log: the review found that --override refused the id of a deleted override. Commit ddaa59a fixes it, with the package name and length findings.

Testing

  • make lint-conventions, make lint, make test and make build pass. golangci-lint reports 0 issues, and the convention tests pass.
  • I made no live test against a server. The owner tests the commands after the server ships. decision list needs safedep/control-tower#1644.

Generated by Claude Code

Admins had no CLI for the tenant policy of SafeDep Cloud. This change adds
the safedep policy tree for safedep/control-tower#1590:

- policy show, get and edit. Edit opens the policy settings document in
  the editor and saves it as a policy change. A file that does not parse
  opens again with the error at the top.
- policy change list, show, edit, sync, delete and publish. Change create
  --from-revision makes a rollback change.
- policy revision list and show.
- policy rule create, list, show, update and delete. Rule create --block
  -f reads a bulk list. --scope all expands to every trust scope that the
  SDK knows, because the contract has no "all" value. A trust entry
  cannot use a prefix, and the CLI says so before the request.

Duration flags accept a day unit, as in --expires 30d. Every data command
writes table, plain and JSON output.

The change bumps the API SDK to 20261031065119-dc85a10c2beb and adds the
verb publish, which makes a policy change live as a new revision. The new
package internal/cloudpolicy holds the YAML form of the policy, labels,
label selectors and the policy of one subject, so the project and
endpoint trees can use them too. The subscription tree now reads the
error reason through the new internal/rpcerror package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
The policy selects projects and endpoints by label, but the CLI could not
list subjects by label, write custom labels, or show which policy applies
to a subject. This change adds them for safedep/control-tower#1591:

- project list --selector, project show, project label set and delete,
  and project policy show.
- endpoint list --applied-revision '<N' and --selector, endpoint label
  set and delete, and endpoint policy show. The endpoint list shows the
  applied policy revision of each tool.
- audit event list, with --since, --until, --action, --resource and
  --actor.

The label commands write only custom/ labels. The CLI rejects every other
prefix before the request, because the server rejects it too. Policy show
names the source of each value: the default policy, the policy base or a
policy override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
A review found these problems in the policy commands:

- The YAML left out the override id, so a rename reached the server as
  a new override. The document now writes the id as "id". The decoder
  keeps the id that the user leaves. The CLI refuses an id that is not
  in the policy and warns before the save for each removed override.
- An edit dropped contract fields that this SDK does not know. The CLI
  now stops before the editor opens and tells the user to update.
- Change publish acted with no preview. It now previews the change,
  shows the change direction and every warning, stops on a stale change
  with the sync hint, and asks before it publishes a change that loosens
  the policy. With no terminal it needs --yes. The success line names
  the direction.
- Server text reached the terminal unescaped. A new helper in
  internal/tui escapes control and bidirectional characters, and every
  table and plain renderer and every warning with server text uses it.
  JSON output stays raw.
- internal/rpcerror repeated usefulerror.ReasonOf of dry. It is gone.
- Rule create warns about a selector that blocks a whole ecosystem, and
  rule create and update refuse a trust expiry over 90 days.
- Policy edit maps PermissionDenied, so a Member sees who can act. A
  restore from a missing revision names the revision.
- The audit help names the resource kinds and the action prefix.

The change also moves the shared display helpers to cloudpolicy, pads
key and value rows by display width, compares decoded documents with
proto.Equal in the edit loop, writes the paging help in active voice,
and splits the leaf files that were over the line cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
@safedep

safedep Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

Package Details
Package Malware Vulnerability Risky License Report
icon buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go @ v1.36.12-20260709200747-435963d16310.1
go.mod
ok icon
ok icon
ok icon
🔗
icon buf.build/gen/go/safedep/api/grpc/go @ v1.6.2-20261104174030-9113dd6a8ea6.1
go.mod
ok icon
ok icon
ok icon
🔗
icon buf.build/gen/go/safedep/api/protocolbuffers/go @ v1.36.12-20261104174030-9113dd6a8ea6.2
go.mod
ok icon
ok icon
ok icon
🔗
icon go.yaml.in/yaml/v3 @ v3.0.5
go.mod
ok icon
ok icon
ok icon
🔗

View complete scan results →

This report is generated by SafeDep GitHub App

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T08:54:29.980208Z 4e649b1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 134 files, which is 34 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: d122d219-85b7-4850-a602-5189a6423c83
Commits

Reviewing files that changed from the base of the PR and between 7456a4e and 3727038.

Files ignored due to path filters: 1

  • go.sum is excluded by !**/*.sum
Files selected for processing: 134

  • .github/pmg/config.yml
  • .github/workflows/ci.yml
  • .github/workflows/goreleaser.yml
  • .mockery.yml
  • README.md
  • docs/cmd/audit-event-list.md
  • docs/cmd/endpoint-activity-list.md
  • docs/cmd/endpoint-inventory-list.md
  • docs/cmd/endpoint-label-delete.md
  • docs/cmd/endpoint-label-set.md
  • docs/cmd/endpoint-list.md
  • docs/cmd/endpoint-policy-show.md
  • docs/cmd/endpoint-show.md
  • docs/cmd/endpoint-status.md
  • docs/cmd/policy-change-create.md
  • docs/cmd/policy-change-delete.md
  • docs/cmd/policy-change-edit.md
  • docs/cmd/policy-change-list.md
  • docs/cmd/policy-change-publish.md
  • docs/cmd/policy-change-show.md
  • docs/cmd/policy-change-sync.md
  • docs/cmd/policy-decision-list.md
  • docs/cmd/policy-edit.md
  • docs/cmd/policy-get.md
  • docs/cmd/policy-revision-list.md
  • docs/cmd/policy-revision-show.md
  • docs/cmd/policy-rule-create.md
  • docs/cmd/policy-rule-delete.md
  • docs/cmd/policy-rule-list.md
  • docs/cmd/policy-rule-show.md
  • docs/cmd/policy-rule-update.md
  • docs/cmd/policy-show.md
  • docs/cmd/project-label-delete.md
  • docs/cmd/project-label-set.md
  • docs/cmd/project-list.md
  • docs/cmd/project-policy-show.md
  • docs/cmd/project-show.md
  • go.mod
  • internal/app/app.go
  • internal/cloudpolicy/document.go
  • internal/cloudpolicy/document_test.go
  • internal/cloudpolicy/fields.go
  • internal/cloudpolicy/fields_test.go
  • internal/cloudpolicy/fixtures_test.go
  • internal/cloudpolicy/labels.go
  • internal/cloudpolicy/labels_test.go
  • internal/cloudpolicy/labelwriter.go
  • internal/cloudpolicy/labelwriter_test.go
  • internal/cloudpolicy/mocks/LabelServiceClient_mock.go
  • internal/cloudpolicy/mocks/PolicyServiceClient_mock.go
  • internal/cloudpolicy/protoyaml.go
  • internal/cloudpolicy/render.go
  • internal/cloudpolicy/subject.go
  • internal/cloudpolicy/subject_test.go
  • internal/cloudpolicy/template.go
  • internal/cloudpolicy/template_test.go
  • internal/cmd/audit/cmd.go
  • internal/cmd/audit/list.go
  • internal/cmd/audit/list_test.go
  • internal/cmd/audit/view.go
  • internal/cmd/endpoint/activity.go
  • internal/cmd/endpoint/cmd.go
  • internal/cmd/endpoint/inventory.go
  • internal/cmd/endpoint/label.go
  • internal/cmd/endpoint/list.go
  • internal/cmd/endpoint/list_test.go
  • internal/cmd/endpoint/policy.go
  • internal/cmd/endpoint/policy_test.go
  • internal/cmd/endpoint/service.go
  • internal/cmd/endpoint/show.go
  • internal/cmd/endpoint/status.go
  • internal/cmd/packages/list.go
  • internal/cmd/policy/change_create.go
  • internal/cmd/policy/change_edit.go
  • internal/cmd/policy/change_list.go
  • internal/cmd/policy/change_ops.go
  • internal/cmd/policy/change_preview.go
  • internal/cmd/policy/change_publish.go
  • internal/cmd/policy/change_render.go
  • internal/cmd/policy/change_show.go
  • internal/cmd/policy/change_test.go
  • internal/cmd/policy/change_view.go
  • internal/cmd/policy/cmd.go
  • internal/cmd/policy/decision_list.go
  • internal/cmd/policy/decision_package.go
  • internal/cmd/policy/decision_test.go
  • internal/cmd/policy/decision_view.go
  • internal/cmd/policy/edit.go
  • internal/cmd/policy/edit_test.go
  • internal/cmd/policy/editor.go
  • internal/cmd/policy/errors.go
  • internal/cmd/policy/fixtures_test.go
  • internal/cmd/policy/get.go
  • internal/cmd/policy/publish_test.go
  • internal/cmd/policy/review_test.go
  • internal/cmd/policy/revision.go
  • internal/cmd/policy/revision_show.go
  • internal/cmd/policy/revision_test.go
  • internal/cmd/policy/rule_create.go
  • internal/cmd/policy/rule_delete.go
  • internal/cmd/policy/rule_filters.go
  • internal/cmd/policy/rule_input.go
  • internal/cmd/policy/rule_list.go
  • internal/cmd/policy/rule_show.go
  • internal/cmd/policy/rule_test.go
  • internal/cmd/policy/rule_update.go
  • internal/cmd/policy/rule_view.go
  • internal/cmd/policy/selector.go
  • internal/cmd/policy/settings.go
  • internal/cmd/policy/show.go
  • internal/cmd/policy/show_test.go
  • internal/cmd/policy/view.go
  • internal/cmd/project/cmd.go
  • internal/cmd/project/inventory.go
  • internal/cmd/project/label.go
  • internal/cmd/project/list.go
  • internal/cmd/project/policy.go
  • internal/cmd/project/policy_test.go
  • internal/cmd/project/resolver.go
  • internal/cmd/project/show.go
  • internal/cmd/project/view.go
  • internal/cmd/safedep.go
  • internal/cmd/subscription/service.go
  • internal/cmd/verbs.go
  • internal/config/config.go
  • internal/config/config_test.go
  • internal/duration/duration.go
  • internal/duration/duration_test.go
  • internal/duration/window.go
  • internal/duration/window_test.go
  • internal/tui/editor.go
  • internal/tui/editor_test.go
  • internal/tui/escape.go
  • internal/tui/escape_test.go

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

abhisek commented Oct 31, 2026

Copy link
Copy Markdown
Member Author

release-preflight fails at go mod tidy. PMG in CI refuses the two SDK modules of this PR with "Package blocked by dependency cooldown":

  • buf.build/gen/go/safedep/api/grpc/go@v1.6.2-20261031065119-dc85a10c2beb.1
  • buf.build/gen/go/safedep/api/protocolbuffers/go@v1.36.12-20261031065119-dc85a10c2beb.2

BSR published both at 2026-10-31 06:51 UTC from safedep/api#254. The PMG default cooldown is 2 days, so the block ends at about 2026-11-02 06:51 UTC. The code builds and its tests pass locally. A re-run before then fails the same way.

Two ways to go green:

  1. Wait until the cooldown ends, then re-run the job.
  2. Exempt the first-party SDK modules (buf.build/gen/go/safedep/api/*) from the cooldown in the PMG config of this workflow. This changes the supply chain policy of CI, so the owner decides.

Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e649b16c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cmd/policy/rule_list.go Resolved
Comment thread internal/cloudpolicy/protoyaml.go Resolved
…imes

Two problems from the review of #67:

- rule list --at-revision N --override NAME resolved the name against
  head, not revision N. An override that a later revision renamed or
  removed failed, and a reused name filtered by the wrong id. The
  command now reads the policy at --at-revision once, and uses that one
  snapshot for the override lookup and for the names of the attached
  overrides.
- The YAML wrote a timestamp with RFC 3339, which drops fractional
  seconds. An expires_at with a fraction then failed the no-change
  check, so policy edit made a draft with a truncated expiry. The YAML
  now writes RFC 3339 with nanoseconds, which omits a zero fraction. The
  decoder accepts both forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
The PMG cooldown of 2 days blocked the SafeDep API SDK that BSR built
right after the API merge, so release-preflight failed. SafeDep publishes
these modules, so the cooldown adds no protection for them. PMG still runs
malware analysis on them. control-tower and malysis skip the same modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
The policy decision log needs the RPC ListPolicyDecisions of
PolicyService. The API build 20261104174030-9113dd6a8ea6 adds it. The
regenerated PolicyServiceClient mock gets the new method. The same build
moves GitRef to safedep.messages.scm.v1. The CLI does not use GitRef, so
no other code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
audit event list turned --since and --until into a time range in its own
code. policy decision list needs the same flags with the same checks. The
logic now lives in duration.Window, so both commands refuse the same
input with the same message. The audit behavior does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
An admin who changes a rule, or who sees a blocked install, could not
ask which decisions a revision, an override or a rule made, and where.
The new command reads ListPolicyDecisions and lists the decisions of pmg
and the pull request check, newest first.

Each filter of the RPC has a flag: --since, --until, --tool, --outcome,
--revision, --rule, --override, --path, --package, --project and
--endpoint. --override takes a name or an id and resolves it in the
policy at --revision, or at head. --package takes a PURL with no version.

Each row shows the time, the tool, the package version, the outcome, the
rule or field with its layer or override, the revision, and the place.
The revision cell adds the default policy revision when the default
policy decided, so a cooldown block shows both. A pmg place is the
hostname and the user, with one hint: the CI repository, else the
Kubernetes workload, else the agent. A check shows the repository, the
pull request number and the link. A scan shows the repository and the
ref. The JSON output writes the messages of the server in protojson.

The errors map to a missing entitlement, a role that cannot read the
policy, a bad page token or filter, and a server without the RPC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
…lengths

A review of policy decision list found these problems:

- --override with the id of a deleted override failed with "no policy
  override is named". A stored decision keeps that id, and the server
  matches it. The command now sends a value with the shape of an
  override id ("ov_" and 8 to 64 Crockford base32 characters) as is when
  the policy does not have it. Other unknown values still fail.
- --package let the PURL parser change the name. The parser lowercases
  a PyPI name and drops the vendor of a Composer package, but the server
  compares the stored name exactly. The command now takes only the
  ecosystem from the parser and builds the name from the PURL as
  written: npm @scope/name, Maven group:artifact, the Go module path,
  Composer vendor/name. It refuses qualifiers and a subpath.
- The command did not check the length limits of the filters. It now
  refuses a --rule or --override over 64 characters, a --path over 256,
  a --project over 128, an --endpoint over 100 and a package name over
  255, with the flag name in the message.
- duration.Window changed the help of audit event list from "for the
  events" to "for the time". The caller now gives the noun, so the
  audit text is the same as before.
- The command built the filters three times. It now checks the flags
  once in Args and passes the result to the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
…exist

A review checked the command docs against control-tower main and pmg.
Some examples showed output that this release cannot give:

- The SafeDep default policy is at revision 1, not 12. It sets only
  scan_gate.fail_on: high and scan_gate.fail_on_attacks: fail, and no
  cooldown. policy show, policy edit, endpoint policy show, project
  policy show and policy decision list now show revision 1. The decision
  list example of the default policy is now a failed pull request check
  on scan_gate.fail_on. Its cooldown example cites a policy override.
- control-tower never sends the warning LOW_ENFORCED_COVERAGE. The
  examples of policy change show and policy change publish no longer
  show it. The tests use ENDPOINT_LABEL_LOOSENS, a warning that the
  server sends.
- No writer sets scm-property/ labels, and the server does not set
  scm/forge-project or scm/visibility. The server sets
  safedep.io/project-id, safedep.io/project-source, and scm/forge,
  scm/owner and scm/repo from the repository binding. The project docs,
  the help of project label and the examples now say so, and use
  custom/ labels for a selector.
- No tool sends managed/ labels. pmg sends reported/os and
  reported/arch. endpoint list, endpoint label set and policy show now
  use reported/ and custom/ labels.

The server writes a selector change of a preview as protojson. The table
of policy change show and the warning of policy change publish now write
it in the selector syntax, as in custom/criticality=high, as the docs
show. plain and json keep the value of the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
A second review found three more examples that this release cannot give:

- policy change publish showed change 18 as TIGHTENS, but policy change
  show showed it as LOOSENS. control-tower gives LOOSENS: a selector edit
  always loosens, and the first cooldown of an override loosens when the
  base and the default policy set none. The publish example now shows
  each part that loosens and the confirmation prompt. Revision 47 shows
  LOOSENS in revision show and revision list. Revision 51 deletes a
  trust entry, so it tightens. The impact of change 18 is now what the
  pull request check reports: it enforces scan_gate.fail_on and does not
  support the cooldown.
- endpoint policy show showed a field that a shared managed file locks.
  That file is not in this release. The example shows no exception. The
  test fixture of the subject policy is now an endpoint, because only
  pmg sends a policy apply report, and it uses the detail that pmg sends
  for global_lockdown.
- project policy show listed the tool scm-check. The pull request check
  registers coverage as pull-request-check and sends no policy apply
  report, so the applied table of a project is empty. The example and
  the text now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
A user ran safedep policy edit on a tenant with no revision and got a file
with only the header and {}. The file did not say which fields exist or
which values they take.

The edit document of policy edit and policy change edit is now a
template of the policy settings:

- The CLI walks the descriptor of the contract, as the YAML codec does,
  so a new field shows after an SDK bump with no change in the CLI.
- A set field keeps its YAML line. An unset field is a commented line at
  its nesting. A tenant with no settings gets a commented base skeleton.
- Each commented field has a note: the enum tokens that the codec reads,
  or the duration form with the range from the protovalidate rules, and
  the value that the subjects get now with the layer that sets it (the
  base or the default policy and its revision). A long note goes on its
  own line above the field.
- A policy with no override gets a commented example override. The codec
  writes it, so its keys are the ones that the codec reads.
- The header points to the field reference:
  https://docs.safedep.io/reference/cloud-policy-settings

A save of the template as it is still changes nothing. The comments are
never values. A message key with only commented lines below it now reads
as a set message with no fields, so a set but empty spec round trips. A
label selector stays unset, because an empty selector selects every
subject. A file with only comments reads as an empty policy only when the
policy was empty. The comment warning now ignores every comment that the
CLI wrote, also the note of a line that the user uncomments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
…otes

A review of the policy edit template found these problems:

- A tenant with values that saved a file with only comments got "the
  file is empty", with no way to clear the policy. The editor now opens
  again with: the file sets no field. To remove every setting, write {}
  on one line.
- A parent key that a person uncommented alone, as base:, made a change
  with an empty message. The edit now compares the documents with their
  empty messages pruned, so that is no change. A field that a person
  removes still makes a change. A label selector, a duration and a time
  are never pruned, because their empty value has a meaning.
- The note of an override field said "Now: medium (base)", but an
  override of a lower priority can also set the field. It now says
  "Below this override". A base field with no value in any layer now
  says that each tool uses its local value.
- The example override wrote min_age: 168h while the notes wrote 7d.
  The template writer now writes it in days. The generated setters build
  it, so a removed field fails the build.
- The header asks for the reason in a description field, but the
  template showed none. It now shows base_description and the
  description of the example override.

Also: MarshalOverride had no caller and is removed. isLeaf and the
codec read one predicate, isFormattedMessage. The comment check reads
only comment lines of the written text, so a "#" in a value is not a
comment. A note that is longer than the line wraps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
The owner found a flag help that joined two sentences with ";": "the
publish message; the change title becomes the title when it is empty".
A sweep of the text that this pull request adds found more:

- 27 flag usages joined two ideas with ";". Each is now one phrase, as
  in "the publish message, or the title of the change when empty" and
  "a label as custom/KEY=VALUE (repeatable)".
- An error joined two sentences with ";". It now uses two sentences.
- Help, warnings and errors used the passive voice or jargon: "was not
  saved", "could not", "rebased", "never merges", "endpoints reporting".
  They now use the active voice and simple words.
- The help of endpoint policy show said that a managed file locks a
  field, and the help of project policy show named a check that
  reports. Neither happens in this release. The help now says what the
  output shows.

The behaviour, the JSON and plain output, and the contract tokens do
not change. A test that asserts a changed error is updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
The owner published a change that adds a policy override and got:
"It loosens added (- -> policy-test) in override "policy-test"". The
CLI wrote every override change in the form "<kind> (<old> -> <new>)",
and that form does not read well for an added or a removed override.

Each kind of override change now has its own sentence in the publish
warning, as in "It adds policy override "policy-test"." and "It changes
the selector of policy override "payments" from custom/team=pay to
custom/criticality=high.". In the table of policy change show, an added
or removed override shows "new policy override" or "removed policy
override", and an expiry shows "none" when there is none. The JSON and
plain output keep the values of the server.

The --limit help of packages list, project scan list and the endpoint
list commands now has the same form as the other commands: "page size,
or the server default when 0".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
@abhisek
abhisek enabled auto-merge (squash) November 5, 2026 14:35

@Sahilb315 Sahilb315 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I built this PR at 13db8a6 and ran it against a live tenant, with the server on control-tower main 64f54637. The commands match the specs for most cases: the change workflow, stale changes and sync, the etag conflict, rule refusals, labels and selectors, rollback, the audit list and the decision log filters all work. Each inline comment below has a reproduction from that run.

One more finding is outside the diff lines, so it is here:

  • internal/cmd/endpoint/list.go:92: --since and --silent-for use cobra DurationVar. The cli row of the MVP in the parent spec says "Duration flags accept a d suffix" and lists endpoint list. Repro: safedep endpoint list --since 7d fails with invalid argument "7d" for "--since" flag: time: unknown unit "d" in duration "7d". policy decision list --since 7d works, because it uses internal/duration. Also, docs/cmd/endpoint-list.md says the default is 24h, and the code uses 168h.

Comment thread internal/cmd/policy/change_edit.go Resolved
Comment thread internal/cmd/policy/settings.go Resolved
Comment thread internal/cmd/policy/errors.go Resolved
Comment thread internal/cmd/policy/errors.go Resolved
Comment thread internal/cmd/policy/editor.go Resolved
Comment thread internal/cmd/policy/change_publish.go Resolved
Comment thread internal/cmd/policy/change_preview.go Resolved
Comment thread internal/cmd/policy/decision_view.go Resolved
A reviewer ran the CLI against a live tenant and found these problems:

1. endpoint list --since 7d failed: the duration flags of the endpoint
   commands did not accept days. They now read durations as the policy
   commands do. The docs now give the real default of --since, 168h.
2. change create --from-revision above head showed "Invalid request".
   The server refuses it as an invalid restore.from_revision, and the
   CLI now says that the revision does not exist. --from-revision 0
   now says that revision 0 has no policy.
3. A FAILED_PRECONDITION of a change or a rule showed raw gRPC text.
   The CLI now shows the detail of the server with a hint: for a change,
   how to handle the package rules of a removed override, and for a
   rule, how to list the rules.
4. The editor opened again for each INVALID_ARGUMENT, also for a title
   that is too long, which no edit can fix. The CLI now checks the
   length of -m before the RPC, from the protovalidate rule of the
   request. The editor opens again only for an error in the document.
5. The preview showed enum values as SEVERITY_MEDIUM. The server writes
   an enum by its value name with no quotes, and the CLI now shows the
   short form of the document, as medium.
6. The editor did not warn about an override that selects on a label
   that a tool sets. It now warns, with no block, for each added or
   changed override that selects on a managed/, reported/ or
   scm-property/ label.
7. After revision 1, the CLI told the user to run endpoint list
   --applied-revision '<1', which endpoint list refuses. The hint now
   starts at revision 2.
8. A decision of the verified malware guard or the license rule of the
   pull request check showed "-". The check cites only the revisions
   for both, so the CLI shows "a fixed rule of the check".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
…ange

policy change edit -m "new title" lost the title when the user closed
the editor with no edit. The editor stops before the save when the
document has no change, so the title never reached the server, and the
command said "No change. Nothing is saved".

When -m differs from the title of the change and the document has no
change, the command now sends an update with only the title and the
etag. The server keeps the settings of the change. The success line says
that the title changed and that the settings did not.

policy edit -m keeps its behaviour: it creates a change only when the
document changes, because a title alone is not a policy change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz

abhisek commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

@Sahilb315 thanks for the run against a live tenant. Every finding of your review is fixed in 5659676 and 3727038. Each thread has a reply and is resolved. The finding in the review body is also fixed: --since and --silent-for of endpoint list now accept 7d, through internal/duration. The other --since flags of endpoint (activity list, inventory list, show, status) also accept it. endpoint-list.md and endpoint-status.md now give the real default, 168h. Two fixes are partial, because the server sends too little data:

  • FAILED_PRECONDITION comes with no reason, so the hint depends on the command, not on the exact case.
  • The decision log cannot name the fixed rule of the check (verified malware guard or license rule), because the stored citation does not hold it. The CLI shows "a fixed rule of the check".

Generated by Claude Code

@Sahilb315 Sahilb315 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked each fix again on a live tenant at 3727038, and CI passes. The decision log still cannot name the verified malware guard or the license rule, because the server stores no rule for them. That needs a control-tower change.

@abhisek
abhisek merged commit 3128d5d into main Nov 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants