agent-security-ops
Security hardening for solopreneur repos. One command to set up pre-commit hooks, secret scanning, and continuous monitoring.
⚠️ Important: --no-verify Bypass Warning
The pre-commit hook can be bypassed with git commit --no-verify. This skips ALL hooks including secret scanning.
Recommendations:
- 1. Never use
--no-verify unless you've manually verified no secrets are staged - Set up CI-side scanning as backup — add TruffleHog to your GitHub Actions / CI pipeline so secrets are caught even if hooks are bypassed
- Run
scan.sh after any --no-verify commit to verify nothing slipped through
The hook is fail-closed: if TruffleHog is not found, commits are blocked (not silently allowed).
Quick Start
CODEBLOCK0
This will:
- 1. Install TruffleHog (pinned version with SHA256 checksum verification, override with
TRUFFLEHOG_VERSION env var) - Set up a fail-closed pre-commit hook that blocks secrets (scans staged changes)
- Harden
.gitignore with common secret patterns (including .security-ops/, .terraform/) - Run initial secret scan (git history + filesystem for untracked files)
What You'll See
setup.sh output:
CODEBLOCK1
scan.sh summary (stderr):
CODEBLOCK2
Commands
All scripts support --help and --version flags.
setup.sh — One-time repo hardening
bash scripts/setup.sh [/path/to/repo]
bash scripts/setup.sh --fix-ssh /path/to/repo # also fix SSH permissions
Idempotent. Safe to run multiple times. Defaults to current directory. Existing pre-commit hooks are preserved (appended to, not overwritten).
scan.sh — Full security scan
CODEBLOCK4
Checks:
- - Secrets: TruffleHog — all secrets found (verified ones highlighted)
- Filesystem: TruffleHog filesystem scan for untracked/working files
- Pattern grep (high-confidence): AWS, GitHub, Anthropic, Slack, OpenAI, Stripe, Google, Twilio, SendGrid, npm, Vault, private keys
- Pattern grep (low-confidence): Database URLs, password/secret assignments, bearer tokens, Firebase, Supabase, JWTs
.gitignore audit: Uses git check-ignore to verify patterns work- Dependency audit:
npm audit / pip audit (results in JSON output) - File permissions: Finds world-readable
.env, .pem, .key, credential files - Open ports: Lists listening ports, flags unexpected ones (note: may need sudo on macOS)
- Environment secrets: Scans shell profiles for hardcoded keys/tokens
- Loose
.env files: Checks $HOME, Desktop, Downloads for .env files (warning only, not counted as repo findings) - Docker secrets: Checks Dockerfiles and compose files for hardcoded secrets
- SSH audit: Verifies
~/.ssh permissions (report only — use setup.sh --fix-ssh to fix) - Git remotes: Flags insecure HTTP remotes, checks GitHub repo visibility
monitor.sh — Cron-friendly monitoring
CODEBLOCK5
Content-based delta detection (hashes scan results, not just counts). Exits 1 on any change, 0 if unchanged. Uses atomic file writes and flock-based locking to prevent concurrent runs.
Cron Integration
CODEBLOCK6
Found Something?
| Finding | What to Do |
|---|
| Verified secret in git | Rotate the credential immediately. Use git filter-repo or BFG to remove from history. |
| Unverified secret in git |
Investigate — may be a false positive or an expired credential. Still consider rotating. |
|
Pattern match (high-confidence) | Move to
.env file or secret manager. Verify it's in
.gitignore. |
|
Pattern match (low-confidence) | Review manually — may be a false positive. Check if it's a real credential. |
|
Missing .gitignore pattern | Run
setup.sh again — it adds missing patterns. |
|
World-readable sensitive file |
chmod 600 <file> — restrict to owner only. |
|
Unexpected open port | Identify the process (
lsof -i :<port>), stop if unnecessary. |
|
Env secret in shell profile | Move to
.env file or
op run (1Password). Remove
export line. |
|
Docker hardcoded secret | Use Docker secrets, env vars with
${VAR} syntax, or
.env file. |
|
SSH permission issue | Run
setup.sh --fix-ssh or manually
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_*. |
|
HTTP git remote |
git remote set-url origin git@github.com:user/repo.git |
|
Public repo detected | If unintentional:
gh repo edit --visibility private |
Limitations
- - Grep ≠ AST analysis: Pattern matching catches literal strings, not obfuscated or dynamically constructed secrets.
- No SAST/DAST: This is not a replacement for static/dynamic application security testing.
- IaC limited to Docker: No Terraform, Kubernetes, or CloudFormation scanning beyond basic grep patterns on
.tf/.tfvars. - TruffleHog verification: Verification depends on service availability — if an API is down, a real secret may show as "unverified." That's why we now scan all secrets, not just verified ones.
- Port scanning: Only detects currently listening ports, not firewall rules or network exposure. May need sudo on macOS for full process info.
$HOME .env scan: Checks outside repo scope as a convenience — findings are warnings only, not counted as repo findings.
What It Scans
| Category | Tool | Coverage |
|---|
| Secrets in code | TruffleHog | Current files + full git history (all, verified highlighted) |
| Filesystem secrets |
TruffleHog | Untracked/working directory files |
| Secret patterns (high) | grep | 20+ providers (AWS, GitHub, Anthropic, Slack, Stripe, etc.) |
| Secret patterns (low) | grep | DB URLs, passwords, bearer tokens, Firebase, Supabase, JWTs |
| .gitignore | git check-ignore |
.env*,
*.pem,
*.key,
*.p12,
*.pfx, credentials, keystores,
.terraform/ |
| Dependencies | npm/pip audit | Known CVEs in packages |
| Permissions | find | World-readable sensitive files |
| Open Ports | lsof/ss | Unexpected listening services |
| Env Secrets | grep | Hardcoded secrets in shell profiles, loose .env files (warning) |
| Docker Secrets | grep | Hardcoded secrets in Dockerfiles and compose files |
| SSH Audit | stat | Permission checks on ~/.ssh, keys, config |
| Git Remotes | git/gh | Insecure HTTP remotes, public repo detection |
Security Model
- - Binary verification: TruffleHog downloaded with SHA256 checksum verification against official release checksums
- Fail-closed hook: Missing TruffleHog blocks commits (not silently passes)
- No brew fallback: Only verified direct download to prevent supply chain attacks
- Version pinning:
TRUFFLEHOG_VERSION validated as semver before use - Self-exclusion: Scripts exclude themselves from grep scans via content marker
Reference Files
- -
references/patterns.md — Regex patterns for all detected secret types, marked as ✅ scanned or 📖 reference only.
Dependencies
- -
git, grep, find (standard) - INLINECODE52 (installed by setup.sh, pinned version with checksum verification)
- INLINECODE53 (optional — produces properly escaped JSON; without it, falls back to shell-based escaping which may break on unusual filenames/content)
Built by
The Agent Wire — a weekly newsletter about AI agents for solopreneurs. Liked this skill? I write about building agent-ops tools like this every Wednesday.
Star ⭐ this skill if it saved you from leaking a secret.
FAQ
What is this skill?
Agent Security Ops installs pre-commit hooks and runs 10-point security scans to prevent AI agents from leaking secrets. Catches API keys, tokens, passwords, and credentials before they reach git history.
What problem does it solve?
AI agents generate and handle credentials constantly — API keys, tokens, database URLs. Without guardrails, these end up in commits, logs, or chat messages. This skill adds automated scanning at commit-time and on-demand.
What are the requirements?
Bash, git, and TruffleHog (installed automatically). Works on macOS and Linux. No API keys or external services needed.
What does the 10-point scan check?
Git staged files, environment files (.env), config files, recent git history, high-entropy strings, known secret patterns, AWS/GCP/Azure credentials, private keys, database URLs, and API tokens.
Does it work with any AI agent framework?
Yes. It's framework-agnostic — operates at the git and filesystem level. Works with OpenClaw, Claude Code, Cursor, Aider, or any tool that writes files.
Can it run on a schedule?
Yes. Pair it with a cron job for periodic scans of your workspace. The scan outputs a structured report suitable for automated monitoring.
agent-security-ops
面向独立开发者仓库的安全加固方案。一条命令即可配置预提交钩子、密钥扫描和持续监控。
⚠️ 重要提示:--no-verify 绕过警告
预提交钩子可通过 git commit --no-verify 绕过。这会跳过包括密钥扫描在内的所有钩子。
建议:
- 1. 除非已手动确认暂存区无密钥,否则切勿使用 --no-verify
- 设置CI端扫描作为备份 — 在GitHub Actions/CI流水线中添加TruffleHog,确保即使钩子被绕过也能捕获密钥
- 执行任何 --no-verify 提交后运行 scan.sh 以验证无遗漏
该钩子采用失败关闭机制:若未找到TruffleHog,提交将被阻止(而非静默允许)。
快速开始
bash
bash skills/agent-security-ops/scripts/setup.sh /path/to/repo
此操作将:
- 1. 安装TruffleHog(固定版本,含SHA256校验和验证,可通过TRUFFLEHOG_VERSION环境变量覆盖)
- 配置失败关闭的预提交钩子,用于阻止密钥(扫描暂存区变更)
- 使用常见密钥模式加固.gitignore(包括.security-ops/、.terraform/)
- 运行初始密钥扫描(Git历史 + 未跟踪文件的文件系统扫描)
你将看到的内容
setup.sh输出:
agent-security-ops: 正在设置 /Users/you/my-project
✓ TruffleHog已安装 (3.88.0)
✓ 预提交钩子已安装
→ 已向.gitignore添加2个模式:.security-ops/ .terraform/
→ 正在运行初始密钥扫描...
✓ 初始扫描:干净
→ 正在运行文件系统扫描(未跟踪文件)...
✓ 文件系统扫描:干净
设置完成:
• 已安装预提交钩子
• 已加固.gitignore(+2个模式)
• 初始扫描:干净
💡 更多agent-ops工具请访问 theagentwire.ai/?utmsource=clawhub&utmmedium=skill&utm_campaign=agent-security-ops
scan.sh摘要(stderr):
--- TruffleHog密钥扫描 ---
✓ 未发现密钥
--- TruffleHog文件系统扫描 ---
✓ 未跟踪文件中无密钥
--- 模式Grep扫描 ---
⚠ 发现2个高置信度密钥模式
./config.js:3: apiKey: sk-proj-abc123...
✓ 无低置信度模式
--- 摘要 ---
⚠ 总计:2(密钥=0[0已验证],文件系统=0,模式=2[+0低置信度],...)
命令
所有脚本均支持--help和--version标志。
setup.sh — 一次性仓库加固
bash
bash scripts/setup.sh [/path/to/repo]
bash scripts/setup.sh --fix-ssh /path/to/repo # 同时修复SSH权限
幂等操作。可安全多次运行。默认为当前目录。现有预提交钩子将被保留(追加而非覆盖)。
scan.sh — 完整安全扫描
bash
JSON报告输出到stdout,人类可读摘要输出到stderr
bash scripts/scan.sh [/path/to/repo]
保存报告
bash scripts/scan.sh /path/to/repo > report.json
检查项:
- - 密钥:TruffleHog — 所有发现的密钥(已验证的会高亮显示)
- 文件系统:TruffleHog文件系统扫描,检查未跟踪/工作文件
- 模式grep(高置信度):AWS、GitHub、Anthropic、Slack、OpenAI、Stripe、Google、Twilio、SendGrid、npm、Vault、私钥
- 模式grep(低置信度):数据库URL、密码/密钥赋值、Bearer令牌、Firebase、Supabase、JWT
- .gitignore审计:使用git check-ignore验证模式是否生效
- 依赖审计:npm audit / pip audit(结果以JSON输出)
- 文件权限:查找全局可读的.env、.pem、.key、凭证文件
- 开放端口:列出监听端口,标记异常端口(注意:macOS上可能需要sudo)
- 环境密钥:扫描shell配置文件中的硬编码密钥/令牌
- 散落的.env文件:检查$HOME、桌面、下载目录中的.env文件(仅警告,不计入仓库发现)
- Docker密钥:检查Dockerfile和compose文件中的硬编码密钥
- SSH审计:验证~/.ssh权限(仅报告 — 使用setup.sh --fix-ssh修复)
- Git远程仓库:标记不安全的HTTP远程仓库,检查GitHub仓库可见性
monitor.sh — 适合Cron的监控工具
bash
bash scripts/monitor.sh [/path/to/repo]
基于内容的差异检测(对扫描结果进行哈希,而非仅比较计数)。有变更时退出码为1,无变更时为0。使用原子文件写入和基于flock的锁定机制防止并发运行。
Cron集成
bash
每小时检查一次,发现新结果时告警
0
bash /path/to/skills/agent-security-ops/scripts/monitor.sh /path/to/repo || notify 安全扫描有变更
发现问题?
| 发现项 | 处理方式 |
|---|
| Git中已验证的密钥 | 立即轮换凭证。使用git filter-repo或BFG从历史记录中移除。 |
| Git中未验证的密钥 |
调查 — 可能是误报或过期凭证。仍建议考虑轮换。 |
|
模式匹配(高置信度) | 移至.env文件或密钥管理器。确认已加入.gitignore。 |
|
模式匹配(低置信度) | 手动审查 — 可能是误报。检查是否为真实凭证。 |
|
缺少.gitignore模式 | 再次运行setup.sh — 它会添加缺失的模式。 |
|
全局可读的敏感文件 | chmod 600 <文件> — 仅限所有者访问。 |
|
意外的开放端口 | 识别进程(lsof -i :<端口>),如非必要则停止。 |
|
Shell配置文件中的环境密钥 | 移至.env文件或op run(1Password)。删除export行。 |
|
Docker硬编码密钥 | 使用Docker密钥、带${VAR}语法的环境变量或.env文件。 |
|
SSH权限问题 | 运行setup.sh --fix-ssh或手动执行chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_*。 |
|
HTTP Git远程仓库 | git remote set-url origin git@github.com:user/repo.git |
|
检测到公开仓库 | 如非本意:gh repo edit --visibility private |
局限性
- - Grep ≠ AST分析:模式匹配捕获字面字符串,无法检测混淆或动态构造的密钥。
- 无SAST/DAST:这不能替代静态/动态应用安全测试。
- IaC仅限Docker:不支持Terraform、Kubernetes或CloudFormation扫描,仅对.tf/.tfvars进行基本grep模式匹配。
- TruffleHog验证:验证依赖于服务可用性 — 如果API不可用,真实密钥可能显示为未验证。这就是我们现在扫描所有密钥(而不仅限于已验证的)的原因。
- 端口扫描:仅检测当前监听的端口,不检测防火墙规则或网络暴露情况。macOS上可能需要sudo才能获取完整进程信息。
- $HOME .env扫描:作为便利功能检查仓库范围之外的文件 — 发现项仅为警告,不计入仓库发现。
扫描内容
| 类别 | 工具 | 覆盖范围 |
|---|
| 代码中的密钥 | TruffleHog | 当前文件 + 完整Git历史(全部,已验证的会高亮显示) |
| 文件系统密钥 |
TruffleHog | 未跟踪/工作目录文件 |
| 密钥模式(高) | grep | 20+个提供商(AWS、GitHub、Anthropic、Slack、Stripe等) |
| 密钥模式(低) | grep | 数据库URL、密码、Bearer令牌、Firebase、Supabase、JWT |
| .gitignore | git check-ignore | .env
、.pem、
.key、.p12、*.pf