Skip to content

Multiline dagger.#Secrets are not hidden properly inside containers #1892

Closed as not planned

Description

@grouville

Issue

When trying to mount an SSH key securely inside my container, I realized that a cat command would not hide multiline env variables set as secrets properly

Repro:

First, export a multiline env var

export FOO='foo
bar
baz
zoo'

Repro config

package main

import (
	"dagger.io/dagger"

	"universe.dagger.io/alpine"
	"universe.dagger.io/docker"
)

dagger.#Plan & {
	client: env: FOO: dagger.#Secret

	actions: {
		_dockerCLI: alpine.#Build & {
			packages: {
				bash: {}
				curl: {}
				"docker-cli": {}
				"openssh-client": {}
			}
		}

		test: docker.#Run & {
			input: _dockerCLI.output
			mounts: ssh_key: {
				dest:     "/foo"
				contents: client.env.FOO
			}

			always: true
			command: {
				name: "sh"
				flags: "-c": #"""
					cat /foo
					"""#
			}
		}
	}
}

output

dagger do test --log-format plain
7:07PM INF actions._dockerCLI._dag."0"._op | computing
7:07PM INF client.env | computing
7:07PM INF client.env | completed    duration=0s
7:07PM INF actions._dockerCLI._dag."0"._op | completed    duration=0s
7:07PM INF actions._dockerCLI._dag."1"._exec | computing
7:07PM INF actions._dockerCLI._dag."1"._exec | completed    duration=0s
7:07PM INF actions._dockerCLI._dag."2"._exec | computing
7:07PM INF actions._dockerCLI._dag."2"._exec | completed    duration=0s
7:07PM INF actions._dockerCLI._dag."3"._exec | computing
7:07PM INF actions._dockerCLI._dag."3"._exec | completed    duration=0s
7:07PM INF actions._dockerCLI._dag."4"._exec | computing
7:07PM INF actions._dockerCLI._dag."4"._exec | completed    duration=0s
7:07PM INF actions.test._exec | computing
7:07PM INF actions.test._exec | #7 0.096 fezds
7:07PM INF actions.test._exec | #7 0.096 fezdseds
7:07PM INF actions.test._exec | #7 0.096 zedsqx
7:07PM INF actions.test._exec | #7 0.096 ezds
7:07PM INF actions.test._exec | completed    duration=100ms
7:07PM INF actions.test._exec |

Root cause

Possible root cause: the issue might come from the print function of secrets ?

One thing is sure though: it works for single line secrets

cc @aluzzardi

Activity

  1. OneCricketeer commented on Apr 1, 2022

    @OneCricketeer

    Maybe I'm not understanding the logs, but how does this

    7:07PM INF actions.test._exec | #7 0.096 fezds
    7:07PM INF actions.test._exec | #7 0.096 fezdseds
    7:07PM INF actions.test._exec | #7 0.096 zedsqx
    7:07PM INF actions.test._exec | #7 0.096 ezds
    

    With contents: client.env.FOO

    Relate to this?

    export FOO='foo
    bar
    baz
    zoo'
    

    And why should usage of cat hide anything?

  2. grouville commented on Apr 1, 2022

    @grouville
    MemberAuthor

    Sorry, I made a mistake between my tests. You're totally right, on the host, I do:

    export FOO='fezds
    fezdseds
    zedsqx
    ezds
    

    Dagger has a primitive type dagger.#Secret which is never directly referenced in the DAG (for security reasons). However, whenever mounting one inside a container, some commands might use it and may inadvertly leak a secret.

    Our way of managing this issue is to make sure that a secret always gets printed as **** when exposed in a container:

    7:07PM INF actions.test._exec | #7 0.096 *****
    7:07PM INF actions.test._exec | #7 0.096 ********
    7:07PM INF actions.test._exec | #7 0.096 ******
    7:07PM INF actions.test._exec | #7 0.096 ****
    
  3. OneCricketeer commented on Apr 3, 2022

    @OneCricketeer

    make sure that a secret always gets printed as ****

    But once you print the secret to a plaintext file, then cat said file, how would you determine that file was a dagger.#Secret?

  4. grouville commented on Apr 6, 2022

    @grouville
    MemberAuthor

    make sure that a secret always gets printed as ****

    But once you print the secret to a plaintext file, then cat said file, how would you determine that file was a dagger.#Secret?

    Sorry, I was flooded in notifications, Buildkit knows as we mount them as secrets in Buildkit (a small repro will prove this point). Cue doesn't understand the concept of secrets, we implemented that, but Buidlkit does

  5. TomChv commented on Jul 12, 2022

    @TomChv
    Member

    @grouville Is this issue still accurate?

  6. added
    kind/bug
    on Jul 12, 2022
  7. grouville commented on Jan 5, 2023

    @grouville
    MemberAuthor

    Closing, even though this issue is Buildkit related, not Cue specific. It might require a future upstream contribution

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

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions