Repository navigation
feat(policy): safedep policy, project, endpoint and audit commands - #67
Conversation
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 Report SummaryPackage Details
This report is generated by SafeDep GitHub App |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important Review skippedToo 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.
|
|
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:
Generated by Claude Code |
There was a problem hiding this comment.
💡 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".
…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
Sahilb315
left a comment
There was a problem hiding this comment.
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:--sinceand--silent-foruse cobraDurationVar. Theclirow of the MVP in the parent spec says "Duration flags accept adsuffix" and listsendpoint list. Repro:safedep endpoint list --since 7dfails withinvalid argument "7d" for "--since" flag: time: unknown unit "d" in duration "7d".policy decision list --since 7dworks, because it usesinternal/duration. Also,docs/cmd/endpoint-list.mdsays the default is 24h, and the code uses 168h.
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
|
@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:
Generated by Claude Code |
Sahilb315
left a comment
There was a problem hiding this comment.
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.




Summary
This PR adds the CLI of the cloud policy MVP:
safedep policycommand tree.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 specdocs/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
policyshow,get [--revision N],edit [-m TITLE] [--override NAME]policy changelist,show,edit,sync,delete,publish [--yes], andcreate --from-revision Nfor a rollbackpolicy revisionlist,showpolicy rulecreate (--block | --trust),list,show,update,delete, with a bulk block from a filepolicy decisionlist [--since] [--until] [--tool] [--outcome] [--revision] [--rule] [--override] [--path] [--package] [--project] [--endpoint]projectlist [--selector],show,label set | delete,policy showendpointlistgets--applied-revision '<N',--selectorand a POLICY column. New:label set | deleteandpolicy showaudit eventlist [--since] [--until] [--action] [--resource KIND[/ID]] [--actor]The tree has 24 new doc pages in
docs/cmd/.Behaviour worth a look
policy edit:proto.Equal.change publishpreviews 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 (--yeswith no TTY).rule create:/*or.*prefix.--scope allexpands to every trust scope that the SDK knows.pkg:<type>/*block warns. A trust expiry over 90 days is refused before the request.decision list:repo#numberand the link.--overridetakes a name or an id. The id of a deleted override goes to the server as it is.--packagetakes a PURL with no version. The CLI keeps the name as each ecosystem stores it.usefulerror.ReasonOffrom 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.--sinceand--untilshare one check ininternal/durationforaudit event listanddecision list.Differences from the walkthrough
These are left out on purpose:
policy show;policy status;field list|show;publish -f;endpoint policy list; step-up lines.rule create, and HITS columns.change show.GetPolicyCatalog. A later change can addpolicy field showfrom that RPC.decision listtakes 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.
--overriderefused the id of a deleted override. Commit ddaa59a fixes it, with the package name and length findings.Testing
make lint-conventions,make lint,make testandmake buildpass. golangci-lint reports 0 issues, and the convention tests pass.decision listneeds safedep/control-tower#1644.Generated by Claude Code