Giter Club home page Giter Club logo

vault-plugin-auth-ory's Introduction

Ory Kratos + Keto Auth Plugin for HashiCorp Vault

This repository contains code for a HashiCorp Vault Auth Plugin that authenticates with Ory Kratos and Ory Keto APIs.

Setup

The setup guide assumes some familiarity with Vault and Vault's plugin ecosystem. You must have a Vault server already running, unsealed, and authenticated.

  1. Download and decompress the latest plugin binary from the Releases tab. Alternatively you can compile the plugin from source.

  2. Move the compiled plugin into Vault's configured plugin_directory:

$ mv vault-auth-plugin-ory /etc/vault/plugins/vault-auth-plugin-ory
  1. Calculate the SHA256 of the plugin and register it in Vault's plugin catalog. If you are downloading the pre-compiled binary, it is highly recommended that you use the published checksums to verify integrity.
$ export SHA256=$(shasum -a 256 "/etc/vault/plugins/vault-auth-plugin-ory" | cut -d' ' -f1)

$ vault plugin register \
    -sha256="${SHA256}" \
    -command="vault-auth-plugin-ory" \
    auth vault-plugin-auth-ory
  1. Mount the auth method:
$ vault auth enable \
    -path="ory" \
    -plugin-name="vault-plugin-auth-ory" plugin

Development Setup

  1. Build the plugin for your platform (os/arch) e.g.:
$ make darwin/arm64

or build for all platforms:

$ make build
  1. Start a Vault server in dev mode pointing to the plugin directory:
$ make start
  1. Login to Vault as root:
$ vault login root
  1. Enable the plugin in Vault:
$ make enable
  1. Write the configs:
$ make configs
  1. Authenticate with the plugin:
$ vault write auth/ory/login \
namespace=files \
object=c5cc3e28-e3c3-45ca-be86-a0a55953bfca \
relation=editor \
kratos_session_cookie=ory_kratos_session=MTY2NzgyMjg2M3xBYVJxa2hmNFlOOFAyZnc3U3VidnZKd1A0VmdyWFgyU3ozbUNvRG4zeC1oNU1DS3Z6dkc1ODllTHdua0s5aFdpcW1ZZ0pveVNBVVM3ZXBIRWdQdlJGWXN0aS1iVU5tenVFbUw1WE1QNDRVcms5eWZZRk52R3dOdTJKLVcxYVlFWFU4ajNFUmc0bnc9PXyq29KzMQjNDdZLeJAuNLUBeU1g1-iD7l31nahltn4mZg==
  1. Add a policy that matches the naming convention namespace_relation (e.g. files_editor) using the example policy found below, replacing the accessor string with the contents returned by:
$ make accessor
  1. Login with the token provided after running the write command:
$ vault login [token]
  1. Attempt to read secrets:
$ vault read secret/files/c5cc3e28-e3c3-45ca-be86-a0a55953bfca/some_secret

Authenticating with Ory Kratos and Keto

To authenticate, the user supplies a valid Ory Kratos session cookie, along with the namespace, object, and relation to check against Keto.

$ vault write auth/ory/login namespace=[namespace] object=[object] relation=[relation] kratos_session_cookie=[full kratos_session_cookie=[...] string]

The response will be a standard auth response with some token metadata:

Key                     Value
--------------------------------
token                   [token]
token_accessor          [accessor]
token_duration          [TTL]
token_renewable         false
token_policies          ["default" "[namespace]_[relation]"]
identity_policies       []
policies                ["default" "[namespace]_[relation]"]

Policy Template

When a token is successfully created, the plugin attach a policy that follows the naming schema of [namespace]_[relation].

You must then create a policy with that name in Vault that utilises the metadata stored in the alias. The following policy template will allow access to a KV secret at the path secret/data/[namespace]/[object]*:

path "secret/data/{{identity.entity.aliases.auth_vault-plugin-auth-ory_e40b77a0.metadata.object}}*" {
  capabilities = ["create", "read", "update", "delete", "list"]
}

path "secret/metadata/{{identity.entity.aliases.auth_vault-plugin-auth-ory_e40b77a0.metadata.object}}/*" {
  capabilities = ["delete", "list"]
}

Being sure to replace auth_vault-plugin-auth-ory_e40b77a0 with the accessor of the auth plugin found by running vault auth list.

Alternatively, you can find the accessor by running the following command:

$ export MOUNT_ACCESSOR=$(vault auth list -format=json | jq -r '."ory/".accessor')

As we already know the namespace at this point, you can also simply use the path:

secret/data/[known namespace]/{{identity.entity.metadata.object}}*

License

This code is licensed under the MPLv2 license.

vault-plugin-auth-ory's People

Contributors

benjaminnolan avatar taylow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vault-plugin-auth-ory's Issues

Add policy suffix/prefix config

Simply adds a suffix or prefix to the policy being attached to the token, making the schema namespace_relation_suffix if set.

e.g. files_edit becomes ory_files_edit (prefix) or files_edit_ory (suffix).

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.