How to handle the space in secret value in github settings

How to handle the space in secret value in github settings,

I am getting the below error, by using secret token above format. Getting the issue with space between secret value “Token xxxxxxxxxxx”. Please help me how to handle this scenario. Thank!

Unable to find image ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:latest’ locally

43docker: Error response from daemon: pull access denied for xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, repository does not exist or may require ‘docker login’: denied: requested access to the resource is denied.

How are you trying to use that secret? Usually the secret value should only contain the part that’s supposed to be secret, not a prefix like “Token”.

actually one of the API we are using Authorization value like “Token 7555xxxxxxxx”. I added this value in github setting secrets. And using workflow yml file to load this secret values.

Do you mean an Authorization HTTP header?

Yes, but exactly how? I assume there’s some step that involves something like

${{ secrets.MY_TOKEN }}

somewhere, and the details of that are important here.

Yes, it’s authorization HTTP header and I am using secret like below

  • name: Load secrets
    run: |

echo “TEST_PROD_TOKEN =${{ TEST_PROD_TOKEN }}” >> $GITHUB_ENV

docker run --rm -v ${PWD}:/app
–env TEST_PROD_TOKEN=${TEST_PROD_TOKEN} \

Okay, in that case I see three problems here:

  1. Having “Token” as part of the secret. That can cause trouble with masking secrets in the logs, and the documentation warns against it.
  2. You can’t use an environment value written to GITHUB_ENV in the same step that sets it, only steps after.
  3. The docker run command contains an unquoted space.

So, what you should do:

  1. Remove the “Token” part from your secret. The value should only be the “7555xxxxxxxx” part.
  2. You can then use it in your workflow like this (assuming the secret is also called TEST_PROD_TOKEN) without the detour via GITHUB_ENV:
- name: run docker with token
  run: |
    docker run --rm -v ${PWD}:/app --env="TEST_PROD_TOKEN=Token ${{ secrets.TEST_PROD_TOKEN}}" ...

Note the quotes around the value for --env, they keep the value from getting cut off at the space after “Token”.

2 Likes

Thank you very much @airtower-luna for your help. Now I am able to run all my tests without issues.

1 Like