hvac icon indicating copy to clipboard operation
hvac copied to clipboard

add kerberos auth support

Open bendemott opened this issue 4 years ago • 6 comments

Hi, privately I implemented Kerberos auth on top of HVAC.

Vault now supports SPNEGO auth (unceremoniously documented here) https://www.vaultproject.io/api/auth/kerberos#login-with-kerberos

The Kerberos auth endpoints are nearly identical to LDAP, so I simply subclassed hvac.api.auth_methods.ldap.Ldap and replaced the DEFAULT_MOUNT_POINT where needed.

Kerberos requires 2 components to work

  • gssapi
  • requests_gssapi

I support both token-based-auth by reading an existing kerberos context from kinit / token-cache as well as keytab authentication.

I can create two explicit login methods, or just have "one".
Currently I have one login method, when keytab_path is omitted it looks for an existing kerberos context via kerberos cache through gssapi.

Here is the signature of my kerberos login method, I tried to keep the arguments similar to what the vault cli expects

    def login(self,
              username,
              service=None,
              realm=None,
              keytab_path=None,
              krb5conf_path=None,
              use_token=True,
              mount_point=DEFAULT_MOUNT_POINT):

If you're interested in this addition I will prepare a pull request

Looking forward to the feedback.

bendemott avatar May 06 '21 20:05 bendemott

I don't have much of a stake in kerberos support personally. However we've historically added any non-disruptive features that folks request as they come up in GitHub issues or otherwise 😄. On the "kerberos requires 2 components to work" point, the implication is that the proposed functionality would introduce two additional requirements in the form of gssapi and requests_gssapi, correct? That is the only bit from the issue's description that gives me some pause. Previously, I have endeavored to keep hvac's requirements as minimal as possible (based on a vague consideration of "hvac is used in secure contexts so keeping the number of requirements to a minimum is helpful in some senses").

All that said, I'm always happy to check out any PR! Just wanted to set that context (and I imagine I would probably first look at ways at enabling the behavior without necessarily needing to include the additional requirements).

jeffwecan avatar May 06 '21 20:05 jeffwecan

We're also interested in kerberos support. Was there any further progress here, or have you shared your implementation in some way (e.g. a PR) @bendemott ?

soxofaan avatar Apr 14 '23 10:04 soxofaan

Hi @soxofaan - I'm trying to dig up the source I wrote so a PR can be started, if you don't hear from me in 7 days ping me again.

bendemott avatar Apr 18 '23 18:04 bendemott

This one would be really useful in any environment with a KDC (e.g. Microsoft Active Directory)

For what it's worth, below is the code one can use to do vault w/ GSSAPI, but w/o hvac

The code implies one single additional dependency per platform

winkerberos ; platform=="Windows"
kerberos ; platform!="Windows"
import requests
try:
  import kerberos
except:
  import winkerberos as kerberos

vault_host = 'vault.service.ny.consul'
service = f'HTTP@{vault_host}'
vault = f'{vault_host}:8200'
rc, vc = kerberos.authGCCClientInit(service=service, mech_oid=kerberos.GSS_MECH_OID_SPNEGO)
kerberos.authGSSClientStep(vc, '')
token - kerberos .authGSSClientResponse(vc)
secret_url = f'https://{vault_host}v1/apps/path/to/some/secret'
auth_url = f'https://{vault}/v1/auth/krb5_ep/login'
r = requests.post(auth_url, headers={'Authorization': f'Negotiate {token}'})
vault_token = r.json()['auth']['client_token']
r = requests.get(secret_url, headers={'X-Vault-Token': vault_token})
secret = r.json()['data']['data']

masariello avatar Jul 10 '23 20:07 masariello

Hi @soxofaan - I'm trying to dig up the source I wrote so a PR can be started, if you don't hear from me in 7 days ping me again.

Hi @bendemott , just seeing this now due to the new comment, figured I'd check in with you to see if you're still interested in opening an PR for this. I think it would be a great addition to the project. No rush, but also don't worry too much about getting the code perfect, we'll work through it in the PR.

briantist avatar Jul 12 '23 21:07 briantist

@briantist @soxofaan see: https://github.com/hvac/hvac/pull/1027

bendemott avatar Jul 13 '23 06:07 bendemott