Skip to content

feat: wildcard for fetching all secrets#247

Closed
matryxxx02 wants to merge 8 commits intohashicorp:mainfrom
Tabuleo:feat/wildcard-all-secrets
Closed

feat: wildcard for fetching all secrets#247
matryxxx02 wants to merge 8 commits intohashicorp:mainfrom
Tabuleo:feat/wildcard-all-secrets

Conversation

@matryxxx02
Copy link
Copy Markdown

@matryxxx02 matryxxx02 commented Aug 26, 2021

fixes #234

This PR allows the use of * (wildcard) to fetch all secrets into env variables.

Example Usage

example of secrets :

{
 ci : {
   aws : {
     URL_API : {
        "http://localhost:3000"
     }
   }
 }
}
jobs:
    build:
        # ...
        steps:
            # ...
            - name: Import Secrets
              uses: hashicorp/vault-action@v2.3.1
              with:
                url: https://vault.mycompany.com:8200
                token: ${{ secrets.VaultToken }}
                caCertificate: ${{ secrets.VAULTCA }}
                secrets: |
                    secret/data/ci/aws *
            # ...
           - name : Test secret
              run: echo "Hello ${{env.URL_API}}"

@hashicorp-cla
Copy link
Copy Markdown

hashicorp-cla commented Aug 26, 2021

CLA assistant check
All committers have signed the CLA.

@matryxxx02 matryxxx02 changed the title feat: wildcard for fetching all secrets (#234) feat: wildcard for fetching all secrets Aug 26, 2021
Co-authored-by: Brian Woodward <brian.woodward@gmail.com>
@slemme1
Copy link
Copy Markdown
Contributor

slemme1 commented Oct 11, 2021

When will this be resolved to get this code merged?

@slemme1
Copy link
Copy Markdown
Contributor

slemme1 commented Oct 11, 2021

When will this get resolved to get this code merged?

@bfaulk96
Copy link
Copy Markdown

This would be great!

@bfaulk96
Copy link
Copy Markdown

@matryxxx02 any chance you could resolve those merge conflicts?

@bfaulk96
Copy link
Copy Markdown

Dang, that was fast!! @doowb What are the chances of this landing in the next release?

@ElenaForester
Copy link
Copy Markdown

Eagerly waiting for this to be released 🙏

@karlanuetzel
Copy link
Copy Markdown

+1 on this landing in next release

@ndrader
Copy link
Copy Markdown

ndrader commented Jan 20, 2022

Any news on this getting merged? Would love to use it.

@ElenaForester
Copy link
Copy Markdown

Any news on this getting merged? Would love to use it.

I figured out that for now you can use

secrets: |
                    secret/data/ci/aws $.$

@Marcanta
Copy link
Copy Markdown

Marcanta commented Feb 8, 2022

Any news on this getting merged? Would love to use it.

I figured out that for now you can use

secrets: |
                    secret/data/ci/aws $.$

I agree, however, it's annoying to use...

      - name: Import env.TEST from vault
        uses: hashicorp/vault-action@v2.3.0
        with:
          url: http://127.0.0.1:8200
          tlsSkipVerify: true
          token: ${{ secrets.VAULT_TOKEN }}
          secrets: |
              secret/data/test $.$ | TEST
              
      - name : echo env
        run: echo "Hello ${{env.TEST.HELLO_WORLD}}"

It would be great if we could drop the TEST.

@karlanuetzel
Copy link
Copy Markdown

Any update on this?

@bfaulk96
Copy link
Copy Markdown

bfaulk96 commented Oct 13, 2022

Currently going on 1 year, 47 days, 21 hours, 50 minutes since this great PR was created and subsequently ignored.

@heatherezell
Copy link
Copy Markdown

Currently going on 1 year, 47 days, 21 hours, 50 minutes since this great PR was created and subsequently ignored.

You're right, and you have my apologies as well as my thanks for resurfacing this. I'll have our engineering team take a look. :)

@bfaulk96
Copy link
Copy Markdown

@hsimon-hashicorp Well, the as the old adage goes, "Better late than never". Thank you for looking into this! 😄

@bfaulk96
Copy link
Copy Markdown

@matryxxx02 looks like there are once again a few merge conflicts, if you have time to address them

…ecrets

# Conflicts:
#	package-lock.json
#	src/action.js
@matryxxx02 matryxxx02 requested a review from doowb January 19, 2023 00:45
Copy link
Copy Markdown

@brewgator brewgator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work so far, just a couple possible issues I noticed. Thank you for sticking with this, I do think that this is a good feature we would want to include.

selector = "data." + selector
body = JSON.parse(body)
if (body.data["data"] != undefined) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the changes here? dist/index.js is generated upon release, so we don't need to include any files in the dist/ directory.

body = JSON.parse(body)
if (body.data["data"] != undefined) {

let value;
Copy link
Copy Markdown

@brewgator brewgator Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we will need to pull out the JSON parse and move it here so body is parsed in both conditional branches.

const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes'];
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];

function addMask(value) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving this to its own function is a good idea, however it seems to cause some issues with the acceptance tests

~$ npm run test

> vault-action@0.1.0 test
> jest

 PASS  src/auth.test.js
 FAIL  src/action.test.js
  ● exportSecrets › single-line secret gets masked

    expect(jest.fn()).toBeCalledTimes(expected)

    Expected number of calls: 1
    Received number of calls: 2

      334 |         await exportSecrets();
      335 |
    > 336 |         expect(command.issue).toBeCalledTimes(1);
          |                               ^
      337 |
      338 |         expect(command.issue).toBeCalledWith('add-mask', 'secret');
      339 |         expect(core.setOutput).toBeCalledWith('key', 'secret');

      at Object.toBeCalledTimes (src/action.test.js:336:31)

  ● exportSecrets › multi-line secret gets masked for each line

    expect(jest.fn()).toBeCalledTimes(expected)

    Expected number of calls: 2
    Received number of calls: 4

      354 |         await exportSecrets();
      355 |
    > 356 |         expect(command.issue).toBeCalledTimes(2); // 1 for each non-empty line.
          |                               ^
      357 |
      358 |         expect(command.issue).toBeCalledWith('add-mask', 'a multi-line string');
      359 |         expect(command.issue).toBeCalledWith('add-mask', 'with blank lines');

      at Object.toBeCalledTimes (src/action.test.js:356:31)

::add-mask::value
::add-mask::value
 PASS  src/retries.test.js

Test Suites: 1 failed, 2 passed, 3 total
Tests:       2 failed, 27 passed, 29 total
Snapshots:   0 total
Time:        2.532 s, estimated 3 s
Ran all test suites.
::add-mask::value
::add-mask::value

@maxcoulombe
Copy link
Copy Markdown
Contributor

Hey everyone, thanks for showing interest in this feature. I'm happy to report that an equivalent implementation was recently merged in #488 . I'll close this PR for now as the functionality implemented appears equivalent.

The wildcard selector feature should be available in an up-coming v2.8.0 release, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to import all keys from specific path