⚠️ This repo is no longer maintained: It has been taken over by Hashicorp as an official plugin which you can find here
This is a standalone backend plugin for use with Hashicorp Vault. This plugin allows for users to authenticate with Vault via Kerberos/SPNEGO.
You can find binaries on the Release page.
You can authenticate by posting a valid SPNEGO Negotiate header to /v1/auth/kerberos/login
.
try:
import kerberos
except:
import winkerberos as kerberos
import requests
service = "HTTP/vault.domain"
rc, vc = kerberos.authGSSClientInit(service=service, mech_oid=kerberos.GSS_MECH_OID_SPNEGO)
kerberos.authGSSClientStep(vc, "")
kerberos_token = kerberos.authGSSClientResponse(vc)
r = requests.post("https://vault.domain:8200/v1/auth/kerberos/login",
json={'authorization': 'Negotiate ' + kerberos_token})
print('Vault token:', r.json()['auth']['client_token'])
- Install and register the plugin.
Put the plugin binary (vault-plugin-auth-kerberos
) into a location of your choice. This directory
will be specified as the plugin_directory
in the Vault config used to start the server.
...
plugin_directory = "path/to/plugin/directory"
...
$ vault write sys/plugins/catalog/auth/kerberos sha_256="$(shasum -a 256 'vault-plugin-auth-kerberos' | cut -d ' ' -f1)" command="vault-plugin-auth-kerberos -client-cert server.crt -client-key server.key"
- Enable the Kerberos auth method:
$ vault auth enable -passthrough-request-headers=Authorization -allowed-response-headers=www-authenticate kerberos
Success! Enabled kerberos auth method at: kerberos/
- Use the /config endpoint to configure Kerberos.
Create a keytab for the kerberos plugin:
$ ktutil
ktutil: addent -password -p [email protected] -e aes256-cts -k 1
Password for [email protected]:
ktutil: list -e
slot KVNO Principal
---- ---- ---------------------------------------------------------------------
1 1 [email protected] (aes256-cts-hmac-sha1-96)
ktutil: wkt vault.keytab
The KVNO (-k 1
) should match the KVNO of the service account. An error will show in the vault logs if this is incorrect.
Different encryption types can also be added to the keytab, for example -e rc4-hmac
with additional addent
commands.
Then base64 encode it:
base64 vault.keytab > vault.keytab.base64
vault write auth/kerberos/config [email protected] service_account="your_service_account"
- Add a SPNs (Service Principal Names) to your KDC for your service and service account. This should map the vault service to the account it is running as:
# for Windows/Active Directory
setspn.exe -U -S HTTP/vault.domain:8200 your_service_account
setspn.exe -U -S HTTP/vault.domain your_service_account
- Configure LDAP backend to look up Vault policies. Configuration for LDAP is identical to the LDAP auth method, but writing to to the Kerberos endpoint:
vault write auth/kerberos/config/ldap @vault-config/auth/ldap/config
vault write auth/kerberos/groups/example-role @vault-config/auth/ldap/groups/example-role
In non-kerberos mode, the LDAP bind and lookup works via the user that is currently trying to authenticate. If you're running LDAP together with Kerberos you might want to set a binddn/bindpass in the ldap config.
If you wish to work on this plugin, you'll first need Go installed on your machine.
For local dev first make sure Go is properly installed, including
setting up a GOPATH.
Next, clone this repository into
$GOPATH/src/github.com/wintoncode/vault-plugin-auth-kerberos
.
You can then download any required build tools by bootstrapping your
environment:
$ make bootstrap
To compile a development version of this plugin, run make
or make dev
.
This will put the plugin binary in the bin
and $GOPATH/bin
folders. dev
mode will only generate the binary for your platform and is faster:
$ make
$ make dev
Put the plugin binary into a location of your choice. This directory
will be specified as the plugin_directory
in the Vault config used to start the server.
...
plugin_directory = "path/to/plugin/directory"
...
Start a Vault server with this config file:
$ vault server -config=path/to/config.json ...
...
Once the server is started, register the plugin in the Vault server's plugin catalog:
$ vault write sys/plugins/catalog/kerberos \
sha_256=<expected SHA256 Hex value of the plugin binary> \
command="vault-plugin-auth-kerberos"
...
Success! Data written to: sys/plugins/catalog/kerberos
Note you should generate a new sha256 checksum if you have made changes to the plugin. Example using openssl:
openssl dgst -sha256 $GOPATH/vault-plugin-auth-kerberos
...
SHA256(.../go/bin/vault-plugin-auth-kerberos)= 896c13c0f5305daed381952a128322e02bc28a57d0c862a78cbc2ea66e8c6fa1
Enable the auth plugin backend using the Kerberos auth plugin:
$ vault auth-enable -plugin-name='kerberos' plugin
...
Successfully enabled 'plugin' at 'kerberos'!
If you are developing this plugin and want to verify it is still functioning (and you haven't broken anything else), we recommend running the tests.
To run the tests, invoke make test
:
$ make test
You can also specify a TESTARGS
variable to filter tests like so:
$ make test TESTARGS='--run=TestConfig'