5
0
Fork 0
mirror of https://github.com/hashicorp/vault-action.git synced 2025-11-07 07:06:56 +00:00
A GitHub Action that simplifies using HashiCorp Vault™ secrets as build variables.
Find a file
Antoine Méausoone 3b9239de79
feat(authenticate): add approle auth method (#10)
* feat(authenticate): add approle auth method

* docs(readme): update readme

* fix: update index.js

* fix: update got to 10.2.2 to fix ncc

* chore: clean up code slightly

* chore: update tests to use got correctly

* chore(test): fix integration tests

* chore: streamline method logic

* chore: make role and secret required in approle

Co-authored-by: Sébastien FAUVART <sebastien.fauvart@gmail.com>
Co-authored-by: Richard Simpson <richardsimpson@outlook.com>
2020-01-28 19:10:19 -06:00
.github/workflows chore(build): re-enable builds on PR and restrict publish to master 2020-01-09 10:45:52 -06:00
dist feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00
integrationTests feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00
.gitignore Initial commit 2019-09-20 12:33:19 -05:00
action.js feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00
action.test.js feat: simplify input parameters and docs 2019-09-20 17:56:08 -05:00
action.yml feat(namespace): handle request on vault namespace (#5) 2019-11-24 15:21:11 -06:00
docker-compose.yml feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00
index.js feat: add initial code logic 2019-09-20 15:09:58 -05:00
jest.config.js chore(test): organize tests a bit better (#7) 2019-11-24 16:00:31 -06:00
jsconfig.json feat: add initial code logic 2019-09-20 15:09:58 -05:00
LICENSE Initial commit 2019-09-20 12:33:19 -05:00
package-lock.json feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00
package.json feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00
README.md feat(authenticate): add approle auth method (#10) 2020-01-28 19:10:19 -06:00

vault-action

A helper action for easily pulling secrets from the default v2 K/V backend of vault.

Example Usage

jobs:
    build:
        # ...
        steps:
            # ...
            - name: Import Secrets
              uses: RichiCoder1/vault-action
              with:
                url: https://vault.mycompany.com:8200
                token: ${{ secrets.VaultToken }}
                secrets: |
                    ci/aws accessKey | AWS_ACCESS_KEY_ID ;
                    ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
                    ci npm_token                    
            # ...

Authentication method

The method parameter can have these value :

  • token: (by default) you must provide a token parameter
...
with:
  url: https://vault.mycompany.com:8200
  token: ${{ secrets.VaultToken }}
  • approle: you must provide a roleId & secretId parameter
...
with:
  url: https://vault.mycompany.com:8200
  method: approle
  roleId: ${{ secrets.roleId }}
  secretId : ${{ secrets.secretId }}

Key Syntax

The secrets parameter is a set of multiple secret requests separated by the ; character.

Each secret request is comprised of the path and the key of the desired secret, and optionally the desired Env Var output name.

{{ Secret Path }} {{ Secret Key }} | {{ Output Environment Variable Name }}

Simple Key

To retrieve a key npmToken from path ci that has value somelongtoken from vault you could do:

with:
    secrets: ci npmToken

vault-action will automatically normalize the given data key, and output:

NPMTOKEN=somelongtoken

Set Environment Variable Name

However, if you want to set it to a specific environmental variable, say NPM_TOKEN, you could do this instead:

with:
    secrets: ci npmToken | NPM_TOKEN

With that, vault-action will now use your requested name and output:

NPM_TOKEN=somelongtoken

Multiple Secrets

This action can take multi-line input, so say you had your AWS keys stored in a path and wanted to retrieve both of them. You can do:

with:
    secrets: |
        ci/aws accessKey | AWS_ACCESS_KEY_ID ;
        ci/aws secretKey | AWS_SECRET_ACCESS_KEY        

Namespace

This action could be use with namespace Vault Enterprise feature. You can specify namespace in request :

steps:
    # ...
    - name: Import Secrets
      uses: RichiCoder1/vault-action
      with:
        url: https://vault-enterprise.mycompany.com:8200
        method: token
        token: ${{ secrets.VaultToken }}
        namespace: ns1
        secrets: |
            ci/aws accessKey | AWS_ACCESS_KEY_ID ;
            ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
            ci npm_token            

Masking

This action uses Github Action's built in masking, so all variables will automatically be masked if printed to the console or to logs.