Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use action to hide sensitive inputs #74

Merged
merged 1 commit into from
May 30, 2024
Merged

Use action to hide sensitive inputs #74

merged 1 commit into from
May 30, 2024

Conversation

joshmenden
Copy link

For some reason, the workflow_dispatch action is somewhat of a second-class citizen, and does not receive a lot of the "safe by default" behavior that other action types do.

For example, there's not clear or obvious way to keep inputs secret & masked from the logs. GitHub's add-mask functionality doesn't work because the echo statement required to create the mask logs the value (see this demo repo run).

If these inputs were automatically injected as environment variables like the documentation suggest it does with $INPUT_, we wouldn't have to worry about the values being logged, but as of right now, workflow_dispatch actions do not receive that behavior.

The common workaround seems to be to parse out the inputs from the GITHUB_EVENT JSON and put those into an env var which then doesn't get logged. Something like:

jobs:
  test-secret:
    runs-on: ubuntu-latest
    steps:
    - name: Create secret environment variables from inputs 
      run: |
        SUPER_SECRET=$(jq -r '.inputs.super_secret' $GITHUB_EVENT_PATH)
        echo ::add-mask::$SUPER_SECRET
        echo SUPER_SECRET="$SUPER_SECRET" >> $GITHUB_ENV
    - name: Now, I can safely use input via environment variable
      run: echo "$SUPER_SECRET" # the output from this command will be "echo ***"

This is suggested a few times here, here and here.

Instead, I stumbled on this GitHub Community Action which goes a step further and uses a node script to access GitHub action's core's setSecret method. This felt like a less hacky way to go about protecting the sensitive information. You can see the results of using it in this demo repo.

@joshmenden joshmenden self-assigned this May 30, 2024
Copy link
Member

@bradymholt bradymholt left a comment

Choose a reason for hiding this comment

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

Looks great.

@joshmenden joshmenden merged commit 90e1e29 into main May 30, 2024
1 check passed
@joshmenden joshmenden deleted the jmm/mask-secrets branch May 30, 2024 15:49
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.

2 participants