Skip to content

Commit 8b1e82b

Browse files
Merge pull request #44 from Aishwarya-Lad/CI-14277-revert
fix:[CI-14277]:revert base64 support added to handle secrets with spe…
2 parents 50c0255 + ef26138 commit 8b1e82b

File tree

3 files changed

+0
-125
lines changed

3 files changed

+0
-125
lines changed

app.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,6 @@ func Run() {
275275
Usage: "secret key value pair eg id=MYSECRET",
276276
EnvVar: "PLUGIN_SECRET",
277277
},
278-
cli.StringSliceFlag{
279-
Name: "encoded-secrets-from-env",
280-
Usage: "list of secret env that are base64 encoded",
281-
EnvVar: "PLUGIN_ENCODED_ENV_SECRET",
282-
},
283-
cli.BoolFlag{
284-
Name: "decode-env-secret",
285-
Usage: "decode env values default-false",
286-
EnvVar: "PLUGIN_DECODE_ENV_SECRET",
287-
},
288278
cli.StringSliceFlag{
289279
Name: "secrets-from-env",
290280
Usage: "secret key value pair eg secret_name=secret",
@@ -419,8 +409,6 @@ func run(c *cli.Context) error {
419409
Platform: c.String("platform"),
420410
SSHAgentKey: c.String("ssh-agent-key"),
421411
BuildxLoad: c.Bool("buildx-load"),
422-
DecodeEnvSecret: c.Bool("decode-env-secret"),
423-
EncodedSecretEnvs: c.StringSlice("encoded-secrets-from-env"),
424412
},
425413
Daemon: Daemon{
426414
Registry: c.String("docker.registry"),

docker.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package docker
22

33
import (
4-
"encoding/base64"
54
"encoding/json"
65
"fmt"
7-
"log"
86
"os"
97
"os/exec"
108
"path/filepath"
@@ -83,8 +81,6 @@ type (
8381
SSHAgentKey string // Docker build ssh agent key
8482
SSHKeyPath string // Docker build ssh key path
8583
BuildxLoad bool // Docker buildx --load
86-
DecodeEnvSecret bool // Decode the secret value in env
87-
EncodedSecretEnvs []string // Docker build env secrets that are encoded using base64
8884
}
8985

9086
// Plugin defines the Docker plugin parameters.
@@ -469,30 +465,6 @@ func commandInfo() *exec.Cmd {
469465
return exec.Command(dockerExe, "info")
470466
}
471467

472-
// helper function to update env var value from base64 encoded to decoded
473-
func updateEnvWithDecodedValue(encodedEnvList []string) error {
474-
for _, envName := range encodedEnvList {
475-
// Get the current base64 encoded value
476-
encodedValue := os.Getenv(envName)
477-
if encodedValue == "" {
478-
return fmt.Errorf("environment variable %s not found", envName)
479-
}
480-
481-
// Decode the base64 value
482-
decodedBytes, err := base64.StdEncoding.DecodeString(encodedValue)
483-
if err != nil {
484-
return fmt.Errorf("failed to decode value for %s: %v", envName, err)
485-
}
486-
487-
// Update the environment variable with the decoded value
488-
err = os.Setenv(envName, string(decodedBytes))
489-
if err != nil {
490-
return fmt.Errorf("failed to set environment variable %s: %v", envName, err)
491-
}
492-
}
493-
return nil
494-
}
495-
496468
// helper function to create the docker buildx command.
497469
func commandBuildx(build Build, builder Builder, dryrun bool, metadataFile string) *exec.Cmd {
498470
args := []string{
@@ -549,13 +521,6 @@ func commandBuildx(build Build, builder Builder, dryrun bool, metadataFile strin
549521
if build.Secret != "" {
550522
args = append(args, "--secret", build.Secret)
551523
}
552-
// update the list of env variables that have been encoded with base64
553-
if build.DecodeEnvSecret {
554-
err := updateEnvWithDecodedValue(build.EncodedSecretEnvs)
555-
if err != nil {
556-
log.Printf("failed to decode harness secrets used as docker secrets in the build command: %v", err)
557-
}
558-
}
559524
for _, secret := range build.SecretEnvs {
560525
if arg, err := getSecretStringCmdArg(secret); err == nil {
561526
args = append(args, "--secret", arg)

docker_test.go

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -207,89 +207,11 @@ func TestCommandBuildx(t *testing.T) {
207207
"--metadata-file /tmp/metadata.json",
208208
),
209209
},
210-
{
211-
name: "encoded secrets from env",
212-
build: Build{
213-
Name: "plugins/drone-docker:latest",
214-
Dockerfile: "Dockerfile",
215-
Context: ".",
216-
SecretEnvs: []string{
217-
"foo_secret=FOO_SECRET_ENV_VAR",
218-
},
219-
EncodedSecretEnvs: []string{
220-
"ENCODED_SECRET",
221-
},
222-
DecodeEnvSecret: true,
223-
Repo: "plugins/drone-docker",
224-
Tags: []string{"latest"},
225-
},
226-
want: exec.Command(
227-
dockerExe,
228-
"buildx",
229-
"build",
230-
"--rm=true",
231-
"-f",
232-
"Dockerfile",
233-
"-t",
234-
"plugins/drone-docker:latest",
235-
"--push",
236-
".",
237-
"--secret", "id=foo_secret,env=FOO_SECRET_ENV_VAR",
238-
),
239-
},
240-
{
241-
name: "multiple secrets with encoding",
242-
build: Build{
243-
Name: "plugins/drone-docker:latest",
244-
Dockerfile: "Dockerfile",
245-
Context: ".",
246-
SecretEnvs: []string{
247-
"foo_secret=FOO_SECRET_ENV_VAR",
248-
"bar_secret=BAR_SECRET_ENV_VAR",
249-
},
250-
EncodedSecretEnvs: []string{
251-
"ENCODED_SECRET1",
252-
"ENCODED_SECRET2",
253-
},
254-
DecodeEnvSecret: true,
255-
Repo: "plugins/drone-docker",
256-
Tags: []string{"latest"},
257-
},
258-
want: exec.Command(
259-
dockerExe,
260-
"buildx",
261-
"build",
262-
"--rm=true",
263-
"-f",
264-
"Dockerfile",
265-
"-t",
266-
"plugins/drone-docker:latest",
267-
"--push",
268-
".",
269-
"--secret", "id=foo_secret,env=FOO_SECRET_ENV_VAR",
270-
"--secret", "id=bar_secret,env=BAR_SECRET_ENV_VAR",
271-
),
272-
},
273210
}
274211

275212
for _, tc := range tcs {
276213
tc := tc
277214
t.Run(tc.name, func(t *testing.T) {
278-
// Set up test environment variables if needed
279-
if tc.build.DecodeEnvSecret && len(tc.build.EncodedSecretEnvs) > 0 {
280-
// Set sample encoded values
281-
os.Setenv("ENCODED_SECRET", "SGVsbG8gV29ybGQ=") // "Hello World" in base64
282-
os.Setenv("ENCODED_SECRET1", "VGVzdFZhbHVlMQ==") // "TestValue1" in base64
283-
os.Setenv("ENCODED_SECRET2", "VGVzdFZhbHVlMg==") // "TestValue2" in base64
284-
285-
// Clean up after test
286-
defer func() {
287-
os.Unsetenv("ENCODED_SECRET")
288-
os.Unsetenv("ENCODED_SECRET1")
289-
os.Unsetenv("ENCODED_SECRET2")
290-
}()
291-
}
292-
293215
cmd := commandBuildx(tc.build, tc.builder, tc.dryrun, tc.metadata)
294216
if !reflect.DeepEqual(cmd.String(), tc.want.String()) {
295217
t.Errorf("Got cmd %v, want %v", cmd, tc.want)

0 commit comments

Comments
 (0)