NetworkConfig struct passed to WithNetwork. Outbound proxies use the sibling WithProxy option. Common policy shapes come from the NetworkPolicy factory; custom firewalls are built by populating NetworkConfig.Rules directly.
Functions
m.WithNetwork()
Example
Example
NetworkPolicy factory, or a custom NetworkConfig value with your own rules, DNS, TLS, and port settings.
Parameters
Returns
m.WithPorts()
Example
Example
127.0.0.1. Called multiple times, the maps merge.
Parameters
portsmap[uint16]uint16Returns
m.WithPortsUDP()
Example
Example
127.0.0.1. Called multiple times, the maps merge.
Parameters
portsmap[uint16]uint16Returns
m.WithPortBindings()
Example
Example
127.0.0.1 bind is too restrictive, for example to expose a port on 0.0.0.0. Accepts one or more PortBinding values.
Parameters
bindings…PortBindingReturns
NetworkPolicy
Factory namespace returning high-level*NetworkConfig values. Access through the package-level NetworkPolicy value.
NetworkPolicy.FromProfiles()
Example
Example
NetworkProfilePublic, NetworkProfilePrivate, and NetworkProfileHost. Duplicate profiles are ignored, rules use canonical order, and each non-empty set receives one gateway DNS rule. An empty profile set permits no egress and adds no DNS; ingress defaults to allow.
FromProfiles panics if passed a value other than the three package-defined NetworkProfile constants.
Returns
NetworkPolicy.FromProfilesChecked()
Example
Example
FromProfiles, but returns an error instead of panicking when a profile is unknown. Use this method for values derived from runtime input.
Returns
NetworkPolicy.None()
Example
Example
Exec and FS still work because they use the host-guest channel.
Returns
NetworkPolicy.AllowAll()
Example
Example
Returns
Rule
The package-levelRule factory provides semantic low-level rules. Rule.AllowDNS() returns a PolicyRule allowing gateway UDP/53 and TCP/53; Rule.DenyDNS() returns its deny counterpart. Put Rule.DenyDNS() before profile-generated rules when you need to override automatic DNS access.
Rule.AllowDNS()
Returns
PolicyRule
Rule.DenyDNS()
Returns
PolicyRule
Custom rules
Build a custom firewall by populatingNetworkConfig.Rules. Rules are evaluated first-match-wins per direction; DefaultEgress and DefaultIngress set the fall-through action. A broad rule placed before a narrow one swallows it, so put specific rules first.
Example
Example
Constants
Destination groups
Used by PolicyRule.Destination
TheDestination field on PolicyRule accepts these well-known group names alongside literal CIDRs and domains. A domain prefixed with . becomes a suffix match: .example.com matches api.example.com but not example.com.
Types
NetworkConfig
Used by WithNetwork() · returned by NetworkPolicy
WithNetwork.
PolicyRule
Used by NetworkConfig.Rules
PolicyDirectionEgress for ICMP.
DNSConfig
Used by NetworkConfig.DNS
TLSConfig
Used by NetworkConfig.TLS
Example
Example
ScopedUpstreamCACert
Used by TLSConfig.ScopedUpstreamCACerts
ScopedVerifyUpstream
Used by TLSConfig.ScopedVerifyUpstream
NetworkRateLimiterConfig
Used by NetworkConfig.RateLimiter
Example
Example
RateLimiterConfig
Held by NetworkRateLimiterConfig
nil bucket leaves that dimension unlimited.
TokenBucketConfig
Used by RateLimiterConfig
Size tokens every RefillTime. The one-time burst is spent before the regular budget and never refills.
PortBinding
Used by WithPortBindings() · NetworkConfig.PortBindings
Protocol defaults to TCP when empty. Use Bind: "0.0.0.0" to expose the published port on all IPv4 interfaces.
PortProtocol
Used by PortBinding.Protocol
PolicyAction
Used by PolicyRule.Action · NetworkConfig.DefaultEgress
PolicyRule.
PolicyDirection
Used by PolicyRule.Direction
PolicyRule. The Go SDK follows the Python naming (egress/ingress); the wire format carries these values.
PolicyProtocol
Used by PolicyRule.Protocol · PolicyRule.Protocols
PolicyRule.
NetworkProfile
NetworkPolicy.FromProfiles().