Skip to content

Instantly share code, notes, and snippets.

@voxxit
Last active July 7, 2022 03:02
Show Gist options
  • Save voxxit/dd6f95398c1bdc9f1038 to your computer and use it in GitHub Desktop.
Save voxxit/dd6f95398c1bdc9f1038 to your computer and use it in GitHub Desktop.

Revisions

  1. voxxit revised this gist May 21, 2015. 1 changed file with 41 additions and 7 deletions.
    48 changes: 41 additions & 7 deletions USING-VAULT.md
    Original file line number Diff line number Diff line change
    @@ -18,14 +18,18 @@ Authorizing using the root token:
    vault auth <root token>
    ```

    Mount AWS, and generate dynamic AWS credentials:
    ### Dynamic AWS Credentials

    https://www.vaultproject.io/docs/secrets/aws/index.html

    ```
    vault mount aws
    $ vault mount aws
    Successfully mounted 'aws' at 'aws'!
    vault write aws/config/root \
    access_key=<aws_access_key_id> \
    secret_key=<aws_secret_access_key> \
    region=us-east-1
    $ vault write aws/config/root \
    access_key=<aws_access_key_id> \
    secret_key=<aws_secret_access_key> \
    region=us-east-1
    # use http://awspolicygen.s3.amazonaws.com/policygen.html to generate policies
    # here is an example one which provides full access to <bucket name>:
    @@ -58,5 +62,35 @@ vault write aws/roles/s3 name=s3 policy=- <<EOF
    }
    EOF
    vault read aws/creds/s3
    $ vault read aws/creds/s3
    Key Value
    lease_id aws/creds/s3/7cb8df71-782f-3de1-79dd-251778e49f58
    lease_duration 3600
    access_key AKIAIOMYUTSLGJOGLHTQ
    secret_key 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
    ```

    ### Dynamic MySQL Usernames/Passwords

    https://www.vaultproject.io/docs/secrets/mysql/index.html

    ```
    $ vault mount mysql
    Successfully mounted 'mysql' at 'mysql'!
    $ vault write mysql/config/connection value="root:secret@tcp(mysql:3306)/"
    Success! Data written to: mysql/config/connection
    $ vault write mysql/config/lease lease=1h lease_max=24h
    Success! Data written to: mysql/config/lease
    $ vault write mysql/roles/readonly sql="CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}'; GRANT SELECT ON *.* TO '{{name}}'@'%';"
    Success! Data written to: mysql/roles/readonly
    $ vault read mysql/creds/readonly
    Key Value
    lease_id mysql/creds/readonly/bd404e98-0f35-b378-269a-b7770ef01897
    lease_duration 3600
    password 132ae3ef-5a64-7499-351e-bfe59f3a2a21
    username root-aefa635a-18
    ```
  2. voxxit revised this gist May 21, 2015. 1 changed file with 57 additions and 0 deletions.
    57 changes: 57 additions & 0 deletions USING-VAULT.md
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,61 @@
    git clone https://gist.github.com/dd6f95398c1bdc9f1038.git vault
    cd vault
    docker-compose up -d
    export VAULT_ADDR=http://192.168.99.100:8200
    ```

    Initializing a vault:
    ```
    vault init
    vault unseal <secret 1>
    vault unseal <secret 2>
    vault unseal <secret 3>
    ```

    Authorizing using the root token:
    ```
    vault auth <root token>
    ```

    Mount AWS, and generate dynamic AWS credentials:
    ```
    vault mount aws
    vault write aws/config/root \
    access_key=<aws_access_key_id> \
    secret_key=<aws_secret_access_key> \
    region=us-east-1
    # use http://awspolicygen.s3.amazonaws.com/policygen.html to generate policies
    # here is an example one which provides full access to <bucket name>:
    vault write aws/roles/s3 name=s3 policy=- <<EOF
    {
    "Statement" : [
    {
    "Effect" : "Allow",
    "Action" : [
    "s3:ListAllMyBuckets"
    ],
    "Resource" : "arn:aws:s3:::*"
    }, {
    "Effect" : "Allow",
    "Action" : [
    "s3:ListBucket",
    "s3:GetBucketLocation"
    ],
    "Resource" : "arn:aws:s3:::<bucket name>"
    }, {
    "Effect" : "Allow",
    "Action" : [
    "s3:PutObject",
    "s3:GetObject",
    "s3:DeleteObject"
    ],
    "Resource":"arn:aws:s3:::<bucket name>/*"
    }
    ]
    }
    EOF
    vault read aws/creds/s3
    ```
  3. voxxit renamed this gist May 21, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. voxxit renamed this gist May 21, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. voxxit revised this gist May 21, 2015. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,5 @@
    `git clone https://gist.github.com/dd6f95398c1bdc9f1038.git vault && cd vault && docker-compose up`
    ```
    git clone https://gist.github.com/dd6f95398c1bdc9f1038.git vault
    cd vault
    docker-compose up -d
    ```
  6. voxxit revised this gist May 21, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    `git clone https://gist.github.com/dd6f95398c1bdc9f1038.git vault && cd vault && docker-compose up`
  7. voxxit revised this gist May 21, 2015. 3 changed files with 9 additions and 3 deletions.
    8 changes: 6 additions & 2 deletions consul.json
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,12 @@
    {
    {
    "http_api_response_headers": {
    "Access-Control-Allow-Origin": "*"
    },
    "client_addr": "0.0.0.0",
    "datacenter": "dc1",
    "acl_datacenter": "dc1",
    "data_dir": "/data",
    "server": true,
    "bootstrap": true
    "bootstrap": true,
    "ui_dir": "/ui"
    }
    2 changes: 2 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,8 @@ mysql:

    consul:
    image: voxxit/consul:latest
    ports:
    - 80:8500
    volumes:
    - ./consul.json:/etc/consul.json
    command: "agent -config-file=/etc/consul.json"
    2 changes: 1 addition & 1 deletion vault.hcl
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    backend "consul" {
    address = "consul:8500"
    advertise_addr = "consul:8301"
    advertise_addr = "consul:8300"
    scheme = "http"
    }

  8. voxxit revised this gist May 21, 2015. 3 changed files with 35 additions and 7 deletions.
    8 changes: 8 additions & 0 deletions consul.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    {
    "client_addr": "0.0.0.0",
    "datacenter": "dc1",
    "acl_datacenter": "dc1",
    "data_dir": "/data",
    "server": true,
    "bootstrap": true
    }
    22 changes: 15 additions & 7 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,21 @@
    vault:
    image: voxxit/vault
    image: voxxit/vault:latest
    volumes:
    - ./vault.hcl:/etc/vault.hcl
    links:
    - consul:consul
    - mysql:mysql
    - "consul:consul"
    - "mysql:mysql"
    ports:
    - 8200:8200
    command: "server -config=/etc/vault.hcl"

    mysql:
    image: mysql
    mysql:
    image: mysql:latest
    environment:
    - MYSQL_ALLOW_BLANK_PASSWORD=true
    - "MYSQL_ROOT_PASSWORD=secret"

    consul:
    image: voxxit/consul
    image: voxxit/consul:latest
    volumes:
    - ./consul.json:/etc/consul.json
    command: "agent -config-file=/etc/consul.json"
    12 changes: 12 additions & 0 deletions vault.hcl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    backend "consul" {
    address = "consul:8500"
    advertise_addr = "consul:8301"
    scheme = "http"
    }

    listener "tcp" {
    address = "0.0.0.0:8200"
    tls_disable = 1
    }

    disable_mlock = true
  9. voxxit revised this gist May 21, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@ vault:

    mysql:
    image: mysql
    environment:
    - MYSQL_ALLOW_BLANK_PASSWORD=true

    consul:
    image: voxxit/consul
  10. voxxit created this gist May 21, 2015.
    11 changes: 11 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    vault:
    image: voxxit/vault
    links:
    - consul:consul
    - mysql:mysql

    mysql:
    image: mysql

    consul:
    image: voxxit/consul