Skip to content

fix(docker): document container_status() and quote its argument - #1982

Merged
mrrobot47 merged 2 commits into
EasyEngine:developfrom
mrrobot47:fix/container-status-contract
Nov 24, 2026
Merged

mrrobot47 merged 2 commits into
EasyEngine:developfrom
mrrobot47:fix/container-status-contract

Conversation

@mrrobot47

@mrrobot47 mrrobot47 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Problem

EE_DOCKER::container_status() returns false whenever docker inspect fails, not only when the container doesn't exist: a daemon that is down or restarting, a socket error or a timeout all return false too. Nothing documented that, so a caller can read false as "no such container" and act on it (create, skip a stop/remove, report a container as gone). The container name was also interpolated into the shell command unquoted.

Change

  • Docblock with the return contract, as observed with docker inspect -f '{{.State.Running}}': 'running' while it runs, which includes paused and restarting containers; 'exited' for created, exited and dead; false when inspect fails for any reason; exits via EE::error() when docker isn't on PATH. It says that callers acting on absence must check that separately.
  • The name goes through escapeshellarg(). Every caller in core and the packages passes one fixed container name or an id from docker-compose ps -q, so results are unchanged. Return values are unchanged.

Core callers: boot_container() runs the given up -d command on false, which is idempotent, so an inspect error there is harmless. GlobalContainers::down_global_containers() skips the stop/remove on false, but nothing calls it (the image migration goes through upgrade_global_service()). No core caller needed a change.

Testing

  • Unit tests (PHPUnit 9.6, PHP 7.4 and 8.5, Docker calls faked): true gives running, false gives exited, no-such-object, daemon-down and timeout errors give false (unchanged from before); the name reaches docker inspect as one quoted argument; shell-injection payloads don't reach the shell (this one fails without the change).
  • PHPCS clean on the changed lines.

Summary by CodeRabbit

  • Documentation
    • Clarified that running, paused, and restarting containers are reported as running; other inspected states are reported as exited; and inspection failures are reported separately.
  • Bug Fixes
    • Improved handling of container names and IDs when checking Docker status.

container_status() returns false for any `docker inspect` failure, not only for a missing container: a daemon that is down or restarting, a socket error or a timeout look the same. Document that contract, and that 'running' includes paused and restarting containers while 'exited' covers created, exited and dead ones, so callers don't read false as "doesn't exist".

The name is now passed through escapeshellarg(). Every caller passes one fixed name or an id from `docker-compose ps -q`, so the results don't change.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Container Status Inspection

Layer / File(s) Summary
Document and escape container inspection
php/class-ee-docker.php
The documentation describes status results and failure cases. The docker inspect command shell-escapes the container name or ID.

Change: Bug fix

Merge Risk: Minimal · up to 6534b

This change documents container_status() and safely quotes its container argument. Results for normal container names and IDs are unchanged, and no merge-blocking concerns remain.

Security architecture risk: Minimal · up to 6534b

The change makes container status checks safer by quoting the supplied identifier before execution. It preserves the existing status results and does not grant additional Docker access or change deployment behavior.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed control applies only to status checks through this helper. The PR adds no caller, endpoint, credential, or Docker permission; the actual host and Docker daemon scope still depends on the invoking CLI environment.

Trust Boundaries and Controls

  • inferred — On the Unix shell path, quoting constrains the supplied value to one shell argument. This is a shell-parsing control, not Docker argument validation or authorization to inspect a particular object.

Resilience and Maintainability Implications

  • observed — The existing boot helper takes its fallback command branch on false, while the global-container removal helper skips stop and remove on false. These pre-existing decisions still cannot distinguish absence from an inspection failure; the PR does not change either branch or introduce a new state transition.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a795788-2251-4d05-9766-83092ee41884
Commits

Reviewing files that changed from the base of the PR and between 4553b91 and 6534bad.

Files selected for processing: 1

  • php/class-ee-docker.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@mrrobot47
mrrobot47 merged commit 652eb5e into EasyEngine:develop Nov 24, 2026
33 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.

1 participant