planetscale

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

README

vault-plugin-database-planetscale

Generate @planetscale usernames and passwords using vault.

Usage

Setup Endpoint
  1. Download and enable plugin locally
vault secrets enable database
vault write sys/plugins/catalog/database/vault-plugin-database-planetscale \
  sha256=<SHA256SUM of plugin> \
  command="vault-plugin-database-planetscale"
  1. Configure a database the plugin

    # you can generate a service token withhttps://docs.planetscale.com/concepts/service-tokens
    vault write database/config/planetscale \
      plugin_name=vualt-plugin-database-planetscale \
      allowed_roles="admin" \
      organization="<your organization>" \
      database="<your database>" \
      service_token="<service_token>" \
      service_token_id="<service_token_id>"
    
    
  2. Configure a role

    vault write database/roles/admin \
        db_name=$MNT_PATH \
        creation_statements='{"branch": "main", "role": "admin"}' \
        default_ttl="1h" \
        max_ttl="24h"
    
Configure Role

Roles are have a configurable 'branch' and 'role' that you can specifying using the creation_statements parameter

vault write database/roles/admin \
    db_name=$MNT_PATH \
    creation_statements='{"branch": "main", "role": "admin"}' \
    default_ttl="1h" \
    max_ttl="24h"
Rotating the Root Token

The is not currently implemented, but will be added in the future.

Generate a new username and password

To generate a new token:

Configure a Role and perform a 'read' operation on the creds/<role-name> endpoint.

# To read data using the api
$ vault read database/creds/admin
Key                Value
---                -----
lease_id           database/creds/admin/p2rG2nCorEVTUTVpXnb0NHsh
lease_duration     1h
lease_renewable    true
password           <password>
username           v-token-admin-qrez41hrdjt3n1zviwaz-1657678284

Development

The provided Earthfile (think makefile, but using docker) is used to build, test, and publish the plugin. See the build targets for more information. Common targets include

# build a local version of the plugin
$ earthly +build

# start vault and enable the plugin locally
earthly +dev

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() (interface{}, error)

Types

type ConnectionParameters

type ConnectionParameters struct {
	Organization string `json:"organization" structs:"organization" mapstructure:"organization"`
	Database     string `json:"database" structs:"database" mapstructure:"database"`
}

type Planetscale

type Planetscale struct {
	// contains filtered or unexported fields
}

func (Planetscale) Close

func (c Planetscale) Close() error

Close terminates the database connection.

func (Planetscale) Connection

func (c Planetscale) Connection(ctx context.Context) (*planetscale.Client, error)

Connection creates or returns an existing a database connection. If the session fails on a ping check, the session will be closed and then re-created. This method does locks the mutex on its own.

func (*Planetscale) DeleteUser

func (p *Planetscale) DeleteUser(ctx context.Context, req dbplugin.DeleteUserRequest) (dbplugin.DeleteUserResponse, error)

func (Planetscale) Init

func (c Planetscale) Init(ctx context.Context, conf map[string]interface{}, verifyConnection bool) (map[string]interface{}, error)

func (*Planetscale) Initialize

func (p *Planetscale) Initialize(ctx context.Context, req dbplugin.InitializeRequest) (dbplugin.InitializeResponse, error)

func (*Planetscale) NewUser

func (p *Planetscale) NewUser(ctx context.Context, req dbplugin.NewUserRequest) (dbplugin.NewUserResponse, error)

func (*Planetscale) Type

func (p *Planetscale) Type() (string, error)

func (*Planetscale) UpdateUser

func (p *Planetscale) UpdateUser(ctx context.Context, req dbplugin.UpdateUserRequest) (dbplugin.UpdateUserResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL