Skip to content

Fix working directory for Docker images without home directories#489

Merged
ameowlia merged 1 commit intocloudfoundry:mainfrom
ivo1116:fix-docker-workdir-nonexistent-home-directory
Mar 13, 2026
Merged

Fix working directory for Docker images without home directories#489
ameowlia merged 1 commit intocloudfoundry:mainfrom
ivo1116:fix-docker-workdir-nonexistent-home-directory

Conversation

@ivo1116
Copy link
Copy Markdown
Contributor

@ivo1116 ivo1116 commented Jan 23, 2026

Summary

Fixes cloudfoundry/diego-release#1089 - Intermittent create-workdir-failed for Docker images using system users with no home directory.

Docker images using adduser --no-create-home crash when Guardian tries to set a non-existent home directory as the working directory. This causes diego-sshd and launcher processes to fail with exit status 2 and error message create-workdir-failed.

Root Cause:
When DesiredLRP doesn't explicitly set a Dir property, Guardian defaults to the home directory from /etc/passwd. For system users created with --no-create-home, this directory doesn't exist in the container's rootFS, causing the process creation to fail.

Solution:
Added getRootDir() function in rundmc/processes/builder.go that:

  • Checks if the working directory exists in the container's rootFS using os.Stat()
  • Falls back to / (which always exists) if the directory doesn't exist
  • Preserves existing behavior for containers with valid home directories

Backward Compatibility

Breaking Change? No

This change is backwards compatible. It only affects containers where the working directory doesn't exist (which currently crash). Containers with existing home directories continue to work as before.

Copy link
Copy Markdown
Member

@ameowlia ameowlia left a comment

Choose a reason for hiding this comment

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

Unit tests please! Other than that it looks fine.

@github-project-automation github-project-automation bot moved this from Inbox to Pending Merge | Prioritized in Application Runtime Platform Working Group Jan 28, 2026
@ameowlia
Copy link
Copy Markdown
Member

I am getting a failure in one of the unit tests that were already there:

• [FAILED] [0.000 seconds]
ProcBuilder the built process when the bundle has no mappings for host root (container is privileged) when a TTY is specified [It] passes the working dir
/home/pivotal/workspace/garden-runc-release/src/guardian/rundmc/processes/builder_test.go:198

  [FAILED] Expected
      <string>: /
  to equal
      <string>: dir
  In [It] at: /home/pivotal/workspace/garden-runc-release/src/guardian/rundmc/processes/builder_test.go:199 @ 03/12/26 15:23:50.968

Docker images using `adduser --no-create-home` crash when Guardian
tries to set a non-existent home directory as the working directory.
This causes `diego-sshd` and `launcher` processes to fail with
`exit status 2` and error message `create-workdir-failed`.

Add getRootDir() function that:
- Uses spec.Dir if set, otherwise falls back to user's home directory
- Checks if the directory exists in the container's rootFS
- Falls back to `/` (which always exists) if the directory doesn't exist

Fixes cloudfoundry/diego-release#1089
@ivo1116 ivo1116 force-pushed the fix-docker-workdir-nonexistent-home-directory branch from 39d1741 to 29a621c Compare March 13, 2026 09:39
@ameowlia ameowlia merged commit f0a8fe2 into cloudfoundry:main Mar 13, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Pending Merge | Prioritized to Done in Application Runtime Platform Working Group Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Intermittent create-workdir-failed for Docker images using system users with no home directory

2 participants