kubevault / project

Enhancements & Issues for KubeVault
https://kubevault.com
Apache License 2.0
7 stars 0 forks source link

Generate SecretProviderClass using KubeVault CLI #112

Closed sakiib closed 2 years ago

sakiib commented 3 years ago

Here's the complete step by step manual procedure and we want to automate the Step 3:

Step 1: Enable SecretEngine and Create SecretEngineRole

Step 2: Create VaultPolicy & bind it to a ServiceAccount using VaultPolicyBinding

Step 3: Create SecretProviderClass

Step 4: Create a Pod & mount


Information we may need to generate the SecretProviderClass:

tamalsaha commented 3 years ago

VaultServer

SecretEngine

-> Enable: /database/config (one-time enable)

/aws/config/root => /k8s.-.{se-type}.se-ns.se-name/config/root

/database/config/:name => /k8s.-.{se-type}.se-ns.se-name/config/database

ElasticsearchRole

https://www.vaultproject.io/api/secret/databases#create-role

api path: /k8s.-.{se-type}.se-ns.se-name/roles/{es-role-cr-name}

Vault Policies

https://www.vaultproject.io/api-docs/system/policies#create-update-acl-policy

metdata.name = replace({se-type}.se-ns.se-name.{es-role-cr-name}, ".", "-")

/sys/policies/acl/:name name = k8s.-.{se-type}.se-ns.se-name.{es-role-cr-name}

PolicyBinding

https://www.vaultproject.io/docs/auth/kubernetes#configuration

metadata.name: replace({se-type}.se-ns.se-name.{secret-role-binding-cr-name}, ".", "-")

vault write auth/kubernetes/role/demo \
    bound_service_account_names=vault-auth \
    bound_service_account_namespaces=default \
    policies=default \
    ttl=1h

demo = k8s.-.{se-type}.se-ns.se-name.{secret-role-binding-cr-name}

tamalsaha commented 3 years ago

    keys := map[string]string{}

    flag.StringToStringVar(&keys, "keys", keys, "Key/Value map used to update pg-coordinator and replication mode detector image")

kubectl vault generate secretproviderclass <name> -n <ns>

--secretrolebinding=ns2/name2
--vault-role=AWSRole/name3

--keys x=y -o json,yaml | kubectl apply -f -