Posts
Building Lab on your local environment for Vault Associate Certification
Set up a local Vagrant lab with Vault and LocalStack to practice for the HashiCorp Vault Associate certification.
Introduction
Sometimes ago in Sept 22 I just finished my vault associate certification that has been delayed many times ( maybe already 3 or 4 times rescheduled haha ). This lab helped me as everything that I need to test are in the lab including testing AWS Dynamic Secret Engine in Vault so I can test it quickly.
Sometimes it’s not enough to just read an example and documentation when we want to learn some tools. To make our learning experiences more rich and it can help us turn the wordy documentation to something that are more easier for our brain to digest.
This article has a purpose to quickly deploy what we need to testing some example by ourselves for Vault Associate Certification.
Scope
We will learn 3 things in this article, covering:
- What we need to prepare for running the lab.
- How to run the lab.
- How to access the lab.
Preparing the Environment
Configuring VirtualBox
Before configuring VirtualBox we need to make sure that our host has already have it installed. After that we need to configure the private network in VirtualBox so that we can access it using static IP and doesn’t need to do port forwarding.
config.vm.network "private_network", ip: "192.168.241.10", name: "VirtualBox Host-Only Ethernet Adapter #4"
Above are the network configuration that we use in our lab. So you need to add a new network by going to tools and choose Network:
Figure: VirtualBox host-only network configuration
After that you just need create a new network by clicking create network button:
Figure: Creating a host-only network
Change the configuration based on what you get from VirtualBox, in this case we got Name: VirtualBox Host-Only Ethernet Adapter #4 with associated subnet 192.168.241.1/24 and you need to set it in the configuration with the desired static IP in this case we choose 192.168.241.10
Other Dependencies
For other dependencies we just need Vagrant that you can easily install following tutorial from Hashicorp docs:
Install Vagrant | Vagrant | HashiCorp Developer
When you are using windows you can use chocolatey to install it quickly.
Before we start the lab you need to pull repository first from below repository and you will found there is multiple file in that repo consist of:
- Vagrantfile is a file that define deployment file for vagrant box.
- Taskfile.yaml is a file that we will use to automate script for installing dependencies and running the apps.
GitHub - EsTelite/vault-local-lab: Vault local deployment using vagrant
Running the Lab
After you finished install and prepare in step before we can continue start the lab by following below step:
-
Open CMD/PowerShell terminal and change directory to pulled repository.
-
Start vagrant by using command
vagrant upafter that it will start to bring up the virtual machine and install all packages. It will take some times, please wait patiently. If you are having a problem and got an error “Timed out while waiting for the machine to boot.” you can runvagrant haltand start againvagrant up.
Vagrant virtual machine startup Figure: Vagrant virtual machine startup
So we successfully create the box and install dependencies, after that we can do:
- SSH to our box using
vagrant sshand move to vagrant shared directory by run commandcd /vagrant/as you already on vagrant shared directory and it has Taskfile we can start service/apps that we need. - Install all dependencies using
task install-alland it will start the installation. - Start vault by starting
task start-vaultusing command and the vault will be started in dev mode, if you want to customize something just go to Taskfile and edit here. - Open a new terminal and do
vagrant sshagain, and start localstack usinglocalstack start, this will pull docker image so you need to wait a bit for the localstack to be started.
Figure: Starting Vault with Task
Figure: LocalStack startup log
Interacting with the Lab
For interacting with the cli we can access it using vagrant ssh as usual. As for accessing other services that you need in VM on Host you can access it via IP Static that we already set before.
Below are the example when we want to access Vault UI, we can directly access it on 192.168.241.10:8299 as vault listen on localhost:8200 so we need to create socat for this, as for other service that listen on all interface you doesn’t need to setup forwarding.
Figure: Vault web UI
For accessing localstack we can access it using awslocal, for example we want to list s3 bucket we can do it using awslocal s3 ls.
Figure: Using awslocal to list S3 buckets
Conclusion
Using local lab as one of means to assist learning help me to learn how the tools works and quickly testing things as when we are using real environment it takes time to prepare the environment.
Hope this automated deployment can help you prepare certification or learn how the tools work quickly.
If you have any question don’t hesitate to ask me on linkedin at LinkedIn or just ask at the medium comment.
Originally published on Medium.
Category: technology