Skip to content

feat(cli): add --read-only mode to block write operations#145

Merged
platinummonkey merged 3 commits intodatadog-labs:mainfrom
swarajrao:feat/read-only-mode
Mar 3, 2026
Merged

feat(cli): add --read-only mode to block write operations#145
platinummonkey merged 3 commits intodatadog-labs:mainfrom
swarajrao:feat/read-only-mode

Conversation

@swarajrao
Copy link
Contributor

@swarajrao swarajrao commented Mar 2, 2026

What does this PR do?

Adds a --read-only flag (+ DD_READ_ONLY / DD_CLI_READ_ONLY env vars + read_only config file option) that blocks all write (CUD) operations at runtime, allowing only read operations. Also fixes 5 missing write command names in the agent JSON schema as a preparatory commit.

Motivation

My primary motivation for this was to derisk actions autonomous agents might take when using the pup CLI. A flag that blocks all mutating actions is a stronger safeguard than updating my instructions to explicitly disallow creates/updates/deletes.

Additional Notes

Design decisions:

  • auth/alias commands are allowed - these only affect local state (credentials and config aliases), not Datadog resources.
  • Guard fires before auth validation - pup --read-only monitors create --file f.json fails fast even without credentials.
  • POST-based reads (e.g., bulk-export) are not flagged - these semantically are read operations. The guard thus checks the leaf subcommand name instead of the HTTP method.
  • No --no-read-only escape hatch in v1 - if read_only: true is in config, it cannot be overridden per-invocation. A safety feature should be hard to bypass especially by agents.
  • patch check tightened - changed name.contains("patch") to name == "patch" || name.starts_with("patch-") since this logic is now a runtime blocker, not just schema metadata.

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

Related Issues

N/A

swarajrao and others added 2 commits March 2, 2026 18:38
Extract inline is_write logic from build_command_schema() into a
standalone pub(crate) fn is_write_command_name() for reuse by the
upcoming read-only runtime guard.

- Added 5 missing write command names: move, link, unlink, configure, upgrade
- Tightened patch check: name.contains("patch") → name == "patch" || name.starts_with("patch-")
- Fixes agent schema JSON output where these commands were incorrectly marked read_only: true

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a --read-only flag, DD_READ_ONLY / DD_CLI_READ_ONLY env vars, and
read_only config file option that blocks all write (CUD) operations at
runtime, allowing only read operations.

- Added read_only field to Config and FileConfig structs
- Added --read-only global CLI flag to Cli struct
- Refactored main_inner() to use ArgMatches for subcommand introspection
- Added get_leaf_subcommand_name() and get_top_level_subcommand_name() helpers
- Runtime guard fires before auth validation (fail-fast)
- auth and alias commands exempted (local-only state)
- Updated all 14 Config struct literals in test_commands.rs
- Added 10 new tests covering write detection, read commands, nested
  commands, and auth/alias exemptions
- Updated COMMANDS.md, ARCHITECTURE.md, and EXAMPLES.md docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@platinummonkey platinummonkey added the enhancement New feature or request label Mar 3, 2026
…x formatting

Two test helpers (client.rs and formatter.rs) were missing the new
`read_only: false` field added to `config::Config`, causing compile
errors in CI. Also run cargo fmt to fix rustfmt violations in
main.rs (is_write_command_name) and test_commands.rs (long array literal).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@platinummonkey platinummonkey merged commit 320f84e into datadog-labs:main Mar 3, 2026
6 checks passed
@swarajrao swarajrao deleted the feat/read-only-mode branch March 3, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants