-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging Vault integration
- Loading branch information
Showing
37 changed files
with
696 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,9 @@ microK8sdown: | |
kubectl apply -f cicd/K8s/web -n micro | ||
kdelete: | ||
kubectl delete -f $FOLDER -n micro | ||
## Port froward to access micro running in K8s | ||
kmicroportfwd: | ||
kubectl port-forward svc/proxy -n micro 8081:443 | ||
|
||
# ------------------------------------------------------------------------------------- | ||
|
||
|
@@ -204,3 +207,74 @@ authviaapigateway: | |
--data-raw '{"pwd":"1234","email":"[email protected]"}' | ||
|
||
|
||
# ------------------------------------------------------------------------------------- | ||
|
||
# Run Micro in K8s with Vault for service secret management | ||
|
||
# ---- Setup Vault ------ | ||
|
||
# init secrets and K8s auth in Vault | ||
vkubinit: | ||
kubectl cp vault/scripts vault-0:/vault/file/ | ||
kubectl exec vault-0 -- /vault/file/scripts/setup.sh $$VAULT_TOKEN | ||
|
||
# Populate secrets, create roles and policies | ||
vkubsetup: | ||
kubectl cp vault/policies vault-0:/vault/file/ | ||
kubectl cp vault/scripts vault-0:/vault/file/ | ||
kubectl exec vault-0 -- /vault/file/scripts/allServices.sh $$VAULT_TOKEN | ||
|
||
# ---- Integrate Vault with App ------ | ||
|
||
# Apply patches to the services' deployments so they are visible to the Vault Agent | ||
# This is done after the pods are already deployed | ||
vkubpatchdeploy: | ||
kubectl apply -f cicd/K8s/vault/serviceAccount -n micro | ||
kubectl patch deployment audit-latest -n micro --patch "$$(cat cicd/K8s/vault/patch/auditsrv-deployment-patch.yaml)" | ||
kubectl patch deployment customer-latest -n micro --patch "$$(cat cicd/K8s/vault/patch/customersrv-deployment-patch.yaml)" | ||
kubectl patch deployment product-latest -n micro --patch "$$(cat cicd/K8s/vault/patch/productsrv-deployment-patch.yaml)" | ||
kubectl patch deployment user-latest -n micro --patch "$$(cat cicd/K8s/vault/patch/usersrv-deployment-patch.yaml)" | ||
kubectl patch deployment promotion-latest -n micro --patch "$$(cat cicd/K8s/vault/patch/promotionsrv-deployment-patch.yaml)" | ||
|
||
# Remove service accounts used to integrate with Vault | ||
# This is done after application is brought down | ||
vkubdelserviceaccounts: | ||
kubectl delete -f cicd/K8s/vault/serviceAccount -n micro | ||
|
||
# ------ Remove setup from Vault ------- | ||
|
||
# Remove secrets, create roles and policies | ||
vkubteardown: | ||
kubectl cp vault/scripts vault-0:/vault/file/ | ||
kubectl exec vault-0 -- /vault/file/scripts/deleteAllSrv.sh $$VAULT_TOKEN | ||
make vkubcleancontainer | ||
|
||
# Remove secret engine and K8s auth in Vault | ||
vkubsetupdelete: | ||
kubectl cp vault/scripts vault-0:/vault/file/ | ||
kubectl exec vault-0 -- /vault/file/scripts/deleteSetup.sh $$VAULT_TOKEN | ||
make vkubcleancontainer | ||
|
||
|
||
# ---- Vault Misc -------- | ||
|
||
# Unseal Vault on startup | ||
vkubunseal: | ||
kubectl exec -ti vault-0 -- vault operator unseal $$KEY | ||
# Enable Vault UI port | ||
vkubui: | ||
kubectl port-forward vault-0 8100:8200 | ||
|
||
|
||
# Commands to test services with Vault secrets and no connections in env vars | ||
vtestnosecrets: | ||
micro run --env_vars 'MICRO_BROKER=nats,DISABLE_AUDIT_RECORDS=false' --name user user/server | ||
micro run --env_vars 'MICRO_BROKER=nats' --name audit audit/server | ||
micro run --env_vars 'MICRO_BROKER=nats,DISABLE_AUDIT_RECORDS=false' --name product product/server | ||
micro run --env_vars 'MICRO_BROKER=nats,DISABLE_AUDIT_RECORDS=false' --name customer customer/server | ||
micro run --env_vars 'MICRO_BROKER=nats,DISABLE_AUDIT_RECORDS=false,MICRO_STORE=redis' --name promotion promotion/server | ||
|
||
# Clean scripts and policies in Vault container | ||
vkubcleancontainer: | ||
kubectl exec vault-0 -- rm -rf /vault/file/scripts/ | ||
kubectl exec vault-0 -- rm -rf /vault/file/policies/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject: "true" | ||
vault.hashicorp.com/role: "gotempm-auditsrv" | ||
vault.hashicorp.com/agent-pre-populate-only: "true" | ||
vault.hashicorp.com/agent-requests-cpu: "100m" | ||
vault.hashicorp.com/agent-inject-secret-timescaledb.txt: "gotempmkv/data/database/timescaledb/auditsrv" | ||
vault.hashicorp.com/agent-inject-template-timescaledb.txt: | | ||
{{- with secret "gotempmkv/data/database/timescaledb/auditsrv" -}} | ||
export DB_CONNECT="postgresql://{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}/{{ .Data.data.dbname }}?application_name={{ .Data.data.application_name }}" | ||
{{- end -}} | ||
vault.hashicorp.com/agent-inject-secret-nats.txt: "gotempmkv/data/broker/nats/auditsrv" | ||
vault.hashicorp.com/agent-inject-template-nats.txt: | | ||
{{- with secret "gotempmkv/data/broker/nats/auditsrv" -}} | ||
export MICRO_BROKER_ADDRESS="{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}" | ||
{{- end -}} | ||
spec: | ||
serviceAccountName: gotempm-auditsrv | ||
containers: | ||
- name: audit | ||
command: ['sh', '-c', 'source /vault/secrets/timescaledb.txt && source /vault/secrets/nats.txt && ./loader' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject: "true" | ||
vault.hashicorp.com/role: "gotempm-customersrv" | ||
vault.hashicorp.com/agent-pre-populate-only: "true" | ||
vault.hashicorp.com/agent-requests-cpu: "100m" | ||
vault.hashicorp.com/agent-inject-secret-arangodb.txt: "gotempmkv/data/database/arangodb/customersrv" | ||
vault.hashicorp.com/agent-inject-template-arangodb.txt: | | ||
{{- with secret "gotempmkv/data/database/arangodb/customersrv" -}} | ||
export DB_USER="{{ .Data.data.username }}" | ||
export DB_ADDRESS="{{ .Data.data.server }}" | ||
export DB_PASS="{{ .Data.data.password }}" | ||
{{- end -}} | ||
vault.hashicorp.com/agent-inject-secret-nats.txt: "gotempmkv/data/broker/nats/customersrv" | ||
vault.hashicorp.com/agent-inject-template-nats.txt: | | ||
{{- with secret "gotempmkv/data/broker/nats/customersrv" -}} | ||
export MICRO_BROKER_ADDRESS="{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}" | ||
{{- end -}} | ||
spec: | ||
serviceAccountName: gotempm-customersrv | ||
containers: | ||
- name: customer | ||
command: ['sh', '-c', 'source /vault/secrets/arangodb.txt && source /vault/secrets/nats.txt && ./loader' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject: "true" | ||
vault.hashicorp.com/role: "gotempm-productsrv" | ||
vault.hashicorp.com/agent-pre-populate-only: "true" | ||
vault.hashicorp.com/agent-requests-cpu: "100m" | ||
vault.hashicorp.com/agent-inject-secret-arangodb.txt: "gotempmkv/data/database/arangodb/productsrv" | ||
vault.hashicorp.com/agent-inject-template-arangodb.txt: | | ||
{{- with secret "gotempmkv/data/database/arangodb/productsrv" -}} | ||
export DB_USER="{{ .Data.data.username }}" | ||
export DB_ADDRESS="{{ .Data.data.server }}" | ||
export DB_PASS="{{ .Data.data.password }}" | ||
{{- end -}} | ||
vault.hashicorp.com/agent-inject-secret-nats.txt: "gotempmkv/data/broker/nats/productsrv" | ||
vault.hashicorp.com/agent-inject-template-nats.txt: | | ||
{{- with secret "gotempmkv/data/broker/nats/productsrv" -}} | ||
export MICRO_BROKER_ADDRESS="{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}" | ||
{{- end -}} | ||
spec: | ||
serviceAccountName: gotempm-productsrv | ||
containers: | ||
- name: product | ||
command: ['sh', '-c', 'source /vault/secrets/arangodb.txt && source /vault/secrets/nats.txt && ./loader' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject: "true" | ||
vault.hashicorp.com/role: "gotempm-promotionsrv" | ||
vault.hashicorp.com/agent-pre-populate-only: "true" | ||
vault.hashicorp.com/agent-requests-cpu: "100m" | ||
vault.hashicorp.com/agent-inject-secret-postgresql.txt: "gotempmkv/data/database/postgresql/promotionsrv" | ||
vault.hashicorp.com/agent-inject-template-postgresql.txt: | | ||
{{- with secret "gotempmkv/data/database/postgresql/promotionsrv" -}} | ||
export POSTGRES_CONNECT="postgresql://{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}/{{ .Data.data.dbname }}?application_name={{ .Data.data.application_name }}" | ||
{{- end -}} | ||
vault.hashicorp.com/agent-inject-secret-nats.txt: "gotempmkv/data/broker/nats/promotionsrv" | ||
vault.hashicorp.com/agent-inject-template-nats.txt: | | ||
{{- with secret "gotempmkv/data/broker/nats/promotionsrv" -}} | ||
export MICRO_BROKER_ADDRESS="{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}" | ||
{{- end -}} | ||
vault.hashicorp.com/agent-inject-secret-redis.txt: "gotempmkv/data/database/redis/promotionsrv" | ||
vault.hashicorp.com/agent-inject-template-redis.txt: | | ||
{{- with secret "gotempmkv/data/database/redis/promotionsrv" -}} | ||
export MICRO_STORE_ADDRESS="redis://:{{ .Data.data.password }}@{{ .Data.data.server }}:6379" | ||
{{- end -}} | ||
spec: | ||
serviceAccountName: gotempm-promotionsrv | ||
containers: | ||
- name: promotion | ||
command: ['sh', '-c', 'source /vault/secrets/postgresql.txt && source /vault/secrets/nats.txt && source /vault/secrets/redis.txt && ./loader' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject: "true" | ||
vault.hashicorp.com/role: "gotempm-usersrv" | ||
vault.hashicorp.com/agent-pre-populate-only: "true" | ||
vault.hashicorp.com/agent-requests-cpu: "100m" | ||
vault.hashicorp.com/agent-inject-secret-postgresql.txt: "gotempmkv/data/database/postgresql/usersrv" | ||
vault.hashicorp.com/agent-inject-template-postgresql.txt: | | ||
{{- with secret "gotempmkv/data/database/postgresql/usersrv" -}} | ||
export POSTGRES_CONNECT="postgresql://{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}/{{ .Data.data.dbname }}?application_name={{ .Data.data.application_name }}" | ||
{{- end -}} | ||
vault.hashicorp.com/agent-inject-secret-nats.txt: "gotempmkv/data/broker/nats/usersrv" | ||
vault.hashicorp.com/agent-inject-template-nats.txt: | | ||
{{- with secret "gotempmkv/data/broker/nats/usersrv" -}} | ||
export MICRO_BROKER_ADDRESS="{{ .Data.data.username }}:{{ .Data.data.password }}@{{ .Data.data.server }}" | ||
{{- end -}} | ||
spec: | ||
serviceAccountName: gotempm-usersrv | ||
containers: | ||
- name: user | ||
command: ['sh', '-c', 'source /vault/secrets/postgresql.txt && source /vault/secrets/nats.txt && ./loader' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: gotempm-auditsrv |
4 changes: 4 additions & 0 deletions
4
cicd/K8s/vault/serviceAccount/customersrv-serviceaccount.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: gotempm-customersrv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: gotempm-productsrv |
4 changes: 4 additions & 0 deletions
4
cicd/K8s/vault/serviceAccount/promotionsrv-serviceaccount.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: gotempm-promotionsrv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: gotempm-usersrv |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.