Skip to content

feat(agent): expose active package policy - #1937

Draft
Benoît Cortier (CBenoit) wants to merge 14 commits into
masterfrom
cbenoit-plan-agent-policy-endpoint
Draft

feat(agent): expose active package policy#1937
Benoît Cortier (CBenoit) wants to merge 14 commits into
masterfrom
cbenoit-plan-agent-policy-endpoint

Conversation

@CBenoit

@CBenoit Benoît Cortier (CBenoit) commented Aug 17, 2026

Copy link
Copy Markdown
Member

Exposes the validated active package-broker policy through the authenticated GET /v1/policy route. Clients receive a stable snapshot, while an unavailable policy returns the shared structured 404 response without exposing policy source or file-security details.

Uses the official now-policy 0.3.0, now-policy-api 0.4.0, and now-policy-server-template 0.4.0 releases. Phase 1 remains read-only: policy management, validation, and replacement routes are not exposed.

Coordinated stack: Devolutions/now-libraries#93 defines the shared contract, this PR implements the Agent endpoint, and Devolutions/UniGetUI#5292 consumes it. Keep this PR in draft while Phase 2 #1963 is restacked and the full stack is finalized.

Issue: Devolutions/now-libraries#93

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Expose the validated active package-broker policy through the shared
authenticated GET /v1/policy route. Return a structured unavailable
error without leaking policy source or file-security details.

This requires now-policy-api and now-policy-server-template 0.4.0 from
Devolutions/now-libraries#93 before the change can ship.

Issue: Devolutions/now-libraries#93

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@CBenoit

Benoît Cortier (CBenoit) commented Aug 17, 2026

Copy link
Copy Markdown
Member Author

Implementation notes:

  • Uses official crates.io releases now-policy 0.3.0, now-policy-api 0.4.0, and now-policy-server-template 0.4.0 with no path or git patches.
  • Serves a stable clone of the validated in-memory Arc<PolicyDocument> through authenticated GET /v1/policy; the policy lock is released before response serialization.
  • Preserves existing named-pipe executable signature authorization, policy owner/DACL validation, and YAML policy-file compatibility.
  • Returns structured NotFound/404 when policy inspection has no active policy, while package evaluation continues to return BrokerPaused/503.
  • Does not expose policy source, path, reason, security metadata, or policy-body logs.
  • Keeps Phase 1 read-only by hiding the shared management and validation routes and rejecting mutation methods with 405 plus Allow: GET, HEAD.

Validation on exact head 8e9cc98e4103b40ddc3511aef39462d9f7610a7a:

cargo +nightly fmt --all -- --check
cargo build --workspace --locked
cargo clippy --workspace --tests --locked -- -D warnings
cargo test --workspace --locked -- --skip winget_app_exec_alias_passes_elevated_verification
cargo test -p now-package-broker --locked policy_response_returns_not_found_when_unavailable
cargo test -p now-package-broker --locked package_evaluation_without_policy_remains_paused
cargo test -p now-package-broker --locked concurrent_policy_replacement_returns_only_complete_snapshots

All commands passed. The skipped test is an existing host-specific check whose local WindowsApps winget.exe grants the current user write access; an unfiltered broker run passed 253 tests with 1 ignored before that expected local DACL failure.

CI run https://github.com/Devolutions/devolutions-gateway/actions/runs/33828611066 passed all 42 checks, including locked Linux/Windows tests and Clippy, Windows Agent builds, and the Agent policy end-to-end test under LocalSystem.

Copilot's exact-head review generated zero findings and left zero unresolved threads. Its Needs a closer look disposition is solely for human scrutiny of the intentionally draft, security-sensitive cross-repository stack.

Note

LLM-assisted content (no human feedback).

Copilot AI 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.

Pull request overview

Adds authenticated active-policy inspection to the Agent’s package broker.

Changes:

  • Implements GET /v1/policy with structured responses.
  • Reuses connection authentication and adds snapshot/concurrency tests.
  • Remains blocked on publishing and committing the 0.4.0 dependencies.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/now-package-broker/src/server/mod.rs Implements and tests policy retrieval.
crates/now-package-broker/src/auth.rs Exposes connection-level authentication for the endpoint.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/now-package-broker/src/server/mod.rs Outdated
Return a generic policy-unavailable message so clients cannot infer
whether the active policy is file-backed, missing, or corrupt.

Issue: Devolutions/now-libraries#93

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adopt the final shared server trait and keep policy-domain conversions owned by the broker after the compatibility feature removal.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Record the registry graph after removing the obsolete policy compatibility features so locked CI can resolve the manifest consistently.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exercise the policy HTTP contract from the repository integration tests while keeping authentication and snapshot-locking invariants beside the broker implementation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Launch the Agent through its CLI and issue HTTP requests over a real Tokio named-pipe client. Build the test Agent with the development signature bypass while requiring the matching debug configuration opt-in.

Remove the in-process broker test harness and its testsuite dependencies; retain authentication and snapshot-locking invariants as broker unit tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move privileged policy endpoint coverage into a dedicated tester so the active-policy path cannot silently skip in normal test runs. Run it as LocalSystem in CI with a development-only signature bypass.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Comment thread .github/workflows/ci.yml
Comment thread crates/now-package-broker/Cargo.toml Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the official policy contract releases while preserving the Phase 1 read-only endpoint and existing YAML policy loading.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🟡 Changes recommended

The custom 405 response violates HTTP requirements by omitting the Allow header.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread crates/now-package-broker/src/server/mod.rs
Include the mandatory Allow header when Phase 1 rejects mutation methods on the policy endpoint.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🔵 Needs a closer look

The coordinated stack remains intentionally draft, and the latest Windows validation was still running during review.

Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@CBenoit
Benoît Cortier (CBenoit) requested a balanced review from Copilot September 4, 2026 02:02

Copilot AI 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.

🟡 Changes recommended

The unavailable-policy response returns 503 although the linked shared contract specifies structured 404 behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread crates/now-package-broker/src/server/mod.rs Outdated
Keep active-policy inspection aligned with the shared 404 contract while package operations continue to report BrokerPaused when no policy can be evaluated.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🔵 Needs a closer look

The implementation is clean and CI passes, but the coordinated stack is intentionally still in draft pending finalization.

Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI 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.

🔵 Needs a closer look

The security-sensitive cross-repository contract remains explicitly draft pending final stack coordination.

Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Benoît Cortier (CBenoit) added a commit that referenced this pull request Sep 4, 2026
Add authenticated policy management and validation for the package broker. Persist JSON policies atomically with secure path, ACL, concurrency, receipt, watcher, and audit checks while preserving stable runtime snapshots.

Stacked on #1937. Uses the contract from Devolutions/now-libraries#99. UniGetUI policy management depends on this API.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants