Skip to content

Commit 83a0695

Browse files
committed
Capitalize Uid as UID and Gid as GID.
Signed-off-by: Francis Laniel <[email protected]>
1 parent b338acc commit 83a0695

File tree

12 files changed

+57
-57
lines changed

12 files changed

+57
-57
lines changed

libcontainer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ config := &configs.Config{
184184
Flags: defaultMountFlags | unix.MS_RDONLY,
185185
},
186186
},
187-
UidMappings: []configs.IDMap{
187+
UIDMappings: []configs.IDMap{
188188
{
189189
ContainerID: 0,
190190
HostID: 1000,
191191
Size: 65536,
192192
},
193193
},
194-
GidMappings: []configs.IDMap{
194+
GIDMappings: []configs.IDMap{
195195
{
196196
ContainerID: 0,
197197
HostID: 1000,

libcontainer/configs/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ type Config struct {
159159
// More information about kernel oom score calculation here: https://lwn.net/Articles/317814/
160160
OomScoreAdj *int `json:"oom_score_adj,omitempty"`
161161

162-
// UidMappings is an array of User ID mappings for User Namespaces
163-
UidMappings []IDMap `json:"uid_mappings"`
162+
// UIDMappings is an array of User ID mappings for User Namespaces
163+
UIDMappings []IDMap `json:"uid_mappings"`
164164

165-
// GidMappings is an array of Group ID mappings for User Namespaces
166-
GidMappings []IDMap `json:"gid_mappings"`
165+
// GIDMappings is an array of Group ID mappings for User Namespaces
166+
GIDMappings []IDMap `json:"gid_mappings"`
167167

168168
// MaskPaths specifies paths within the container's rootfs to mask over with a bind
169169
// mount pointing to /dev/null as to prevent reads of the file.

libcontainer/configs/config_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ var (
1313
// different when user namespaces are enabled.
1414
func (c Config) HostUID(containerId int) (int, error) {
1515
if c.Namespaces.Contains(NEWUSER) {
16-
if c.UidMappings == nil {
16+
if len(c.UIDMappings) == 0 {
1717
return -1, errNoUIDMap
1818
}
19-
id, found := c.hostIDFromMapping(containerId, c.UidMappings)
19+
id, found := c.hostIDFromMapping(containerId, c.UIDMappings)
2020
if !found {
2121
return -1, errNoUserMap
2222
}
@@ -36,10 +36,10 @@ func (c Config) HostRootUID() (int, error) {
3636
// different when user namespaces are enabled.
3737
func (c Config) HostGID(containerId int) (int, error) {
3838
if c.Namespaces.Contains(NEWUSER) {
39-
if c.GidMappings == nil {
39+
if len(c.GIDMappings) == 0 {
4040
return -1, errNoGIDMap
4141
}
42-
id, found := c.hostIDFromMapping(containerId, c.GidMappings)
42+
id, found := c.hostIDFromMapping(containerId, c.GIDMappings)
4343
if !found {
4444
return -1, errNoGroupMap
4545
}

libcontainer/configs/config_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestHostRootUIDNoUSERNS(t *testing.T) {
3434
func TestHostRootUIDWithUSERNS(t *testing.T) {
3535
config := &Config{
3636
Namespaces: Namespaces{{Type: NEWUSER}},
37-
UidMappings: []IDMap{
37+
UIDMappings: []IDMap{
3838
{
3939
ContainerID: 0,
4040
HostID: 1000,
@@ -67,7 +67,7 @@ func TestHostRootGIDNoUSERNS(t *testing.T) {
6767
func TestHostRootGIDWithUSERNS(t *testing.T) {
6868
config := &Config{
6969
Namespaces: Namespaces{{Type: NEWUSER}},
70-
GidMappings: []IDMap{
70+
GIDMappings: []IDMap{
7171
{
7272
ContainerID: 0,
7373
HostID: 1000,

libcontainer/configs/validate/rootless.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ func rootlessEUIDMappings(config *configs.Config) error {
4242
return errors.New("rootless container requires user namespaces")
4343
}
4444

45-
if len(config.UidMappings) == 0 {
45+
if len(config.UIDMappings) == 0 {
4646
return errors.New("rootless containers requires at least one UID mapping")
4747
}
48-
if len(config.GidMappings) == 0 {
48+
if len(config.GIDMappings) == 0 {
4949
return errors.New("rootless containers requires at least one GID mapping")
5050
}
5151
return nil
@@ -68,7 +68,7 @@ func rootlessEUIDMount(config *configs.Config) error {
6868
// Ignore unknown mount options.
6969
continue
7070
}
71-
if !hasIDMapping(uid, config.UidMappings) {
71+
if !hasIDMapping(uid, config.UIDMappings) {
7272
return errors.New("cannot specify uid= mount options for unmapped uid in rootless containers")
7373
}
7474
}
@@ -79,7 +79,7 @@ func rootlessEUIDMount(config *configs.Config) error {
7979
// Ignore unknown mount options.
8080
continue
8181
}
82-
if !hasIDMapping(gid, config.GidMappings) {
82+
if !hasIDMapping(gid, config.GIDMappings) {
8383
return errors.New("cannot specify gid= mount options for unmapped gid in rootless containers")
8484
}
8585
}

libcontainer/configs/validate/rootless_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ func rootlessEUIDConfig() *configs.Config {
1616
{Type: configs.NEWUSER},
1717
},
1818
),
19-
UidMappings: []configs.IDMap{
19+
UIDMappings: []configs.IDMap{
2020
{
2121
HostID: 1337,
2222
ContainerID: 0,
2323
Size: 1,
2424
},
2525
},
26-
GidMappings: []configs.IDMap{
26+
GIDMappings: []configs.IDMap{
2727
{
2828
HostID: 7331,
2929
ContainerID: 0,
@@ -52,15 +52,15 @@ func TestValidateRootlessEUIDUserns(t *testing.T) {
5252

5353
func TestValidateRootlessEUIDMappingUid(t *testing.T) {
5454
config := rootlessEUIDConfig()
55-
config.UidMappings = nil
55+
config.UIDMappings = nil
5656
if err := Validate(config); err == nil {
5757
t.Errorf("Expected error to occur if no uid mappings provided")
5858
}
5959
}
6060

6161
func TestValidateNonZeroEUIDMappingGid(t *testing.T) {
6262
config := rootlessEUIDConfig()
63-
config.GidMappings = nil
63+
config.GIDMappings = nil
6464
if err := Validate(config); err == nil {
6565
t.Errorf("Expected error to occur if no gid mappings provided")
6666
}
@@ -93,13 +93,13 @@ func TestValidateRootlessEUIDMountUid(t *testing.T) {
9393
}
9494

9595
config.Mounts[0].Data = "uid=2"
96-
config.UidMappings[0].Size = 10
96+
config.UIDMappings[0].Size = 10
9797
if err := Validate(config); err != nil {
9898
t.Errorf("Expected error to not occur when setting uid=2 in mount options and UidMapping[0].size is 10")
9999
}
100100

101101
config.Mounts[0].Data = "uid=20"
102-
config.UidMappings[0].Size = 10
102+
config.UIDMappings[0].Size = 10
103103
if err := Validate(config); err == nil {
104104
t.Errorf("Expected error to occur when setting uid=20 in mount options and UidMapping[0].size is 10")
105105
}
@@ -130,21 +130,21 @@ func TestValidateRootlessEUIDMountGid(t *testing.T) {
130130
}
131131

132132
config.Mounts[0].Data = "gid=5"
133-
config.GidMappings[0].Size = 10
133+
config.GIDMappings[0].Size = 10
134134
if err := Validate(config); err != nil {
135135
t.Errorf("Expected error to not occur when setting gid=5 in mount options and GidMapping[0].size is 10")
136136
}
137137

138138
config.Mounts[0].Data = "gid=11"
139-
config.GidMappings[0].Size = 10
139+
config.GIDMappings[0].Size = 10
140140
if err := Validate(config); err == nil {
141141
t.Errorf("Expected error to occur when setting gid=11 in mount options and GidMapping[0].size is 10")
142142
}
143143
}
144144

145145
func BenchmarkRootlessEUIDMount(b *testing.B) {
146146
config := rootlessEUIDConfig()
147-
config.GidMappings[0].Size = 10
147+
config.GIDMappings[0].Size = 10
148148
config.Mounts = []*configs.Mount{
149149
{
150150
Source: "devpts",

libcontainer/configs/validate/validator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func namespaces(config *configs.Config) error {
9595
return errors.New("USER namespaces aren't enabled in the kernel")
9696
}
9797
} else {
98-
if config.UidMappings != nil || config.GidMappings != nil {
98+
if config.UIDMappings != nil || config.GIDMappings != nil {
9999
return errors.New("User namespace mappings specified, but USER namespace isn't enabled in the config")
100100
}
101101
}
@@ -264,13 +264,13 @@ func checkIDMapMounts(config *configs.Config, m *configs.Mount) error {
264264
if config.RootlessEUID {
265265
return fmt.Errorf("gidMappings/uidMappings is not supported when runc is being launched with EUID != 0, needs CAP_SYS_ADMIN on the runc parent's user namespace")
266266
}
267-
if len(config.UidMappings) == 0 || len(config.GidMappings) == 0 {
267+
if len(config.UIDMappings) == 0 || len(config.GIDMappings) == 0 {
268268
return fmt.Errorf("not yet supported to use gidMappings/uidMappings in a mount without also using a user namespace")
269269
}
270-
if !sameMapping(config.UidMappings, m.UIDMappings) {
270+
if !sameMapping(config.UIDMappings, m.UIDMappings) {
271271
return fmt.Errorf("not yet supported for the mount uidMappings to be different than user namespace uidMapping")
272272
}
273-
if !sameMapping(config.GidMappings, m.GIDMappings) {
273+
if !sameMapping(config.GIDMappings, m.GIDMappings) {
274274
return fmt.Errorf("not yet supported for the mount gidMappings to be different than user namespace gidMapping")
275275
}
276276
if !filepath.IsAbs(m.Source) {

libcontainer/configs/validate/validator_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestValidateUsernamespaceWithoutUserNS(t *testing.T) {
192192
uidMap := configs.IDMap{ContainerID: 123}
193193
config := &configs.Config{
194194
Rootfs: "/var",
195-
UidMappings: []configs.IDMap{uidMap},
195+
UIDMappings: []configs.IDMap{uidMap},
196196
}
197197

198198
err := Validate(config)
@@ -405,8 +405,8 @@ func TestValidateIDMapMounts(t *testing.T) {
405405
name: "idmap mount without bind opt specified",
406406
isErr: true,
407407
config: &configs.Config{
408-
UidMappings: mapping,
409-
GidMappings: mapping,
408+
UIDMappings: mapping,
409+
GIDMappings: mapping,
410410
Mounts: []*configs.Mount{
411411
{
412412
Source: "/abs/path/",
@@ -422,8 +422,8 @@ func TestValidateIDMapMounts(t *testing.T) {
422422
isErr: true,
423423
config: &configs.Config{
424424
RootlessEUID: true,
425-
UidMappings: mapping,
426-
GidMappings: mapping,
425+
UIDMappings: mapping,
426+
GIDMappings: mapping,
427427
Mounts: []*configs.Mount{
428428
{
429429
Source: "/abs/path/",
@@ -454,8 +454,8 @@ func TestValidateIDMapMounts(t *testing.T) {
454454
name: "idmap mounts with different userns and mount mappings",
455455
isErr: true,
456456
config: &configs.Config{
457-
UidMappings: mapping,
458-
GidMappings: mapping,
457+
UIDMappings: mapping,
458+
GIDMappings: mapping,
459459
Mounts: []*configs.Mount{
460460
{
461461
Source: "/abs/path/",
@@ -477,8 +477,8 @@ func TestValidateIDMapMounts(t *testing.T) {
477477
name: "idmap mounts with different userns and mount mappings",
478478
isErr: true,
479479
config: &configs.Config{
480-
UidMappings: mapping,
481-
GidMappings: mapping,
480+
UIDMappings: mapping,
481+
GIDMappings: mapping,
482482
Mounts: []*configs.Mount{
483483
{
484484
Source: "/abs/path/",
@@ -500,8 +500,8 @@ func TestValidateIDMapMounts(t *testing.T) {
500500
name: "idmap mounts without abs source path",
501501
isErr: true,
502502
config: &configs.Config{
503-
UidMappings: mapping,
504-
GidMappings: mapping,
503+
UIDMappings: mapping,
504+
GIDMappings: mapping,
505505
Mounts: []*configs.Mount{
506506
{
507507
Source: "./rel/path/",
@@ -517,8 +517,8 @@ func TestValidateIDMapMounts(t *testing.T) {
517517
name: "idmap mounts without abs dest path",
518518
isErr: true,
519519
config: &configs.Config{
520-
UidMappings: mapping,
521-
GidMappings: mapping,
520+
UIDMappings: mapping,
521+
GIDMappings: mapping,
522522
Mounts: []*configs.Mount{
523523
{
524524
Source: "/abs/path/",
@@ -534,8 +534,8 @@ func TestValidateIDMapMounts(t *testing.T) {
534534
{
535535
name: "simple idmap mount",
536536
config: &configs.Config{
537-
UidMappings: mapping,
538-
GidMappings: mapping,
537+
UIDMappings: mapping,
538+
GIDMappings: mapping,
539539
Mounts: []*configs.Mount{
540540
{
541541
Source: "/another-abs/path/",
@@ -550,8 +550,8 @@ func TestValidateIDMapMounts(t *testing.T) {
550550
{
551551
name: "idmap mount with more flags",
552552
config: &configs.Config{
553-
UidMappings: mapping,
554-
GidMappings: mapping,
553+
UIDMappings: mapping,
554+
GIDMappings: mapping,
555555
Mounts: []*configs.Mount{
556556
{
557557
Source: "/another-abs/path/",

libcontainer/container_linux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,7 @@ func (c *Container) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Namespa
22192219
_, joinExistingUser := nsMaps[configs.NEWUSER]
22202220
if !joinExistingUser {
22212221
// write uid mappings
2222-
if len(c.config.UidMappings) > 0 {
2222+
if len(c.config.UIDMappings) > 0 {
22232223
if c.config.RootlessEUID {
22242224
// We resolve the paths for new{u,g}idmap from
22252225
// the context of runc to avoid doing a path
@@ -2231,7 +2231,7 @@ func (c *Container) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Namespa
22312231
})
22322232
}
22332233
}
2234-
b, err := encodeIDMapping(c.config.UidMappings)
2234+
b, err := encodeIDMapping(c.config.UIDMappings)
22352235
if err != nil {
22362236
return nil, err
22372237
}
@@ -2242,8 +2242,8 @@ func (c *Container) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Namespa
22422242
}
22432243

22442244
// write gid mappings
2245-
if len(c.config.GidMappings) > 0 {
2246-
b, err := encodeIDMapping(c.config.GidMappings)
2245+
if len(c.config.GIDMappings) > 0 {
2246+
b, err := encodeIDMapping(c.config.GIDMappings)
22472247
if err != nil {
22482248
return nil, err
22492249
}
@@ -2356,5 +2356,5 @@ func requiresRootOrMappingTool(c *configs.Config) bool {
23562356
gidMap := []configs.IDMap{
23572357
{ContainerID: 0, HostID: os.Getegid(), Size: 1},
23582358
}
2359-
return !reflect.DeepEqual(c.GidMappings, gidMap)
2359+
return !reflect.DeepEqual(c.GIDMappings, gidMap)
23602360
}

libcontainer/integration/exec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,8 +1774,8 @@ func TestBindMountAndUser(t *testing.T) {
17741774
})
17751775

17761776
// Set HostID to 1000 to avoid DAC_OVERRIDE bypassing the purpose of this test.
1777-
config.UidMappings[0].HostID = 1000
1778-
config.GidMappings[0].HostID = 1000
1777+
config.UIDMappings[0].HostID = 1000
1778+
config.GIDMappings[0].HostID = 1000
17791779

17801780
// Set the owner of rootfs to the effective IDs in the host to avoid errors
17811781
// while creating the folders to perform the mounts.

0 commit comments

Comments
 (0)