Repository navigation
Reject symlink traversal in backup and restore - #37
Merged
Merged
Conversation
Open copied directories with O_NOFOLLOW and walk the directory fd, so a symlink, a non-UTF-8 name, or a special file fails the command instead of importing or deleting an external target. Manifest CRC checks, safe relative paths, and the existing publish and scratch behavior stay in place. This does not freeze a regular file against a concurrent writer. Co-authored-by: RustFS <hello@rustfs.com>
Live raft copy reads through the data-directory fd while the log lock is held, so a final or intermediate symlink is not followed. Backup create, restore, and manifest publication walk from that anchor on Linux. Other platforms compile and backup copy returns an unsupported error instead of using Linux open flags. A symlink temporary manifest is not truncated, and scratch cleanup removes the directory inode it opened. Co-authored-by: RustFS <hello@rustfs.com>
A manifest name is checked as one relative component before any child open, including open_child. Restore and publish read the staged registry, Raft log, and LSM through the directory fd instead of reopening paths. Linux open-flag constants are cfg-gated. macOS and Windows still have no anchored backup copy; that remains an explicit unsupported path. Co-authored-by: RustFS <hello@rustfs.com>
Bring in readiness reporting and explicit unauthenticated opt-in while keeping the anchored backup copy. Co-authored-by: RustFS <hello@rustfs.com>
Use cap-primitives 4.0.3 and cap-fs-ext 4.0.3 so Unix openat O_NOFOLLOW and Windows handle-relative reparse opens share one path. Names are still rejected before any open, and restore checks stay on the directory handle. Co-authored-by: RustFS <hello@rustfs.com>
The publish and restore checks were still walking the staging path and opening CELL_MANAGER_STATE with File::open. They now receive bytes already read with nofollow, so a swapped symlink is not opened. Co-authored-by: RustFS <hello@rustfs.com>
Keep the control-plane observation work from #40 and the anchored backup checks on this branch. Co-authored-by: RustFS <hello@rustfs.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backup and restore anchor at the operator-supplied data directory, the artifact directory, or the staging directory this process created. Each component below that anchor is one relative name. That name is rejected before any open when it is empty,
.,.., absolute, or contains/,\,:, or NUL. The open does not follow a symlink.On Unix the open is
openatwithO_NOFOLLOW(cap-primitives4.0.3). On Windows it isCreateFilerelative to the directory handle withFILE_FLAG_OPEN_REPARSE_POINT. A Windows reparse point thatis_symlinkdoes not report is rejected fromFILE_ATTRIBUTE_REPARSE_POINTbefore its bytes are read. Linux directory descriptors that come back asO_PATHare reopened through/proc/self/fd/<n>for the same inode. That reopen does not walk the original path.CURRENTis still checked as one relative file name before any child open. Publish and restore read the staged registry, Raft log, LSMCURRENT, SST names, and eachcell_*/CELL_MANAGER_STATEthrough the directory handle. The shard-reference check receives those cell-state bytes. It does not callfs::read_dirorFile::openon the staging path.The live log path uses the same anchor.
copy_durable_logstill holds the log lock and syncs the active segment before reading. It does not callfs::readonsegment.path.This branch includes current
main(36f50655: #40 control-plane observations and placement gating, plus the earlier readiness reporting and unauthenticated opt-in). Those docs andCELL_CONTROL_PLANEstay.committed_or_purged_indexis unchanged.Manifest CRC32C checks,
safe_relative, rejection of a non-empty restore target, the outside-data-dir backup destination check, and the publish lock stay. There is no new command WAL and no transaction or on-disk format change.Dependency decision
docs/DEVELOPMENT_PLAN.md§1.3 forbidsunsafeC/C++ bindings (rocksdb/leveldbFFI). It does not forbid a pure-Rust syscall crate.deny.tomlallows Apache-2.0, MIT, BSD-3-Clause, Unicode-3.0, and Zlib. Its graph targets are Linux only.multiple-versionsis a warning.Direct dependencies added on
metadb-raft:cap-primitives4.0.3 —Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MITcap-fs-ext4.0.3 with default features off, socap-stdis not pulled — same license expressioncap-fs-extis only the publicfollow(FollowSymlinks::No)hook. Transitive crates on the Linux graph (ambient-authority,fs-set-times,io-extras,io-lifetimes3.0.1,ipnet2.12.2,maybe-owned,rustix-linux-procfs) use that same OR expression, orMIT OR Apache-2.0foripnetandmaybe-owned.rustixstays 1.1.6, already in the lock.ipnetis compiled becausecap-primitivesdepends on it unconditionally. It is not used by backup.Windows-only
winx0.36.4 isApache-2.0 WITH LLVM-exceptionand nothing else. That identifier is outside thedeny.tomlallow list. This change does not editdeny.toml, and it does not drop Windows from the graph to hidewinx. No other published crate found here gives both Unixopenat/O_NOFOLLOWand Windows handle-relative reparse opens under the allow list without newunsafeor withoutwinx. Whether to keepcap-primitivesis still an explicit policy decision. Backup behavior is unchanged while that decision is open.Platform behavior
O_NOFOLLOWon the final component, directory listing from the directory descriptor, pre-open name checks unchanged.openat/O_NOFOLLOWpath. It was not built or run here.cap-primitives4.0.3 directory listing turns the handle back into a path and callsstd::fs::read_dir(read_dirwithout following symlinks is not implemented in that crate). Child bytes are still read through the handle. Windows was not built or run here.What is enforced
open_childrejects a name that is not one relative component before it opens that name.read_lsm_indexandManifestLog::read_checkpoint_readonlyreject a badCURRENTbefore opening the named manifest.CELL_MANAGER_STATEare read from the staging directory handle before publish.check_backup_treeparses those bytes. It does not opencell_*/CELL_MANAGER_STATEby path.What is not claimed
This is not a race-free copy.
disk_floorand ordinary snapshot publication still open raft paths directly. Those paths are outside this copy walk.cap-primitives4.0.3. A name from that listing is not read unless the handle-relative open accepts it.winx0.36.4 remains outside the license allow list. That policy choice is not made here.Tests
This round compiled only. It did not run the suite.
cargo check --offline --tests -p metadb-raft -p metadb-storage -p metadb-server -p metadb-clusterfinished with no new crate warnings.current_escape_is_rejected_before_the_external_file_is_openedandcell_state_symlink_is_rejected_before_the_external_file_is_opened. The second points a stagingcell_directory andCELL_MANAGER_STATEat a fifo and fails if a writer blocked on that fifo is released. It also rejects symlink metadata throughreject_reparse.Not run: the regression binaries,
metadb-serverintegration tests, a macOS build, a Windows build, and CI..github/workflows/ci.ymlwas not edited.Leftovers
.backup-ckpt-<shard>is still not deleted.