]> git.hungrycats.org Git - bees/commitdiff
config: remove the last of the untrusted local-config machinery
authorZygo Blaxell <bees@furryterror.org>
Mon, 31 Aug 2026 00:50:52 +0000 (20:50 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
Support for an untrusted local config file was removed, but three pieces
of it stayed behind because nothing referred to them by that name any
more.

BeesStringFile::allow_symlink() has no callers.  It existed so the
untrusted local-config reader could opt out of the resolve-beneath-dirfd
open and follow a symlink on the target filesystem; with that reader
gone, m_allow_symlink is set at construction and never changed, and the
bees_openat2() branch it guards is unreachable.  Delete the flag, the
setter, and the branch.  The surviving open is the one that was actually
running, so behaviour is unchanged.  The path-components check keeps its
THROW_CHECK and gets a comment saying what it is really for -- the
atomic rename in write() renames within m_dir_fd, and a name with a
slash in it would name some other directory.

The local-config-filename load site says only "now we can load local
configuration data", which does not explain why the absolute-path rule
below it exists.  Say it: a config file living on the filesystem being
deduplicated is writable by whoever controls that filesystem, and every
knob in it -- thread counts, transid lag, hash table size -- is a way to
make the daemon behave badly.  ${ROOT} is how to opt back in on purpose.

Finally, point the config-file documentation at --show-config, which is
how an operator answers "what did it actually load", and fix the startup
log line that labelled path.reports with the old plural section name.

Assisted-by: Claude-Code:claude-opus-5
docs/config-file.md
src/bees-config.cc
src/bees-util.cc
src/bees.cc
src/bees.h

index 24cbe96ea42b7c9aa9a27099ff914737f861fc8a..64ea60bd1e72a7e7914abfed4f4b19124c707951 100644 (file)
@@ -77,6 +77,9 @@ explicitly with `${ROOT}`:
 The substitution expands to an absolute path before the check, so this opts
 back in with eyes open.
 
+To inspect the effective merged values, use
+[`--show-config`](options.md#configuration-debug-options).
+
 ### Notes
 
 * Default layouts:
index 3be6e57e8de1a8885fa5914aac39a7caf9ecee76..b9b1ca805fecad1464bfee80901b74bdf6b584ba 100644 (file)
@@ -339,7 +339,13 @@ BeesConfig::set_argv(const Innie &startup_ini)
        // Search global config to locate local config
        boot_innie.set_fallback(m_global);
 
-       // Now we can load local configuration data
+       // Now we can load local configuration data.
+       // Like the global config filename, the local config filename must be
+       // absolute.  A filename living on the target filesystem itself is a
+       // security hazard — any config knob (thread counts, transid lag, etc.)
+       // can be turned into a DoS vector by an attacker controlling that
+       // filesystem.  Use ${ROOT}/relative/path/on/target/filesystem.conf if
+       // you really want to opt in.
        static const auto lcf_key = "config.local-config-filename";
        const auto local_config_filename = subst(boot_innie.get(lcf_key));
        if (!local_config_filename.empty()) {
index 0bde460f536101d84955ed8810a4a98d68715ad5..ff899bd55e370403edb0838b5ea83d336569fae6 100644 (file)
@@ -212,12 +212,6 @@ BeesStringFile::name() const
        return m_name;
 }
 
-void
-BeesStringFile::allow_symlink(bool do_allow)
-{
-       m_allow_symlink = do_allow;
-}
-
 string
 BeesStringFile::read()
 {
@@ -232,13 +226,8 @@ BeesStringFile::read()
        }
 
        BEESNOTE("opening " << m_name << " in " << name_fd(m_dir_fd));
-       Fd fd;
        const auto fdcwd = (!m_dir_fd) ? AT_FDCWD : m_dir_fd.operator int();
-       if (m_allow_symlink) {
-               fd = openat(fdcwd, m_name.c_str(), FLAGS_OPEN_FILE);
-       } else {
-               fd = bees_openat2(fdcwd, m_name.c_str(), FLAGS_OPEN_FILE);
-       }
+       Fd fd = openat(fdcwd, m_name.c_str(), FLAGS_OPEN_FILE);
        if (!fd) {
                // ENOENT means the file simply doesn't exist
                if (errno == ENOENT) {
@@ -334,7 +323,8 @@ BeesStringFile::write(string contents)
                THROW_ERROR(runtime_error, "BeesStringFile write on inert handle: m_dir_fd unset and relative name '" << m_name << "'");
        }
 
-       // Path components not allowed - this code can't implement m_allow_symlink with them
+       // Atomic-rename below renames within m_dir_fd; path components in
+       // m_name would name a different directory and break that invariant.
        THROW_CHECK1(invalid_argument, m_name, m_name.find_first_of("/") == string::npos);
 
        THROW_CHECK2(out_of_range, contents.size(), m_limit, contents.size() < m_limit);
index c5bf7313dbfdffdd2383e8727630699db8c84fd3..86440afec0d4459bfe7fd2570a61bc14e6ff56aa 100644 (file)
@@ -462,7 +462,7 @@ bees_main(int argc, char *argv[])
        {
                const auto reports_dir = bc->get_config().subst(
                        bc->get_config().get("path.reports", [](const string &s) { return s; }));
-               BEESLOGINFO("paths.reports = '" << reports_dir << "' [path.reports]");
+               BEESLOGINFO("path.reports = '" << reports_dir << "' [path.reports]");
 
                // Parse all report sections into a vector first
                const auto parse_report_interval = [](const string &s) {
index d713867ceec4f60309d49b271502cc3a0ac0147b..bd99c04cc8c92d7bc946106d01c11079375c5e2d 100644 (file)
@@ -682,7 +682,6 @@ class BeesStringFile {
        Fd      m_dir_fd;   ///< Directory containing the file.
        string  m_name;     ///< Filename within m_dir_fd.
        size_t  m_limit;    ///< Maximum number of bytes read() will return.
-       bool    m_allow_symlink = true;  ///< If true, allow symlinks and paths outside of m_dir_fd.
 
 public:
        /// Construct referencing @p name within @p dir_fd; read() is capped at @p limit bytes.
@@ -695,8 +694,6 @@ public:
        void name(const string &new_name);
        /// Return the current filename.
        string name() const;
-       /// Control whether to allow symlinks outside of m_dir_fd.
-       void allow_symlink(bool do_allow);
 };
 
 /**