fix: retrospective review fixes for merged PR #92#114
Merged
Conversation
…own error detail Retrospective review of merged PR #92 (issue #74's reused-datadir fix). `ensureDatadirWritableByContainer`'s doc comment claimed "On macOS Docker Desktop the VirtioFS proxy papers over the uid mismatch and chown also succeeds." Verified empirically (real os.Chown call on this Darwin host, plus a real elasticsearch:7.17.29 container bind-mounted through Docker Desktop) that this is false: chown to an arbitrary uid is _POSIX_CHOWN_RESTRICTED on macOS exactly like non-root Linux — it EPERMs. What actually makes macOS work is that a container process writing as uid 1000 is reflected back to the host as owned by the invoking host user (not uid 1000), and a plain 0o755-mode datadir is already sufficient for the container to write with no AccessDeniedException — which is what the PRE-#92 comment said before it was rewritten. Restored an accurate description of both platforms' actual behavior. Also fixed a real information-loss bug in the hard-fail path: the final error claimed "chown and chmod both failed" but only wrapped chmod's error via %w — the chown error was computed in an inner `if err :=` scope and discarded once >it went out of scope, never reaching the caller. Extracted the message into `actionableDatadirError` and wrapped both errors (Go 1.20+ supports multiple %w), with a unit test that exercises it directly with synthetic errors since the underlying directory-owned-by-a-different-uid case cannot be constructed portably without root. No functional regression: traced both the fresh-datadir and reused-datadir paths against the corrected mental model and confirmed ensureDatadirWritableByContainer still returns nil in both, and the real `make conformance-local PLUGIN=elasticsearch` suite (two full Up/Down iterations against real containers) passes unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Retrospective
/code-reviewsweep of merged PR #92 (which itself fixed #74: don't hard-failUpon a reused elasticsearch datadir owned by the container uid). That PR shipped without pre-merge review, per the repo's established retrospective-review pattern (see PRs #56-58, #63, #84, #85, #88, #108-#112).What / Why
Reviewed
ensureDatadirWritableByContainer(plugins/engine/elasticsearch/docker.go) from every angle in the fix's own risk class (ownership-detection edge cases across OSes, the original chmod-fallback path staying reachable, TOCTOU, error actionability). Two confirmed, still-live issues, both introduced by PR #92 itself:False doc claim about macOS, empirically verified false. The doc comment asserted "On macOS Docker Desktop the VirtioFS proxy papers over the uid mismatch and chown also succeeds." I disproved this on a real Darwin host:
os.Chownto an arbitrary uid is_POSIX_CHOWN_RESTRICTEDon macOS exactly like non-root Linux — it EPERMs regardless of Docker Desktop, since the call happens on the host filesystem before any container touches the path. I further ran a realelasticsearch:7.17.29container bind-mounted through Docker Desktop for Mac and confirmed what actually makes macOS work: a plain 0o755, host-owned datadir is already sufficient (noAccessDeniedException), and files the container writes as uid 1000 are reflected back to the host as owned by the host user, not uid 1000 — the opposite of native Linux bind-mount behavior. This is what the pre-PR-92 comment correctly said ("VirtioFS hides the uid mismatch, plain 0o755 works") before PR fix(elasticsearch): don't hard-fail Up on a reused datadir owned by the container uid (#74) #92 rewrote it into the false "chown succeeds" claim. Restored an accurate description for both platforms.Chown error silently dropped from the "actionable" hard-fail message. The final error claimed
"chown and chmod both failed (%w)"but only wrapped the chmod error via%w— the chown error was computed in an innerif err := ...; err != nilscope and never reached the message-building branch. Extracted the message intoactionableDatadirError(datadir, chownErr, chmodErr)and wrap both (Go 1.20+ supports multiple%win onefmt.Errorf), soerrors.Isand log correlation retain the true cause of both failed syscalls, not just one.No functional regression: traced both the fresh-datadir and reused-datadir paths against the corrected mental model and confirmed
ensureDatadirWritableByContainerstill returnsnilin both cases exactly as before.Test plan
go build ./...go test ./...(full suite, all packages green)golangci-lint run ./...(0 issues)make conformance-local PLUGIN=elasticsearch— real Docker containers, two full Up→Down iterations (exercises the reused-datadir path), all greenTestActionableDatadirErrorunit test, deterministic via synthetic errors (the underlying "datadir owned by a third uid" case can't be constructed portably without root)elasticsearch:7.17.29container via Docker Desktop (not just code reasoning)