Skip to content

feat(builtins): add logrotate#536

Merged
matt-dz merged 24 commits into
mainfrom
matt-dz/logrotate-remediation
Jun 24, 2026
Merged

feat(builtins): add logrotate#536
matt-dz merged 24 commits into
mainfrom
matt-dz/logrotate-remediation

Conversation

@matt-dz

@matt-dz matt-dz commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a remediation-only logrotate builtin for rshell that keeps the familiar logrotate intent while staying explicit about its safe subset: it truncates log files to zero bytes through AllowedPaths, but does not parse configs, rename/retain copies, compress logs, write state files, or run rotate scripts.

Key behavior:

  • supports --size/-s, --force/-f, --dry-run/-n, --verbose/-v, and --help/-h
  • requires exactly one of --size or --force
  • dry-run reports per-file actions without mutating files
  • missing files are errors and are not created
  • threshold checks and truncation happen on the same fd via a new narrow sandbox capability
  • write targets that traverse symlinks are rejected with symlinks are not supported as write targets

Also extracts shared coreutils-style size parsing for truncate and logrotate, wires the new write-capable CallContext field through remediation mode only, and updates docs/analyzer metadata.

Validation

  • make fmt
  • go test ./allowedpaths ./interp
  • go test ./tests/ -run TestShellScenarios -timeout 120s
  • RSHELL_BASH_TEST=1 go test ./tests/ -run TestShellScenariosAgainstBash -timeout 120s
  • go test ./...

@matt-dz
matt-dz changed the base branch from main to codex/rshell-path-modes-poc June 22, 2026 18:09
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 22, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

Static Analysis Verification | Static Analysis Label Check   View in Datadog   GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f871fff | Docs | Datadog PR Page | Give us feedback!

@matt-dz

matt-dz commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 906104e71c

ℹ️ 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".

Comment thread builtins/logrotate/logrotate.go Outdated
@matt-dz

matt-dz commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 00cd10a689

ℹ️ 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".

@matt-dz
matt-dz changed the base branch from codex/rshell-path-modes-poc to main June 22, 2026 20:38
@matt-dz matt-dz changed the title feat(builtins): add logrotate remediation helper feat(builtins): add logrotate Jun 22, 2026
Comment thread analysis/symbols_builtins.go
Comment thread analysis/symbols_builtins.go Outdated

@julesmcrt julesmcrt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we split the PR?
The :ro/:rw path-mode suffix feels like it should be a standalone change

@julesmcrt

julesmcrt commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

From Claude review:

allowedpaths/internal/writeopen/writeopen_unix.go — Symlinked log files get a confusing ELOOP error

openWriteFile applies O_NOFOLLOW to the final path component, so any file that is a symlink (even within a :rw root) fails with ELOOP ("too many levels of symbolic links"). In logrotate's context this is particularly visible: logrotate --dry-run --force /var/log/app.log where app.log is a common → /data/logs/app.log-style managed symlink would print:

logrotate: "app.log": too many levels of symbolic links

rather than something actionable. This is intentional per the symlink policy, but the error surfaced to the user doesn't say "symlinks are not supported as write targets." Adding a specific check and error before the openWriteFile call would improve diagnosability. Also worth a note in the help text / SHELL_FEATURES.md entry.

Comment thread allowedpaths/sandbox.go
Comment thread builtins/logrotate/logrotate.go
@matt-dz
matt-dz changed the base branch from main to codex/rshell-path-modes-poc June 23, 2026 13:10
@matt-dz

matt-dz commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f97a64931

ℹ️ 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".

Comment thread allowedpaths/write_open.go Outdated
@matt-dz

matt-dz commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: fa5852059b

ℹ️ 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".

@matt-dz
matt-dz requested a review from julesmcrt June 23, 2026 17:36
Base automatically changed from codex/rshell-path-modes-poc to main June 24, 2026 09:47
@matt-dz
matt-dz marked this pull request as ready for review June 24, 2026 14:14
@matt-dz matt-dz added the verified/analysis Human-reviewed static analysis changes label Jun 24, 2026
@matt-dz
matt-dz added this pull request to the merge queue Jun 24, 2026
Merged via the queue into main with commit e44cffa Jun 24, 2026
41 of 42 checks passed
@matt-dz
matt-dz deleted the matt-dz/logrotate-remediation branch June 24, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

verified/analysis Human-reviewed static analysis changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants