Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit 9be4068

Browse files
author
Riaan Nolan
committed
Merge branch 'feature/vault-updates' into 'master'
some updates to vault and postgres and some readme cleanups See merge request all-staff/hashiqube!117
1 parent f7a0383 commit 9be4068

File tree

3 files changed

+93
-39
lines changed

3 files changed

+93
-39
lines changed

README.md

+14-30
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ HashiCorp blog post about HashiQube: https://www.hashicorp.com/resources/hashiqu
88
HashiQube website: https://servian.github.io/hashiqube <br />
99
HashiQube github: https://github.com/servian/hashiqube <br />
1010
HashiQube youtube: https://www.youtube.com/watch?v=6jGDAGWaFiw
11+
HashiQube medium: https://medium.com/search?q=hashiqube
1112

1213
## HashiQube runs all HashiCorp's products
1314
![HashiQube](images/thestack.png?raw=true "HashiQube")
@@ -30,11 +31,13 @@ Thanks to the flexibility of the HashiCorp products there is no need wonder how
3031
| mac apple ||||
3132

3233
## Instructions
33-
* Vagrant - Please download __Vagrant__ from https://www.vagrantup.com/downloads.html and install
34+
:bulb: Docker is the Default and preferred way to run Hashiqube
35+
3436
* Docker - Please download __Docker__ from https://www.docker.com/products/docker-desktop and install
37+
* Vagrant - Please download __Vagrant__ from https://www.vagrantup.com/downloads.html and install
3538
* Virtualbox (Optional) - Please download __Virtualbox__ from https://www.virtualbox.org/wiki/Downloads and install
3639
* Using `git` - clone this repo `git clone $repo .` [__What is Git?__](git/#git)
37-
* Inside the local repo folder, do `vagrant up --provision --provider docker` - This will setup, Vault, Nomad, Consul, Terraform, Localstack and Docker
40+
* Inside the local repo folder, do `vagrant up --provision` - This will setup, Vault, Nomad, Consul, Terraform, Localstack and Docker
3841
* Documentation locally available at http://localhost:3333
3942

4043
## Components
@@ -73,29 +76,7 @@ Please create the following file: __/etc/vbox/networks.conf__ with the following
7376
* 2001::/64
7477
```
7578

76-
and re-run `vagrant up --provision --provider docker`
77-
78-
## Dependencies
79-
To get started we are now going to install some core dependencies to get the Lab started, you need to install
80-
below dependencies before you can do anything
81-
82-
__Mac Users only, Windows Users can skip this step__
83-
Let's first check if we have an __M1 Mac__, if that is the case the __virtualbox__ provider will not work.
84-
85-
Click on the Apple Icon top left
86-
![About this Mac](images/mac_apple_icon.png?raw=true "About this Mac")
87-
88-
and click on __About this Mac__
89-
90-
If you see an __Intel__ chip, you can proceed with the `virtualbox` provider.
91-
![About this Mac Intel](images/mac_intel.png?raw=true "About this Mac Intel")
92-
93-
If you see an __Apple M1__ chip, please ensure you specify the environment variable and the provider to be docker.
94-
```
95-
vagrant plugin uninstall vagrant-hostsupdater # the hostsupdator plugin does not work with the docker provider
96-
```
97-
98-
![About this Mac M1](images/mac_m1.png?raw=true "About this Mac M1")
79+
and re-run `vagrant up --provision`
9980

10081
#### Docker Desktop
10182
Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to build and share containerized applications and microservices. It's a graphical user interface for the docker service.
@@ -115,7 +96,7 @@ Now that docker has been installed we need to ensure that your docker environmen
11596

11697
![Docker Desktop Resources](images/docker_installed_resources.png?raw=true "Docker Desktop Resources")
11798

118-
* Please ensure that you give your docker daemon at least __12G of RAM__ and sufficient disk space
99+
* Please ensure that you give your docker daemon at least __8G of RAM__ and sufficient disk space
119100

120101
## Consul DNS
121102
__Local DNS via Consul__ <br />
@@ -128,11 +109,11 @@ Now you can use DNS like nomad.service.consul:9999 vault.service.consul:9999 via
128109

129110
## Pre-requisites
130111
* 10GB of disk space
131-
* 4GB RAM
112+
* 8GB RAM
132113
* Admin rights / sudo (you will be asked to update ETC Host file)
133114
* Virtualbox
134115
* Vagrant
135-
* `vagrant up --provision --provider docker`
116+
* `vagrant up --provision`
136117

137118
## Additional Information
138119
* [__Multi Cloud__](multi-cloud/#terraform-hashicorp-hashiqube) - Hashiqube on AWS, GCP and Azure (Clustered) https://registry.terraform.io/modules/star3am/hashiqube/hashicorp/latest
@@ -166,7 +147,7 @@ For Documentation please open http://localhost:3333 in your browser
166147
* Vault http://localhost:8200
167148
* Nomad http://localhost:4646
168149
* Consul http://localhost:8500
169-
* Localstack http://localhost:8080
150+
* Docsify http://localhost:3333
170151

171152
## HashiQube runs all HashiCorp's products
172153
![HashiQube](images/hashicorp_products.png?raw=true "HashiQube")
@@ -183,7 +164,7 @@ For Documentation please open http://localhost:3333 in your browser
183164
* Fabio http://localhost:9999
184165

185166
### Vagrant Basic Usage
186-
* vagrant up --provision OR vagrant up --provision-with bootstrap|nomad|consul|vault|docker|ldap --provider docker
167+
* vagrant up --provision OR vagrant up --provision-with bootstrap|nomad|consul|vault|docker|ldap
187168
* vagrant global-status # to see which VMs are active
188169
* vagrant global-status --prune # to remove stale VMs from Vagrant cache
189170
* vagrant status # vagrant status
@@ -255,6 +236,7 @@ __Solution__ Ensure the following contents are present in `/etc/vbox/networks.co
255236
For suggestions, feedback and queries please branch or and submit a Pull Request or directly contact the architects of the HashiQube via email:
256237

257238
Lead Automation Architect [riaan.nolan@servian.com](mailto:riaan.nolan@servian.com)
239+
https://www.linkedin.com/in/riaannolan/
258240

259241
## Contributors and Special mentions
260242
A Very special mention to HashiQube's contributors, Thank You All for your help, suggestions and contributions no matter how small <3
@@ -264,6 +246,8 @@ A Very special mention to HashiQube's contributors, Thank You All for your help,
264246
- Ringo Chan
265247
- Ehsan Mirzaei
266248
- Greg Luxford
249+
- Byron Tuckett
250+
- Lane Birmingham
267251

268252
## Videos
269253
Videos were made with asciinema https://asciinema.org/

database/postgresql.sh

+67-8
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,104 @@
11
#!/bin/bash
22
# https://hub.docker.com/_/postgres
3-
# https://www.vaultproject.io/docs/secrets/databases/postgresql
3+
# https://www.vaultproject.io/docs/secrets/databases/postgresql
4+
5+
echo -e '\e[38;5;198m'"++++ "
6+
echo -e '\e[38;5;198m'"++++ Ensure postgres docker container is running"
7+
echo -e '\e[38;5;198m'"++++ "
48
sudo docker stop postgres
59
sudo docker rm postgres
610
yes | sudo docker system prune -a
711
yes | sudo docker system prune --volumes
812
sudo docker run --name postgres -e POSTGRES_USER=root \
913
-e POSTGRES_PASSWORD=rootpassword \
1014
-d -p 5432:5432 postgres
15+
1116
sleep 15;
1217

13-
// Vagrant install as a dependency
14-
bash /vagrant/hashicorp/vault.sh
18+
echo -e '\e[38;5;198m'"++++ "
19+
echo -e '\e[38;5;198m'"++++ Ensure postgresql-client is installed"
20+
echo -e '\e[38;5;198m'"++++ "
21+
sudo apt-get install -y postgresql-client libpq-dev python3.9-dev
1522

23+
if pgrep -x "vault" >/dev/null
24+
then
25+
echo -e '\e[38;5;198m'"++++ "
26+
echo -e '\e[38;5;198m'"++++ Vault is running"
27+
echo -e '\e[38;5;198m'"++++ "
28+
echo -e '\e[38;5;198m'""
29+
echo -e '\e[38;5;198m'"++++ "
30+
echo -e '\e[38;5;198m'"++++ Vault status"
31+
echo -e '\e[38;5;198m'"++++ "
32+
vault status
33+
else
34+
echo -e '\e[38;5;198m'"++++ "
35+
echo -e '\e[38;5;198m'"++++ Ensure Vault is running.."
36+
echo -e '\e[38;5;198m'"++++ "
37+
sudo bash /vagrant/hashicorp/vault.sh
38+
echo -e '\e[38;5;198m'"++++ "
39+
echo -e '\e[38;5;198m'"++++ Vault status"
40+
echo -e '\e[38;5;198m'"++++ "
41+
vault status
42+
fi
43+
44+
echo -e '\e[38;5;198m'"++++ "
1645
echo -e '\e[38;5;198m'"++++ Show users in database"
46+
echo -e '\e[38;5;198m'"++++ "
1747
sudo docker exec postgres psql -U root -c '\du'
48+
49+
sleep 15;
50+
51+
echo -e '\e[38;5;198m'"++++ "
52+
echo -e '\e[38;5;198m'"++++ Vault token lookup"
53+
echo -e '\e[38;5;198m'"++++ "
54+
vault token lookup
55+
56+
echo -e '\e[38;5;198m'"++++ "
1857
echo -e '\e[38;5;198m'"++++ Enable Vault Database PostgreSQL secret engine"
58+
echo -e '\e[38;5;198m'"++++ "
1959
vault secrets enable database
60+
61+
echo -e '\e[38;5;198m'"++++ "
2062
echo -e '\e[38;5;198m'"++++ Configure PostgreSQL "
63+
echo -e '\e[38;5;198m'"++++ "
2164
vault write database/config/postgresql \
2265
plugin_name=postgresql-database-plugin \
2366
allowed_roles=postgresql-role \
24-
connection_url='postgresql://root:rootpassword@localhost:5432/postgres?sslmode=disable'
67+
connection_url='postgresql://root:rootpassword@localhost:5432/postgres?sslmode=disable'
68+
69+
echo -e '\e[38;5;198m'"++++ "
2570
echo -e '\e[38;5;198m'"++++ Create a role"
71+
echo -e '\e[38;5;198m'"++++ "
2672
vault write database/roles/postgresql-role db_name=postgresql \
2773
creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
2874
GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";" \
29-
default_ttl=1h max_ttl=24h
75+
default_ttl=1h max_ttl=24h
76+
77+
echo -e '\e[38;5;198m'"++++ "
3078
echo -e '\e[38;5;198m'"++++ Create policy"
79+
echo -e '\e[38;5;198m'"++++ "
3180
vault policy write apps -<<EOF
3281
# Get credentials from the database secrets engine
3382
path "database/creds/postgresql-role" {
3483
capabilities = [ "read" ]
3584
}
3685
EOF
37-
echo -e '\e[38;5;198m'"++++ Create new token"
38-
# Create a new token with apps policy attached
39-
# vault token create -policy="apps"
86+
87+
echo -e '\e[38;5;198m'"++++ "
88+
echo -e '\e[38;5;198m'"++++ Create a new token with apps policy attached"
89+
echo -e '\e[38;5;198m'"++++ "
4090
VAULT_TOKEN_APPS=$(vault token create -policy="apps" -field token)
91+
92+
echo -e '\e[38;5;198m'"++++ "
4193
echo -e '\e[38;5;198m'"++++ New Token: $VAULT_TOKEN_APPS"
94+
echo -e '\e[38;5;198m'"++++ "
95+
96+
echo -e '\e[38;5;198m'"++++ "
4297
echo -e '\e[38;5;198m'"++++ Create new connection with token"
98+
echo -e '\e[38;5;198m'"++++ "
4399
VAULT_TOKEN=$VAULT_TOKEN_APPS vault read database/creds/postgresql-role
100+
101+
echo -e '\e[38;5;198m'"++++ "
44102
echo -e '\e[38;5;198m'"++++ Now show users in database again with new user created"
103+
echo -e '\e[38;5;198m'"++++ "
45104
sudo docker exec postgres psql -U root -c '\du'

hashicorp/vault.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ echo -e '\e[38;5;198m'"CPU is $ARCH"
3030
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install curl unzip jq
3131
# only do if vault is not found
3232
if [ ! -f /usr/local/bin/vault ]; then
33-
33+
34+
echo -e '\e[38;5;198m'"++++ "
3435
echo -e '\e[38;5;198m'"++++ Vault not installed, installing.."
36+
echo -e '\e[38;5;198m'"++++ "
3537

3638
LATEST_URL=$(curl -sL https://releases.hashicorp.com/vault/index.json | jq -r '.versions[].builds[].url' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | egrep -v 'rc|ent|beta' | egrep "linux.*$ARCH" | sort -V | tail -n 1)
3739
wget -q $LATEST_URL -O /tmp/vault.zip
3840

3941
mkdir -p /usr/local/bin
4042
(cd /usr/local/bin && unzip /tmp/vault.zip)
43+
echo -e '\e[38;5;198m'"++++ "
4144
echo -e '\e[38;5;198m'"++++ Installed `/usr/local/bin/vault --version`"
45+
echo -e '\e[38;5;198m'"++++ "
4246

4347
# enable command autocompletion
4448
vault -autocomplete-install
@@ -130,8 +134,11 @@ EOF
130134
sleep 20
131135
vault operator init > /etc/vault/init.file
132136

137+
echo -e '\e[38;5;198m'"++++ "
133138
echo -e '\e[38;5;198m'"++++ Vault http://localhost:8200/ui and enter the following codes displayed below"
139+
echo -e '\e[38;5;198m'"++++ "
134140
echo -e '\e[38;5;198m'"++++ Auto unseal vault"
141+
echo -e '\e[38;5;198m'"++++ "
135142
for i in $(cat /etc/vault/init.file | grep Unseal | cut -d " " -f4 | head -n 3); do vault operator unseal $i; done
136143
vault status
137144
cat /etc/vault/init.file
@@ -164,11 +171,15 @@ else
164171
else
165172
sed -i "s%VAULT_ADDR=.*%VAULT_ADDR=http://127.0.0.1:8200%g" /etc/environment
166173
fi
174+
echo -e '\e[38;5;198m'"++++ "
167175
echo -e '\e[38;5;198m'"++++ Vault already installed and running"
168176
echo -e '\e[38;5;198m'"++++ Vault http://localhost:8200/ui and enter the following codes displayed below"
177+
echo -e '\e[38;5;198m'"++++ "
169178
# check vault status
170179
# vault status
180+
echo -e '\e[38;5;198m'"++++ "
171181
echo -e '\e[38;5;198m'"++++ Auto unseal vault"
182+
echo -e '\e[38;5;198m'"++++ "
172183
for i in `cat /etc/vault/init.file | grep Unseal | cut -d " " -f4 | head -n 3`; do vault operator unseal $i; done
173184
vault status
174185
cat /etc/vault/init.file

0 commit comments

Comments
 (0)