Skip to content

feat!: keep a writable HOME of non-root users - #8445

Merged
viceice merged 1 commit into
mainfrom
viceice/feat/keep-writable-home
Nov 25, 2026
Merged

viceice merged 1 commit into
mainfrom
viceice/feat/keep-writable-home

Conversation

@viceice

@viceice viceice commented Nov 25, 2026

Copy link
Copy Markdown
Member

Changes

  • The containerbase env (/usr/local/etc/env, loaded by every shim and wrapper through BASH_ENV) keeps the HOME of a non-root user when it's non-empty, not / and writable.
  • An empty, /, missing or non-writable HOME is still replaced by the containerbase user's home (eg. OpenShift's random user ids).
  • HOME is always exported, also when the caller's env had none.
  • Before, every non-root user always got the containerbase user's home, so an explicit HOME=/x <tool> was ignored.
  • The read-only test covers an explicit, a missing, a /, a non-writable and a read-only HOME.
  • Part of v15, the upgrade note is in docs: add v15 upgrade notes #8375.

Context

Please select one of the following:

  • This closes an existing Issue, Closes: #
  • This doesn't close an Issue, but I accept the risk that this PR may be closed if maintainers disagree with its opening or implementation

AI assistance disclosure

Did you use AI tools to create any part of this pull request?

Please select one option and, if yes, briefly describe how AI was used (e.g., code, tests, docs) and which tool(s) you used.

  • No — I did not use AI for this contribution.
  • Yes — minimal assistance (e.g., IDE autocomplete, small code completions, grammar fixes).
  • Yes — substantive assistance (AI-generated non‑trivial portions of code, tests, or documentation).
  • Yes — other (please describe):

Code and tests written by Claude Opus 5.5 (Claude Code), reviewed with Claude Fable 5.2.

Use of AI in replying to PR comments

Who answers review comments:

  • @viceice will read and reply directly. Name the account.
  • An agent will draft replies and @viceice will read them before they are posted. Name the account.
  • An agent will draft replies and reply autonomously. This is heavily discouraged, and we prefer that there are humans in the loop
  • Nobody has explicitly committed to replying.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified tests

🤖 Generated with Claude Code

@viceice
viceice added this pull request to stack #8427 November 25, 2026 07:45
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

viceice added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice force-pushed the viceice/feat/keep-writable-home branch from 9f3fb85 to c5c1f67 Compare November 25, 2026 07:45
@viceice
viceice marked this pull request as ready for review November 25, 2026 08:06
@qodo-code-review

qodo-code-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Preserve writable HOME for non-root users

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Preserve an explicit, writable HOME for non-root users instead of always replacing it.
• Fall back to the containerbase home when HOME is empty, /, missing, or unwritable.
• Test HOME handling through shells, a Git shim, and a wrapped tool on read-only containers.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 3 capabilities

  • 3 affected capabilities span independent functional scopes: Containerbase Docker-build cache cleanup, Containerbase runtime-environment initialization, Java/Android tool preparation integration.
  • The changed shell logic determines the HOME presented to non-root commands.
  • The generated environment file and entrypoint are propagation mechanisms for this one runtime-environment outcome, not independent user capabilities.
  • Java preparation creates the SDK link, writes the environment contract, and sdkmanager consumes that contract.
  • These are propagation hops of one bounded Java/Android preparation outcome rather than separate capabilities.
  • The changed deletion list independently changes which root cache paths are removed after Docker-build installs.
  • This is a cleanup lifecycle outcome, distinct from Java SDK preparation even though the path was removed because the SDK is now stored under USER_HOME.
Sources

src/cli/tools/java/index.ts[101-105]

    // the link only exists in the containerbase user home, not in another
    // HOME the env keeps
    await this.pathSvc.exportEnv({
      ANDROID_HOME: path.join(this.envSvc.userHome, '.android-sdk'),
    });
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, every non-root process unconditionally received USER_HOME.
  • After, the logic first excludes root, preserves HOME when it equals USER_HOME, and otherwise evaluates empty, root, directory-type, writability, and searchability conditions before falling back to USER_HOME.
  • New correctness condition: each relevant EUID, HOME-value, directory-type, writability, and searchability combination must produce the intended exported environment without changing root behavior.
  • The existing export mechanism is reused; no new persistence protocol, concurrency ordering, or nontrivial transformation is introduced.
Potential damage 🟡 Medium 🩹 Recoverable

  • If this behavior regresses, non-root commands may receive an unusable or unintended HOME.
  • Configuration and cache writes can fail, or tools can write under an unintended writable directory.
  • This is a conditional consequence assessment, not a claim that the PR contains a specific fault.
  • Restoring the environment-generation logic or image restores future invocations, and failed operations can generally be retried.
  • Files already written under an unintended HOME may require manual cleanup or relocation; no automatic state repair or external compensation is established.
Assessed commit c8e9e07
Diagram

graph TD
  Caller["Non-root caller"] --> Env["Shared environment"] --> Check{"Keep HOME?"} -->|Yes| Keep["Preserve HOME"] --> Tools["Shims and wrappers"]
  Check -->|No| Fallback["Containerbase home"] --> Tools
Loading
High-Level Assessment

The shared environment is the appropriate place for this policy because it reaches shells, shims, and wrappers. Keeping the previous unconditional override would discard explicit writable homes; relying solely on a passwd home would not address unknown user IDs.

Files changed (2) +38 / -2

Enhancement (1) +5 / -2
environment.shPreserve usable non-root HOME values +5/-2

Preserve usable non-root HOME values

• Changes generated environment setup to retain a non-root HOME when it is writable or already equals USER_HOME. Empty, root-directory, missing, and unwritable alternatives fall back to USER_HOME; HOME is then exported.

src/usr/local/containerbase/utils/environment.sh

Tests (1) +33 / -0
test.shCover non-root HOME behavior in read-only containers +33/-0

Cover non-root HOME behavior in read-only containers

• Adds Docker integration checks for an explicit writable HOME through Git, default and unknown users, an unset HOME through Bash and Node, and missing or unwritable homes.

test/readonly/test.sh

@qodo-code-review

qodo-code-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

Resolved findings
1. Android builds lose the installed SDK ✓ Resolved High

Resolving commit: 27c1365

Resolution reason
The Java prepare service now exports ANDROID_HOME as the absolute path under the containerbase user
home (envSvc.userHome/.android-sdk) instead of the tilde-relative '~/.android-sdk', so a custom HOME
no longer redirects the SDK location. A spec asserts the exported env line and that the sdk link
points to the cache SDK path.
Description
The new HOME condition preserves a writable custom directory, but the generated ANDROID_HOME
default expands ~/.android-sdk against that directory while Java setup links the SDK directory
only under USER_HOME. When a non-root caller supplies such a HOME, sdkmanager uses the new,
unlinked location instead of the containerbase-managed SDK, so installed platforms are unavailable
to Android builds.

2. Tools fail with a writable non-directory home ✓ Resolved Medium

Resolving commit: 40fd890

Resolution reason
The HOME fallback condition now also requires the path to be a directory (-d) and searchable
(-x) in addition to writable, so a writable file or a writable directory without search permission
is replaced by the containerbase user home. A test in test/readonly/test.sh covers both cases.
Description
The new HOME check uses -w without verifying that the path is a searchable directory, so a
writable file or a directory without search permission is preserved. When a non-root caller supplies
either path, commands such as git config --global cannot create their configuration under it
instead of receiving the containerbase home.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@viceice
viceice removed this pull request from stack #8427 November 25, 2026 09:25
viceice added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice force-pushed the viceice/feat/keep-writable-home branch from c5c1f67 to 40fd890 Compare November 25, 2026 09:25
@viceice
viceice added this pull request to stack #8446 November 25, 2026 09:25
viceice added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice force-pushed the viceice/feat/keep-writable-home branch from 40fd890 to 27c1365 Compare November 25, 2026 10:48
viceice added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice force-pushed the viceice/feat/keep-writable-home branch from 27c1365 to 179a3c6 Compare November 25, 2026 11:50
Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice force-pushed the viceice/feat/keep-writable-home branch from 179a3c6 to c8e9e07 Compare November 25, 2026 13:59
Base automatically changed from viceice/docs/upgrading-v15 to main November 25, 2026 15:45
@viceice
viceice merged commit c8e9e07 into main Nov 25, 2026
58 of 59 checks passed
@viceice
viceice deleted the viceice/feat/keep-writable-home branch November 25, 2026 15:46
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