initial: xop source tree

This commit is contained in:
xop-bot committed 2026-10-02 18:25:29 +08:00
commit e4c93e1e13
43 files changed
+7599

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Dry-run demo — show effective policy without executing.
#
# This is the killer feature for AI agents:
# Agent: "Run X with these secrets."
# User: "Hold on, let me see exactly what policy you'd be running under."
# $ xop --dry-run ...
#
# No Touch ID / PAM needed, no real secrets required. Pure policy inspection.
set -euo pipefail
cd "$(dirname "$0")/.."
./target/release/xop \
--dry-run \
--secret DB_PASS='DB_PASS' \
--secret API_KEY='API_KEY' \
--allow-net='mysql.internal:3306,api.internal:443' \
--deny-net='*' \
--deny-read='/etc/shadow,~/.aws/credentials' \
--on-leak=kill \
-- \
./deploy.sh --target=staging
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Read a secret — MASKED by default.
#
# `xop get` prints `su****【xop禁止将密钥泄漏】` (first 2 chars, same format
# as the stdout leak guard). This is deliberate: stdout of this command often
# lands in a model context / log / shell history, so the plaintext path must
# be an explicit human decision.
#
# Human visual inspection (plaintext, prints a stderr warning too):
#
# ./target/release/xop get DB_PASS -v
#
# DO NOT pipe the plaintext into another command, and never add -v from an
# AI agent session. To hand a secret to a child process use injection:
#
# xop run --secret MYSQL_PWD=DB_PASS --allow-net=db.local:3306 --deny-net='*' \
# -- mysql -h db.local -u readonly mydb
set -euo pipefail
cd "$(dirname "$0")/.."
KEY="${1:-YOUR_KEY_HERE}"
shift || true
./target/release/xop get "$KEY" "$@"
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# First-time vault setup + first secret.
#
# This script is interactive: it prompts for the vault passphrase twice
# (Touch ID / PAM is NOT required for init — there is nothing to protect yet).
#
# Re-run safely? No: `xop init` refuses if the vault already exists.
set -euo pipefail
cd "$(dirname "$0")/.."
./target/release/xop init
echo "Vault created. Now store a secret:"
echo " echo \"hunter2\" | ./target/release/xop set DB_PASS"
# Uncomment to add a sample secret automatically (you will need to pipe the value):
# echo "hunter2" | ./target/release/xop set DB_PASS
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# List stored key names (no values).
#
# Triggers Touch ID (macOS) or pkexec (Linux) + vault passphrase prompt.
set -euo pipefail
cd "$(dirname "$0")/.."
./target/release/xop list
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Real MySQL exec — secrets stored locally, gated by Touch ID / PAM + passphrase.
#
# Before running, you must have stored the secret:
# xop init # set vault passphrase
# echo "..." | xop set MYSQL_PWD # store MySQL password
#
# At spawn time, xop will:
# 1. Prompt Touch ID (macOS) or pkexec (Linux) to confirm your identity
# 2. Prompt for the vault passphrase (hidden)
# 3. Decrypt MYSQL_PWD from ~/.xop/key.db
# 4. Spawn `mysql` with MYSQL_PWD env var set
#
# Why MYSQL_PWD env var? mysql's `-p` flag leaks the password via argv
# (visible in `ps aux`). Env var avoids that exposure.
set -euo pipefail
cd "$(dirname "$0")/.."
./target/release/xop \
--secret MYSQL_PWD='MYSQL_PWD' \
--allow-net='mysql.internal:3306' \
--deny-net='*' \
-- \
mysql -h mysql.internal -u readonly -D mydb --table -e 'SELECT 1 AS connected'
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Real SSH exec — secrets stored locally, gated by Touch ID / PAM + passphrase.
#
# Before running, you must have stored the secret:
# xop init
# echo "..." | xop set SSH_PASS
#
# At spawn time, xop will:
# 1. Trigger Touch ID (macOS) or pkexec (Linux) to confirm your identity
# 2. Prompt for the vault passphrase (hidden)
# 3. Decrypt SSH_PASS from `~/.xop/key.db`
# 4. Spawn `ssh` with SSH_PASS in env (askpass strategy still P1)
#
# v0.2 currently passes the password via env var (fallback strategy).
# Askpass strategy (which avoids any trace in /proc/<pid>/environ) is P1.
set -euo pipefail
cd "$(dirname "$0")/.."
HOST="${HOST:-192.168.1.19}"
USER="${USER:-rong}"
./target/release/xop \
--secret SSH_PASS='ssh_pass' \
--allow-net="${HOST}:22" \
--deny-net='*' \
-- \
ssh -o StrictHostKeyChecking=accept-new \
-o UserKnownHostsFile=/dev/null \
"${USER}@${HOST}"