Coder Social home page Coder Social logo

lkubb / vault-plugin-database-influxdb2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 77 KB

Vault database plugin which provides short-lived authorizations for InfluxDB v2

License: Mozilla Public License 2.0

Go 100.00%
influxdb influxdb2 vault vault-plugins

vault-plugin-database-influxdb2's Introduction

InfluxDB v2 Vault Database Plugin

This plugin allows to use Vault to manage InfluxDB version 2 authentication.

Prerequisites

InfluxDB

After initialization, you will need to create a dedicated user account for Vault, add it to an organization and issue an authorization (token) that carries all necessary permissions.

Creating a user account is easy:

influx user create --name vault --org $INFLUX_ORG

Creating an authorization is more involved since the influx auth create command scopes authorizations permissions to an organization, but this plugin needs them to apply to all organizations. Furthermore, the root token needs to carry all permissions you intend to issue to clients.

Creating the authorization:

curl -H "Authorization: Token ${INFLUX_TOKEN}" -d "$definitions" "https://${INFLUX_HOST}/api/v2/authorizations"

Example authorization definition:

{
    "orgId": "1337cafebabe1337",
    "userID": "deadbeefdabbad00",
    "permissions": [
        {
            "action": "read",
            "resource": {
                "type": "authorizations"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "authorizations"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "orgs"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "orgs"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "users"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "users"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "buckets"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "buckets"
            }
        }
    ]
}

Vault

First, ensure your Vault configuration defines plugin_directory and api_address correctly (the latter is used for inter-process communication, consider TLS certificates!).

Currently, there are no binary releases, hence you will need to compile this plugin, e.g.:

go build ./cmd/influxdb2-database-plugin
# or gox -osarch="linux/amd64" ./cmd/influxdb2-database-plugin

Then move the plugin into plugin_directory, ensure correct ownership/permissions and register it:

vault plugin register -sha256=${BINARY_SHA_SUM} influxdb2-database-plugin

Configuration

Connection

  • host: FQDN/IP address of the InfluxDB v2 server. Required.
  • port: The port the InfluxDB v2 server is listening on (int). Defaults to 8086.
  • organization: The organization the vault user is part of. Will also be default organization for roles. Required.
  • password: The authorization token you created. Required.
  • tls: Whether to enable TLS. Defaults to false.
  • insecure_tls: Whether to skip verifying server certificates. Defaults to false.
  • ca_cert: The path to a PEM-encoded CA cert file to use to verify the InfluxDB v2 server's identity.
  • ca_path: The path to a directory of PEM-encoded CA cert files to use to verify the InfluxDB v2 server's identity.
  • client_cert: The path to a certificate for the InfluxDB v2 client to present for communication.
  • client_key: The path to the key for the InfluxDB v2 client to use for communication.
  • tls_min_version: Minimum acceptable TLS version (string). Defaults to "1.2"
  • connect_timeout: Timeout for HTTP connections. Defaults to 5s.

Role

A role's creation_statements define which permissions the issued authorization will carry and, optionally, the organization the user will belong to. It should be a list containing a single, JSON-encoded string value. The JSON data can contain the following fields:

  • read: A list of resources to allow read access to.
  • write: A list of resources to allow write access to.
  • read_bucket: A list of bucket names to allow read access to.
  • write_bucket: A list of bucket names to allow write access to.
  • org: A valid organization name the user should belong to. Defaults to the connection's organization.

Credentials

InfluxDB v2 is a bit weird with authentication and authorization. User accounts are used in some places, but the entity providing authentication and describing resource access (authorization) is called Authorization (~ API Key). It works like a Vault token. A user name therefore is separate from the duties Vault usually fulfills.

Generated user names match the Vault database role name by default to avoid unexpected behavior in InfluxDB. You can change that behavior by specifying an alternative username template. Mind that by default, this plugin revokes Authorizations only.

  • username_template: A template describing username generation. See the Vault docs for details. Defaults to the database role name.
  • ephemeral_users: When the template above generates unique usernames, enable deletion of user accounts during lease revocation. Defaults to false.
  • description_template: A template describing the authorization. See the Vault docs for details. Defaults to the requesting token's display name + database role name.

Notes

  • This plugin is in very early development.
  • Ironically, to support the new InfluxDB API, this plugin needs to be written using the old (v4) SDK for Vault database plugins, which is deprecated. The reason is that tokens must be generated on the InfluxDB server and cannot be forced by Vault. Until there is a workaround, this plugin might stop working with future Vault releases once support for the old SDK is removed entirely.

References

vault-plugin-database-influxdb2's People

Contributors

lkubb avatar

Watchers

 avatar

vault-plugin-database-influxdb2's Issues

unable to write config into vault

Hi

I am using latest vault: Vault 1.14.0
Influx : InfluxDB v2.7.1

I was following ur readme, all good acceptnot clear how to add influxdb config into vault.
I have registered plugin no prob, but not managed to run write command:

VAULT_TOKEN=$root_token vault write database/config/mydb plugin_name="influxdb-database-plugin" host=localhost connection_url="http://influxhost:8086/" username=vault password=myniceinfluxuserpass allowed_roles=my-role

all I get is

Error writing data to database/config/mydb: Error making API request.

URL: PUT https://vault_host:8200/v1/database/config/mydb
Code: 400. Errors:

* error creating database object: unable to parse connection url

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.