Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created November 9, 2018 08:51
Show Gist options
  • Save yurenju/d3effbfc0ab7c4c2361a13cd4556e7ce to your computer and use it in GitHub Desktop.
Save yurenju/d3effbfc0ab7c4c2361a13cd4556e7ce to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
# Load .env variables
export $(egrep -v '^#' .env | xargs)
vault secrets enable database
vault write database/config/my-database \
plugin_name=mysql-database-plugin \
connection_url="{{username}}:{{password}}@tcp(mysql:3306)/" \
allowed_roles=my-role username=${MYSQL_ROOT_USERNAME} password=${MYSQL_ROOT_PASSWORD}
vault write database/roles/my-role \
db_name=my-database \
creation_statements="CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';GRANT SELECT ON *.* TO '{{name}}'@'%';" \
default_ttl="10s" \
max_ttl="20s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment