GitLab Stack Secrets Manager by rknall/claude-skills
npx skills add https://github.com/rknall/claude-skills --skill 'GitLab Stack Secrets Manager'此技能管理 GitLab 栈项目的密钥,确保密钥安全存储,绝不暴露在配置文件中,并与 Docker 密钥正确集成。
当用户请求以下操作时激活此技能:
关键规则 - 绝不可违反:
步骤 1:确定操作
自问用户想要做什么:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
检查当前项目状态:
审查 docker-compose.yml:
扫描安全问题:
时机 :用户想要创建新密钥
步骤 1:验证先决条件
检查 ./secrets 目录是否存在:
ls -ld ./secrets
如果缺失,以正确的权限创建:
mkdir -p ./secrets
chmod 700 ./secrets
步骤 2:确定密钥详情
询问用户(或从上下文推断):
步骤 3:创建密钥文件
生成或接受密钥值
在 ./secrets 中创建文件:
echo -n "secret-value" > ./secrets/secret_name
设置正确的权限:
chmod 600 ./secrets/secret_name
验证所有权(不应是 root)
步骤 4:更新 docker-compose.yml
添加到顶层的 secrets 部分:
secrets:
secret_name:
file: ./secrets/secret_name
添加到相应的服务:
services:
myservice:
secrets:
- secret_name
步骤 5:验证 .gitignore
确保 ./secrets 被排除:
/secrets/
/secrets/*
!secrets/.gitkeep
时机 :用户想要验证密钥配置,或作为其他操作的一部分
步骤 1:目录结构验证
检查 ./secrets 是否存在:
[ -d ./secrets ] && echo "exists" || echo "missing"
检查权限(应为 700):
stat -c "%a" ./secrets # Linux
stat -f "%OLp" ./secrets # macOS
检查所有权(非 root):
ls -ld ./secrets
步骤 2:密钥文件验证
列出所有密钥文件:
find ./secrets -type f ! -name .gitkeep
对于每个文件,检查:
步骤 3:docker-compose.yml 验证
解析 secrets 部分:
检查服务密钥引用:
secrets: 键,而非环境变量关键 :扫描环境变量中的密钥:
步骤 4:.env 文件验证
关键 :扫描 .env 中的密钥:
如果在 .env 中发现密钥:
步骤 5:Git 安全检查
验证 .gitignore 排除了 ./secrets:
grep -q "secrets" .gitignore
检查是否有任何密钥已暂存:
git status --porcelain | grep secrets/
检查 git 历史记录中的密钥(如果请求):
git log --all --full-history -- ./secrets/
步骤 6:生成验证报告
🔐 密钥验证报告
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📁 目录结构
✅ ./secrets 存在,权限为 700
✅ 由用户拥有 (1000:1000)
✅ ./secrets 在 .gitignore 中
📄 密钥文件 (3)
✅ db_password - 权限 600,32 字节
✅ api_key - 权限 600,64 字节
⚠️ jwt_secret - 权限 644 (应为 600)
🐳 Docker 集成
✅ docker-compose.yml 中定义了 3 个密钥
✅ 所有密钥文件都存在
⚠️ 服务 'worker' 使用 docker-entrypoint.sh
❌ 关键安全问题
❌ .env 包含密钥:
* DB_PASSWORD=supersecret123
* API_KEY=sk_live_abc123
** 需要立即采取行动 **
❌ docker-compose.yml 环境变量包含密钥:
* 服务 'app' - 环境变量中的 JWT_SECRET
** 必须迁移到 Docker 密钥 **
✅ Git 安全性
✅ git 暂存区中没有密钥
✅ .gitignore 配置正确
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
状态:失败 (2 个关键问题)
🔧 需要立即采取的行动
1. 将密钥从 .env 迁移到 Docker 密钥
2. 从 docker-compose.yml 环境中移除密钥
3. 修复 jwt_secret 文件的权限
时机 :在 .env 或 docker-compose.yml 环境变量中发现密钥
关键 :这是一个必须修复的安全问题
步骤 1:识别要迁移的密钥
扫描 .env 中的密钥模式:
grep -E "(PASSWORD|SECRET|KEY|TOKEN|API)" .env
扫描 docker-compose.yml 的环境部分:
# 在环境变量中查找模式
列出所有检测到的密钥,包含:
步骤 2:与用户确认
展示发现并询问:
步骤 3:创建密钥文件
对于每个要迁移的密钥:
提取当前值
创建密钥文件:
echo -n "$value" > ./secrets/secret_name
chmod 600 ./secrets/secret_name
添加到 docker-compose.yml 的 secrets 部分
步骤 4:更新服务配置
对于每个使用该密钥的服务:
添加到服务密钥列表
从环境变量中移除
如果容器支持 _FILE 后缀:
environment:
DB_PASSWORD_FILE: /run/secrets/db_password
如果容器不支持原生密钥:
步骤 5:清理
步骤 6:验证
时机 :需要生成安全的随机密钥时
步骤 1:确定格式要求
常见格式:
步骤 2:确定长度
标准长度:
步骤 3:生成密钥
使用加密安全的方法:
# 字母数字 (32 个字符)
openssl rand -base64 32 | tr -d '/+=' | head -c 32
# 十六进制 (64 个字符)
openssl rand -hex 32
# Base64 (32 字节)
openssl rand -base64 32
# UUID
uuidgen
# 自定义 (例如,16 个字母数字)
LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 16
步骤 4:安全存储
写入文件(无尾随换行符):
echo -n "$secret" > ./secrets/secret_name
设置权限:
chmod 600 ./secrets/secret_name
时机 :用户想要审计密钥使用、查找泄露或审查安全性时
步骤 1:密钥清单
列出所有密钥及其详情:
步骤 2:使用分析
对于每个密钥:
步骤 3:查找未使用的密钥
步骤 4:泄露检测
检查常见的泄露位置:
.env 文件(关键):
grep -E "(PASSWORD|SECRET|KEY|TOKEN)" .env
docker-compose.yml 环境(关键):
配置文件 :
grep -r "password\|secret\|key" ./config/
Git 历史记录 :
git log -p --all -S "secret-pattern"
Docker 日志 :
步骤 5:权限审计
检查 ./secrets 中的所有文件:
find ./secrets -type f -not -perm 600
检查目录权限:
[ "$(stat -c '%a' ./secrets)" = "700" ]
检查所有权:
find ./secrets -user root
步骤 6:生成审计报告
包括:
时机 :容器不支持原生 Docker 密钥时
步骤 1:确定必要性
检查容器是否支持密钥:
_FILE 后缀 ✅仅在以下情况下创建入口点脚本:
_FILE 后缀步骤 2:识别所需密钥
列出需要加载的密钥:
步骤 3:生成入口点脚本
#!/bin/bash
set -e
# 将 docker 密钥加载到环境中的函数
load_secret() {
local secret_name=$1
local env_var=$2
local secret_file="/run/secrets/${secret_name}"
if [ -f "$secret_file" ]; then
export "${env_var}=$(cat "$secret_file")"
echo "Loaded secret: $secret_name -> $env_var"
else
echo "ERROR: Secret file $secret_file not found!" >&2
exit 1
fi
}
# 加载所有必需的密钥
load_secret "db_password" "DB_PASSWORD"
load_secret "api_key" "API_KEY"
load_secret "jwt_secret" "JWT_SECRET"
# 执行主命令
exec "$@"
步骤 4:设置权限
chmod +x docker-entrypoint.sh
步骤 5:更新 docker-compose.yml
services:
myservice:
entrypoint: /docker-entrypoint.sh
command: ["original-command"]
volumes:
- ./docker-entrypoint.sh:/docker-entrypoint.sh:ro
secrets:
- db_password
- api_key
步骤 6:记录
添加注释说明为什么需要入口点脚本:
# 需要 docker-entrypoint.sh,因为此容器
# 不支持原生 Docker 密钥
管理密钥时:
这些是必须通过的安全标准:
User: "为我的数据库设置密钥"
1. 检查当前状态
- ./secrets 缺失 → 创建它
- docker-compose.yml 的 DB_PASSWORD 在环境变量中 → 关键问题
2. 报告发现:
"我发现一个关键安全问题:DB_PASSWORD 在 docker-compose.yml
环境变量中。我将把它迁移到 Docker 密钥。"
3. 迁移:
- 提取密码值
- 创建 ./secrets/db_password
- chmod 600 ./secrets/db_password
- 更新 docker-compose.yml 的 secrets 部分
- 更新 postgres 服务以使用密钥
- 从环境中移除
4. 验证:
- 运行验证
- 确认 compose 中没有密钥
- 检查 .gitignore
- 验证权限
5. 报告:
"✅ 数据库密码现在使用 Docker 密钥保护
✅ 已从 docker-compose.yml 环境中移除
✅ 文件权限设置正确
✅ 已添加到 .gitignore"
此技能确保密钥得到安全管理,绝不暴露在配置文件或版本控制中。
每周安装次数
–
仓库
GitHub 星标数
33
首次出现时间
–
安全审计
This skill manages secrets for GitLab stack projects, ensuring secrets are stored securely, never exposed in configuration files, and properly integrated with Docker secrets.
Activate this skill when the user requests:
CRITICAL RULES - Never violated:
Step 1: Determine the Operation
Ask yourself what the user wants to do:
Step 2: Gather Context
Check current project state:
Review docker-compose.yml:
Scan for security issues:
When : User wants to create new secrets
Step 1: Validate Prerequisites
Check if ./secrets directory exists:
ls -ld ./secrets
If missing, create with proper permissions:
mkdir -p ./secrets
chmod 700 ./secrets
Step 2: Determine Secret Details
Ask the user (or infer from context):
Step 3: Create Secret File
Generate or accept secret value
Create file in ./secrets:
echo -n "secret-value" > ./secrets/secret_name
Set proper permissions:
chmod 600 ./secrets/secret_name
Verify ownership (should not be root)
Step 4: Update docker-compose.yml
Add to top-level secrets section:
secrets:
secret_name:
file: ./secrets/secret_name
Add to appropriate service:
services:
myservice:
secrets:
- secret_name
Step 5: Verify .gitignore
Ensure ./secrets is excluded:
/secrets/
/secrets/*
!secrets/.gitkeep
When : User wants to validate secret configuration, or as part of other operations
Step 1: Directory Structure Validation
Check ./secrets exists:
[ -d ./secrets ] && echo "exists" || echo "missing"
Check permissions (should be 700):
stat -c "%a" ./secrets # Linux
stat -f "%OLp" ./secrets # macOS
Check ownership (not root):
ls -ld ./secrets
Step 2: Secret Files Validation
List all secret files:
find ./secrets -type f ! -name .gitkeep
For each file, check:
Step 3: docker-compose.yml Validation
Parse secrets section:
Check service secret references:
secrets: key, not environment varsCRITICAL : Scan for secrets in environment variables:
Step 4: .env File Validation
CRITICAL : Scan .env for secrets:
If secrets found in .env:
Step 5: Git Safety Check
Verify .gitignore excludes ./secrets:
grep -q "secrets" .gitignore
Check if any secrets are staged:
git status --porcelain | grep secrets/
Check git history for secrets (if requested):
git log --all --full-history -- ./secrets/
Step 6: Generate Validation Report
🔐 Secrets Validation Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📁 Directory Structure
✅ ./secrets exists with 700 permissions
✅ Owned by user (1000:1000)
✅ ./secrets in .gitignore
📄 Secret Files (3)
✅ db_password - 600 permissions, 32 bytes
✅ api_key - 600 permissions, 64 bytes
⚠️ jwt_secret - 644 permissions (should be 600)
🐳 Docker Integration
✅ 3 secrets defined in docker-compose.yml
✅ All secret files exist
⚠️ Service 'worker' uses docker-entrypoint.sh
❌ CRITICAL SECURITY ISSUES
❌ .env contains secrets:
* DB_PASSWORD=supersecret123
* API_KEY=sk_live_abc123
** IMMEDIATE ACTION REQUIRED **
❌ docker-compose.yml environment variables contain secrets:
* Service 'app' - JWT_SECRET in environment
** MUST MIGRATE TO DOCKER SECRETS **
✅ Git Safety
✅ No secrets in git staging
✅ .gitignore properly configured
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Status: FAILED (2 critical issues)
🔧 IMMEDIATE ACTIONS REQUIRED
1. Migrate secrets from .env to Docker secrets
2. Remove secrets from docker-compose.yml environment
3. Fix permissions on jwt_secret file
When : Secrets found in .env or docker-compose.yml environment variables
CRITICAL : This is a security issue that must be fixed
Step 1: Identify Secrets to Migrate
Scan .env for secret patterns:
grep -E "(PASSWORD|SECRET|KEY|TOKEN|API)" .env
Scan docker-compose.yml environment sections:
# Look for patterns in environment variables
List all detected secrets with:
Step 2: Confirm with User
Present findings and ask:
Step 3: Create Secret Files
For each secret to migrate:
Extract current value
Create secret file:
echo -n "$value" > ./secrets/secret_name
chmod 600 ./secrets/secret_name
Add to docker-compose.yml secrets section
Step 4: Update Service Configurations
For each service using the secret:
Add to service secrets list
Remove from environment variables
If container supports _FILE suffix:
environment:
DB_PASSWORD_FILE: /run/secrets/db_password
If container doesn't support native secrets:
Step 5: Clean Up
Step 6: Verification
When : Need to generate secure random secrets
Step 1: Determine Format Requirements
Common formats:
Step 2: Determine Length
Standard lengths:
Step 3: Generate Secret
Use cryptographically secure methods:
# Alphanumeric (32 chars)
openssl rand -base64 32 | tr -d '/+=' | head -c 32
# Hex (64 chars)
openssl rand -hex 32
# Base64 (32 bytes)
openssl rand -base64 32
# UUID
uuidgen
# Custom (e.g., 16 alphanumeric)
LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 16
Step 4: Store Securely
Write to file (no trailing newline):
echo -n "$secret" > ./secrets/secret_name
Set permissions:
chmod 600 ./secrets/secret_name
When : User wants to audit secret usage, find leaks, or review security
Step 1: Secret Inventory
List all secrets with details:
Step 2: Usage Analysis
For each secret:
Step 3: Find Unused Secrets
Step 4: Leak Detection
Check common leak locations:
.env file (CRITICAL):
grep -E "(PASSWORD|SECRET|KEY|TOKEN)" .env
docker-compose.yml environment (CRITICAL):
Configuration files :
grep -r "password\|secret\|key" ./config/
Git history :
git log -p --all -S "secret-pattern"
Docker logs :
Step 5: Permission Audit
Check all files in ./secrets:
find ./secrets -type f -not -perm 600
Check directory permissions:
[ "$(stat -c '%a' ./secrets)" = "700" ]
Check ownership:
find ./secrets -user root
Step 6: Generate Audit Report
Include:
When : Container doesn't support native Docker secrets
Step 1: Determine Necessity
Check if container supports secrets:
_FILE suffix ✅Only create entrypoint if:
_FILE suffix supportStep 2: Identify Required Secrets
List secrets that need to be loaded:
Step 3: Generate Entrypoint Script
#!/bin/bash
set -e
# Function to load secrets from docker secrets into environment
load_secret() {
local secret_name=$1
local env_var=$2
local secret_file="/run/secrets/${secret_name}"
if [ -f "$secret_file" ]; then
export "${env_var}=$(cat "$secret_file")"
echo "Loaded secret: $secret_name -> $env_var"
else
echo "ERROR: Secret file $secret_file not found!" >&2
exit 1
fi
}
# Load all required secrets
load_secret "db_password" "DB_PASSWORD"
load_secret "api_key" "API_KEY"
load_secret "jwt_secret" "JWT_SECRET"
# Execute the main command
exec "$@"
Step 4: Set Permissions
chmod +x docker-entrypoint.sh
Step 5: Update docker-compose.yml
services:
myservice:
entrypoint: /docker-entrypoint.sh
command: ["original-command"]
volumes:
- ./docker-entrypoint.sh:/docker-entrypoint.sh:ro
secrets:
- db_password
- api_key
Step 6: Document
Add comment explaining why entrypoint is needed:
# docker-entrypoint.sh required because this container
# doesn't support Docker secrets natively
When managing secrets:
These are must-pass security criteria:
User: "Set up secrets for my database"
1. Check current state
- ./secrets missing → create it
- docker-compose.yml has DB_PASSWORD in environment → CRITICAL ISSUE
2. Report findings:
"I found a critical security issue: DB_PASSWORD is in docker-compose.yml
environment variables. I'll migrate this to Docker secrets."
3. Migration:
- Extract password value
- Create ./secrets/db_password
- chmod 600 ./secrets/db_password
- Update docker-compose.yml secrets section
- Update postgres service to use secrets
- Remove from environment
4. Verification:
- Run validation
- Confirm no secrets in compose
- Check .gitignore
- Verify permissions
5. Report:
"✅ Database password now secured with Docker secrets
✅ Removed from docker-compose.yml environment
✅ File permissions set correctly
✅ Added to .gitignore"
This skill ensures secrets are managed securely and never exposed in configuration files or version control.
Weekly Installs
–
Repository
GitHub Stars
33
First Seen
–
Security Audits
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
114,200 周安装