🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Hashicorp Vault: Working with Vault Leases

# First of all we are going to start Vault in development mode
vault server -dev
# Now set your Vault address environment variable
export VAULT_ADDR=http://127.0.0.1:8200
# Set the root token variable
root_token=ROOT_TOKEN_VALUE
# And log into Vault using the root token
vault login $root_token
# Re-enable consul secrets engine
vault secrets enable consul
# Get consul up and running
# Create a data subdirectory in m8
mkdir data
# Launch consul server instance
consul agent -bootstrap -config-file="consul-config.hcl" -bind="127.0.0.1"
# From a separate terminal window run the following
consul acl bootstrap
# Set CONSUL_HTTP_TOKEN to SecretID
# Linux and MacOS
export CONSUL_HTTP_TOKEN=SECRETID_VALUE
# Next we have to create a policy and role for new tokens
# that Vault will generate on Consul
consul acl policy create -name=web -rules @web-policy.hcl
# Now we'll configure out Consul secrets engine
vault write consul/config/access address="http://127.0.0.1:8500" token=$CONSUL_HTTP_TOKEN
vault write consul/roles/web name=web policies=web ttl=3600 max_ttl=7200
# And finally generate a bunch of leases to work with
vault read consul/creds/web
# Let's renew one of the leases for 30 minutes
vault lease renew -increment=30m LEASE_ID
vault lease renew -increment=30m consul/creds/web/neZNeIkXoxLdFLDZ5n9FTy3z
# Now get the properties of the lease
vault write sys/leases/lookup lease_id=LEASE_ID
vault write sys/leases/lookup lease_id=consul/creds/web/neZNeIkXoxLdFLDZ5n9FTy3z
# What if we exceed the lease max ttl?
vault lease renew -increment=120m consul/creds/web/neZNeIkXoxLdFLDZ5n9FTy3z
# Now we can try and revoke one of the leases
# First we'll get a list of active leases
vault list sys/leases/lookup/consul/creds/web/
# Now revoke the lease
vault lease revoke LEASE_ID
vault lease revoke consul/creds/web/neZNeIkXoxLdFLDZ5n9FTy3z
# Confirm our lease is gone
# What if we want to revoke all of them? Prefix time
vault lease revoke -prefix consul/creds/web/
# Confirm that all the leases are gone
vault list sys/leases/lookup/consul/creds/web/
## server.hcl
ui = true
server = true
bootstrap_expect = 1
datacenter = "dc1"
data_dir = "./data"
acl = {
enabled = true
default_policy = "deny"
enable_token_persistence = true
}
service "web" {
policy = "read"
}
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x