Skip to content

feat: add system service allowlist policy#552

Merged
matt-dz merged 6 commits into
mainfrom
matthew.deguzman/systemd-allowlist
Jul 15, 2026
Merged

feat: add system service allowlist policy#552
matt-dz merged 6 commits into
mainfrom
matthew.deguzman/systemd-allowlist

Conversation

@matt-dz

@matt-dz matt-dz commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add a default-deny system service allowlist with read, reload, and restart actions.
  • Add the interp.AllowedSystemServices API and --allowed-services CLI flag.
  • Expose atomic service authorization through builtins.CallContext.
  • Enforce RemediationOnly centrally before builtin argument parsing.
  • Update documentation and add policy, CLI, and remediation regression tests.

Motivation

Future systemctl and journalctl builtins need granular authorization so operators can restrict which services rshell may inspect or control. Command authorization alone is too broad because enabling either command could otherwise expose every system service.

Behavior

Service grants use exact, case-sensitive matching:

mysql.service:restart+reload+read,nginx.service:read
  • mysql does not match mysql.service.
  • Service names are not normalized or resolved as aliases.
  • Empty names, whitespace, path-like names, and glob patterns are rejected.
  • Missing configuration denies all services.
  • --allow-all-commands does not bypass the service policy.
  • Service authorization requires remediation mode.
  • Multi-service requests are authorized as a complete set before execution, preventing partial operations.

Library configuration:

interp.AllowedSystemServices([]interp.SystemServiceControlGrant{
    {
        Service: "mysql.service",
        Actions: []interp.SystemServiceAction{
            interp.SystemServiceRestart,
            interp.SystemServiceReload,
            interp.SystemServiceRead,
        },
    },
})

Future builtins can enforce the policy with:

callCtx.AuthorizeSystemServices(action, services...)

This PR adds the authorization foundation only. systemctl and journalctl are not implemented yet.

Remediation Enforcement

builtins.Command.RemediationOnly is now enforced centrally by command registration before flags or help are parsed. Remediation mode is also propagated through nested builtin execution paths such as find -exec and xargs.

Testing

  • make fmt
  • go test -p 1 ./...
  • RSHELL_BASH_TEST=1 go test ./tests/ -run TestShellScenariosAgainstBash -timeout 120s
  • git diff --check
  • gofmt -l .

@matt-dz
matt-dz marked this pull request as ready for review July 14, 2026 19:36
@matt-dz

matt-dz commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 13c9cdaecd

ℹ️ 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 added this pull request to the merge queue Jul 15, 2026
Merged via the queue into main with commit 714d25c Jul 15, 2026
41 of 42 checks passed
@matt-dz
matt-dz deleted the matthew.deguzman/systemd-allowlist branch July 15, 2026 12:04

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

Pull request overview

Introduces a default-deny “system service allowlist” policy to support future system-service builtins by adding a new interpreter option/API, a CLI flag for configuring grants, and plumbing for builtins to atomically authorize service operations.

Changes:

  • Add interp.AllowedSystemServices and enforcement helper (Runner.authorizeSystemServices) with validation + warnings.
  • Expose service authorization through builtins.CallContext and wire it in interp/runner_exec.go.
  • Add --allowed-services flag parsing plus unit tests and documentation updates.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
SHELL_FEATURES.md Documents the new AllowedSystemServices policy and its semantics.
README.md Adds system services to the default-deny security model and describes the new policy/CLI syntax.
interp/system_services.go Implements service grant storage, validation, warnings, and runtime authorization.
interp/system_services_test.go Adds tests for exact-match authorization, default-deny, remediation gating, and warning behavior.
interp/runner_exec.go Plumbs AuthorizeSystemServices into builtin call contexts.
interp/api.go Adds runner config storage for allowed system services and generalizes warning buffering semantics.
cmd/rshell/main.go Adds --allowed-services flag and parsing to interpreter options.
cmd/rshell/main_test.go Adds CLI regression tests for --allowed-services parsing, errors, and warnings.
builtins/builtins.go Introduces SystemServiceAction and adds AuthorizeSystemServices to CallContext.
analysis/symbols_interp.go Allowlists unicode.IsControl / unicode.IsSpace symbols used by validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread interp/system_services.go
Comment thread README.md
Comment thread SHELL_FEATURES.md
Comment thread interp/runner_exec.go
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.

3 participants