BuildStream fails to cache a file w/ mode 0000
- Dominant language
- Python
- Stars
- 140
- Forks
- 45
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
Basically, whenever a file exists w/ a mode of 0000 in a directory that BuildStream will try to cache, the job BuildStream is executing will fail.
I can reproduce this with the following versions. It didn't used to happen with older versions of bst2 (or bst1 for that matter)
- BuildStream 2.1.0
- `/usr/local/lib64/python3.11/site-packages/buildstream/subprojects/buildbox/buildbox-casd 1.0.0-0-g824ee5f`
Here's a trivial reproducer element:
```yaml
kind: manual
build-depends:
- buildsystems/base.bst # Basic CLI environment
config:
install-commands:
- touch %{install-root}/foo
- chmod 000 %{install-root}/foo
```
If you try to build this element, you'll get the following failure (TL;DR: it's a permission denied error trying to access /buildsteream-install/foo in the container)
```
2023-12-11T18:03:34.906-0500 [1542603:140399133368256] [buildboxcommon_runner.cpp:437] [ERROR] [actionDigest=b763e5057f3167fb391ded391c34753b52287a66021277b4fe025ce3d75947f6/178] Error executing command: std::runtime_error exception thrown at [buildboxcommon_localcasstageddirectory.cpp:124], errMsg = "Error capturing "buildstream/carbonOS/test.bst/../../../buildstream-install" in "/var/home/adrian/.cache/buildstream/cas/staging/cas-tmpdirTeNNPU": System error in `make_nesteddirectory()` for path "buildstream/carbonOS/test.bst/../../../buildstream-install": std::system_error exception thrown at [buildboxcommon_merklize.cpp:69] [system:13], errMsg = "Failed to open path "foo"", errno : Permission denied"
[00:00:00] FAILURE test.bst: Running commands
[00:00:01] FAILURE [6371c55b] test.bst: buildbox-run failed with returncode 1
```
An alternative way to trigger it looks something like the following. The failure will happen right after all the integration commands finish running for `bst build test2.bst` or `bst shell --build test2.bst`
```yaml
# test1.bst
kind: stack
depends:
- buildsystems/base.bst
public:
bst:
integration-commands:
- touch /foo
- chmod 000 /foo
```
```yaml
# test2.bst
# <...>
build-depends:
- test1.bst
# <...>
# <...>
```
The way I actually triggered this in my carbonOS build is an element that runs `systemd-sysusers` as an integration command. This command creates the files /etc/shadow and /etc/gshadow inside of the container, which BuildStream will try to capture. However, /etc/shadow and /etc/gshadow typically have their mode set to 0000. So, when systemd-sysusers creates the file like this, we get the failure. My workaround for now is to set the integration commands like so:
```yaml
# <...>
integration-commands:
- systemd-sysusers
- chmod 400 %{sysconfdir}/{,g}shadow
# <...>
```
Contributor guide
Research direction
Reproduce the failure with the manual element and the `bst build` or `bst shell --build` commands described in the issue. Inspect the cache-capture failure in `buildboxcommon_localcasstagedirectory.cpp` and `buildboxcommon_merklize.cpp`. Done means builds and cache capture succeed for files with mode 0000, including integration-generated shadow files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100