ITADN

`TestIsDirWriteable` in `client/pkg/fileutil` fails as root on non-Debian distributions

#21787Closedvivekpatani 创建于 2026-05-21
type/featurepriority/backlog
V
vivekpatanicommented
### Bug report criteria - [x] This bug report is not security related, security issues should be disclosed privately via security@etcd.io. - [x] This is not a support request or question, support requests or questions should be raised in the etcd [discussion forums](https://github.com/etcd-io/etcd/discussions). - [x] You have read the etcd [bug reporting guidelines](https://github.com/etcd-io/etcd/blob/main/Documentation/contributor-guide/reporting_bugs.md). - [x] Existing open issues along with etcd [frequently asked questions](https://etcd.io/docs/latest/faq) have been checked and this is not a duplicate. ### What happened? `TestIsDirWriteable` in https://github.com/etcd-io/etcd/blob/f0192fa50106189c025eb0a8fd81ade3b32b0dff/client/pkg/fileutil/fileutil_test.go#L34-L51 is intended to skip when running as root (since root bypasses POSIX permission checks and the test asserts that `IsDirWriteable` returns an error against a chmod 0444 directory). The skip is gated on `user.Current().Name == "root"`, which inspects the GECOS (full-name) field of `/etc/passwd` rather than the login name. GECOS equals the literal string "root" only by Debian/Ubuntu convention; on other distributions it may either empty or set to a different string. When that mismatch happens, the skip doesn't fire, the assertion runs as root, and the test fails because root bypasses the 0444 restriction. ### What did you expect to happen? `--- SKIP: TestIsDirWriteable` on every Linux distribution (and Windows) when running as uid 0, matching the test's documented intent ("ideally we should check CAP_DAC_OVERRIDE"). ### How can we reproduce it (as minimally and precisely as possible)? ```bash root:x:0:0:Super User:/root:/bin/bash uid=0(root) gid=0(root) groups=0(root) === RUN TestIsDirWriteable fileutil_test.go:50: Error Trace: /etcd/client/pkg/fileutil/fileutil_test.go:50 Error: An error is expected but got nil. Test: TestIsDirWriteable Messages: expected IsDirWriteable to error --- FAIL: TestIsDirWriteable (0.00s) FAIL FAIL go.etcd.io/etcd/client/pkg/v3/fileutil 0.271s ``` the same test on Debian: ```bash root:x:0:0:root:/root:/bin/bash uid=0(root) gid=0(root) groups=0(root) === RUN TestIsDirWriteable fileutil_test.go:48: running as a superuser or in windows --- SKIP: TestIsDirWriteable (0.00s) PASS ``` GECOS is "root" ### Anything else we need to know? `/etc/passwd` colon-separated fields are: `login:passwd:uid:gid:GECOS:home:shell`. `user.Current().Name` reads the 5th field (GECOS / display-name), while `user.Current().Username` reads the 1st (login name). The skip in `fileutil_test.go:44` reads Name, not Username, so the check is conditional on a display-name convention specific to Debian/Ubuntu rather than the actual root identity. ### Etcd version (please run commands below) <details> ```console $ etcd --version etcd Version: 3.7.0-beta.0 Git SHA: c3fd3a8e2 Go Version: go1.26.3 Go OS/Arch: darwin/arm64 $ etcdctl version etcdctl version: 3.7.0-beta.0 API version: 3.7 ``` </details> ### Etcd configuration (command line flags or environment variables) <details> N/A </details> ### Etcd debug information (please run commands below, feel free to obfuscate the IP address or FQDN in the output) <details> N/A </details> ### Relevant log output ```Shell ```
关闭于 2026-05-23 2 条评论