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

Fix: Securely mask secrets in Reusable Workflows #180

Merged
merged 1 commit into from
Aug 6, 2024
Merged

Conversation

askb
Copy link
Contributor

@askb askb commented Aug 5, 2024

Problem:

This commit addresses the issue of secret exposure when passing secrets between reusable workflows in GitHub Actions. Automatic secret masking within reusable workflows is lost due to secret inheritance limitations. Additionally, multiline secrets and special characters pose challenges [1.] is undefined with Github actions.

Proposed Solution:

To redact and mask secrets from console logs, I propose the two-step Base64 encoding approach inspired by [2.]:

  1. Double Base64 Encoding: Before storing secrets in the organization or repository secret store, encode them twice using the base64 command. This prevents secret exposure when GitHub Actions outputs them.

example:
cat clouds.yaml | base64 -w0 | base64 -w0 > clouds-2xb64.yaml cat clouds-env.pkrvars.hcl | base64 -w0 | base64 -w0 >
clouds-2xb64.yaml

  1. Pass Encoded Values and Decode in Reusable Workflows: Pass the encoded values as secret inputs to reusable workflows. Inside the workflows, decode them twice before masking to ensure they remain masked throughout the logs and usable in subsequent steps.

Limitation:

Rerunning jobs in debug mode might reveal secrets in the workflow logs. However, only authorized users with "owner" permissions can trigger debug re-runs, mitigating the overall risk.

Benefits:

  • Consistent secret masking within reusable workflows.
  • Secure handling of multiline secrets and special characters.
  • Reduced risk of accidental secret exposure in workflow logs.

Note: The secrets have been renamed as and encoded twice and saved on the Github secret store.

References:
[1.] https://github.com/orgs/community/discussions/65057 [2.] https://github.com/orgs/community/discussions/26671

@askb askb requested a review from tykeal August 5, 2024 13:56
@askb askb force-pushed the main branch 4 times, most recently from 2f53640 to 121b5d2 Compare August 6, 2024 09:34
Problem:

This commit addresses the issue of secret exposure when passing
secrets between reusable workflows in GitHub Actions. Automatic
secret masking within reusable workflows is lost due to secret
inheritance limitations. Additionally, multiline secrets and
special characters pose challenges [1.] is undefined with
Github actions since non UTF-8 bytes will cause encoding
problems (Internally stored as UTF-16).

Proposed Solution:

To redact and mask secrets from console logs, I propose the
two-step Base64 encoding approach inspired by [2.]:

1. Double Base64 Encoding: Before storing secrets in the
organization or repository secret store, encode them twice using
the base64 command. This prevents secret exposure when GitHub
Actions outputs them.

example:
cat clouds.yaml | base64 -w0 | base64 -w0 > clouds-2xb64.yaml
cat clouds-env.pkrvars.hcl | base64 -w0 | base64 -w0 > \
clouds-2xb64.yaml

2. Pass Encoded Values and Decode in Reusable Workflows: Pass the
encoded values as secret inputs to reusable workflows. Inside the
workflows, decode them twice before masking to ensure they remain
masked throughout the logs and usable in subsequent steps.

Limitation:

Rerunning jobs in debug mode might reveal secrets in the workflow
logs. However, only authorized users with "owner" permissions can
trigger debug re-runs, mitigating the overall risk.

Benefits:

+ Consistent secret masking within reusable workflows.
+ Secure handling of multiline secrets and special characters.
+ Reduced risk of accidental secret exposure in workflow logs.

Note: The secrets have been renamed as and encoded twice
and saved on the Github secret store.

References:
[1.] https://github.com/orgs/community/discussions/65057
[2.] https://github.com/orgs/community/discussions/26671

Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
@tykeal tykeal merged commit 662f5ee into lfit:main Aug 6, 2024
4 checks passed
@askb
Copy link
Contributor Author

askb commented Aug 6, 2024

Thanks for the review, test latest run show the required info being filtered out of the console logs.

https://github.com/opendaylight/releng-builder/actions/runs/10275164319/job/28433330366

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