GithubHelp home page GithubHelp logo

wintoncode / vault-plugin-auth-kerberos Goto Github PK

View Code? Open in Web Editor NEW
35.0 10.0 11.0 57.23 MB

[DEPRECATED] Plugin for Hashicorp Vault enabling Kerberos authentication

License: Mozilla Public License 2.0

Makefile 4.34% Go 88.73% Shell 6.93%
vault vault-plugins kerberos kerberos-spnego go

vault-plugin-auth-kerberos's Introduction

[DEPRECATED] Vault Plugin: Kerberos Auth Backend

โš ๏ธ 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.

Usage

Authentication

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'])

Configuration

  1. 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"
  1. 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/
  1. 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"
  1. 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
  1. 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.

Developing

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'!

Tests

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'

vault-plugin-auth-kerberos's People

Contributors

ah- avatar baileydoestech avatar jcmturner avatar sambott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vault-plugin-auth-kerberos's Issues

policies not being assigned to authenticated kerberos user

Hi,

This may be related to the latest version of vault/vault-plugin-auth-kerberos as this was working pre upgrade to latest versions of vault and vault-plugin-auth-kerberos.

Issue - I am able to authenticate correctly to vault using the plugin and I do get a token back. However the user is not granted the policies defined in auth/kerberos/groups/ldap_group. I can confirm that reading this config with root taken yields the required policies. The user which definetely belongs to ldap_group gets only the "default" vault permission.

auth/kerberos/groups/ldap_group  policies='devops_admin, systems_admin, vault_list_secrets'
 
vault read auth/kerberos/groups/ldap_group 
Key         Value
---         -----
policies    [devops_admin systems_admin vault_list_secrets]

Authenticating with plain ldap as the same user does work.

Does anyone have a working setup using vault Vault v0.10.1 and the latest vault-plugin-auth-kerberos plugin?

Thanks.

Basic C# .NET Client code example for this?

Apologies if this isn't the correct place for this type of question but has anyone got this working with a .NET/C# client?

I can't for the life of me get it to work, my local user has permissions via kerberos and works with the README python code:

var spn = "HTTP/[email protected]";
KerberosSecurityTokenProvider tokenProvider = new KerberosSecurityTokenProvider(spn,
    TokenImpersonationLevel.Impersonation, CredentialCache.DefaultNetworkCredentials);
KerberosRequestorSecurityToken securityToken = tokenProvider.GetToken(TimeSpan.FromMinutes(1)) as KerberosRequestorSecurityToken;
var token = Convert.ToBase64String(securityToken.GetRequest());

HttpClient client = new HttpClient();//new HttpClientHandler { UseDefaultCredentials = true, PreAuthenticate = true });

var serializeObject = JsonConvert.SerializeObject(new { authorization = "Negotiate " + token });
var resp = await client.PostAsync(new Uri(vaultUri, "v1/auth/kerberos/login"),
    new StringContent(serializeObject)); // 500 error

var content = await resp.Content.ReadAsStringAsync(); // {"errors":["SPNEGO negotiation token is not a NegTokenInit: OID does not match SPNEGO OID 1.3.6.1.5.5.2"]}

Kerberos Login

When I try to login via SPNEGO I got following error:

{"errors":["SPNEGO OID of MechToken is not of type KRB5"]}

When I look via WireShark in my request there are 4 mechTypes:

MechType: 1.3.6.1.4.1.311.2.2.10 (NTLMSSP - Microsoft NTLM Security Support Provider)
MechType: 1.2.840.48018.1.2.2 (MS KRB5 - Microsoft Kerberos 5)
MechType: 1.2.840.113554.1.2.2 (KRB5 - Kerberos 5)
MechType: 1.3.6.1.4.1.311.2.2.30 (NEGOEX - SPNEGO Extended Negotiation Security Mechanism)

Seems like only the first one is checked.

Decrypting_Error: Service key not available

Hello,

I am having trouble configuring this plugin. I filled out the auth/kerberos/config path with the base64-encoded keytab file content and the service_account entry (in the format HTTP/[email protected]). The plugin seems to be properly mounted, but when trying to authenticate against this backend (using both the example Python script from README and a custom curl command call yields the same result), I receive the following error from the API:

{u'errors': [u'[Root cause: Decrypting_Error] Decrypting_Error: Error decrypting encpart of service ticket provided: [KRB Error: (45) KRB_AP_ERR_NOKEY Service key not available - Could not get key from keytab: Matching key not found in keytab. Looking for [HTTP/[email protected]] realm: EXAMPLE.COM kvno: 1 etype: 18]']}

However, when I klist -kt the keytab used, the principal that I put into the service_account config entry is there.

Has anybody seen such an issue, or do you have any idea how to resolve this? Thanks a lot.

Mapping Users to Groups

Hi, perhaps I am just not understanding correctly. My situation:

When requesting a token via ldap auth and then logging into vault, my user is showing the correct group/policy mapping:

Key                    Value
---                    -----
token                  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
token_accessor         xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
token_duration         767h59m46s
token_renewable        true
token_policies         [default custom-application]
token_meta_username    jeremyjohnson

I created this group delegation like this:
# vault write "auth/ldap/users/jeremy johnson" groups=custom-application

So, that's all working great... But when I request a token via kerberos auth and log into vault there is no such group mapping:

Key                 Value
---                 -----
token               yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
token_accessor      yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
token_duration      767h59m41s
token_renewable     false
token_policies      [default]
token_meta_user     jeremyjohnson
token_meta_realm    REALM

If anyone could offer some advise I would greatly appreciate it. Thank you!

Jeremy

Authentication fails when KVNO is not 1

Hello,

I cannot seem to get the authentication to work when the key in my keytab has a KVNO higher than one. I've looked into the code of both the plugin and the underlying gokrb5 library extensively, but haven't been able to decipher the exact way the KVNO is parsed and checked (I suspect it's done in https://github.com/jcmturner/gokrb5/blob/master/messages/APReq.go#L124 but I'm not sure).

I don't have a way to reset the KVNO to 1 because of the way that the ipa-getkeytab command in FreeIPA works (increasing the KVNO after each keytab retrieval). I've tried to work-around this temporarily by skipping the KVNO check, but the authentication started failing on an integrity verification failed error.

Could you please help me find out whether this is an issue with the gokrb5 library itself, or rather in the way the plugin handles the keytab and passes it to the library? Thanks a lot.

ClientClaimsInfo error when authenticating with winkerberos

The below code fails when running from a windows machine:

import requests
import winkerberos as kerberos
service = "HTTP/vault.DOMAIN@REALM"
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/v1/auth/kerberos/login", json={'authorization': 'Negotiate ' + kerberos_token}, verify=False)

See error below:
{"time":"2018-05-29T21:48:01.052877076Z","type":"response","auth":{"client_token":"","accessor":"","display_name":"","policies":null,"metadata":null,"entity_id":""},"request":{"id":"e03ae638-16fb-8bb9-513c-ebe0334acbdc","operation":"update","client_token":"","client_token_accessor":"","path":"auth/kerberos/login","data":{"authorization":"hmac-sha256:1705419e6936724587ae0e5b1a4560736ecd6124ca9c0b63050c76ea17862c53"},"policy_override":false,"remote_address":"127.0.0.1","wrap_ttl":0,"headers":{}},"response":{},"error":"error processing ClientClaimsInfo: error parsing byte stream headers: Malformed NDR steam: Not enough bytes."}

This works fine from a linux machine. Only difference is we then use standard python kerberos module.

Does this work from a windows machine by any chance?

PLUGIN_MIN_PORT and PLUGIN_MAX_PORT

Hello,

please improve error messages from strconv.ParseInt in file vendor/github.com/hashicorp/go-plugin/server.go on line 366 and 371:

minPort, err := strconv.ParseInt(os.Getenv("PLUGIN_MIN_PORT"), 10, 32) if err != nil { return nil, err } maxPort, err := strconv.ParseInt(os.Getenv("PLUGIN_MAX_PORT"), 10, 32) if err != nil { return nil, err }

When I tried to enable the plugin with vault auth enable -passthrough-request-headers=Authorization -allowed-response-headers=www-authenticate kerberos there was only following response:

Error enabling kerberos auth: Error making API request.

URL: POST http://127.0.0.1:8200/v1/sys/auth/kerberos
Code: 400. Errors:

* rpc error: code = Unknown desc = timeout waiting for connection info

The server debug log shows:

2019-05-09T11:52:04.022+0200 [DEBUG] auth.kerberos.auth_kerberos_84e98ff5.kerberos: starting plugin: metadata=true path=C:\Vault\plugins\vault-plugin-auth-kerberos.exe args=[C:\Vault\plugins\vault-plugin-auth-kerberos.exe, -ca-cert=C:/ca/ca.pem, -client-cert=C:/ca/vault_plugin_kerberos-01.pem, -client-key=C:/ca/vault_plugin_kerberos-01.key, -tls-skip-verify]
2019-05-09T11:52:04.025+0200 [DEBUG] auth.kerberos.auth_kerberos_84e98ff5.kerberos: plugin started: metadata=true path=C:\Vault\plugins\vault-plugin-auth-kerberos.exe pid=3860
2019-05-09T11:52:04.026+0200 [DEBUG] auth.kerberos.auth_kerberos_84e98ff5.kerberos: waiting for RPC address: metadata=true path=C:\Vault\plugins\vault-plugin-auth-kerberos.exe
2019-05-09T11:52:04.037+0200 [DEBUG] auth.kerberos.auth_kerberos_84e98ff5.kerberos: using plugin: metadata=true version=4
2019-05-09T11:52:04.037+0200 [DEBUG] auth.kerberos.auth_kerberos_84e98ff5.kerberos.vault-plugin-auth-kerberos.exe: plugin address: metadata=true address=127.0.0.1:10012 network=tcp timestamp=2019-05-09T11:52:04.036+0200
2019-05-09T11:52:04.038+0200 [TRACE] auth.kerberos.auth_kerberos_84e98ff5.kerberos: setup: transport=gRPC status=started
2019-05-09 11:52:04.039625 I | [ERR] plugin: plugin acceptAndServe error: strconv.ParseInt: parsing "": invalid syntax
2019-05-09T11:52:09.048+0200 [TRACE] auth.kerberos.auth_kerberos_84e98ff5.kerberos: setup: transport=gRPC status=finished err="rpc error: code = Unknown desc = timeout waiting for connection info" took=5.0100258s
2019-05-09T11:52:09.049+0200 [ERROR] secrets.system.system_76024223: enable auth mount failed: path=kerberos/ error="rpc error: code = Unknown desc = timeout waiting for connection info"

Please add a error description like "Please set the env variables PLUGIN_MIN_PORT and PLUGIN_MAX_PORT"

Thank you!

Error enabling plugin auth: Error making API request (plugin exited before we could connect)

We have the following setup

# vault config
plugin_directory = "/etc/vault_plugins"

# kerberos-auth-plugin registration
vault write sys/plugins/catalog/kerberos-auth-plugin sha_256=PLUGIN_SHA command="vault-plugin-auth-kerberos -ca-cert /etc/vault_pki/consul.pem -client-cert /etc/vault_pki/consul.crt /etc/vault_pki/consul.key -tls-skip-verify"

# where in /etc/vault_pki we have the certifcates we use for communicating with consul backend
# These certificates work with our consul clients and vault works fine with them.

# Enabling vault with this command.
vault auth enable -path=kerberos -plugin-name=kerberos-auth-plugin plugin
# returns error below
Error enabling plugin auth: Error making API request.

URL: POST http://127.0.0.1:8200/v1/sys/auth/kerberos
Code: 400. Errors:

* plugin exited before we could connect

# In syslog we have:
Apr 17 16:47:33 node_name vault[17802]: 2018/04/17 16:47:33.631477 [ERROR] sys: enable auth mount failed: path=kerberos/ error=plugin exited before we could connect

Vault version:
ault v0.9.6+ent
Consul version:
Consul v1.0.6

Any help with getting this working will be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.