How to see my git secrets? #26277
-
BackgroundI had some secrets in my code and upon learning about GitHub Actions I decided to save them in the repositories secret menu for later use in my pipeline. ProblemHowever, now I need to access this secrets to develop a new feature and I can’t. Every time I try to see the value it asks me to update the secrets. I dont want to update anything I just want to see their values. QuestionHow can i see the unencrypted values of my secrets in the project? |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 7 replies
-
I recommend that you should avoid trying to output the values of repository secrets in the workflow runs. This may lead to the risk that the secrets are leaked. If you want to use the repository secrets in the source code files of your project when you build the project in the workflow runs, maybe you can try the following methods.
In the source code files, use the appropriate expressions to access environment variables. The expressions may be different between different types of the files. The expressions may include “${ENV_VAR_NAME}”, “$ENV_VAR_NAME”, “$env:ENV_VAR_NAME”, etc…
Below is a simple example that is applying both of the above two methods. TestGitHubPackagesRML/TestNpm/blob/080990526adbb61b0365e4b207d972de7d46dc77/.npmrc#L1
github.com TestGitHubPackagesRML/TestNpm/blob/080990526adbb61b0365e4b207d972de7d46dc77/package.json#L3
github.com TestGitHubPackagesRML/TestNpm/blob/080990526adbb61b0365e4b207d972de7d46dc77/.github/workflows/CI.yml#L27
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. My app can read the secrets from environment variables and is indeed doing so. My question is more aimed at “How can I, a human being, see the secrets I saved earlier?” Is this even possible? Let’s say I need to show someone the content of these secrets, how can I do it? |
Beta Was this translation helpful? Give feedback.
-
We have no safe way to fetch the values of secrets, and actually it is not recommended to try fetching and sharing the secrets. |
Beta Was this translation helpful? Give feedback.
-
while there is no safe way to display the secret, the tricky & unsafe way (if you really need to) is to run something like |
Beta Was this translation helpful? Give feedback.
-
Is there any way to avoid this? For instance if you have a serviceaccount.json in your gitaction secret and a potentially nefarious actor wants to read it? It seems that this is pretty damning of gitactions because the secrets are scoped to people who have access to the repository and not people themselves (or is that wrong?) |
Beta Was this translation helpful? Give feedback.
-
Then underlying assumption is basically that anyone with direct write access to the repository is trusted. After all, with that access they could put malicious things directly into the code. Forks are a different story, see Using encrypted secrets in a workflow:
So someone making a pull request would have to trick you into merging the secret-stealing code. |
Beta Was this translation helpful? Give feedback.
-
You make a good point about the write access. But injecting malicious code seems like a whole different problem, dependencies alone may cause this. |
Beta Was this translation helpful? Give feedback.
-
Github secrets are not really that secret, especially when combined with Github actions. You can for example have your github action create a new branch, create a new file, write your secrets, add it to the new branch, commit it and push it. Then you can navigate to that branch in the UI and the secret will be there for everyone to see. So as long as Github actions are enabled, no secret is safe. |
Beta Was this translation helpful? Give feedback.
-
To answer your question:
The trick is to encrypt the secret before printing it, with a known |
Beta Was this translation helpful? Give feedback.
-
It would be nice if there were some sort of comment we could insert Much like the comments to tell pylint to stop nagging about thing sin python "# pylint: disable=W0103" If we could put a comment like "# github: secret" which would then cause github to replace it _in the checked out code, that would be fantastic too. |
Beta Was this translation helpful? Give feedback.
-
Just do: jobs:
debug_secrets:
name: 'debug secrets'
steps:
run: echo '${{ toJSON(secrets) }}' | base64
name: '[apps] debug secrets'
on:
pull_request:
types:
- opened
- synchronize
- reopened |
Beta Was this translation helpful? Give feedback.
@Fl4m3Ph03n1x,
We have no safe way to fetch the values of secrets, and actually it is not recommended to try fetching and sharing the secrets.