Coder Social home page Coder Social logo

dawright22 / vault-azure-python-mysql-webapp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from assareh/vault-azure-python-mysql-webapp

0.0 0.0 0.0 33.96 MB

Vault demo with python webapp and mysql on azure with transform, transit, db secret engine, dynamic credentials, encryption and jwt auth and machine identities

Shell 56.16% HCL 43.84%

vault-azure-python-mysql-webapp's Introduction

Dynamic Secrets Retrieval in Microsoft Azure App Service with HashiCorp Vault

Read the companion blog post on the HashiCorp Solutions Engineering blog!

This HashiCorp Terraform and Vault demo includes the following:

  1. A Python webapp running on Azure App Service (code is here)
  2. A MySQL database used by the webapp (running as a Docker container on the Vault demo VM)
  3. A Vault demo VM

This demo includes:

  • Azure and JWT auth methods and includes Vault auto unseal using Azure Key Vault
  • Azure machine identity
  • Database secret engine with MySQL
  • Dynamic credentials for MySQL
  • Transit and Transform secret engines
  • Encryption as a service

Prequisites / Dependencies

Terraform variables

A few of the Terraform variables in this configuration have defaults that you can use. Others are required and must be configured. The variables are documented via the descriptions in the variables.tf file, so we won't repeat the definitions here. The variables you must define do not have defaults defined in variables.tf. The variables you must define are listed in the terraform.tfvars.example. You can make a copy of this file and save it as terraform.tfvars, or you can define these variables as TF_VAR_<variable_name>.

Running this Terraform code

Please don't store credentials in plain text and please do NOT check them into GitHub or any other VCS provider, be it public or privately hosted!

Initialize Terraform

terraform init

Plan

terraform plan

Apply

terraform apply

Outputs

  • vault_https_addr - When you run Terraform, you'll get the public web address of the Vault instance that you've provisioned.
  • vault_ssh_addr - When you run Terraform, you'll get the public SSH address of the Vault instance that you've provisioned.
  • webapp_url - When you run Terraform, you'll get the public web address of the web app that you've provisioned.

Accessing the instance

You can SSH into the instance that was provisioned via the vault_ssh_addr output which provides the command with username using the SSH key you provided.

Accessing Vault

When Vault is initialized, the initial root token is stored in the /home/azureuser/root_token file and the recovery key is stored in the /home/azureuser/recovery_key file. Additionally, the initial root token is saved as the VAULT_ROOT_TOKEN environment variable in the /etc/vault.d/vaultrc file. You can source this file in order to interact with Vault on the instance.

sudo su -
. /etc/vault.d/vaultrc
vault status
VAULT_TOKEN=$VAULT_ROOT_TOKEN vault read sys/license

Notes:

  • The Vault VM takes a few minutes to configure after provisioning has completed.
  • The web app on Azure App Service takes a few minutes to spin up the first time you try to view it.
  • Due to the way IP addresses are assigned in Azure, outputs will appear following the second terraform apply. Per https://www.terraform.io/docs/providers/azurerm/r/public_ip.html#ip_address
  • If you'd like to access the Vault demo VM directly, the root token will be saved in the azureuser home folder of the Vault demo VM.

Troubleshooting

The purpose of this configuration is to allow you to provision Vault Enterprise fully unattended. If something goes wrong, you can examine the following items to see what may have gone wrong.

Where you ran Terraform

terraform show

On the instance

  • Userdata install and configure script logs in /var/log/user-data.log
  • Vault configuration: /etc/vault.d/vault.hcl
  • Vault PKI certs: /opt/vault/tls/
  • Vault data: /opt/vault/data/
  • Vault audit log in /var/log/vault_audit.log
  • You can view the webapp logs using the Azure CLI with az webapp log tail after enabling logging, or in the Azure Portal on the App Service > Container Settings pane.

vault-azure-python-mysql-webapp's People

Contributors

assareh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.