Skip to content

Help us avoid credential leak into containers - Use a default credential file path #123

@thclark

Description

@thclark

TL;DR

Use google's usual default path (google_credentials.json) for generated application credentials, or alternatively allow us to specify the path of the credentials file that gets created.

This will help us avoid by default a significant vulnerability that it's easy to introduce by mistake: baking credentials into images for all to see.

Detailed design

Lets say I use this action to do a typical thing: build a container and push it to GCR:

name: build_container_and_push_to_gcr

on:
  workflow_dispatch:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Authenticate with GCP Workload Identity
        id: auth
        uses: google-github-actions/auth@v0.5.0
        with:
          create_credentials_file: true
          workload_identity_provider: REDACTED
          service_account: REDACTED

      - name: Setup gcloud
        uses: 'google-github-actions/setup-gcloud@v0'

      - name: Configure Docker to push images to GCP
        run: gcloud auth configure-docker

      - name: Build
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfile
          tags: this-contains:the-account-credentials
          
      - name: Other stuff
         run: echo "Do testing stuff which might require the credentials file"

The auth step creates a credentials file with a randomised name - like /home/runner/work/me/myrepo/4c33e43f60be11e1a7b5d5f4.

The problem occurs when Dockerfile contains the following extremely common line:

COPY . .

If you're like me, you'll have a .dockerignore file will include something like:

# NEVER bake in environment variables or credentials
.env
.env*
google_credentials.json

But, because in this case the credentials file name cannot be known a priori, the .dockerignore can't be configured not to copy it in.

Proposed solution

  • Revert to a predictable file name, or make user specify as a required argument
  • [Optional, but nice] Check for presence of .dockerignore and if it doesn't contain the file then warn the user
  • [Optional, but nice] Add a boolean--update-dockerignore option, true by default, that creates or updates a .dockerignore file with the credentials file name

A possible workaround

As one possible workaround, I'd have to introduce a step something like

    - name: Prevent secret from getting into container
      # WARNING UNTESTED!!!
      run: touch .dockerignore && echo ${${{ steps.auth.outputs.credentials_file_path }}##*/} >> .dockerignore

    - name: Now its safe to build
      #...

Additional information

I also think it's a bit more intuitive for it to end up in google_credentials.json, the location given in most of google's tutorials on application credentials.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions