Coder Social home page Coder Social logo

bruj0 / vault-plugin-auth-u2f Goto Github PK

View Code? Open in Web Editor NEW
46.0 4.0 4.0 28.6 MB

This is a nonofficial plugin for HashiCorp Vault that uses a FIDO U2F enabled device as a way to authenticate a human.By requiring something you know, a PIN with something you have, the physical token.

License: Mozilla Public License 2.0

Makefile 1.93% Go 60.65% Shell 4.23% JavaScript 33.18%
hashicorp-vault golang u2f yubikey fido-u2f vault

vault-plugin-auth-u2f's Introduction

vault-plugin-auth-u2f

This is a non official plugin for HashiCorp Vault that uses a FIDO U2F enabled device as way to authenticate a human.

By requiring something you know, a PIN with something you have, the physical token.

It works by assigning a role to a device when an administrator registers it.

It currently support the web browser implementation of the U2F protocol from Google https://github.com/google/u2f-ref-code/blob/master/u2f-gae-demo/war/js/u2f-api.js

It uses the u2f for Go library by Ryan Kurte: https://github.com/ryankurte/go-u2f

Have any questions or comments? Please use the Discussions forums.

Roles

Roles must be created to associate a set of policies to a token created for a device:

$ vault write auth/u2f/roles/my-role token_policies="polA,polB"

Registrations

Registration of new devices is done by a POST to the endpoint auth/<u2f>/registerRequest/<mydevice> with the payload of role_name: <my-role> as json.

<mydevice> Is meant to be the friendly name given to the physical token when an administrator "registers" it in Vault.

Internally its the unique ID that will be used as a key to save all the data for future authentication.

There is no expected format, only that its in simple ascii and url safe.

This ID will have to be known by the person to be authenticated, could be an email or a PIN.

Finishing with another POST to auth/<u2f>/registerResponse with a payload of the protocol data signed by the device when the user presses the physical button.

See the demo in the directory u2f-frontend.

These endpoints should be protected for writting and only given access to admistrators.

Authentication

This is done via the endpoints auth/<u2f>/signRequest and auth/<u2f>/signResponse with appropiate protocol data as payload.

Demo

  • In the directory u2f-frontend you will find a shell script that will start Vault in dev mode and load the plugin:
$ make 
$ cd u2f-frontend
$ ./start_vault.sh
+ set +e
++ pidof vault
+ kill -TERM 236661
+ export VAULT_ADDR=http://127.0.0.1:8200
+ VAULT_ADDR=http://127.0.0.1:8200
+ unset VAULT_TOKEN
+ sleep 3s
+ /usr/local/bin/vault server -dev -dev-listen-address=0.0.0.0:8200 -dev-root-token-id=root -dev-plugin-dir=../plugins -log-level=trace
+ vault auth enable u2f
Success! Enabled u2f auth method at: u2f/
+ sleep 1s
+ vault write auth/u2f/roles/my-role token_policies=polA,polB
Success! Data written to: auth/u2f/roles/my-role
+ sleep 1s
+ vault read auth/u2f/roles/my-role
Key                        Value
---                        -----
token_bound_cidrs          []
token_explicit_max_ttl     0s
token_max_ttl              0s
token_no_default_policy    false
token_num_uses             0
token_period               0s
token_policies             [polA polB]
token_ttl                  0s
token_type                 default

This creates a role that assigns two policies to any device that is registered with it.

  • Start the frontend UI
$ ./u2f-frontend
2020/10/20 15:21:36 Running on https://localhost:3483

postPasstrough data: { "role_name": "my-role"}
postPasstrough returned: {"appId":"https://lxc1:3483","registerRequests":[{"version":"U2F_V2","challenge":"ney1ncntfiOH6RR9L51Tg_YgnBQOc-4pGb6DvDK3sYM","appId":"https://lxc1:3483"}],"registeredKeys":null}
2020/10/20 15:23:56 1 registerRequest: {"appId":"https://lxc1:3483","registerRequests":[{"version":"U2F_V2","challenge":"ney1ncntfiOH6RR9L51Tg_YgnBQOc-4pGb6DvDK3sYM","appId":"https://lxc1:3483"}],"registeredKeys":null}
2020/10/20 15:24:01 registerResponse regResp: {BQRB..WxzZX0}
postPasstrough data: {"clientData":"eyJ0eXAiO..JTxHP79SNhWc9JYtYT8U","name":"mydevice"}
postPasstrough returned: {"ok"}
2020/10/20 15:24:01 Registration success
2020/10/20 15:25:49 1 signRequest: {"appId":"https://lxc1:3483","challenge":"vAgX_uthFHN56nUdt6PTkWg3XY1nsJds5aBJH2ZVBuQ","registeredKeys":[{"version":"U2F_V2","keyHandle":"jhHhu3cu2Km3QHLDrqY_ZoCPeGKMbAZXWs10vmzNkH-t_V5lVUEbxnzJHG8yOE4C83lrtz95s9XjB60L2dDvPw"}]}
2020/10/20 15:25:51 signResponse: {KeyHandle:jhHhu3cu..FiUGV4In0}
postPasstrough data: {"keyHandle":"jh..V4In0","name":"mydevice"}
postPasstrough returned: {"request_id":"90b6b928-4d50-cc78-474a-609e84f59b48","lease_id":"","renewable":false,"lease_duration":0,"data":null,"wrap_info":null,"warnings":null,"auth":{"client_token":"s.BkuppRwBgxIdy7hr4soFQC00","accessor":"e5xVaunuBVdLHA7f5D3jr0us","policies":["default","pola","polb"],"token_policies":["default","pola","polb"],"metadata":{"device_name":"mydevice","role":"my-role"},"lease_duration":2764800,"renewable":true,"entity_id":"8977a412-c7ad-1e03-f654-b91bfd30a6b3","token_type":"service","orphan":true}}
2020/10/20 15:25:51 Authentication success
  • Go to a browser to https://localhost:3483

  • Click in Register token and press the button in your device

  • Click in Authenticate and press the button in your device

The token that you receive will have the policies attached that your role was assigned at the begining:

$ vault token lookup  s.BkuppRwBgxIdy7hr4soFQC00
Key                 Value
---                 -----
accessor            e5xVaunuBVdLHA7f5D3jr0us
creation_time       1603200351
creation_ttl        768h
display_name        u2f-u2f_mydevice
entity_id           8977a412-c7ad-1e03-f654-b91bfd30a6b3
expire_time         2020-11-21T14:25:51.27807041+01:00
explicit_max_ttl    0s
id                  s.BkuppRwBgxIdy7hr4soFQC00
issue_time          2020-10-20T15:25:51.278108041+02:00
meta                map[device_name:mydevice role:my-role]
num_uses            0
orphan              true
path                auth/u2f/signResponse/mydevice
*policies            [default pola polb]*
renewable           true
ttl                 767h59m34s
type                service

License

Mozilla Public License Version 2.0

Created by Rodrigo A. Diaz Leven

vault-plugin-auth-u2f's People

Contributors

bruj0 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vault-plugin-auth-u2f's Issues

obtaining value for device

in the registration request you make this post

req, statusCode := postPasstrough("auth/u2f/registerRequest/mydevice", []byte(dataJSON))

where "mydevice" I presume is a string identifier for the hardware key . How would you implement this in production if there are hundreds of users ? If this is being used as the primary login , then there is no user-identifying string that could be used pre-login , unless you can get an ID from the key itself

Curious minds want to know ;)

error enabling the plugin

I know I must be doing something stupid, but can't get the plugin to load

/ # vault plugin register -sha256=c2ab819bf43aba52230b6a7447ceeac9404fa6035bb0e834152d0d641a488aee -command=u2f auth u2f
Success! Registered plugin: u2f
/ # vault plugin info auth u2f
Key        Value
---        -----
args       []
builtin    false
command    u2f
name       u2f
sha256     c2ab819bf43aba52230b6a7447ceeac9404fa6035bb0e834152d0d641a488aee
/ # ls -l /vault/plugins
total 24640
-rwxr-xr-x    1 522411   89939     12328960 Mar 17 11:09 u2f
-rw-r--r--    1 root     root            65 Mar 17 11:22 u2f.shasum
/ # vault auth enable u2f
Error enabling u2f auth: Error making API request.

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

* fork/exec /vault/plugins/u2f: no such file or directory
/ # 

as you can see, it seems to register ok, but fails when trying to enable the plugin

Would appreciate someone telling me where I am going wrong ;)

build instructions

Would it be possible to put together a set of instructions on how to build and compile this plugin from source ?

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.