Skip to content

Commit 2429193

Browse files
committed
common: add support for default_host_ip in containers.conf
This adds support for configuring a default host IP via containers.conf to bind published container ports to when no host IP is explicitly specified (e.g. -p 8000:8000). Note that explicit host IP still overrides the default option set in containers.conf. Refers containers/podman#27186 Signed-off-by: Danish Prakash <[email protected]>
1 parent cacf855 commit 2429193

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

common/docs/containers.conf.5.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ run on the machine.
525525
A list of default pasta options that should be used running pasta.
526526
It accepts the pasta cli options, see pasta(1) for the full list of options.
527527

528+
**default_host_ip**=""
529+
530+
The default host IP address to bind published container ports to when no host IP
531+
is explicitly specified (e.g., `-p 8000:8000`). If empty, the default behavior is to
532+
bind to all network interfaces (`0.0.0.0`). For instance, setting this to `127.0.0.1` restricts
533+
published ports to localhost only, improving security on desktop installations.
534+
Note that explicitly specifying a host IP in the `-p` flag (e.g., `-p 192.168.1.10:8000:8000`)
535+
will always override this default.
536+
528537
## ENGINE TABLE
529538
The `engine` table contains configuration options used to set up container engines such as Podman and Buildah.
530539

common/pkg/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,11 @@ type NetworkConfig struct {
634634
// PastaOptions contains a default list of pasta(1) options that should
635635
// be used when running pasta.
636636
PastaOptions attributedstring.Slice `toml:"pasta_options,omitempty"`
637+
638+
// DefaultHostIP is the default host IP to bind published container ports
639+
// to when no host IP is explicitly specified in the -p flag (e.g., -p 80:80).
640+
// If empty, the default behavior is to bind to all interfaces (0.0.0.0).
641+
DefaultHostIP string `toml:"default_host_ip,omitempty"`
637642
}
638643

639644
type SubnetPool struct {

common/pkg/config/containers.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,14 @@ default_sysctls = [
445445
#
446446
#pasta_options = []
447447

448+
# The default host IP address to bind published container ports to when no
449+
# host IP is explicitly specified (e.g., -p 8000:8000). If empty, the default
450+
# behavior is to bind to all network interfaces (0.0.0.0). For instance,
451+
# setting this to 127.0.0.1 restricts published ports to localhost only.
452+
# Note that explicitly specifying a host IP via `-p` will always override this.
453+
#
454+
#default_host_ip = ""
455+
448456
[engine]
449457
# Index to the active service
450458
#

common/pkg/config/containers.conf-freebsd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ default_sysctls = [
335335
#
336336
#network_config_dir = "/usr/local/etc/cni/net.d/"
337337

338+
# The default host IP address to bind published container ports to when no
339+
# host IP is explicitly specified (e.g., -p 8000:8000). If empty, the default
340+
# behavior is to bind to all network interfaces (0.0.0.0). For instance,
341+
# setting this to 127.0.0.1 restricts published ports to localhost only.
342+
# Note that explicitly specifying a host IP via `-p` will always override this.
343+
#
344+
#default_host_ip = ""
345+
338346
[engine]
339347
# Index to the active service
340348
#

0 commit comments

Comments
 (0)