Skip to content

Commit

Permalink
feat(secretmanager): add k8s auth method to vault (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Jan 25, 2024
1 parent 4f56794 commit 7ad31b2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions keep/secretmanager/vaultsecretmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,27 @@ class VaultSecretManager(BaseSecretManager):
def __init__(self, context_manager, **kwargs):
super().__init__(context_manager)
vault_token = os.environ.get("HASHICORP_VAULT_TOKEN")
vault_use_k8s = os.environ.get("HASHICORP_VAULT_USE_K8S", False)
if vault_token:
self.client = hvac.Client(
url=self.HASHICORP_VAULT_ADDR,
namespace=self.HASHICORP_VALUT_NAMESPACE,
token=vault_token,
)
elif vault_use_k8s:
k8s_role = os.environ.get("HASHICORP_VAULT_K8S_ROLE")
if not k8s_role:
raise Exception(
"HASHICORP_VAULT_K8S_ROLE is required when using k8s auth method"
)
from hvac.api.auth_methods import Kubernetes

self.client = hvac.Client(
url=self.HASHICORP_VAULT_ADDR, namespace=self.HASHICORP_VALUT_NAMESPACE
)
f = open("/var/run/secrets/kubernetes.io/serviceaccount/token")
jwt = f.read()
Kubernetes(self.client.adapter).login(role=k8s_role, jwt=jwt)
else:
raise Exception("Unsupported vault login method")
self.logger.info("Using Vault Secret Manager")
Expand Down

0 comments on commit 7ad31b2

Please sign in to comment.