|
| 1 | +--- |
| 2 | +status: proposed |
| 3 | +date: 2025-02-28 |
| 4 | +story: Standardize filesystem hierarchy for Zebra deployments |
| 5 | +--- |
| 6 | + |
| 7 | +# Standardize Filesystem Hierarchy: FHS vs. XDG |
| 8 | + |
| 9 | +## Context & Problem Statement |
| 10 | + |
| 11 | +Zebra currently has inconsistencies in its filesystem layout, particularly regarding where configuration, data, cache files, and binaries are stored. We need a standardized approach compatible with: |
| 12 | + |
| 13 | +1. Traditional Linux systems. |
| 14 | +2. Containerized deployments (Docker). |
| 15 | +3. Cloud environments with stricter filesystem restrictions (e.g., Google's Container-Optimized OS). |
| 16 | + |
| 17 | +We previously considered using the Filesystem Hierarchy Standard (FHS) exclusively ([Issue #3432](https://github.com/ZcashFoundation/zebra/issues/3432)). However, recent changes introduced the XDG Base Directory Specification, which offers a user-centric approach. We need to decide whether to: |
| 18 | + |
| 19 | +* Adhere to FHS. |
| 20 | +* Adopt XDG Base Directory Specification. |
| 21 | +* Use a hybrid approach, leveraging the strengths of both. |
| 22 | + |
| 23 | +The choice impacts how we structure our Docker images, where configuration files are located, and how users interact with Zebra in different environments. |
| 24 | + |
| 25 | +## Priorities & Constraints |
| 26 | + |
| 27 | +* **Security:** Minimize the risk of privilege escalation by adhering to least-privilege principles. |
| 28 | +* **Maintainability:** Ensure a clear and consistent filesystem layout that is easy to understand and maintain. |
| 29 | +* **Compatibility:** Work seamlessly across various Linux distributions, Docker, and cloud environments (particularly those with restricted filesystems like Google's Container-Optimized OS). |
| 30 | +* **User Experience:** Provide a predictable and user-friendly experience for locating configuration and data files. |
| 31 | +* **Flexibility:** Allow users to override default locations via environment variables where appropriate. |
| 32 | +* **Avoid Breaking Changes:** Minimize disruption to existing users and deployments, if possible. |
| 33 | + |
| 34 | +## Considered Options |
| 35 | + |
| 36 | +### Option 1: FHS |
| 37 | + |
| 38 | +* Configuration: `/etc/zebrad/` |
| 39 | +* Data: `/var/lib/zebrad/` |
| 40 | +* Cache: `/var/cache/zebrad/` |
| 41 | +* Logs: `/var/log/zebrad/` |
| 42 | +* Binary: `/opt/zebra/bin/zebrad` or `/usr/local/bin/zebrad` |
| 43 | + |
| 44 | +### Option 2: XDG Base Directory Specification |
| 45 | + |
| 46 | +* Configuration: `$HOME/.config/zebrad/` |
| 47 | +* Data: `$HOME/.local/share/zebrad/` |
| 48 | +* Cache: `$HOME/.cache/zebrad/` |
| 49 | +* State: `$HOME/.local/state/zebrad/` |
| 50 | +* Binary: `$HOME/.local/bin/zebrad` or `/usr/local/bin/zebrad` |
| 51 | + |
| 52 | +### Option 3: Hybrid Approach (FHS for System-Wide, XDG for User-Specific) |
| 53 | + |
| 54 | +* System-wide configuration: `/etc/zebrad/` |
| 55 | +* User-specific configuration: `$XDG_CONFIG_HOME/zebrad/` |
| 56 | +* System-wide data (read-only, shared): `/usr/share/zebrad/` (e.g., checkpoints) |
| 57 | +* User-specific data: `$XDG_DATA_HOME/zebrad/` |
| 58 | +* Cache: `$XDG_CACHE_HOME/zebrad/` |
| 59 | +* State: `$XDG_STATE_HOME/zebrad/` |
| 60 | +* Runtime: `$XDG_RUNTIME_DIR/zebrad/` |
| 61 | +* Binary: `/opt/zebra/bin/zebrad` (system-wide) or `$HOME/.local/bin/zebrad` (user-specific) |
| 62 | + |
| 63 | +## Pros and Cons of the Options |
| 64 | + |
| 65 | +### FHS |
| 66 | + |
| 67 | +* **Pros:** |
| 68 | + * Traditional and well-understood by system administrators. |
| 69 | + * Clear separation of configuration, data, cache, and binaries. |
| 70 | + * Suitable for packaged software installations. |
| 71 | + |
| 72 | +* **Cons:** |
| 73 | + * Less user-friendly; requires root access to modify configuration. |
| 74 | + * Can conflict with stricter cloud environments restricting writes to `/etc` and `/var`. |
| 75 | + * Doesn't handle multi-user scenarios as gracefully as XDG. |
| 76 | + |
| 77 | +### XDG Base Directory Specification |
| 78 | + |
| 79 | +* **Pros:** |
| 80 | + * User-centric: configuration and data stored in user-writable locations. |
| 81 | + * Better suited for containerized and cloud environments. |
| 82 | + * Handles multi-user scenarios gracefully. |
| 83 | + * Clear separation of configuration, data, cache, and state. |
| 84 | + |
| 85 | +* **Cons:** |
| 86 | + * Less traditional; might be unfamiliar to some system administrators. |
| 87 | + * Requires environment variables to be set correctly. |
| 88 | + * Binary placement less standardized. |
| 89 | + |
| 90 | +### Hybrid Approach (FHS for System-Wide, XDG for User-Specific) |
| 91 | + |
| 92 | +* **Pros:** |
| 93 | + * Combines strengths of FHS and XDG. |
| 94 | + * Allows system-wide defaults while prioritizing user-specific configurations. |
| 95 | + * Flexible and adaptable to different deployment scenarios. |
| 96 | + * Clear binary placement in `/opt`. |
| 97 | + |
| 98 | +* **Cons:** |
| 99 | + * More complex than either FHS or XDG alone. |
| 100 | + * Requires careful consideration of precedence rules. |
| 101 | + |
| 102 | +## Decision Outcome |
| 103 | + |
| 104 | +Pending |
| 105 | + |
| 106 | +## Expected Consequences |
| 107 | + |
| 108 | +Pending |
| 109 | + |
| 110 | +## More Information |
| 111 | + |
| 112 | +* [Filesystem Hierarchy Standard (FHS) v3.0](https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html) |
| 113 | +* [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/latest/) |
| 114 | +* [Zebra Issue #3432: Use the Filesystem Hierarchy Standard (FHS) for deployments and artifacts](https://github.com/ZcashFoundation/zebra/issues/3432) |
| 115 | +* [Google Container-Optimized OS: Working with the File System](https://cloud.google.com/container-optimized-os/docs/concepts/disks-and-filesystem#working_with_the_file_system) |
0 commit comments