Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save solovyovk/a413c2f78929c088c9f0f3d8f7ec187f to your computer and use it in GitHub Desktop.

Select an option

Save solovyovk/a413c2f78929c088c9f0f3d8f7ec187f to your computer and use it in GitHub Desktop.

Revisions

  1. @greenbrian greenbrian revised this gist Feb 1, 2019. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions Terraform.hcl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    resource "vault_policy" "example" {
    name = "basic"
    policy = "${file("policies/basic.hcl")}"
    }

    # contents of basic.hcl
    path "sys/renew/*" {
    capabilities = ["update"]
    }

    # Allow renewal of token leases
    path "auth/token/renew/*" {
    capabilities = ["update"]
    }
  2. @greenbrian greenbrian revised this gist Sep 7, 2017. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion HashiCorp Vault - methods of writing ACL policies
    Original file line number Diff line number Diff line change
    @@ -1 +1,11 @@
    There are many methods for writing Vault policies, I've just used this gist to collect the most common methods such that they can be easily used as references for syntax, as well as evaluation for which method suits a particular purpose.
    There are many methods for writing Vault policies.

    This gist was created to collect the most common methods
    such that they can be easily used as references for syntax,
    as well as evaluation for which method suits a particular purpose.

    TODO:

    - Add complex policy examples
    - Add @json.file examples
    - Add httpie examples
  3. @greenbrian greenbrian revised this gist Sep 7, 2017. No changes.
  4. @greenbrian greenbrian revised this gist Sep 7, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions HashiCorp Vault - methods of writing ACL policies
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    There are many methods for writing Vault policies, I've just used this gist to collect the most common methods such that they can be easily used as references for syntax, as well as evaluation for which method suits a particular purpose.
  5. @greenbrian greenbrian revised this gist Sep 6, 2017. No changes.
  6. @greenbrian greenbrian created this gist Sep 6, 2017.
    15 changes: 15 additions & 0 deletions Using Curl - JSON body
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    curl \
    --silent \
    --header "X-Vault-Token: root" \
    --request POST \
    --data '{"rules":"path \"secret/foo\" {\n capabilities = [\"list\",\"read\"]\n} \npath \"supersecret/*\" {\n capabilities = [\"list\", \"read\"]\n} \npath \"auth/token/lookup-self\" {\n capabilities = [\"read\"]\n}"}' \
    http://127.0.0.1:8200/v1/sys/policy/test


    # read back policy
    curl \
    --silent \
    --header "X-Vault-Token: root" \
    --request GET \
    http://127.0.0.1:8200/v1/sys/policy/test | jq '.rules'
    "path \"secret/foo\" {\n capabilities = [\"list\",\"read\"]\n} \npath \"supersecret/*\" {\n capabilities = [\"list\", \"read\"]\n} \npath \"auth/token/lookup-self\" {\n capabilities = [\"read\"]\n}"
    24 changes: 24 additions & 0 deletions Using Vault CLI - using stdin
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    echo '
    path "secret/foo" {
    capabilities = ["list","read"]
    }
    path "supersecret/*" {
    capabilities = ["list", "read"]
    }
    path "auth/token/lookup-self" {
    capabilities = ["create", "read"]
    }
    ' | vault policy-write user -

    ## read policy back
    #$ vault policies user

    path "secret/foo" {
    capabilities = ["list","read"]
    }
    path "supersecret/*" {
    capabilities = ["list", "read"]
    }
    path "auth/token/lookup-self" {
    capabilities = ["create", "read"]
    }
    56 changes: 56 additions & 0 deletions Using Vault CLI - write using HCL file
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    echo '
    path "secret/foo" {
    capabilities = ["list","read"]
    }
    path "supersecret/*" {
    capabilities = ["list", "read"]
    }
    path "auth/token/lookup-self" {
    capabilities = ["create", "read"]
    }
    ' > policy.hcl

    vault policy-write test2 policy.hcl
    ####################################################
    # read back policy
    #$ vault policies test2

    path "secret/foo" {
    capabilities = ["list","read"]
    }
    path "supersecret/*" {
    capabilities = ["list", "read"]
    }
    path "auth/token/lookup-self" {
    capabilities = ["create", "read"]
    }

    ####################################################
    vault read -format=json sys/policy/test2
    {
    "request_id": "dae10a3f-1334-9cb9-df2e-4571d32c6530",
    "lease_id": "",
    "lease_duration": 0,
    "renewable": false,
    "data": {
    "name": "test2",
    "rules": "\npath \"secret/foo\" {\n capabilities = [\"list\",\"read\"]\n}\npath \"supersecret/*\" {\n capabilities = [\"list\", \"read\"]\n}\npath \"auth/token/lookup-self\" {\n capabilities = [\"create\", \"read\"]\n}\n\n"
    },
    "warnings": null
    }


    ####################################################
    vault read sys/policy/test2
    Key Value
    --- -----
    name test2
    rules path "secret/foo" {
    capabilities = ["list","read"]
    }
    path "supersecret/*" {
    capabilities = ["list", "read"]
    }
    path "auth/token/lookup-self" {
    capabilities = ["create", "read"]
    }