blablacar/vaultprov is a custom provider to generate and store random secrets directly into Vault without storing any
sensitive value into Terraform state. Secrets metadata are still stored into Terraform state as for any other resources,
only the secret itself isn't.
There are two resources: vaultprov_random_secret for generating random secrets and vaultprov_keypair_secret for generating cryptographic keypairs.
Generate fully random bytes that can be used as secret keys for symmetric cryptography operation (encryption, MAC).
resource "vaultprov_random_secret" "my_key" {
path = "/secrets/foo/bar"
length = 32
metadata = {
owner = "my_team"
some-key = "some-value"
}
}vaultprov_random_secret attributes:
path: path of the generated Secret into Vault. Must be a path to a KV v2 mount. Used as ID for the resourcelength: length of the secret in bytes. Default is32metadata: Key/value (stringonly) custom metadata that will be added to the Vault Secretforce_destroy: If set totrue, removing the resource will delete the secret and all versions in Vault. If set tofalseor not defined, removing the resource will fail.
The resulting Vault secret will have 2 additional metadata:
secret_type: will be set torandom_secretsecret_length: secret length in bytes
Once created, only metadata can be updated without deleting the secret. path can't be changed afterward.
Changing length will cause the secret to be deleted and re-created.
vaultprov_random_secret resource, every secret's versions and metadata will be permanently
deleted.
Generate a Curve25519 keypair that can be used for asymmetric cryptography operation (key exchange, signatures). The private and public keys are stored as two separate Vault secrets.
resource "vaultprov_keypair_secret" "my_keypair" {
base_path = "/secrets/bar/foo"
type = "curve25519"
metadata = {
owner = "my_team"
some-key = "some-value"
}
}vaultprov_keypair_secret attributes:
base_path: base path of the keypair secrets in Vault. Two Vault secrets will be created at this path: one for the private key (private) and one for the public one (public). For example, for abase_path/secrets/bar/foo, the keypair secrets will be/secrets/bar/foo/privateand/secrets/bar/foo/public. Serves as the resource id.type: type of keypair to create. Only supported value for now iscurve25519(default)metadata: Key/value (stringonly) custom metadata that will be added to the Vault Secretsforce_destroy: If set totrue, removing the resource will delete the secrets and all versions in Vault. If set tofalseor not defined, removing the resource will fail.
The resulting Vault secrets will have additional metadata:
secret_type: will be set tocurve25519secret_length: secret length in bytes (32 for Curve25519)keypair_linked_secret_path: path to the other part of the keypairkeypair_part: eitherprivateorpublic
Once created, only metadata can be updated without deleting the secrets. base_path and type can't be changed afterward.
vaultprov_keypair_secret resource, both secrets' versions and metadata will be permanently
deleted.
In order to communicate with a Vault cluster, the provider needs to be configured accordingly. Only Kubernetes authentication is supported.
terraform {
required_providers {
vaultprov = {
source = "blablacar/vaultprov"
version = "0.4.0"
}
}
}
provider "vaultprov" {
address = "https://some.vault.com:8200"
auth = {
path = "auth/kubernetes/login"
role = "some-role"
jwt = file("/var/run/secrets/kubernetes.io/serviceaccount/token")
}
}Provider attributes:
address: Vault addressauthpath: Authentication endpoint to use with Vaultrole: Vault Kubernetes authentication role to usejwt: Path of the local Kubernetes service account to be used for authentication
To build for current or specific arch:
make build
# or
OS_ARCH="linux_amd64" make buildTo build & install on locally
make install
# or
OS_ARCH="linux_amd64" make installTo build for release:
make releaseTo generate documentation:
make docsIn order to launch acceptance you must first have a running Vault instance:
vault server -dev -dev-root-token-id=ROOT_TOKENYou must also set the following environment variables:
export VAULT_ADDR='http://127.0.0.1:8200'
export VAULT_TOKEN='ROOT_TOKEN'Then you can launch tests: make testacc
In order to use the provider locally (without publishing it on Terraform Registry), use the make install command in
order to copy the provider binary in the local provider registry.
GitHub action is used to released new versions of the provider in Terraform Registry.
Follow the official Terraform documentation for the publishing procedure.