https://github.com/gsmlg-dev/secrethub
https://github.com/gsmlg-dev/secrethub
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/gsmlg-dev/secrethub
- Owner: gsmlg-dev
- Created: 2025-10-20T14:23:13.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-20T05:04:46.000Z (7 months ago)
- Last Synced: 2025-11-20T11:03:49.565Z (7 months ago)
- Language: Elixir
- Size: 1 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Security: docs/security/authentication_flows_review.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# SecretHub
> Enterprise-grade Machine-to-Machine secrets management platform
**Status:** π v1.0.0-rc3 Released
---
## π― Project Overview
SecretHub is a secure, reliable, and highly automated secrets management platform designed specifically for Machine-to-Machine (M2M) communication. Built in Elixir with a HashiCorp Vault-like architecture, it eliminates hardcoded credentials through centralized management, dynamic generation, and automatic rotation.
### Core Features
| Feature | Description |
|---------|-------------|
| π **mTLS Everywhere** | Mutual TLS for all Core-Agent communications with PKI-issued certificates |
| π **Dynamic Secrets** | Short-lived credentials for PostgreSQL, Redis, and AWS STS |
| π **Automatic Rotation** | Oban-scheduled zero-downtime secret rotation |
| π **Template Rendering** | EEx-based secret injection into configuration files |
| π **Tamper-Proof Audit** | SHA-256 hash-chained logs with HMAC signatures |
| π‘οΈ **Vault Seal/Unseal** | Shamir's Secret Sharing for master key protection |
| β‘ **High Availability** | Multi-node deployment with distributed locking |
| π **Auto-Unseal** | AWS KMS, Azure Key Vault, GCP KMS integrations |
| π¨ **Anomaly Detection** | Real-time security anomaly detection and alerting |
| π **Policy Templates** | Pre-built policy templates for common use cases |
---
## ποΈ Architecture
SecretHub implements a **two-tier architecture** with a central Core service and distributed Agents:
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SecretHub Core β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β PKI β β Policy β β Secret β β Audit β β
β β Engine β β Engine β β Engines β β Logger β β
β β β β β β β β β β
β β β’ Root CA β β β’ JSONB β β β’ Static β β β’ Hash β β
β β β’ Int. CA β β β’ Glob β β β’ Dynamic β β Chain β β
β β β’ CSR β β Match β β β’ Leases β β β’ HMAC β β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β AppRole β β Vault β β Anomaly β β Apps β β
β β Auth β β Seal/ β β Detection β β Manager β β
β β β β Unseal β β β β β β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β
β REST API + WebSocket + LiveView Admin β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β mTLS WebSocket
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SecretHub Agent β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β Bootstrap β βConnection β β Cache β β Sinker β β
β β β β Manager β β Layer β β β β
β β β’ AppRole β β β β β β β’ Atomic β β
β β β’ CSR Gen β β β’ Reconn β β β’ TTL β β Write β β
β β β’ Cert β β β’ Backoff β β β’ LRU β β β’ Reload β β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β
β βββββββββββββ βββββββββββββ βββββββββββββββββββββββββββββ β
β β Template β β Lease β β Unix Domain Socket API β β
β β Renderer β β Renewer β β (for local applications) β β
β βββββββββββββ βββββββββββββ βββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β UDS + mTLS
ββββββββββββββββββββββββ
β Applications β
ββββββββββββββββββββββββ
```
### Agent Lifecycle
1. **Bootstrap Phase**: AppRole auth β RSA-2048 keypair generation β CSR β Certificate issuance
2. **Operational Phase**: mTLS WebSocket to Core β Secret requests β Local caching
3. **Delivery Phase**: EEx template rendering β Atomic file writes β Application reload triggers
4. **Local Access**: Unix Domain Socket API for application secret retrieval
---
## π Security Architecture
### Encryption
| Layer | Algorithm | Details |
|-------|-----------|---------|
| At Rest | AES-256-GCM | Per-secret nonces, 128-bit auth tags |
| Master Key | Shamir's Secret Sharing | Configurable N shares, K threshold |
| Key Derivation | PBKDF2-SHA256 | 100,000 iterations |
### Authentication Flow
```
βββββββββββββββ RoleID/SecretID βββββββββββββββ
β Agent β ββββββββββββββββββββββββββΆβ Core β
β Bootstrap β β AppRole β
βββββββββββββββ βββββββββββββββ
β β
β CSR Request β
β βββββββββββββββββββββββββββββββββββββββββ
β β
β Signed Certificate β
β βββββββββββββββββββββββββββββββββββββββββΆ
β β
βΌ βΌ
βββββββββββββββ mTLS WebSocket βββββββββββββββ
β Agent β βββββββββββββββββββββββββΆβ Core β
β Running β β Running β
βββββββββββββββ βββββββββββββββ
```
### PKI Hierarchy
- **Root CA**: Self-signed, RSA-4096 or ECDSA P-384
- **Intermediate CA**: Root-signed, issues client certificates
- **Client Certificates**: 1-year validity, auto-renewal 7 days before expiry
---
## π Secret Engines
### Static Secrets
- Encrypted storage with versioning
- Oban-scheduled rotation
- Template rendering support
### Dynamic Secrets
| Engine | Description | Lease Management |
|--------|-------------|------------------|
| **PostgreSQL** | Temporary users with `VALID UNTIL`, custom SQL templates | Auto-revocation |
| **Redis** | Dynamic ACL-based credentials | Auto-revocation |
| **AWS STS** | Temporary IAM credentials via AssumeRole | TTL-based |
---
## π Quick Start
### Prerequisites
- **devenv:** [Install from devenv.sh](https://devenv.sh/getting-started/)
- **direnv (optional):** [Install from direnv.net](https://direnv.net/)
### Installation
```bash
# Clone the repository
git clone https://github.com/gsmlg-dev/secrethub.git
cd secrethub
# Activate devenv (or use direnv allow)
devenv shell
# Set up the database
db-setup
# Start the development server
server
```
**Available at:**
- **Web UI / Admin Dashboard:** http://localhost:4000/admin
- **REST API:** http://localhost:4000/v1
- **Metrics:** http://localhost:9090 (Prometheus)
### Quick Commands
```bash
# Database
db-setup # Create and migrate database
db-reset # Reset database (drop, create, migrate, seed)
# Development
server # Start Phoenix server
console # Start IEx shell with app loaded
# Testing
mix test # Run all tests
mix coveralls.html # Generate coverage report
# Code Quality
quality # Run format, credo, dialyzer
```
---
## π Project Structure
```
secrethub/ # Elixir Umbrella Application
βββ apps/
β βββ secrethub_core/ # Core Business Logic
β β βββ lib/secrethub_core/
β β βββ auth/app_role.ex # AppRole authentication
β β βββ pki/ca.ex # PKI/CA management
β β βββ policies.ex # Policy engine
β β βββ policy_templates.ex # Pre-built policy templates
β β βββ apps.ex # Application management
β β βββ audit.ex # Hash-chained audit logs
β β βββ vault/seal_state.ex # Seal/unseal with Shamir
β β βββ engines/dynamic/ # PostgreSQL, Redis, AWS STS
β β βββ auto_unseal/providers/ # AWS KMS, Azure KV, GCP KMS
β β βββ anomaly_detection.ex # Security anomaly detection
β β βββ alerting.ex # Multi-channel alerting
β β βββ lease_manager.ex # Lease lifecycle
β β βββ rotation_manager.ex # Oban-scheduled rotation
β β
β βββ secrethub_web/ # Phoenix Web Layer
β β βββ lib/secrethub_web_web/
β β βββ controllers/ # REST API endpoints
β β βββ live/admin/ # LiveView admin dashboard
β β βββ channels/ # Agent WebSocket channels
β β βββ plugs/ # Rate limiter, mTLS verification
β β
β βββ secrethub_agent/ # Distributed Agent Daemon
β β βββ lib/secrethub_agent/
β β βββ bootstrap.ex # AppRole β Certificate flow
β β βββ connection.ex # WebSocket client with reconnect
β β βββ cache.ex # TTL + LRU secret cache
β β βββ sinker.ex # Atomic file writer
β β βββ template_renderer.ex # EEx template engine
β β βββ uds_server.ex # Unix Domain Socket API
β β βββ lease_renewer.ex # Auto lease renewal
β β
β βββ secrethub_shared/ # Shared Code
β βββ lib/secrethub_shared/
β βββ schemas/ # 20+ Ecto schemas
β βββ crypto/ # AES-256-GCM, Shamir
β
βββ config/ # Environment configs
βββ infrastructure/ # IaC
β βββ helm/ # Helm charts
β βββ kubernetes/ # K8s manifests
β βββ prometheus/ # Prometheus configs
βββ .github/workflows/ # CI/CD pipelines
```
---
## π API Reference
### System Endpoints (`/v1/sys`)
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/v1/sys/init` | POST | Initialize vault with Shamir shares |
| `/v1/sys/seal` | POST | Seal the vault |
| `/v1/sys/unseal` | POST | Unseal vault with key shares |
| `/v1/sys/seal-status` | GET | Get vault seal status |
| `/v1/sys/health` | GET | Health check |
| `/v1/sys/health/ready` | GET | Kubernetes readiness probe |
| `/v1/sys/health/live` | GET | Kubernetes liveness probe |
### Authentication (`/v1/auth`)
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/v1/auth/approle/login` | POST | AppRole login |
| `/v1/auth/approle/role` | GET | List all roles |
| `/v1/auth/approle/role/:role_name` | POST | Create AppRole |
| `/v1/auth/approle/role/:role_name` | DELETE | Delete AppRole |
| `/v1/auth/approle/role/:role_name/role-id` | GET | Get Role ID |
| `/v1/auth/approle/role/:role_name/secret-id` | POST | Generate Secret ID |
### Secrets (`/v1/secrets`)
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/v1/secrets/:path` | GET | Read secret |
| `/v1/secrets/:path` | POST | Write secret |
| `/v1/secrets/:path` | DELETE | Delete secret |
| `/v1/secrets/dynamic/postgresql/creds/:role` | POST | Generate PostgreSQL credentials |
| `/v1/secrets/dynamic/redis/creds/:role` | POST | Generate Redis credentials |
| `/v1/secrets/dynamic/aws/creds/:role` | POST | Generate AWS STS credentials |
### PKI (`/v1/pki`)
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/v1/pki/ca/root/generate` | POST | Generate Root CA |
| `/v1/pki/ca/intermediate/generate` | POST | Generate Intermediate CA |
| `/v1/pki/issue` | POST | Issue certificate |
| `/v1/pki/sign-request` | POST | Sign a CSR |
| `/v1/pki/certificates` | GET | List certificates |
| `/v1/pki/certificates/:id` | GET | Get certificate details |
| `/v1/pki/certificates/:id/revoke` | POST | Revoke certificate |
| `/v1/pki/app/issue` | POST | Issue app certificate (bootstrap) |
| `/v1/pki/app/renew` | POST | Renew app certificate |
### Applications (`/v1/apps`)
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/v1/apps` | GET | List applications |
| `/v1/apps` | POST | Register application |
| `/v1/apps/:id` | GET | Get application details |
| `/v1/apps/:id` | PUT | Update application |
| `/v1/apps/:id` | DELETE | Delete application |
| `/v1/apps/:id/suspend` | POST | Suspend application |
| `/v1/apps/:id/activate` | POST | Activate application |
| `/v1/apps/:id/certificates` | GET | List app certificates |
### Leases (`/v1/sys/leases`)
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/v1/sys/leases` | GET | List active leases |
| `/v1/sys/leases/stats` | GET | Get lease statistics |
| `/v1/sys/leases/renew` | POST | Renew a lease |
| `/v1/sys/leases/revoke` | POST | Revoke a lease |
---
## π₯οΈ Admin Dashboard
The LiveView-based admin dashboard (`/admin`) provides:
### Core Management
- **Dashboard**: System overview, health metrics, quick stats
- **Secrets**: Secret browser, version history, bulk operations
- **Policies**: Policy editor, entity bindings, simulator
- **Policy Templates**: Pre-built templates for common scenarios
### Security & PKI
- **PKI**: Root/Intermediate CA management, certificate issuance
- **Certificates**: Certificate browser, revocation, renewal
- **AppRoles**: Role management, secret ID rotation
### Infrastructure
- **Agents**: Connected agents, status monitoring, health checks
- **Dynamic Engines**: PostgreSQL/Redis engine configuration
- **Engine Health**: Real-time engine status dashboard
- **Leases**: Active lease management, bulk revocation
### Operations
- **Audit**: Log viewer, search, CSV export
- **Rotations**: Rotation schedules, history, manual triggers
- **Templates**: Secret template management
### Cluster & Monitoring
- **Cluster**: Node health, distributed state, deployment status
- **Auto-Unseal**: KMS provider configuration
- **Alerts**: Alert rules, notification channels
- **Anomalies**: Anomaly detection rules, triggered alerts
- **Performance**: Performance metrics dashboard
---
## π¨ Anomaly Detection
SecretHub includes a built-in anomaly detection engine with rules for:
| Rule Type | Description |
|-----------|-------------|
| Failed Logins | Detect brute-force authentication attempts |
| Bulk Deletion | Alert on mass secret deletion |
| Unusual Access Time | Detect access outside business hours |
| Mass Secret Access | Alert on abnormal secret read patterns |
| Credential Export Spike | Detect unusual credential generation |
| Rotation Failures | Alert on failed secret rotations |
| Policy Violations | Detect policy bypass attempts |
### Alert Channels
- Email notifications
- Slack webhooks
- Generic webhooks
- PagerDuty integration
- Opsgenie integration
---
## π Policy Templates
Pre-built policy templates for common scenarios:
| Template | Description |
|----------|-------------|
| `business_hours` | Access restricted to business hours (9-5) |
| `ip_restricted` | Access limited to specific IP ranges |
| `read_only` | Read-only access to secrets |
| `emergency_access` | Break-glass emergency access |
| `dev_environment` | Development environment access |
| `production_readonly` | Production read-only access |
| `time_limited` | Time-limited access with expiration |
| `multi_region` | Multi-region access policies |
---
## π’ Deployment
### Release Artifacts
| Release | Includes |
|---------|----------|
| `secrethub_core` | Core + Web + Shared |
| `secrethub_agent` | Agent + Shared |
### Docker Images
```bash
# Core Service
docker run -d -p 4000:4000 \
-e DATABASE_URL="postgresql://..." \
-e SECRET_KEY_BASE="..." \
ghcr.io/gsmlg-dev/secrethub/core:v1.0.0-rc3
# Agent
docker run -d \
-e SECRETHUB_CORE_URL="wss://core:4000" \
-e SECRETHUB_ROLE_ID="..." \
-e SECRETHUB_SECRET_ID="..." \
ghcr.io/gsmlg-dev/secrethub/agent:v1.0.0-rc3
```
### Kubernetes (Helm)
```bash
helm install secrethub ./infrastructure/helm/secrethub \
--set core.database.url="postgresql://..." \
--set core.secretKeyBase="..."
```
### Environment Variables
```bash
# Core Service
DATABASE_URL=postgresql://user:pass@host/db # Or with socket: ?host=/var/run/postgresql
SECRET_KEY_BASE=<64-char-hex>
PHX_HOST=secrethub.example.com
POOL_SIZE=10
# Agent
SECRETHUB_CORE_URL=wss://core.example.com:4000
SECRETHUB_ROLE_ID=
SECRETHUB_SECRET_ID=
```
---
## π§ͺ Development Status
### β
Completed Features
- [x] Umbrella project structure with 4 apps
- [x] PostgreSQL 16 with UUID, pgcrypto extensions (Unix socket support)
- [x] AppRole authentication (RoleID/SecretID)
- [x] Full PKI engine (Root CA, Intermediate CA, CSR)
- [x] Vault seal/unseal with Shamir's Secret Sharing
- [x] Policy engine with glob patterns and conditions
- [x] Policy templates for common scenarios
- [x] Tamper-evident audit logging (hash chains + HMAC)
- [x] Dynamic secret engines (PostgreSQL, Redis, AWS STS)
- [x] Auto-unseal providers (AWS KMS, Azure Key Vault, GCP KMS)
- [x] Agent bootstrap and mTLS WebSocket connection
- [x] Secret caching with TTL and LRU eviction
- [x] Template rendering and atomic file writes
- [x] Lease management with auto-renewal
- [x] Oban-scheduled secret rotation
- [x] Application management system
- [x] Anomaly detection engine
- [x] Multi-channel alerting (Email, Slack, PagerDuty, Opsgenie)
- [x] LiveView admin dashboard (20+ pages)
- [x] CI/CD with GitHub Actions
- [x] Multi-arch Docker images (amd64/arm64)
- [x] Helm charts for Kubernetes deployment
---
## π Contributing
### Commit Convention
```
type(scope): subject
Types: feat, fix, docs, style, refactor, test, chore
```
**Example:**
```
feat(core): implement AWS STS dynamic secret engine
- Add AssumeRole credential generation
- Implement lease management
- Add integration tests
```
---
## π License
MIT License
---
## π Links
- **Repository:** https://github.com/gsmlg-dev/secrethub
- **Latest Release:** [v1.0.0-rc3](https://github.com/gsmlg-dev/secrethub/releases/tag/v1.0.0-rc3)
- **Docker Images:** `ghcr.io/gsmlg-dev/secrethub/core` | `ghcr.io/gsmlg-dev/secrethub/agent`