Skip to content

🐞 secrets with whitespace are not scrubbed (yet) #4608

Closed

Description

@dolanor

What is the issue?

When I use an env variable as a secret, I would like to not get it leaked.
If the secret contains some whitespace, a simple echo would output it and break those characters which will defeat the secret scrub first implementation (which base itself on perfect string match). We need to improve it.

Log output

First execution

DBGTHE: {"query":"query{host{envVariable(name:\"MY_SECRET_ID\"){secret{id}}}}","operationName":""}
DBGTHE: {"query":"query{container{from(address:\"alpine:latest\"){withEnvVariable(value:\"2023-02-15 18:10:32.602423457 +0100 CET m=+2.044853212\", name:\"CACHEBUSTER\"){withSecretVariable(name:\"MY_SECRET_ID\", secret:\"eyJob3N0X2VudiI6Ik1ZX1NFQ1JFVF9JRCJ9\"){withExec(args:[\"sh\",\"-c\",\"echo super secret: $MY_SECRET_ID; date;\"]){stdout}}}}}}","operationName":""}
#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 0.7s

#2 importing cache manifest from dagger:10686922502337221602
#2 DONE 0.0s

#3 
#3 DONE 0.0s

#4 from alpine:latest
#4 resolve docker.io/library/alpine:latest
#4 resolve docker.io/library/alpine:latest 0.1s done
#4 CACHED

#3 
2023/02/15 18:10:33 LOGSTDOUT: super secret: my secret value
Wed Feb 15 17:10:33 UTC 2023

second execution after changing var

DBGTHE: {"query":"query{host{envVariable(name:\"MY_SECRET_ID\"){secret{id}}}}","operationName":""}
DBGTHE: {"query":"query{container{from(address:\"alpine:latest\"){withEnvVariable(name:\"CACHEBUSTER\", value:\"2023-02-15 18:11:00.37254732 +0100 CET m=+2.402145986\"){withSecretVariable(name:\"MY_SECRET_ID\", secret:\"eyJob3N0X2VudiI6Ik1ZX1NFQ1JFVF9JRCJ9\"){withExec(args:[\"sh\",\"-c\",\"echo super secret: $MY_SECRET_ID; date;\"]){stdout}}}}}}","operationName":""}
#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 0.4s

#2 importing cache manifest from dagger:10686922502337221602
#2 DONE 0.0s

#3 
#3 DONE 0.0s

#4 from alpine:latest
#4 resolve docker.io/library/alpine:latest
#4 resolve docker.io/library/alpine:latest 0.2s done
#4 CACHED

#3 
2023/02/15 18:11:01 LOGSTDOUT: super secret: ***
Wed Feb 15 17:11:01 UTC 2023

In the query, we can see the withSecretVariable.secret has the same value, so some caching is not basing itself on the value, but more on the name.

Steps to reproduce

package main

import (
	"context"
	"log"
	"os"

	"dagger.io/dagger"
)

func main() {
	// Change this value and reexecute.
	err := os.Setenv("MY_SECRET_ID", "my secret value ")
	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))

	secret := c.Host().EnvVariable("MY_SECRET_ID").Secret()

	stdout, err := c.Container().
		From("alpine:latest").
		//WithEnvVariable("CACHEBUSTER", time.Now().String()).
		WithSecretVariable("MY_SECRET_ID", secret).
		WithExec([]string{"sh", "-c", "echo super secret: $MY_SECRET_ID; date;"}).
		Stdout(ctx)

	log.Println("LOGSTDOUT:", stdout)
}

SDK version

Go SDK v0.4.5

OS version

Ubuntu 20.04

Activity

  1. mircubed commented on Mar 8, 2023

    @mircubed
    Contributor

    note from @dolanor "This one can be improved upon without breaking the API. So once I'm done breaking the API with the dynamic secrets, I can work on this. And I think it is pretty important because it could make some multiline secrets (like ssh/PGP/PEM keys) leak " cc @d3rp3tt3

  2. dolanor commented on Mar 16, 2023

    @dolanor
    ContributorAuthor

    Concourse implementation for reference: #4518 (comment)

  3. linked a pull request that will close this issuefeat: scrub secrets containing whitespace #4772on Mar 21, 2023
  4. mircubed commented on Mar 21, 2023

    @mircubed
    Contributor

    I am adding "user request" label since @rawkode mentioned needing this during a call today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions