Skip to content

gsmlg-dev/secrethub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

πŸ—οΈ 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   β”‚  β”‚      REST API + WebSocket  β”‚       β”‚
β”‚  β”‚   Auth    β”‚  β”‚ Seal/     β”‚  β”‚  /v1/secrets, /v1/auth,   β”‚       β”‚
β”‚  β”‚           β”‚  β”‚ Unseal    β”‚  β”‚  /v1/pki, /v1/sys         β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”‚                                                                      β”‚
β”‚                    Phoenix LiveView Admin Dashboard                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↕ 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

Installation

# 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:

Quick Commands

# 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
β”‚   β”‚       β”œβ”€β”€ audit.ex                # Hash-chained audit logs
β”‚   β”‚       β”œβ”€β”€ vault/seal_state.ex     # Seal/unseal with Shamir
β”‚   β”‚       β”œβ”€β”€ engines/dynamic/        # PostgreSQL, Redis, AWS STS
β”‚   β”‚       β”œβ”€β”€ auto_unseal/providers/  # KMS integrations
β”‚   β”‚       β”œβ”€β”€ 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 (Docker, K8s, Terraform)
└── .github/workflows/                  # CI/CD pipelines

🌐 API Endpoints

Endpoint Description
POST /v1/sys/init Initialize vault with Shamir shares
POST /v1/sys/unseal Unseal vault with key shares
GET /v1/sys/health Health check
POST /v1/auth/approle/login AppRole authentication
GET /v1/secrets/:path Read secret
POST /v1/secrets/:path Write secret
POST /v1/secrets/dynamic/postgresql/creds/:role Generate PostgreSQL credentials
POST /v1/pki/issue Issue certificate
GET /v1/sys/leases List active leases
POST /v1/sys/leases/revoke Revoke lease

πŸ–₯️ Admin Dashboard

The LiveView-based admin dashboard provides:

  • Dashboard: System overview, health metrics
  • Agents: Connected agents, status monitoring
  • Secrets: Secret browser, version history
  • Policies: Policy management, entity bindings
  • PKI: CA management, certificate issuance
  • Audit: Log viewer, CSV export
  • Dynamic Engines: PostgreSQL/Redis configuration
  • Leases: Active lease management
  • Cluster: Node health, distributed state

🚒 Deployment

Release Artifacts

Release Includes
secrethub_core Core + Web + Shared
secrethub_agent Agent + Shared

Docker Images

# 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

Environment Variables

# 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

# Agent
SECRETHUB_CORE_URL=wss://core.example.com:4000
SECRETHUB_ROLE_ID=<role-id>
SECRETHUB_SECRET_ID=<secret-id>

πŸ§ͺ Development Status

βœ… Completed Features

  • Umbrella project structure with 4 apps
  • PostgreSQL 16 with UUID, pgcrypto extensions
  • AppRole authentication (RoleID/SecretID)
  • Full PKI engine (Root CA, Intermediate CA, CSR)
  • Vault seal/unseal with Shamir's Secret Sharing
  • Policy engine with glob patterns and conditions
  • Tamper-evident audit logging (hash chains + HMAC)
  • Dynamic secret engines (PostgreSQL, Redis, AWS STS)
  • Auto-unseal providers (AWS KMS, Azure, GCP)
  • Agent bootstrap and mTLS WebSocket connection
  • Secret caching with TTL and LRU eviction
  • Template rendering and atomic file writes
  • Lease management with auto-renewal
  • Oban-scheduled secret rotation
  • LiveView admin dashboard
  • CI/CD with GitHub Actions
  • Multi-arch Docker images (amd64/arm64)

πŸ“ 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •