1
1
package configs
2
2
3
- import "fmt"
4
-
5
3
type Rlimit struct {
6
4
Type int `json:"type"`
7
5
Hard uint64 `json:"hard"`
@@ -15,6 +13,9 @@ type IDMap struct {
15
13
Size int `json:"size"`
16
14
}
17
15
16
+ // TODO Windows. Many of these fields should be factored out into those parts
17
+ // which are common across platforms, and those which are platform specific.
18
+
18
19
// Config defines configuration options for executing a process inside a contained environment.
19
20
type Config struct {
20
21
// NoPivotRoot will use MS_MOVE and a chroot to jail the process into the container's rootfs
@@ -104,49 +105,3 @@ type Config struct {
104
105
// sysctl -w my.property.name value in Linux.
105
106
SystemProperties map [string ]string `json:"system_properties"`
106
107
}
107
-
108
- // Gets the root uid for the process on host which could be non-zero
109
- // when user namespaces are enabled.
110
- func (c Config ) HostUID () (int , error ) {
111
- if c .Namespaces .Contains (NEWUSER ) {
112
- if c .UidMappings == nil {
113
- return - 1 , fmt .Errorf ("User namespaces enabled, but no user mappings found." )
114
- }
115
- id , found := c .hostIDFromMapping (0 , c .UidMappings )
116
- if ! found {
117
- return - 1 , fmt .Errorf ("User namespaces enabled, but no root user mapping found." )
118
- }
119
- return id , nil
120
- }
121
- // Return default root uid 0
122
- return 0 , nil
123
- }
124
-
125
- // Gets the root uid for the process on host which could be non-zero
126
- // when user namespaces are enabled.
127
- func (c Config ) HostGID () (int , error ) {
128
- if c .Namespaces .Contains (NEWUSER ) {
129
- if c .GidMappings == nil {
130
- return - 1 , fmt .Errorf ("User namespaces enabled, but no gid mappings found." )
131
- }
132
- id , found := c .hostIDFromMapping (0 , c .GidMappings )
133
- if ! found {
134
- return - 1 , fmt .Errorf ("User namespaces enabled, but no root user mapping found." )
135
- }
136
- return id , nil
137
- }
138
- // Return default root uid 0
139
- return 0 , nil
140
- }
141
-
142
- // Utility function that gets a host ID for a container ID from user namespace map
143
- // if that ID is present in the map.
144
- func (c Config ) hostIDFromMapping (containerID int , uMap []IDMap ) (int , bool ) {
145
- for _ , m := range uMap {
146
- if (containerID >= m .ContainerID ) && (containerID <= (m .ContainerID + m .Size - 1 )) {
147
- hostID := m .HostID + (containerID - m .ContainerID )
148
- return hostID , true
149
- }
150
- }
151
- return - 1 , false
152
- }
0 commit comments