Giter Club home page Giter Club logo

vault-auth-spire's Introduction

SPIRE Vault Authentication Plugin

SPIRE Vault Authentication Plugin is an authentication plugin for Hashicorp Vault which allows logging into Vault using a SPIRE provided SVID.

Menu

Rationale

This plugin exists to allow SPIRE authenticated workloads to authenticate with Vault using their SPIRE provided SVID, and then interact with Vault as they would if they authenticated with Vault via any other Vault supported authentication mechanism. The intention is to support the following login scenerio

$> vault write auth/spire/login jwt="<jwt svid>"
$> vault write auth/spire/login -client-cert=svid.0.pem  -client-key=svid.0.key" <-- TLS connection using X509-SVID

where the SVID contains a valid SpiffeID which is used to determine which policies to apply during the Vault session.

Currently the plugin is coded to accept X509-SVID documents via the non-TLS method but that is just for speed of development purposes - it will not be true in a released version. See #12 for a discussion on accepting X509-SVIDs.

During the login process the provided SVID will be verified against CA trust bundles known to the plugin. The SVID must have been generated using one of the known CA trust bundles. As per the rules in Spiffe regarding trust domains and bundles, each trust domain known to the plugin will use 1 or more public CAs to verify SVIDs generated in that domain. The vault-auth-spire plugin supports the configuration of multiple trust domains, each with 1 or more root or intermediate CAs used to verify the SVIDs. This use of 1 or more CAs allows the plugin to support CA rotation.

The plugin uses Trust Sources to manage from where it receives trusted CAs. There are two types of trust sources: read from file and pushed from SPIRE. The trust sources are configured in the plugin settings and will be used to acquire trust CAs. The plugin can simultaneously acquire trust CAs from file and SPIRE.

Trust Sources

A Trust Source provides a way for vault-auth-spire to acquire trust CAs. There are two types of trust sources: from file and SPIRE. Both types of trust sources can be used at the same time.

File Trust Source

When using a File Trust Source one needs to map a Trust Domain to one or more files containing the trusted CAs for that domain. This information is provided to the plugin via its settings file.

{
  "trustsource": {
    "file": {
      "domains": {
        "spiffe://some.domain.com": ["/path/to/ca/for/domain.crt", "/path/to/secondary/ca/for/domain.crt"],
        "spiffe://some.otherdomain.com": ["/path/to/ca/for/otherdomain.crt"]
      }
    }
  }
}

Each domain can be provided with one or more trusted CA files and each CA file can contain one or more actual certificates. The full set of certificates found across all files will be used to verify SVIDs claiming to be within the configured domain. This structure allows the plugin to fully support certificate rotation.

SPIRE Trust Source

This is still under development and some details are unknown at this time

When using the SPIRE Trust Source one needs to provide enough information for the plugin to connect to SPIRE and retreive its known trust CAs. The information is provided to the plugin via its settings file

{
  "trustsource": {
    "spire": ...unknown at the moment...
  }
}

Current ideas for this trust source include

  1. Support connecting to multiple SPIRE instances (agents or servers) to allow for broad authentication, particularly where different systems are using the same Vault instance.
  2. Support saving the SPIRE provided CAs to disk so they can be used if the plugin is unable to connect to a SPIRE instance. This will help limit the blast radius of a failing SPIRE connection.

Quick Start

Building

The plugin can be built using standard go commands or simply by using the provided Makefile.

$> make build
GOOS=linux GOARCH=amd64 go build -o vault-auth-spire cmd/plugin/vault-auth-spire.go

Installation

The plugin is installed and registered just like any other Vault plugin. It should be placed in the appropriate plugin directory and registered in the catalog. When registering the plugin it is necessary to provide the location of the plugin settings file.

$> vault write sys/plugins/catalog/auth/spire \
    sha_256="$(shasum -a 256 '/path/to/plugin/vault-auth-spire' | cut -d' ' -f1)" \
    command="vault-auth-spire" \
    args="--settings-file=/path/to/settings/vault-auth-spire-settings.json"

Before usage all plugins need to be enabled

$> vault auth enable \
    -path="spire" \
    -plugin-name="spire" plugin

Contributions

We ❤️ contributions.

Have you had a good experience with this project? Why not share some love and contribute code, or just let us know about any issues you had with it?

We welcome issue reports here; be sure to choose the proper issue template for your issue, so that we can be sure you're providing the necessary information.

Before sending a Pull Request, please make sure you read our Contribution Guidelines.

License

Please read the LICENSE file.

Code of Conduct

This project has adopted a Code of Conduct. If you have any concerns about the Code, or behavior which you have experienced in the project, please contact us at [email protected].

Security Vulnerability Reporting

If you believe you have identified a security vulnerability in this project, please send email to the project team at [email protected], detailing the suspected issue and any methods you've found to reproduce it.

Please do NOT open an issue in the GitHub repository, as we'd prefer to keep vulnerability reports private until we've had an opportunity to review and address them.

vault-auth-spire's People

Contributors

dennisgove avatar kpfleming 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vault-auth-spire's Issues

Add Integration Tests

Integration tests should exist to test the usage of this plugin in a running Vault instance.

Initial list of things that should be tested

  • Registering & enabling the plugin within Vault
  • Logging in with both valid and invalid SVIDs
  • Logging in with valid but expired SVIDs
  • Logging in with valid SVIDs against expired trust sources

SPIFFE ID extracted from SVID is not guaranteed to be for the workload

Describe the bug
The assumption in this line is that of all the URIs found in the SVID SAN blocks the first one will be for the workload. This is not necessarily true if the SVID contains multiple PEM blocks.

SVIDs will contain multiple PEM blocks if SPIRE service option upstream_bundle = true is set. Those additional PEM blocks contain the full chain of trust and while important for verification are not the appropriate SpiffeIDs to use when generating Vault policy IDs (discussed in #1). I'm unsure if SPIFFE guarantees the order of PEM blocks within an SVID (see spiffe/spiffe#32 for discussion about the order of SPIFFE IDs in a certificate).

As such, this assumption that the first PEM block contains the workload's SpiffeID is wrong.

uris := []string{}
for _, svidCert := range svidCerts {
  for _, uri := range svidCert.URIs {
    logrus.Info("Found URI: " + uri.String())
    uris = append(uris, uri.String())
  }
}

...

Metadata: map[string]string{
  "spiffeId": uris[0],
}

To Reproduce
Steps to reproduce the behavior:

  1. Start SPIRE Server with upstream_bundle = true option.
  2. Register a workload
  3. Export/view SVID for workload
  4. See that the SVID contains multiple PEM blocks.

Expected behavior
The extracted SpiffeID from the SVID should always be for the workload and not for another entry in the trust chain.

Support Spire as a TrustSource

The plugin is designed to support multiple sources of trust used to verify SVIDs but currently the only implemented one is TrustFileSource.

Purpose: Track the implementation of a TrustSpireSource.

Goal

The goal of this to support Spire as a live source of trust for the plugin. The final implementation should be able to connect to one or more instances of Spire (via local agents or otherwise) in order to receive from Spire the known trust CAs that SVIDs can be verified against.

Ownership of X509-SVIDs are currently unknown

Background

Authentication using X509 SVIDs is a three-step process.

  1. Prove client logging into Vault is the owner of the X509-SVID being passed in.
  2. Prove the X509-SVID was generated by a trusted source.
  3. Use the SPIFFE ID to generate a list of policies to apply to the session.

Step (1) occurs during the initial TLS connection between the client and Vault. The mechanisms of that connection result in the verification of the public X509-SVID certificate against the private key used to generate it. If that TLS connection can be made then ownership of the X509-SVID has been proven.

Steps (2) and (3) occur during the execution of this plugin. The plugin receives the X509-SVID certificate (and peers) via logical.Request object passed into the login/renew methods. The X509-SVID can then be verified against known trust sources using spiffe.VerifyPeerCertificate.

Problem

I've discovered there is a problem with this plan stemming from a faulty assumption. It appears that not all of the original TLS connection state is passed to plugins. Here, here, and here show that only the remote_addr is passed from Vault proper into Vault plugins. The faulty assumption stems from my original review of the existing built in TLS authentication method. Seen here this auth built-in plugin uses the peer information in its execution and I incorrectly assumed this information is available in all plugins. In fact, it is not if Vault interacts with the plugin via gRPC (which is the standard communication mechanism for non built-in plugins).

If the X509-SVID is not passed into the plugin via request.Connection.ConnState.PeerCertificates then the ownership of that certificate cannot be guaranteed, thus invalidating step (1).

Path Forward

It appears (though I have not confirmed) that the lack of additional TLS connection information passed to plugins is merely a result of "hasn't been added yet" and not "the information cannot be passed for reasons". If this is true then technically it would be possible to enhance Vault to pass such information to plugins. But, such an action expands the scope of this specific plugin and adds a version dependency. So this approach should not be taken lightly.

It may also be possible to instead enhance the existing TLS authentication built-in to support the usage of SPIFFE IDs. As far as I can tell (though I haven't dug super deep yet) the policies applied to the login/token are passed in as part of something with the certificate. I don't think this approach works well with our use-case (as it may require adding Vault logic to the generation of the certificate, which IMHO should be avoided). Instead, I'd like to find a way to use the SPIFFE ID contained in the certificate to generate the list of policies to apply to the login session.

Discussion: Convert SPIFFE ID into a list of Vault policy IDs

One of the pieces of data returned from the pathAuthLogin method is a list of Vault policy ids to apply to the login session. A core component of this plugin will be to generate those policy IDs from the SPIFFE ID contained in the SVID.

Purpose: Discuss the logic used to convert a SPIFFE ID into a list of policy IDs.

Problem

Given some SPIFFE ID like spiffe://trust-domain/path what is the best way to generate a list of Vault policy IDs such that different structures of SPIFFE IDs and Vault policy IDs can be supported? Ideally this plugin will not place any unnecessary requirements on the structures of either of those identifiers (if any requirements at all).

Thoughts

I'd suggest that a static translation (ie, not able to take into account alternative structures) to be something to avoid. Ideally the plugin can support some level of translation logic provided by the administrators of the Vault instance, whether via code, plugin, or some type of templating.

Not all required X509-SVID validations are taking place

Describe the bug

Not all required validations of X509 based SVIDs are taking place. Specifically, the following are not happening:

  • The certificate is a leaf certificate (I'm not 100% sure this check is occurring)
  • CA field is set to false
  • keyCertSign is not set
  • cRLSign is not set

Per a conversation in the SPIFFE Slack workspace (#spire channel) the current thinking is that these validations should take place in the go-spiffe::VerifyPeerCertificate method. Issue spiffe/go-spiffe#25 has been created on that project to track the addition of those validations.

This ticket will ensure one of the following occurs:

  1. Validations are added to VerifyPeerCertificates (spiffe/go-spiffe#25) and our dependency is changed to require at least the version with those validations.
  2. The validations are added to this project (perhaps as a stopgap while waiting for closure of spiffe/go-spiffe#25).

Add Unit Tests

The project currently doesn't include any tests of individual methods / classes and should.

Initial set of tests to add:

  • Settings file parsing
  • Loading invalid certificates from valid PEM files
  • Loading invalid PEM files
  • File Trust sources with
    • expired certificates
    • multiple certificates, both in multiple files and single files
  • SVID Verification
    • where domain is not in trusted sources

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.