{"id":35148359,"url":"https://github.com/andrefaria24/demo-vault-db-secrets-engine","last_synced_at":"2026-04-28T16:32:53.022Z","repository":{"id":317946165,"uuid":"1069324337","full_name":"andrefaria24/demo-vault-db-secrets-engine","owner":"andrefaria24","description":"A compact demo that shows how HashiCorp Vault's Database Secrets Engine can manage both static and dynamic credentials for Microsoft SQL Server and PostgreSQL","archived":false,"fork":false,"pushed_at":"2025-12-16T19:09:13.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-12T02:36:29.496Z","etag":null,"topics":["demo","dynamic-secrets","hashicorp","mssql","postgresql","powershell","tsql","vault"],"latest_commit_sha":null,"homepage":"","language":"TSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrefaria24.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-03T18:47:01.000Z","updated_at":"2025-12-16T19:09:17.000Z","dependencies_parsed_at":"2025-10-08T21:18:39.021Z","dependency_job_id":null,"html_url":"https://github.com/andrefaria24/demo-vault-db-secrets-engine","commit_stats":null,"previous_names":["andrefaria24/vault-db-secrets-engine-demo","andrefaria24/demo-vault-db-secrets-engine"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andrefaria24/demo-vault-db-secrets-engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefaria24%2Fdemo-vault-db-secrets-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefaria24%2Fdemo-vault-db-secrets-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefaria24%2Fdemo-vault-db-secrets-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefaria24%2Fdemo-vault-db-secrets-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrefaria24","download_url":"https://codeload.github.com/andrefaria24/demo-vault-db-secrets-engine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefaria24%2Fdemo-vault-db-secrets-engine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32389896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["demo","dynamic-secrets","hashicorp","mssql","postgresql","powershell","tsql","vault"],"created_at":"2025-12-28T14:41:31.742Z","updated_at":"2026-04-28T16:32:52.992Z","avatar_url":"https://github.com/andrefaria24.png","language":"TSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vault Database Secrets Engine Demo\n\nA compact demo that shows how HashiCorp Vault's Database Secrets Engine can manage both static and dynamic credentials\nfor Microsoft SQL Server and PostgreSQL.\n\nThe repo includes a Docker Compose file for local databases and a sample\n`setup.sql` script to initialize the SQL Server databases and logins.\n\n## Table of Contents\n- Prerequisites\n- Demo Setup\n- Manual Vault configuration examples (static \u0026 dynamic roles)\n- Cleanup\n\n---\n\n## Prerequisites\n- Docker (to run database containers)\n- HashiCorp Vault CLI (tested with Vault v1.20.x)\n- `psql` client for PostgreSQL testing\n- `sqlcmd` client for running T-SQL scripts against SQL Server\n- (Optional) SQL Server Management Studio for interactive inspection\n- PowerShell 7.x is recommended for wrapper scripts in this repo (or adapt the commands for your shell)\n\n---\n\n## Demo Setup\nThese steps get the demo running locally with minimal friction.\n\n1. Clone the repository and change into it:\n\n```powershell\ngit clone \u003crepo-url\u003e\ncd vault-db-secrets-engine-demo\n```\n\n2. Start the database containers (this repo's `docker-compose.yml` will bring up SQL Server and PostgreSQL):\n\n```powershell\ndocker compose up -d\n```\n\n3. Initialize the SQL Server objects securely.\n\n- Open `setup.sql` in SSMS (Query \u003e SQLCMD Mode) and replace placeholders like `\u003cYOUR_PASSWORD\u003e` with secure values provided at runtime.\n\n4. Start a Vault dev server for testing:\n\n```powershell\nvault server -dev\n```\n\n5. Configure Vault environment variables for the CLI:\n\n```powershell\n$env:VAULT_ADDR = 'http://127.0.0.1:8200'\n$env:VAULT_TOKEN = '\u003cROOT_TOKEN_FROM_DEV_SERVER\u003e'\n```\n\n6. Enable the database secrets engine:\n\n```powershell\nvault secrets enable database\n```\n\n### MSSQL — Static credentials\nConfigure the database connection in Vault (static credentials example):\n\n```powershell\nvault write database/config/mssql_static `\n  plugin_name=mssql-database-plugin `\n  connection_url='sqlserver://{{username}}:{{password}}@localhost:1433' `\n  allowed_roles=\"mssql_static\" `\n  username=\"vault_login\" `\n  password=\"\u003cYOUR_PASSWORD\u003e\"\n```\n\nCreate a static role mapping (long rotation period used in demo to emulate static creds):\n\n```powershell\nvault write database/static-roles/mssql_static `\n  db_name=mssql_static `\n  username=\"vault_static\" `\n  rotation_statements=\"ALTER LOGIN [{{name}}] WITH PASSWORD = '{{password}}';\" `\n  rotation_period=\"876000h\"\n```\n\nRead the credential (returns username/password):\n\n```powershell\nvault read database/static-creds/mssql_static\n```\n\n### MSSQL — Dynamic credentials\nConfigure connection (use a user with privilege to create logins/users):\n\n```powershell\nvault write database/config/mssql_dynamic `\n  plugin_name=mssql-database-plugin `\n  connection_url='sqlserver://{{username}}:{{password}}@localhost:1433' `\n  allowed_roles=\"mssql_dynamic\" `\n  username=\"vault_login\" `\n  password=\"\u003cYOUR_PASSWORD\u003e\"\n```\n\nRole that creates a temporary login and user with SELECT privileges:\n\n```powershell\nvault write database/roles/mssql_dynamic `\n  db_name=mssql_dynamic `\n  creation_statements=\"CREATE LOGIN [{{name}}] WITH PASSWORD = '{{password}}'; USE [test_db_2]; CREATE USER [{{name}}] FOR LOGIN [{{name}}]; GRANT SELECT ON SCHEMA::dbo TO [{{name}}];\" `\n  revocation_statements=\"DROP USER IF EXISTS [{{name}}]; DROP LOGIN IF EXISTS [{{name}}];\" `\n  default_ttl=\"1h\" `\n  max_ttl=\"24h\"\n```\n\nGenerate dynamic credentials:\n\n```powershell\nvault read database/creds/mssql_dynamic\n```\n\n### PostgreSQL — Dynamic credentials\nConfigure connection to PostgreSQL (use a privileged account):\n\n```powershell\nvault write database/config/postgresql_dynamic `\n  plugin_name=\"postgresql-database-plugin\" `\n  allowed_roles=\"postgresql_dynamic\" `\n  connection_url=\"postgresql://{{username}}:{{password}}@localhost:5432/test_db_1\" `\n  username=\"vault_user\" `\n  password=\"\u003cYOUR_PASSWORD\u003e\" `\n  password_authentication=\"scram-sha-256\"\n```\n\nRole that creates a temporary PostgreSQL role with SELECT privileges:\n\n```powershell\nvault write database/roles/postgresql_dynamic `\n  db_name=\"postgresql_dynamic\" `\n  creation_statements=\"CREATE ROLE \\\"{{name}}\\\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO \\\"{{name}}\\\";\" `\n  default_ttl=\"1h\" `\n  max_ttl=\"24h\"\n```\n\nGenerate a credential and connect using `psql`:\n\n```powershell\n$creds = vault read -format=json database/creds/postgresql_dynamic | ConvertFrom-Json\npsql -h localhost -p 5432 -U $creds.data.username -d test_db_1\n```\n\n---\n\n## Cleanup\n- Stop and remove containers:\n\n```powershell\ndocker compose down -v\n```\n\n- Remove any generated logins/users you created during the demo (use SSMS or `sqlcmd` to run cleanup statements).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrefaria24%2Fdemo-vault-db-secrets-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrefaria24%2Fdemo-vault-db-secrets-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrefaria24%2Fdemo-vault-db-secrets-engine/lists"}