auto pass http_proxy into container

Signed-off-by: James Cassell <code@james.cassell.me>
This commit is contained in:
James Cassell 2019-04-17 14:16:37 +00:00
parent 39c937ee45
commit 354d80626a
9 changed files with 60 additions and 0 deletions

View file

@ -313,6 +313,10 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"hostname", "h", "",
"Set container hostname",
)
createFlags.Bool(
"http-proxy", true,
"Set proxy environment variables in container based on the host proxy vars",
)
createFlags.String(
"image-volume", cliconfig.DefaultImageVolume,
"Tells podman how to handle the builtin image volumes. The options are: 'bind', 'tmpfs', or 'ignore'",

View file

@ -624,6 +624,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
GroupAdd: c.StringSlice("group-add"),
Hostname: c.String("hostname"),
HostAdd: c.StringSlice("add-host"),
HTTPProxy: c.Bool("http-proxy"),
NoHosts: c.Bool("no-hosts"),
IDMappings: idmappings,
Image: imageName,

View file

@ -404,6 +404,7 @@ func NewIntermediateLayer(c *cliconfig.PodmanCommand, remote bool) GenericCLIRes
m["healthcheck-start-period"] = newCRString(c, "healthcheck-start-period")
m["healthcheck-timeout"] = newCRString(c, "healthcheck-timeout")
m["hostname"] = newCRString(c, "hostname")
m["http-proxy"] = newCRBool(c, "http-proxy")
m["image-volume"] = newCRString(c, "image-volume")
m["init"] = newCRBool(c, "init")
m["init-path"] = newCRString(c, "init-path")

View file

@ -1711,6 +1711,7 @@ _podman_container_run() {
--gidmap
--group-add
--hostname -h
--http-proxy
--image-volume
--init-path
--ip

View file

@ -244,6 +244,16 @@ inside of the container.
Read in a line delimited file of environment variables
**--http-proxy**=*true*|*false*
By default proxy environment variables are passed into the container if set
for the podman process. This can be disabled by setting the `--http-proxy`
option to `false`. The environment variables passed in include `http_proxy`,
`https_proxy`, `ftp_proxy`, `no_proxy`, and also the upper case versions of
those.
Defaults to `true`
**--expose**=[]
Expose a port, or a range of ports (e.g. --expose=3300-3310) to set up port redirection

View file

@ -251,6 +251,16 @@ inside of the container.
Read in a line delimited file of environment variables
**--http-proxy**=*true*|*false*
By default proxy environment variables are passed into the container if set
for the podman process. This can be disabled by setting the `--http-proxy`
option to `false`. The environment variables passed in include `http_proxy`,
`https_proxy`, `ftp_proxy`, `no_proxy`, and also the upper case versions of
those.
Defaults to `true`
**--expose**=[]
Expose a port, or a range of ports (e.g. --expose=3300-3310) to set up port redirection

View file

@ -87,6 +87,7 @@ type CreateConfig struct {
NoHosts bool
HostAdd []string //add-host
Hostname string //hostname
HTTPProxy bool
Image string
ImageID string
BuiltinImgVolumes map[string]struct{} // volumes defined in the image config

View file

@ -192,6 +192,24 @@ func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint
}
g.SetRootReadonly(config.ReadOnlyRootfs)
if config.HTTPProxy {
for _, envSpec := range []string{
"http_proxy",
"HTTP_PROXY",
"https_proxy",
"HTTPS_PROXY",
"ftp_proxy",
"FTP_PROXY",
"no_proxy",
"NO_PROXY",
} {
envVal := os.Getenv(envSpec)
if envVal != "" {
g.AddProcessEnv(envSpec, envVal)
}
}
}
hostname := config.Hostname
if hostname == "" && (config.NetMode.IsHost() || config.UtsMode.IsHost()) {
hostname, err = os.Hostname()

View file

@ -763,4 +763,18 @@ USER mail`
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).ToNot(Equal(0))
})
It("podman run --http-proxy test", func() {
os.Setenv("http_proxy", "1.2.3.4")
session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv", "http_proxy"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
match, _ := session.GrepString("1.2.3.4")
Expect(match).Should(BeTrue())
session = podmanTest.Podman([]string{"run", "--rm", "--http-proxy=false", ALPINE, "printenv", "http_proxy"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(1))
os.Unsetenv("http_proxy")
})
})