-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add secure input only channel for data streaming #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MoeMahhouk
wants to merge
2
commits into
main
Choose a base branch
from
moe-secure-input-channel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ Packages=podman | |
| openssh-sftp-server | ||
| udev | ||
| libsnappy1v5 | ||
| pv | ||
|
|
||
| BuildPackages=build-essential | ||
| git | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| searcher ALL=(root) NOPASSWD: /usr/bin/toggle, /usr/bin/tdx-init set-passphrase, /usr/bin/systemctl restart lighthouse, /usr/local/bin/reboot | ||
| searcher ALL=(root) NOPASSWD: /usr/bin/toggle, /usr/bin/tdx-init set-passphrase, /usr/bin/systemctl restart lighthouse, /usr/local/bin/reboot, /usr/bin/feed-data-helper |
15 changes: 15 additions & 0 deletions
15
bob-common/mkosi.extra/etc/systemd/system/searcher-input-fifo.service
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [Unit] | ||
| Description=Searcher Input FIFO Setup | ||
| After=persistent-mount.service | ||
| Requires=persistent-mount.service | ||
| Before=searcher-container.service | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/bin/setup-input-fifo.sh | ||
| RemainAfterExit=yes | ||
| User=root | ||
| Group=root | ||
|
|
||
| [Install] | ||
| WantedBy=minimal.target |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/bin/bash | ||
| # Safely pipes authenticated data from searcher into container | ||
| # Security-hardened version with strict FIFO validation | ||
| # Supports continuous streaming without timeout | ||
| set -eu -o pipefail | ||
|
|
||
| FIFO_PATH="/persistent/input/data.fifo" | ||
| LOG_DIR="/persistent/delayed_logs" | ||
| LOG_FILE="$LOG_DIR/output.log" | ||
| MAX_RATE="100M" # 100MB/s rate limit to prevent accidental DoS | ||
|
|
||
| # Create log directory if it doesn't exist | ||
| mkdir -p "$LOG_DIR" | ||
|
|
||
| log_error() { | ||
| echo "[$(date -Iseconds)] feed-data ERROR: $1" >> "$LOG_FILE" | ||
| echo "Error: $1" >&2 | ||
| } | ||
|
|
||
| log_info() { | ||
| echo "[$(date -Iseconds)] feed-data INFO: $1" >> "$LOG_FILE" | ||
| } | ||
|
|
||
| # Check system is initialized | ||
| if [ ! -f /etc/searcher-network.state ]; then | ||
| log_error "System not initialized. Run 'initialize' first." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # CRITICAL SECURITY VALIDATION: Verify FIFO exists and is not a symlink | ||
| if [ -L "$FIFO_PATH" ]; then | ||
| log_error "SECURITY VIOLATION: $FIFO_PATH is a symlink!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -e "$FIFO_PATH" ]; then | ||
| log_error "Input FIFO does not exist at $FIFO_PATH." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -p "$FIFO_PATH" ]; then | ||
| log_error "SECURITY VIOLATION: $FIFO_PATH is not a FIFO!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Security: Verify ownership MUST be root (no exceptions in production) | ||
| FIFO_OWNER=$(stat -c %u "$FIFO_PATH") | ||
| if [ "$FIFO_OWNER" -ne 0 ]; then | ||
| log_error "SECURITY VIOLATION: FIFO not owned by root!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify we can write to the FIFO | ||
| if [ ! -w "$FIFO_PATH" ]; then | ||
| log_error "Cannot write to FIFO at $FIFO_PATH." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Log start of data feed | ||
| log_info "Starting secure data feed to container (continuous stream)" | ||
|
|
||
| # Rate limit and pipe stdin to FIFO | ||
| # No timeout - this is a continuous stream that runs until: | ||
| # - The sender closes the connection (EOF) | ||
| # - The container stops reading (SIGPIPE) | ||
| # - The SSH connection drops | ||
| if pv -q -L "$MAX_RATE" > "$FIFO_PATH" 2>/dev/null; then | ||
| log_info "Data feed completed successfully" | ||
| exit 0 | ||
| else | ||
| EXIT_CODE=$? | ||
| if [ $EXIT_CODE -eq 141 ]; then | ||
| log_info "Container disconnected (SIGPIPE)" | ||
| else | ||
| log_error "Feed terminated with exit code $EXIT_CODE" | ||
| fi | ||
| exit $EXIT_CODE | ||
| fi | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/bash | ||
| # Sets up the input FIFO for searcher data feed with hardened security | ||
| # MUST run as root to ensure proper ownership and prevent tampering | ||
| set -eu -o pipefail | ||
|
|
||
| # Use /persistent/input to match existing /persistent/searcher pattern | ||
| INPUT_DIR="/persistent/input" | ||
| FIFO_PATH="$INPUT_DIR/data.fifo" | ||
|
|
||
| echo "Setting up hardened searcher input FIFO..." | ||
|
|
||
| # Ensure we're running as root for security | ||
| if [ "$EUID" -ne 0 ]; then | ||
| echo "ERROR: This script must be run as root for security reasons" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create directory on persistent storage with secure ownership | ||
| mkdir -p "$INPUT_DIR" | ||
|
|
||
| # Set directory ownership to root with read/execute for searcher group | ||
| # Directory must be root-owned to prevent tampering | ||
| chown root:root "$INPUT_DIR" | ||
| chmod 755 "$INPUT_DIR" # rwxr-xr-x - searcher can traverse but not modify | ||
|
|
||
| # Remove any existing FIFO/symlink (security check) | ||
| if [ -e "$FIFO_PATH" ] || [ -L "$FIFO_PATH" ]; then | ||
| echo "Removing existing file at $FIFO_PATH for security..." | ||
| rm -f "$FIFO_PATH" | ||
| fi | ||
|
|
||
| # Create FIFO with secure permissions | ||
| mkfifo "$FIFO_PATH" | ||
| echo "Created FIFO at $FIFO_PATH" | ||
|
|
||
| # Set FIFO ownership: root owns it, searcher group can read | ||
| # This prevents the container from modifying/replacing the FIFO | ||
| chown root:1000 "$FIFO_PATH" # root:searcher | ||
| chmod 640 "$FIFO_PATH" # rw-r----- (root write, group read, others none) | ||
|
|
||
| # Verify the FIFO was created correctly (security validation) | ||
| if [ ! -p "$FIFO_PATH" ]; then | ||
| echo "ERROR: Failed to create FIFO at $FIFO_PATH" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify no symlinks (extra security check) | ||
| if [ -L "$FIFO_PATH" ]; then | ||
| echo "ERROR: Security violation - FIFO is a symlink!" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Hardened searcher input FIFO ready at $FIFO_PATH" | ||
| echo "Security features enabled:" | ||
| echo " - Root-owned directory (prevents tampering)" | ||
| echo " - Root-owned FIFO (prevents replacement)" | ||
| echo " - Read-only mount in container (prevents modification)" | ||
| echo " - Group read permission only (searcher UID 1000)" | ||
| echo "" | ||
| echo "Container will access it READ-ONLY at /persistent/input/data.fifo" | ||
| echo "Usage: cat data.json | ssh searcher@host feed-data" | ||
| exit 0 |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the searcher influence this, leaking data through how they read the data? Might be fine, but I would also worry about the rate limit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no they can't because this is set by the host-os and not the searcher.
I added the rate-limit just to avoid self DoSing but ofc we can relax it even more or remove it fully while documenting/communicating it with the searcher to keep an eye on the ingress