Skip to content

Can't use multiple line val in env_vars #139

Open

Description

@onel

TL;DR

I'm trying to deploy to cloud run and one of the env_vars has a value that is multi line, specifically it is a PEM key.
This seems to make the key not be used properly in cloud run UI.
The problem is with GH_APP_PRIVATE_KEY
Tried with with both "" and without.

In the google console UI the output looks like this
image

This might be a yaml question more than a deploy-cloudrun one.

Expected behavior

No response

Observed behavior

No response

Action YAML

- name: Deploy to Google Cloud Run
        uses: google-github-actions/deploy-cloudrun@v2

        with:
          service: ${{ env.RUN_SERVICE }}
          image: ${{ env.GAR_LOCATION }}
          region: ${{ env.REGION }}

          env_vars: |-
            DEBUG='False'
            GH_APP_PRIVATE_KEY=${{ secrets.GH_APP_PRIVATE_KEY }}

Log output

No response

Additional information

No response

Activity

  1. added
    bug
    on Dec 20, 2024
  2. sethvargo commented on Dec 20, 2024

    @sethvargo
    Contributor

    Have you tried:

    env_vars: |-
      GH_APP_PRIVATE_KEY="${{ secrets.GH_APP_PRIVATE_KEY }}"

    If so, please provide the debug logs.

  3. onel commented on Dec 21, 2024

    @onel
    Author

    Yes, I've tried with quotes as well.

    This is the log output specifically for the deploy job (the link expires in 1 week)
    https://pastebin.com/r75Qjzaq

  4. sethvargo commented on Dec 21, 2024

    @sethvargo
    Contributor

    Pasting the relevant bits here for history:

    GH_APP_PRIVATE_KEY="***,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***=,***"= 
    

    It looks like parsing is actually successful, but then re-serialization is incorrect.

  5. onel commented on Dec 29, 2024

    @onel
    Author

    I see, so this might be a deploy-cloudrun bug?

  6. Azzerty23 commented on Apr 6, 2025

    @Azzerty23

    Is there a workaround for this?

  7. onel commented on Apr 21, 2025

    @onel
    Author

    The workaround I went with is adding the PEM keys to the repo and loading them if dev / prod. Not ideal

  8. sethvargo commented on Apr 21, 2025

    @sethvargo
    Contributor

    There are a couple options:

    1. Remove the newlines from the PEM:

      awk 'NF {sub(/\nr\r?/, ""); printf "%s\\n",$0;}'
    2. Encode the PEM (e.g. base64) so it's safe to transport as a single line. Your application or workflow would need to decode it on the other side though.

    3. Escape the newline on each row with a backslash (this is a fake private key we use in tests):

    -----BEGIN PRIVATE KEY-----\
    MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDRJRbmz9Qi7or8\
    G342x0t5eILuU/DmDz/K+aF+HCmKpiNMM3VVXop5r70jtuDwTg2Hj4Wq+/VUFy9m\
    7N2c6NcjhekEZZbtGBoaiddffX7S54Y5La4ynJooLwkHm2mLp2et5gIjhwHiRvXa\
    ftyRyC/83GkAjs88l5eGxNE=\
    -----END PRIVATE KEY-----
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions