Skip to content

Commit d2cb052

Browse files
authored
Merge pull request #10653 from Loyen/add-listen-address-flag
Add flag "--listen-address" for docker and podman driver
2 parents 3d27f0f + 3110bd1 commit d2cb052

File tree

8 files changed

+28
-1
lines changed

8 files changed

+28
-1
lines changed

cmd/minikube/cmd/start.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,10 @@ func validateFlags(cmd *cobra.Command, drvName string) {
10791079
validateChangedMemoryFlags(drvName)
10801080
}
10811081

1082+
if cmd.Flags().Changed(listenAddress) {
1083+
validateListenAddress(viper.GetString(listenAddress))
1084+
}
1085+
10821086
if cmd.Flags().Changed(containerRuntime) {
10831087
runtime := strings.ToLower(viper.GetString(containerRuntime))
10841088

@@ -1199,6 +1203,14 @@ func validateRegistryMirror() {
11991203
}
12001204
}
12011205

1206+
// This function validates if the --listen-address
1207+
// match the format 0.0.0.0
1208+
func validateListenAddress(listenAddr string) {
1209+
if len(listenAddr) > 0 && net.ParseIP(listenAddr) == nil {
1210+
exit.Message(reason.Usage, "Sorry, the IP provided with the --listen-address flag is invalid: {{.listenAddr}}.", out.V{"listenAddr": listenAddr})
1211+
}
1212+
}
1213+
12021214
// This function validates that the --insecure-registry follows one of the following formats:
12031215
// "<ip>[:<port>]" "<hostname>[:<port>]" "<network>/<netmask>"
12041216
func validateInsecureRegistry() {

cmd/minikube/cmd/start_flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const (
117117
sshSSHPort = "ssh-port"
118118
defaultSSHUser = "root"
119119
defaultSSHPort = 22
120+
listenAddress = "listen-address"
120121
)
121122

122123
var (
@@ -217,6 +218,7 @@ func initDriverFlags() {
217218
startCmd.Flags().String(hypervExternalAdapter, "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)")
218219

219220
// docker & podman
221+
startCmd.Flags().String(listenAddress, "", "IP Address to use to expose ports (docker and podman driver only)")
220222
startCmd.Flags().StringSlice(ports, []string{}, "List of ports that should be exposed (docker and podman driver only)")
221223
}
222224

@@ -326,6 +328,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
326328
CPUs: viper.GetInt(cpus),
327329
DiskSize: diskSize,
328330
Driver: drvName,
331+
ListenAddress: viper.GetString(listenAddress),
329332
HyperkitVpnKitSock: viper.GetString(vpnkitSock),
330333
HyperkitVSockPorts: viper.GetStringSlice(vsockPorts),
331334
NFSShare: viper.GetStringSlice(nfsShare),

pkg/drivers/kic/kic.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"k8s.io/minikube/pkg/minikube/download"
4343
"k8s.io/minikube/pkg/minikube/driver"
4444
"k8s.io/minikube/pkg/minikube/out"
45+
"k8s.io/minikube/pkg/minikube/style"
4546
"k8s.io/minikube/pkg/minikube/sysinit"
4647
"k8s.io/minikube/pkg/util/retry"
4748
)
@@ -102,8 +103,14 @@ func (d *Driver) Create() error {
102103
params.IP = ip.String()
103104
}
104105
drv := d.DriverName()
106+
105107
listAddr := oci.DefaultBindIPV4
106-
if oci.IsExternalDaemonHost(drv) {
108+
if d.NodeConfig.ListenAddress != "" && d.NodeConfig.ListenAddress != listAddr {
109+
out.Step(style.Tip, "minikube is not meant for production use. You are opening non-local traffic")
110+
out.WarningT("Listening to {{.listenAddr}}. This is not recommended and can cause a security vulnerability. Use at your own risk",
111+
out.V{"listenAddr": d.NodeConfig.ListenAddress})
112+
listAddr = d.NodeConfig.ListenAddress
113+
} else if oci.IsExternalDaemonHost(drv) {
107114
out.WarningT("Listening to 0.0.0.0 on external docker host {{.host}}. Please be advised",
108115
out.V{"host": oci.DaemonHost(drv)})
109116
listAddr = "0.0.0.0"

pkg/drivers/kic/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ type Config struct {
6262
ContainerRuntime string // container runtime kic is running
6363
Network string // network to run with kic
6464
ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
65+
ListenAddress string // IP Address to listen to
6566
}

pkg/minikube/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type ClusterConfig struct {
7878
StartHostTimeout time.Duration
7979
ScheduledStop *ScheduledStopConfig
8080
ExposedPorts []string // Only used by the docker and podman driver
81+
ListenAddress string // Only used by the docker and podman driver
8182
Network string // only used by docker driver
8283
MultiNodeRequested bool
8384
}

pkg/minikube/registry/drvs/docker/docker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
8383
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
8484
ExtraArgs: extraArgs,
8585
Network: cc.Network,
86+
ListenAddress: cc.ListenAddress,
8687
}), nil
8788
}
8889

pkg/minikube/registry/drvs/podman/podman.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
9595
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
9696
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
9797
ExtraArgs: extraArgs,
98+
ListenAddress: cc.ListenAddress,
9899
}), nil
99100
}
100101

site/content/en/docs/commands/start.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ minikube start [flags]
7272
--kvm-network string The KVM network name. (kvm2 driver only) (default "default")
7373
--kvm-numa-count int Simulate numa node count in minikube, supported numa node count range is 1-8 (kvm2 driver only) (default 1)
7474
--kvm-qemu-uri string The KVM QEMU connection URI. (kvm2 driver only) (default "qemu:///system")
75+
--listen-address string IP Address to use to expose ports (docker and podman driver only)
7576
--memory string Amount of RAM to allocate to Kubernetes (format: <number>[<unit>], where unit = b, k, m or g).
7677
--mount This will start the mount daemon and automatically mount files into minikube.
7778
--mount-string string The argument to pass the minikube mount command on start.

0 commit comments

Comments
 (0)