Skip to content

Commit 340c486

Browse files
[feat]: [CI-18603]: Give option to disable tls verification for dlc (#73)
* [feat]: [CI-18603]: Give option to disable tls verification for dlc * Update docker_test.go
1 parent a46e7ef commit 340c486

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ func Run() {
185185
Usage: "Allows you to enable the client to use path-style addressing, i.e., https://s3.amazonaws.com/BUCKET/KEY. By default, the S3 client will use virtual hosted bucket addressing when possible(https://BUCKET.s3.amazonaws.com/KEY).",
186186
EnvVar: "PLUGIN_PATH_STYLE,AWS_PLUGIN_PATH_STYLE",
187187
},
188+
&cli.BoolFlag{
189+
Name: "cache-tls-insecure",
190+
Usage: "Allows you to skip the verification of the server's certificate chain and host name for docker layer caching",
191+
EnvVar: "PLUGIN_CACHE_TLS_INSECURE",
192+
},
188193
cli.BoolFlag{
189194
Name: "squash",
190195
Usage: "squash the layers at build time",
@@ -488,6 +493,7 @@ func run(c *cli.Context) error {
488493
Pull: c.BoolT("pull-image"),
489494
CacheFrom: c.Generic("cache-from").(*CustomStringSliceFlag).GetValue(),
490495
CacheTo: c.Generic("cache-to").(*CustomStringSliceFlag).GetValue(),
496+
CacheTlsInsecure: c.Bool("cache-tls-insecure"),
491497
PathStyle: c.Bool("path-style"),
492498
Compress: c.Bool("compress"),
493499
Repo: c.String("repo"),

buildkit/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"buildkit_version": "harness/buildkit:1.0.8"
2+
"buildkit_version": "harness/buildkit:1.0.9"
33
}

docker.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type (
7575
Pull bool // Docker build pull
7676
CacheFrom []string // Docker buildx cache-from
7777
CacheTo []string // Docker buildx cache-to
78+
CacheTlsInsecure bool // Docker buildx cache-tls-insecure
7879
PathStyle bool // Docker buildx path-style for s3 DLC
7980
Compress bool // Docker build compress
8081
Repo string // Docker build repository
@@ -767,6 +768,15 @@ func sanitizeCacheCommand(build *Build) {
767768
}
768769
}
769770

771+
if build.CacheTlsInsecure {
772+
if strings.Contains(arg, "tls_insecure_skip_verify=false") {
773+
fmt.Printf("tls_insecure_skip_verify is set to false in cache-from or cache-to but env var PLUGIN_PATH_STYLE is true\n")
774+
} else if !strings.Contains(arg, "tls_insecure_skip_verify=") {
775+
// Add use_path_style=true, assuming comma-delimited key=val pairs
776+
arg = arg + ",tls_insecure_skip_verify=true"
777+
}
778+
}
779+
770780
// Update the argument
771781
args[i] = arg
772782
}

docker_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,46 @@ func TestSanitizeCacheCommand(t *testing.T) {
365365
expectedCacheFrom: []string{"type=s3,bucket=my-bucket"},
366366
expectedCacheTo: []string{},
367367
},
368+
{
369+
name: "Add tls_insecure_skip_verify=true if not present and CacheTlsInsecure is true",
370+
build: Build{
371+
CacheFrom: []string{"type=s3,bucket=my-bucket"},
372+
CacheTo: []string{},
373+
CacheTlsInsecure: true,
374+
},
375+
expectedCacheFrom: []string{"type=s3,bucket=my-bucket,tls_insecure_skip_verify=true"},
376+
expectedCacheTo: []string{},
377+
},
378+
{
379+
name: "Leave tls_insecure_skip_verify=false untouched when CacheTlsInsecure is true",
380+
build: Build{
381+
CacheFrom: []string{"type=s3,bucket=my-bucket,tls_insecure_skip_verify=false"},
382+
CacheTo: []string{"type=s3,tls_insecure_skip_verify=false"},
383+
CacheTlsInsecure: true,
384+
},
385+
expectedCacheFrom: []string{"type=s3,bucket=my-bucket,tls_insecure_skip_verify=false"},
386+
expectedCacheTo: []string{"type=s3,tls_insecure_skip_verify=false"},
387+
},
388+
{
389+
name: "Leave tls_insecure_skip_verify=true untouched when already correct",
390+
build: Build{
391+
CacheFrom: []string{"type=s3,tls_insecure_skip_verify=true"},
392+
CacheTo: []string{},
393+
CacheTlsInsecure: true,
394+
},
395+
expectedCacheFrom: []string{"type=s3,tls_insecure_skip_verify=true"},
396+
expectedCacheTo: []string{},
397+
},
398+
{
399+
name: "Don't add use_path_style when CacheTlsInsecure is false",
400+
build: Build{
401+
CacheFrom: []string{"type=s3,bucket=my-bucket"},
402+
CacheTo: []string{},
403+
CacheTlsInsecure: false,
404+
},
405+
expectedCacheFrom: []string{"type=s3,bucket=my-bucket"},
406+
expectedCacheTo: []string{},
407+
},
368408
}
369409

370410
for _, tt := range tests {

0 commit comments

Comments
 (0)