Skip to content

intrinsic: keep iac state directories under an operator root - #870

Merged
general-kroll-4-life merged 1 commit into
stackql:mainfrom
RyoKusnadi:fix/iac-state-under-operator-root
Oct 24, 2026
Merged

general-kroll-4-life merged 1 commit into
stackql:mainfrom
RyoKusnadi:fix/iac-state-under-operator-root

Conversation

@RyoKusnadi

Copy link
Copy Markdown
Contributor

Fixes #834

What

With the unstable preview on, the state predicate on stackql_preview.iac relations went straight to omnisdk.NewLedger. A query could therefore create ledger and journal files anywhere the process can write.

Now:

  • The operator sets the state root with a new iacStateRoot field in --preview, e.g. --preview '{"unstable": true, "iacStateRoot": "/srv/stackql/iac"}'. When it's unset, the root is <approot>/iac, the same default as before.
  • state is now a relative name resolved under that root (state = 'prod' → <root>/prod). Leaving it out still uses the root itself.
  • Names are refused if they are absolute, contain a volume, climb out with .., or go through a symlink (or a junction on Windows) that leads out of the root. The root itself may be a link, so an operator can still point it at another disk.
  • The check happens in ledgerPredicates, before omnisdk.Prepare. A refused query writes nothing and makes no provider calls.
  • Collections that name the same state directory share its ledger, each under its own collection key. This is noted on the new field.

For a local CLI run, the operator keeps the override through iacStateRoot, which the process owner controls. A query can no longer choose the path on its own. That's a behaviour change: any query that passed an absolute state path now has to use a name under the root, or the operator has to set iacStateRoot. Since this is preview-only, I think that's acceptable, but I'm happy to change it.

Notes

  • The symlink check runs on the parts of the path that already exist. A link swapped in between the check and the write isn't covered. Covering that would need omnisdk to open state relative to a root handle (os.Root), which is outside this repo.
  • I haven't added the pgwire/MCP end-to-end case from the issue. The new unit tests cover the path resolution directly. If you'd like a robot test as well, let me know which mock provider you'd want it to use.

Tests

  • New internal/stackql/intrinsic/iac_test.go:
    • The default root, and allowed names.
    • Absolute, .. and nested .. escapes are refused, and nothing is created on disk.
    • A symlink inside the root that points out of it is refused.
    • A root that is itself a symlink is allowed.
    • --preview parsing of iacStateRoot.
  • go build ./..., go vet ./internal/stackql/intrinsic/ and go test ./internal/stackql/intrinsic/... pass on Go 1.27.3.

The 'state' predicate on stackql_preview.iac relations was passed
straight to the ledger, so a query could create state anywhere the
process can write. It is now a relative name resolved under the state
root (the new iacStateRoot preview setting, or <approot>/iac), and
names that are absolute, climb out with '..', or follow a link out of
the root are refused before anything touches disk.

Fixes #834

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>

@general-kroll-4-life general-kroll-4-life 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.

@RyoKusnadi thanks again, great contribution.

@general-kroll-4-life
general-kroll-4-life merged commit bd54a49 into stackql:main Oct 24, 2026
31 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.

[SECURITY] Keep preview IaC state paths under operator control on server surfaces

2 participants