Skip to content

🐞 client.Host().EnvVariable().Secret() is cached even when the var changes #4607

Closed

Description

@dolanor

What is the issue?

When I use an env variable as a secret, I would like to re-execute the pipeline if I update the env var.

Log output

First execution

DBGTHE: {"query":"query{host{envVariable(name:\"MY_SECRET_ID\"){secret{id}}}}","operationName":""}
DBGTHE: {"query":"query{container{from(address:\"alpine:latest\"){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.8s

#2 
#2 DONE 0.0s

#3 from alpine:latest
#3 resolve docker.io/library/alpine:latest
2023/02/15 17:59:38 LOGSTDOUT: super secret: my secret value
Wed Feb 15 16:56:13 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\"){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
2023/02/15 18:00:30 LOGSTDOUT: super secret: my secret value
Wed Feb 15 16:56:13 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. added
    kind/bug
    on Feb 15, 2023
  2. elebeaup commented on Feb 15, 2023

    @elebeaup

    I think this is relevant moby/buildkit#2547. Invalidate the cache when the value changes would be an information leak

  3. removed
    kind/bug
    on Mar 7, 2023
  4. dolanor commented on Mar 8, 2023

    @dolanor
    ContributorAuthor

    This should be solved with the new implementation.
    We can re-assess once it's in.

  5. dolanor commented on Apr 18, 2023

    @dolanor
    ContributorAuthor

    With the implementation in #4971, it shouldn't invalidate the cache and therefore respect moby/buildkit#2547 which is better for security.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions