Skip to content

Read only cli commands#156

Open
aprimakina wants to merge 2 commits into
mainfrom
read-only-cli-commands
Open

Read only cli commands#156
aprimakina wants to merge 2 commits into
mainfrom
read-only-cli-commands

Conversation

@aprimakina
Copy link
Copy Markdown
Contributor

@aprimakina aprimakina commented May 18, 2026

Extend read-only mode enforcement to CLI commands and DB connections

Previously, read-only mode only blocked MCP tool calls. This PR extends the gate to:

  • CLI destructive commands — service create/fork/start/stop/resize/update-password/delete now call common.CheckReadOnly before any API request
  • DB connections — db connection-string and db connect now OR the --read-only flag with cfg.ReadOnly, so the global config forces read-only PostgreSQL sessions even without the flag

@ggodeke requested the change, we prefer a more locked-down experience in the tiger CLI compared to ghost

aprimakina and others added 2 commits May 18, 2026 11:30
The read_only config flag previously only refused destructive Tiger MCP
tool calls. Extend it to the equivalent CLI commands (service create,
fork, start, stop, resize, update-password, delete) so a single config
flip prevents accidental mutation through either entry point.

CheckReadOnly + ErrReadOnly move from internal/tiger/mcp/errors.go to
internal/tiger/common/errors.go so both packages share them.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tiger db connect and tiger db connection-string now OR the --read-only
flag with the global read_only config option, so flipping the config on
guarantees that any database session opened through the CLI is opened
with the tsdb_admin.read_only_connection GUC — matching how the
db_execute_query MCP tool already behaves.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@aprimakina aprimakina marked this pull request as ready for review May 18, 2026 10:03
Copy link
Copy Markdown
Member

@nathanjcochran nathanjcochran left a comment

Choose a reason for hiding this comment

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

Left two minor comments, but overall LGTM! ✅

// CheckReadOnly returns ErrReadOnly if read-only mode is enabled. Callers
// should invoke this before any destructive API call.
func CheckReadOnly(cfg *config.Config) error {
if cfg != nil && cfg.ReadOnly {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In what case would cfg be nil? It looks like the prior version of this function (which was moved here from the ./internal/tiger/mcp package) always assumed cfg was non-nil (which makes sense to me - I believe we usually error-out if we can't load the config). Just want to make sure we don't end up silently ignoring an error that caused the config to not load, and reporting that read-only mode is not enabled (when it actually might be).

Comment thread internal/tiger/cmd/db.go
Comment on lines +64 to +66
The global read_only config option (or TIGER_READ_ONLY=true) also forces this
behavior, so connection strings produced while read-only mode is on always
open read-only sessions.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we include a similar note in the tiger db connect description/help text? That command's help text doesn't include much about read-only mode at all, except for one example of using the --read-only flag.

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.

2 participants