Git Product home page Git Product logo

aws-secrets-manager-actions's Introduction

AWS Secrets Manager Actions

npm version GitHub Actions Test GitHub Actions Release GitHub license

This GitHub Action lets you export secrets stored in AWS Secrets Manager to environment values in your GitHub runner.

Usage

Add the AWS IAM keys and the secret name that you want to use from your AWS Secrets Manager secrets list to your GitHub repo secrets. Then, in the GitHub actions yaml, add the following step.

  1. Using github openid-connect (Recommended)
steps:
 - name: Store ENV from AWS SecretManager
   uses: say8425/aws-secrets-manager-actions@v2
   with:
     AWS_DEFAULT_REGION: "YOUR-AWS-REGION"
     SECRET_NAME: ${{ env.SECRET_NAME }}
     OUTPUT_PATH: '.env' # optional
  1. Using github secrets
steps:
 - name: Export ENV from AWS SecretManager
   uses: say8425/aws-secrets-manager-actions@v2
   with:
     AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
     AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
     AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
     SECRET_NAME: ${{ secrets.SECRET_NAME }}
     OUTPUT_PATH: '.env' # optional

AWS IAM

You need an AWS IAM user that has policies to access/read the AWS Secrets Manager secret. Add this IAM user's access id/keys as AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and region as AWS_DEFAULT_REGION in your repo's GitHub Secrets.

Policy

An example policy to provide the permissions to the user is given below:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "secretsmanager:GetSecretValue",
            "Resource": "*"
        }
    ]
}

We recommend being more specific with the Resource in the policy by adding the secret ARN.

Get more information at AWS User Guide.

Secret Name

This is the secret name that you want to read the secrets from. Only one secret name is supported.

Environment Values

Your secrets will be exported as environment values into the github runner. These environment values are masked with *** in logs in the GitHub Actions for security purposes.

Raw string values

Most of the secrets can be parsed. However, in some case, parsing of secrets can fail. An example case is an invalid json. In such cases, the unparsed raw sting is stored in asm_secret env key.

Export environment variables to file

The environment variables can also be exported to a file with OUTPUT_PATH input parameter. When OUTPUT_PATH is defined, the GitHub action writes the environment variables to the specified filename.

Contributing

Your contributions are always welcome! Feel free to check issues or Pull Requests

License

This project is MIT licensed.

aws-secrets-manager-actions's People

Contributors

brunocascio avatar dependabot[bot] avatar mohammedalabd avatar monkeymon avatar rishang avatar say8425 avatar slesaad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aws-secrets-manager-actions's Issues

Possible to omit certain environment variables?

This is definitely a feature request, but I think it would be a great one. Some environment variables are needed for the app to run, some are just needed to log into the instance and create the docker container, for example.

Therefore, it would be wonderful to have an omit property, which is simply a comma-separated list of keys to omit from the environment output.

So if the collection of environment variables is:

[
    { key: 'ENV1', value: 'value 1' },
    { key: 'ENV2', value: 'value 2' },
    { key: 'ENV3', value: 'value 3' },
    { key: 'ENV4', value: 'value 4' },
]

Then you could supply an omit property of something like:

omit: ENV1,ENV3

Then the resulting environment variables would only be:

ENV2=value 2
ENV4=value 4

Support for plaintext values

Very nice work! One issue I ran into when testing this myself is that AWS SM supports raw text values, in addition to key-value pairs. It would be good to have a flag to set whether to try to parse key value pairs, or just read the raw secretstring and assign it to a supplied environment variable name.

I don't know how often plaintext gets used in SM overall, but some other tools expect plaintext values such as https://github.com/Accenture/hiera-aws-sm, so it would be great to support that as an option.

add test for gh workflow

jobs:  
  test:  
    runs-on: ubuntu-latest  
    name: test-action  
    steps:  
     - name: Store ENV from AWS SecretManager
       uses: say8425/aws-secrets-manager-actions@v1
       with:
         AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
         AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
         AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
         SECRET_NAME: ${{ secrets.SECRET_NAME }}
     - name: Should have SCIENTIFIC_NAME
       uses: therussiankid92/gat
       with:  
         assertion: should.equal  
         expected: Pygoscelis adeliae
         actual: ${{ env.SCIENTIFIC_NAME }}  
  • add test tag

refactor eslint

Current eslint config look so stupid.
For example why we need jsx option?

Erroring from deprecated set-env command

Hi, when I try to use your action, I get errors with messages like "The set-env command is disabled. "

I believe this is because your most recent release is v1.2.1, which was released before you upgraded to @actions/core version 1.2.6.

Would you mind publishing a new release to the actions marketplace?

Backward path

It would be great if you can make secrets pushing to Secret Manager from json file

Change file output to end with newline?

I am using this great package for some GitHub Actions which export some environment variables to a file. One issue I am running into is that I am using DamianReeves/write-file-action to append additional environment variables to the outputted file. However, because of the limitations of .yml files, I am unable to insert a preceeding line break in the DamianReeves/write-file-action content property, so the appended items corrupt the last line of the output file from your action. I think this would be easily solved if the output file content has all items output with a newline at the end.

In order to make all lines end with a newline (including the last line), would it be acceptable to change this line:

      const secretsAsEnv = Object.entries(parsedSecret).map(([key, value]) => `${key}=${value}`).join('\n')

to this:

      const secretsAsEnv = Object.entries(parsedSecret).map(([key, value]) => `${key}=${value}\n`)

Fatal bug in v1.3.2

Action just crashes with this error:
File not found: '/home/runner/work/_actions/say8425/aws-secrets-manager-actions/v1.3.2/dist/index.js'

getInput() looks not worked

Run say8425/[email protected]
 with:
   AWS_ACCESS_KEY_ID: ***
   AWS_SECRET_ACCESS_KEY: ***
   AWS_DEFAULT_REGION: ap-northeast-2
   SECRET_NAME: pongdang-env-test
/home/runner/work/_actions/say8425/aws-secrets-manager-actions/v0.9.1/dist/index.js:208
const secretName = _actions_core__WEBPACK_IMPORTED_MODULE_0___default().getInput('SECRET_NAME')

TypeError: Cannot read property 'getInput' of undefined
  at Module.104 (/home/runner/work/_actions/say8425/aws-secrets-manager-actions/v0.9.1/dist/index.js:208:72)
  at __webpack_require__ (/home/runner/work/_actions/say8425/aws-secrets-manager-actions/v0.9.1/dist/index.js:22:30)
  at startup (/home/runner/work/_actions/say8425/aws-secrets-manager-actions/v0.9.1/dist/index.js:37:19)
  at /home/runner/work/_actions/say8425/aws-secrets-manager-actions/v0.9.1/dist/index.js:43:18
  at Object.<anonymous> (/home/runner/work/_actions/say8425/aws-secrets-manager-actions/v0.9.1/dist/index.js:46:10)
  at Module._compile (internal/modules/cjs/loader.js:774:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
  at Module.load (internal/modules/cjs/loader.js:641:32)
  at Function.Module._load (internal/modules/cjs/loader.js:556:12)
  at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
##[error]Node run failed with exit code 1

looks github core module not imported well.
https://github.com/say8425/PongDang-API/runs/299328097

Export env variables to file

Hi @say8425 ,

I'm using SSM to save a lot of env variables so I'm looking for a way to pass them at once.

Example:

- name: Make environment variables from AWS SecretManager global available
  uses: say8425/[email protected]
  with:
     AWS_ACCESS_KEY_ID: ${{ secrets.staging_AWS_ACCESS_KEY_ID }}
     AWS_SECRET_ACCESS_KEY: ${{ secrets.staging_AWS_SECRET_ACCESS_KEY }}
     AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
     SECRET_NAME: ${{ secrets.staging_SECRET_NAME }}

- name: Build package
  run: |
      env > .env
      docker-compose -f docker-compose.deploy.yml run \
        --rm --no-deps -u root \
        -v ${GITHUB_WORKSPACE}/build:/home/node/app/build \
        frontend \
        npm run build

As you see, I pass them via env > .env but it contains a lot of system envs like PATH, HOME, etc

A possible solution might be export SSM env variables to $GITHUB_WORKSPACE/<ssm-var-name> file.

With that implemented I would do this:

- name: Make environment variables from AWS SecretManager global available
  uses: say8425/[email protected]
  with:
     AWS_ACCESS_KEY_ID: ${{ secrets.staging_AWS_ACCESS_KEY_ID }}
     AWS_SECRET_ACCESS_KEY: ${{ secrets.staging_AWS_SECRET_ACCESS_KEY }}
     AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
     SECRET_NAME: ${{ secrets.staging_SECRET_NAME }}
     OUTPUT_PATH: ${{ github.workspace }}/.env

- name: Build package
  run: |
      # .env is present here
      docker-compose -f docker-compose.deploy.yml run \
        --rm --no-deps -u root \
        -v ${GITHUB_WORKSPACE}/build:/home/node/app/build \
        frontend \
        npm run build

With the above configuration, I only pass SSM values instead of the whole system vars

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.