Skip to content

Instantly share code, notes, and snippets.

View GuyBarros's full-sized avatar

Guy Barros GuyBarros

View GitHub Profile
@GuyBarros
GuyBarros / kmip_counter.sh
Created October 28, 2025 18:40
script to count KMIP certificates
export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=
export VAULT_NAMESPACE=
export KMIP_PATH=kmip
# Iterate over the KMIP Secret Engine to get all Scopes
KMIP_SCOPES=$(curl -H "X-Vault-Token: ${VAULT_TOKEN}" -H "X-Vault-Request: true" "${VAULT_ADDR}/v1/${KMIP_PATH}/scope?list=true" | jq -r '.data.keys[]' )
# KMIP_SCOPES=$(curl -H "X-Vault-Token: ${VAULT_TOKEN}" -H "X-Vault-Request: true" -H "X-Vault-Namespace: ${VAULT_NAMESPACE}" "${VAULT_ADDR}/v1/${KMIP_PATH}/scope?list=true" | jq -r '.data.keys[]' )
@GuyBarros
GuyBarros / datakey.sh
Created October 27, 2025 18:01
datakey.sh
#!/usr/bin/env bash
set -euo pipefail
# --- Config (override via env or CLI) -----------------------------------------
VAULT_ADDR="${VAULT_ADDR:-http://127.0.0.1:8200}"
VAULT_TOKEN="${VAULT_TOKEN:-root}"
VAULT_NAMESPACE="${VAULT_NAMESPACE:-}" # e.g., "admin" or "" for root
TRANSIT_PATH="${TRANSIT_PATH:-transit}" # mount path of transit (e.g., "transit")
KEY_NAME="${KEY_NAME:-dek-demo}" # transit key name (must exist)
MESSAGE="${MESSAGE:-hello-envelope}" # message to encrypt
@GuyBarros
GuyBarros / hotp.sh
Created October 24, 2025 15:28
HOTP script
#!/usr/bin/env bash
set -euo pipefail
# ================== Config (env overrides allowed) ============================
VAULT_ADDR="${VAULT_ADDR:-http://127.0.0.1:8200}"
VAULT_TOKEN="${VAULT_TOKEN:?set VAULT_TOKEN}"
VAULT_NAMESPACE="${VAULT_NAMESPACE:-}" # leave empty if not using namespaces
TRANSIT_MOUNT="${TRANSIT_MOUNT:-transit}" # transit mount
HOTP_KEY_NAME="${HOTP_KEY_NAME:-hotp-demo}" # transit HMAC key name
@GuyBarros
GuyBarros / consul_instance_count.sh
Created October 16, 2025 10:27
A Script to Query a consul cluster then output a summary of services instances and a CSV files containing services names and service instance IDs
#! /bin/bash
################################
# Requirements: curl, jq
################################
## avoid the last trailling forward slash /
usage="$(basename "$0") [-a consul_http_address] [-t acl_token] [-e IS_ENTERPRISE] [-l LIST_INSTACES]
where
-a Consul HTTP(s) Address.
@GuyBarros
GuyBarros / count.sh
Created July 9, 2025 12:33
RUM Count for tfstate
#!/bin/bash
#
# Usage: Pass in a Terraform State file through a pipe
# e.g.
# cat terraform.tfstate | count.sh
# For each resource in the TF State file...
# we only count managed resources (i.e. not data sources)
# we explicitly ignore null resources (terraform_data and null_resource)
@GuyBarros
GuyBarros / get_secret_count.sh
Created January 15, 2025 13:23
script to get secret count from telemetry
#!/bin/bash
minutes=30 # Note that this script may take up to 30m to run, or longer if `minutes=30` was changed.
# The count_secrets.sh script is intended to be used to query the sys/metrics endpoint of a Vault cluster and extract the
# sum of all KV secrets counts across all namespaces. This relies on the
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#usage_gauge_period configuration not being disabled,
# and on
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus_retention_time not being set to 0.
#
@GuyBarros
GuyBarros / manual_pki.sh
Last active May 15, 2025 09:39
manual PKI creation script
export VAULT_ADDR=https://localhost:8200
export VAULT_TOKEN=root
# Root CA
vault secrets enable -path=pki_root pki
# tune to 10 years
vault secrets tune -max-lease-ttl=87600h pki_root
# Generate internal certificate
vault write -field=certificate pki_root/root/generate/internal \
@GuyBarros
GuyBarros / main.tf
Last active May 15, 2025 09:47
vault pki terraform
resource "vault_mount" "ca_root" {
path = "ca_root"
type = "pki"
max_lease_ttl_seconds = 315360000 # 10 years
}
resource "vault_pki_secret_backend_root_cert" "ca_root" {
backend = vault_mount.ca_root.path
@GuyBarros
GuyBarros / CKA.md
Created November 28, 2023 20:46
Multipass CKA single script set up
multipass launch -m2G -c2 -d5G -n "k8scp" lts --network "en0" 

K8SCP

wget https://cm.lf.training/LFS258/LFS258_V2023-09-14_SOLUTIONS.tar.xz --user=LFtraining --password=Penguin2014

tar -xvf LFS258_V2023-09-14_SOLUTIONS.tar.xz
@GuyBarros
GuyBarros / vault-non-disruptive-pki-rotation_sh
Created December 16, 2022 15:25
vault 1.11+ non disruptive pki rotation example script
#!/usr/bin/env zsh
###########
# Root CA #
###########
vault secrets enable pki
vault secrets tune -max-lease-ttl=87600h pki