Skip to content

Commit 3f20277

Browse files
committed
Allow skipping TLS verification
Added a --tls-verify flag to the run command which allows skipping TLS verification when connecting to registries. Signed-off-by: Hariharan <[email protected]>
1 parent 0125ec1 commit 3f20277

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

cmd/run.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type osVmConfig struct {
2323
RemoveVm bool // Kill the running VM when it exits
2424
RemoveDiskImage bool // After exit of the VM, remove the disk image
2525
Quiet bool
26+
TLSVerify bool
2627
}
2728

2829
var (
@@ -52,6 +53,7 @@ func init() {
5253
runCmd.Flags().BoolVar(&vmConfig.Quiet, "quiet", false, "Suppress output from bootc disk creation and VM boot console")
5354
runCmd.Flags().StringVar(&diskImageConfigInstance.RootSizeMax, "root-size-max", "", "Maximum size of root filesystem in bytes; optionally accepts M, G, T suffixes")
5455
runCmd.Flags().StringVar(&diskImageConfigInstance.DiskSize, "disk-size", "", "Allocate a disk image of this size in bytes; optionally accepts M, G, T suffixes")
56+
runCmd.Flags().BoolVar(&vmConfig.TLSVerify, "tls-verify", true, "Require HTTPS and verify certificates when accessing the registry")
5557
}
5658

5759
func doRun(flags *cobra.Command, args []string) error {
@@ -71,6 +73,10 @@ func doRun(flags *cobra.Command, args []string) error {
7173
// create the disk image
7274
idOrName := args[0]
7375
bootcDisk := bootc.NewBootcDisk(idOrName, machine.Ctx, user)
76+
77+
// skip tls verification if tls-verfiy flag is set to false
78+
bootcDisk.SkipTLSVerify = !vmConfig.TLSVerify
79+
7480
err = bootcDisk.Install(vmConfig.Quiet, diskImageConfigInstance)
7581

7682
if err != nil {

pkg/bootc/bootc_disk.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type BootcDisk struct {
5656
Directory string
5757
file *os.File
5858
bootcInstallContainerId string
59+
SkipTLSVerify bool
5960
}
6061

6162
// create singleton for easy cleanup
@@ -106,7 +107,7 @@ func (p *BootcDisk) GetCreatedAt() time.Time {
106107
func (p *BootcDisk) Install(quiet bool, config DiskImageConfig) (err error) {
107108
p.CreatedAt = time.Now()
108109

109-
err = p.pullImage()
110+
err = p.pullImage(p.SkipTLSVerify)
110111
if err != nil {
111112
return
112113
}
@@ -261,8 +262,8 @@ func (p *BootcDisk) bootcInstallImageToDisk(quiet bool, diskConfig DiskImageConf
261262
}
262263

263264
// pullImage fetches the container image if not present
264-
func (p *BootcDisk) pullImage() error {
265-
imageData, err := utils.PullAndInspect(p.Ctx, p.ImageNameOrId)
265+
func (p *BootcDisk) pullImage(skipTLSVerify bool) error {
266+
imageData, err := utils.PullAndInspect(p.Ctx, p.ImageNameOrId, skipTLSVerify)
266267
if err != nil {
267268
return err
268269
}

pkg/utils/podman.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"github.com/containers/podman/v5/pkg/bindings/images"
9-
"github.com/containers/podman/v5/pkg/domain/entities/types"
108
"os"
119
"os/exec"
1210
"strings"
1311

12+
"github.com/containers/podman/v5/pkg/bindings/images"
13+
"github.com/containers/podman/v5/pkg/domain/entities/types"
14+
1415
"github.com/containers/podman/v5/pkg/bindings"
1516
"github.com/containers/podman/v5/pkg/machine"
1617
"github.com/containers/podman/v5/pkg/machine/define"
@@ -31,9 +32,9 @@ type machineInfo struct {
3132
}
3233

3334
// PullAndInspect inpects the image, pulling in if the image if required
34-
func PullAndInspect(ctx context.Context, imageNameOrId string) (*types.ImageInspectReport, error) {
35+
func PullAndInspect(ctx context.Context, imageNameOrId string, skipTLSVerify bool) (*types.ImageInspectReport, error) {
3536
pullPolicy := "missing"
36-
_, err := images.Pull(ctx, imageNameOrId, &images.PullOptions{Policy: &pullPolicy})
37+
_, err := images.Pull(ctx, imageNameOrId, &images.PullOptions{Policy: &pullPolicy, SkipTLSVerify: &skipTLSVerify})
3738
if err != nil {
3839
return nil, fmt.Errorf("failed to pull image: %w", err)
3940
}

0 commit comments

Comments
 (0)