Skip to content

Commit dc390b4

Browse files
authored
[envsec] Ensure build environment is the same (#1703)
## Summary This is combined with jetify-com/opensource#251 to ensure devbox and envsec environments are always the same. Otherwise, when using dev devbox, it will install a prod envsec and environments won't match which causes issues because dev environment uses a different authentication issuer so keys are not compatible. ## How was it tested?
1 parent 59b20da commit dc390b4

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

internal/devbox/devbox.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,7 @@ func (d *Devbox) computeEnv(ctx context.Context, usePrintDevEnvCache bool) (map[
883883
env["PATH"],
884884
)
885885

886-
env["PATH"], err = d.addUtilitiesToPath(ctx, env["PATH"])
887-
if err != nil {
886+
if err = d.addUtilitiesToEnv(ctx, env); err != nil {
888887
return nil, err
889888
}
890889

internal/devbox/util.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111

1212
"github.com/pkg/errors"
13+
"go.jetpack.io/devbox/internal/build"
1314
"go.jetpack.io/devbox/internal/integrations/envsec"
1415
"go.jetpack.io/devbox/internal/nix/nixprofile"
1516

@@ -34,22 +35,26 @@ func (d *Devbox) addDevboxUtilityPackage(ctx context.Context, pkg string) error
3435
})
3536
}
3637

37-
// addDevboxUtilityPackages adds binaries that we want the user to have access
38-
// to (e.g. envsec).
38+
// addUtilitiesToEnv adds binaries that we want the user to have access
39+
// to (e.g. envsec) and associated env vars.
3940
// Question: Should we add utilityBinPath here? That would allow user to use
4041
// process-compose, etc
41-
func (d *Devbox) addUtilitiesToPath(
42+
func (d *Devbox) addUtilitiesToEnv(
4243
ctx context.Context,
43-
path string,
44-
) (string, error) {
44+
env map[string]string,
45+
) error {
4546
if d.cfg.IsEnvsecEnabled() {
4647
envsecPath, err := envsec.EnsureInstalled(ctx)
4748
if err != nil {
48-
return "", err
49+
return err
50+
}
51+
env["PATH"] = env["PATH"] + string(os.PathListSeparator) + filepath.Dir(envsecPath)
52+
if build.IsDev {
53+
// Ensure that devbox and envsec build envs are the same
54+
env["ENVSEC_BUILD_ENV"] = "dev"
4955
}
50-
path = path + string(os.PathListSeparator) + filepath.Dir(envsecPath)
5156
}
52-
return path, nil
57+
return nil
5358
}
5459

5560
func utilityLookPath(binName string) (string, error) {

internal/integrations/envsec/envsec.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func EnsureInstalled(ctx context.Context) (string, error) {
4949
return binPathCache, nil
5050
}
5151

52-
paths, err := pkgtype.RunXClient().Install(ctx, "jetpack-io/[email protected].14")
52+
paths, err := pkgtype.RunXClient().Install(ctx, "jetpack-io/[email protected].15")
5353
if err != nil {
5454
return "", errors.Wrap(err, "failed to install envsec")
5555
}
@@ -87,6 +87,11 @@ func envsecList(
8787
"--environment", environment,
8888
"--json-errors")
8989
cmd.Dir = projectDir
90+
if build.IsDev {
91+
// Ensure that devbox and envsec build envs are the same
92+
cmd.Env = append(os.Environ(), "ENVSEC_BUILD_ENV=dev")
93+
}
94+
9095
var bufErr bytes.Buffer
9196
cmd.Stderr = &bufErr
9297
out, err := cmd.Output()

0 commit comments

Comments
 (0)