Codebase list golang-github-containers-common / c8fc08f
New upstream version 0.14.10+ds1 Reinhard Tartler 3 years ago
15 changed file(s) with 170 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
309309 changed, a lock renumbering must be performed, using the
310310 `podman system renumber` command.
311311
312 **active_service**=""
313 Name of destination for accessing the Podman service.
314
315 **[service_destinations]**
316
317 **[service_destinations.{name}]**
318 **uri="ssh://user@production.example.com/run/user/1001/podman/podman.sock"**
319
320 Example URIs:
321
322 - **rootless local** - unix://run/user/1000/podman/podman.sock
323 - **rootless remote** - ssh://user@engineering.lab.company.com/run/user/1000/podman/podman.sock
324 - **rootfull local** - unix://run/podman/podman.sock
325 - **rootfull remote** - ssh://root@10.10.1.136:22/run/podman/podman.sock
326
327 **identity="~/.ssh/id_rsa**
328 Path to file containing ssh identity key
329
312330 **pull_policy**="always"|"missing"|"never"
313331 Pull image before running or creating a container. The default is **missing**.
314332
5656 return capabilityList
5757 }
5858
59 // normalizeCapabilities normalizes caps by adding a "CAP_" prefix (if not yet
59 // NormalizeCapabilities normalizes caps by adding a "CAP_" prefix (if not yet
6060 // present).
61 func normalizeCapabilities(caps []string) ([]string, error) {
61 func NormalizeCapabilities(caps []string) ([]string, error) {
6262 normalized := make([]string, len(caps))
6363 for i, c := range caps {
6464 c = strings.ToUpper(c)
9797 var caps []string
9898
9999 // Normalize the base capabilities
100 base, err := normalizeCapabilities(base)
100 base, err := NormalizeCapabilities(base)
101101 if err != nil {
102102 return nil, err
103103 }
105105 // Nothing to tweak; we're done
106106 return base, nil
107107 }
108 capDrop, err := normalizeCapabilities(drops)
108 capDrop, err := NormalizeCapabilities(drops)
109109 if err != nil {
110110 return nil, err
111111 }
112 capAdd, err := normalizeCapabilities(adds)
112 capAdd, err := NormalizeCapabilities(adds)
113113 if err != nil {
114114 return nil, err
115115 }
5959
6060 func TestNormalizeCapabilities(t *testing.T) {
6161 strSlice := []string{"SYS_ADMIN", "net_admin", "CAP_CHOWN"}
62 caps, err := normalizeCapabilities(strSlice)
62 caps, err := NormalizeCapabilities(strSlice)
6363 require.Nil(t, err)
6464 err = ValidateCapabilities(caps)
6565 require.Nil(t, err)
6666 strSlice = []string{"no_ADMIN", "net_admin", "CAP_CHMOD"}
67 _, err = normalizeCapabilities(strSlice)
67 _, err = NormalizeCapabilities(strSlice)
6868 assert.Error(t, err)
6969 }
7070
194194 // The first path pointing to a valid file will be used.
195195 ConmonPath []string `toml:"conmon_path,omitempty"`
196196
197 //DetachKeys is the sequence of keys used to detach a container.
197 // DetachKeys is the sequence of keys used to detach a container.
198198 DetachKeys string `toml:"detach_keys,omitempty"`
199199
200200 // EnablePortReservation determines whether engine will reserve ports on the
265265 // Indicates whether the application should be running in Remote mode
266266 Remote bool `toml:"-"`
267267
268 // RemoteURI is deprecated, see ActiveService
268269 // RemoteURI containers connection information used to connect to remote system.
269270 RemoteURI string `toml:"remote_uri,omitempty"`
270271
271 // Identity key file for RemoteURI
272 // RemoteIdentity is deprecated, ServiceDestinations
273 // RemoteIdentity key file for RemoteURI
272274 RemoteIdentity string `toml:"remote_identity,omitempty"`
275
276 // ActiveService index to Destinations added v2.0.3
277 ActiveService string `toml:"active_service,omitempty"`
278
279 // Destinations mapped by service Names
280 ServiceDestinations map[string]Destination `toml:"service_destinations,omitempty"`
273281
274282 // RuntimePath is the path to OCI runtime binary for launching containers.
275283 // The first path pointing to a valid file will be used This is used only
384392
385393 // NetworkConfigDir is where CNI network configuration files are stored.
386394 NetworkConfigDir string `toml:"network_config_dir,omitempty"`
395 }
396
397 // Destination represents destination for remote service
398 type Destination struct {
399 // URI, required. Example: ssh://root@example.com:22/run/podman/podman.sock
400 URI string `toml:"uri"`
401
402 // Identity file with ssh key, optional
403 Identity string `toml:"identity,omitempty"`
387404 }
388405
389406 // NewConfig creates a new Config. It starts with an empty config and, if
856873 return OverrideContainersConfig
857874 }
858875
859 func customConfigFile() (string, error) {
860 path := os.Getenv("CONTAINERS_CONF")
861 if path != "" {
862 return path, nil
863 }
864 if unshare.IsRootless() {
865 path, err := rootlessConfigPath()
866 if err != nil {
867 return "", err
868 }
869 return path, nil
870 }
871 return OverrideContainersConfig, nil
872 }
873
874 //ReadCustomConfig reads the custom config and only generates a config based on it
875 //If the custom config file does not exists, function will return an empty config
876 // ReadCustomConfig reads the custom config and only generates a config based on it
877 // If the custom config file does not exists, function will return an empty config
876878 func ReadCustomConfig() (*Config, error) {
877879 path, err := customConfigFile()
878880 if err != nil {
929931 }
930932 return nil
931933 }
934
935 // Reload reloads the configuration from containers.conf files
936 func Reload() (*Config, error) {
937 var err error
938 config, err = NewConfig("")
939 if err != nil {
940 return nil, errors.Wrapf(err, "containers.conf reload failed")
941 }
942 return Default()
943 }
944
945 func (c *Config) ActiveDestination() (string, string, error){
946 if uri, found := os.LookupEnv("CONTAINER_HOST"); found {
947 var ident string
948 if v, found := os.LookupEnv("CONTAINER_SSHKEY"); found {
949 ident = v
950 }
951 return uri, ident, nil
952 }
953
954 switch {
955 case c.Engine.ActiveService != "":
956 d, found := c.Engine.ServiceDestinations[c.Engine.ActiveService]
957 if !found {
958 return "", "", errors.Errorf("%q service destination not found", c.Engine.ActiveService)
959 }
960 return d.URI, d.Identity, nil
961 case c.Engine.RemoteURI != "":
962 return c.Engine.RemoteURI, c.Engine.RemoteIdentity, nil
963 }
964 return "", "", errors.New("no service destination configured")
965 }
0 package config
1
2 import (
3 "os"
4 )
5
6 func customConfigFile() (string, error) {
7 if path, found := os.LookupEnv("CONTAINERS_CONF"); found {
8 return path, nil
9 }
10 return rootlessConfigPath()
11 }
00 package config
11
2 import selinux "github.com/opencontainers/selinux/go-selinux"
2 import (
3 "os"
4
5 "github.com/containers/storage/pkg/unshare"
6 selinux "github.com/opencontainers/selinux/go-selinux"
7 )
38
49 func selinuxEnabled() bool {
510 return selinux.GetEnabled()
611 }
12
13 func customConfigFile() (string, error) {
14 if path, found := os.LookupEnv("CONTAINERS_CONF"); found {
15 return path, nil
16 }
17 if unshare.IsRootless() {
18 path, err := rootlessConfigPath()
19 if err != nil {
20 return "", err
21 }
22 return path, nil
23 }
24 return OverrideContainersConfig, nil
25 }
55 "io/ioutil"
66 "os"
77 "path"
8 "strings"
89
910 . "github.com/onsi/ginkgo"
1011 "github.com/onsi/gomega"
173174 // Then
174175 gomega.Expect(err).To(gomega.BeNil())
175176 gomega.Expect(config.Engine.Remote).To(gomega.BeFalse())
177 })
178
179 It("verify getDefaultEnv", func() {
180 envs := []string{
181 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
182 "TERM=xterm",
183 }
184
185 // When
186 config, err := Default()
187 // Then
188 gomega.Expect(err).To(gomega.BeNil())
189 gomega.Expect(config.GetDefaultEnv()).To(gomega.BeEquivalentTo(envs))
190 config.Containers.HTTPProxy = true
191 gomega.Expect(config.GetDefaultEnv()).To(gomega.BeEquivalentTo(envs))
192 os.Setenv("HTTP_PROXY", "localhost")
193 os.Setenv("FOO", "BAR")
194 newenvs := []string{"HTTP_PROXY=localhost"}
195 envs = append(newenvs, envs...)
196 gomega.Expect(config.GetDefaultEnv()).To(gomega.BeEquivalentTo(envs))
197 config.Containers.HTTPProxy = false
198 config.Containers.EnvHost = true
199 envString := strings.Join(config.GetDefaultEnv(), ",")
200 gomega.Expect(envString).To(gomega.ContainSubstring("FOO=BAR"))
201 gomega.Expect(envString).To(gomega.ContainSubstring("HTTP_PROXY=localhost"))
176202 })
177203
178204 It("write", func() {
22 import (
33 "os"
44 "sort"
5 "strings"
65
76 "github.com/containers/common/pkg/apparmor"
87 "github.com/containers/common/pkg/capabilities"
152151
153152 envs := []string{
154153 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
154 "TERM=xterm",
155155 }
156156
157157 // Then
229229
230230 envs := []string{
231231 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
232 "TERM=xterm",
232233 }
233234
234235 // When
243244 gomega.Expect(config.Engine.OCIRuntimes["runc"]).To(gomega.Equal(OCIRuntimeMap["runc"]))
244245 })
245246
246 It("verify getDefaultEnv", func() {
247 envs := []string{
248 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
249 }
250
251 // When
252 config, err := Default()
253 // Then
254 gomega.Expect(err).To(gomega.BeNil())
255 gomega.Expect(config.GetDefaultEnv()).To(gomega.BeEquivalentTo(envs))
256 config.Containers.HTTPProxy = true
257 gomega.Expect(config.GetDefaultEnv()).To(gomega.BeEquivalentTo(envs))
258 os.Setenv("HTTP_PROXY", "localhost")
259 os.Setenv("FOO", "BAR")
260 newenvs := []string{"HTTP_PROXY=localhost"}
261 envs = append(newenvs, envs...)
262 gomega.Expect(config.GetDefaultEnv()).To(gomega.BeEquivalentTo(envs))
263 config.Containers.HTTPProxy = false
264 config.Containers.EnvHost = true
265 envString := strings.Join(config.GetDefaultEnv(), ",")
266 gomega.Expect(envString).To(gomega.ContainSubstring("FOO=BAR"))
267 gomega.Expect(envString).To(gomega.ContainSubstring("HTTP_PROXY=localhost"))
268 })
269
270247 It("should success with valid user file path", func() {
271248 // Given
272249 // When
0 package config
1
2 import "os"
3
4 func customConfigFile() (string, error) {
5 if path, found := os.LookupEnv("CONTAINERS_CONF"); found {
6 return path, nil
7 }
8 return os.Getenv("APPDATA") + "\\containers\\containers.conf", nil
9 }
115115 #
116116 # env = [
117117 # "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
118 # "TERM=xterm",
118119 # ]
119120
120121 # Pass all host environment variables into the container.
365366
366367 # Number of seconds to wait for container to exit before sending kill signal.
367368 # stop_timeout = 10
369
370 # Index to the active service
371 # active_service = production
372
373 # map of service destinations
374 # [service_destinations]
375 # [service_destinations.production]
376 # URI to access the Podman service
377 # Examples:
378 # rootless "unix://run/user/$UID/podman/podman.sock" (Default)
379 # rootfull "unix://run/podman/podman.sock (Default)
380 # remote rootless ssh://engineering.lab.company.com/run/user/1000/podman/podman.sock
381 # remote rootfull ssh://root@10.10.1.136:22/run/podman/podman.sock
382 # uri="ssh://user@production.example.com/run/user/1001/podman/podman.sock"
383 # Path to file containing ssh identity key
384 # identity = "~/.ssh/id_rsa"
368385
369386 # Paths to look for a valid OCI runtime (runc, runv, kata, etc)
370387 [engine.runtimes]
175175 EnableLabeling: selinuxEnabled(),
176176 Env: []string{
177177 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
178 "TERM=xterm",
178179 },
179180 EnvHost: false,
180181 HTTPProxy: false,
1717 # environment variables to conmon or the runtime.
1818 # env = [
1919 # "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
20 # "TERM=xterm",
2021 # ]
2122
2223 # proxy environment variables are passed into the container
5555 # environment variables to conmon or the runtime.
5656 env = [
5757 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
58 "TERM=xterm",
5859 ]
5960
6061 # Path to OCI hooks directories for automatically executed hooks.
1717 # environment variables to conmon or the runtime.
1818 env = [
1919 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
20 "TERM=xterm",
2021 ]
2122
2223 # proxy environment variables are passed into the container
00 package version
11
22 // Version is the version of the build.
3 const Version = "0.14.6"
3 const Version = "0.14.10"