Configuring venafi-connection
Learn about different ways to configure VenafiConnection custom resources.
Use Case: Store Venafi Username / Password in HashiCorp Vault and Authenticate to HashiCorp Vault using OIDC
The following example shows a cluster issuer resource which uses a Kubernetes ServiceAccount Token to authenticate to HashiCorp Vault which contains the credentials for Venafi TPP.
Configure the Kubernetes resources
# 1. Create a ServiceAccount which the Venafi Connection will use to authenticate to HashiCorp Vault.apiVersion: v1kind: ServiceAccountmetadata:name: application-team-1namespace: jetstack-secure
# 2. Give the 'venafi-connection' ServiceAccount the permission to create tokens for this ServiceAccount# create role that allows creating sa tokens for 'application-team-1'apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata:name: create-tokens-for-application-team-1namespace: jetstack-securerules:- apiGroups: [ "" ]resources: [ "serviceaccounts/token" ]verbs: [ "create" ]resourceNames: [ "application-team-1" ]---# link the controller's service account to the 'create-tokens-for-vault-sa' roleapiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata:name: application-team-1-sa-rolebindingnamespace: jetstack-secureroleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: create-tokens-for-application-team-1subjects:- kind: ServiceAccountname: venafi-connectionnamespace: jetstack-secure
# 3. Create the VenafiConnection CR that has a reference to the Venafi Control Plane server, HashiCorp Vault instance and to the ServiceAccountapiVersion: jetstack.io/v1alpha1kind: VenafiConnectionmetadata:name: application-team-1-connectionnamespace: jetstack-securespec:tpp:url: https://tpp1.example.comaccessToken:- serviceAccountToken:name: application-team-1audiences: [ "vault.vault.svc.cluster.local" ]- hashicorpVaultOAuth:authInputType: OIDCrole: application-team-1authPath: /v1/auth/example-corp/loginurl: http://vault.vault.svc.cluster.local:8200- hashicorpVaultSecret:secretPath: /v1/secret/data/application-team-1/tpp-username-passwordfields: [ "username", "password" ]url: http://vault.vault.svc.cluster.local:8200- tppOAuth:authInputType: UsernamePasswordurl: https://tpp1.example.com
Configure HashiCorp Vault
Now configure HashiCorp Vault for "Kubernetes" authentication, and create Role which will allow the application-team-1 ServiceAccount to authenticate and impersonate it.
kubectl exec -n vault pods/vault-0 -- \vault auth enable -path=example-corp kuberneteskubectl exec -n vault pods/vault-0 -- \vault write auth/example-corp/config \kubernetes_host=https://kubernetes.default.svckubectl exec -n vault pods/vault-0 -- \vault write auth/example-corp/role/application-team-1 \role_type=jwt \bound_audiences=vault.vault.svc.cluster.local \user_claim=sub \bound_service_account_names=application-team-1 \bound_service_account_namespaces=jetstack-secure \policies=application-team-1-readonly \ttl=5m
ℹ️ In this example HashiCorp Vault is configured to use Kubernetes authentication, and it is running inside the Kubernetes cluster. Alternatively you can configure HashiCorp Vault to use JWT authentication, which is similar but with some important differences. The disadvantage is that with JWT authentication HashiCorp Vault will not be able to check for revoked Kubernetes JWT tokens. The advantage is that Vault won't need to connect to the Kubernetes API server which makes it easier to connect to a HashiCorp Vault server that is running outside the Kubernetes cluster where venafi-connection is running.
Store TPP Credentials in HashiCorp Vault
Next store the Venafi TPP credentials in a secret in HashiCorp Vault and create an access policy to allow these to be read by the Role that was created in the previous step.
# hashicorp-vault.policy.hclpath "secret/data/application-team-1/tpp-username-password" {capabilities = ["read"]}
kubectl exec -i -n vault pods/vault-0 -- \vault policy write application-team-1-readonly - < hashicorp-vault.policy.hclkubectl exec -n vault pods/vault-0 -- \vault kv put -mount=secret application-team-1/tpp-username-password username=application-team-1 password=xxxx-xxxx-xxxx-xxxx
Next Steps
- Read more Reference Documentation for venafi-connection to learn about different configuration use-cases and to read the full API documentation and CLI documentation.