mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Capitalize [UG]idMappings as [UG]IDMappings
Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
This commit is contained in:
@@ -42,10 +42,10 @@ func rootlessEUIDMappings(config *configs.Config) error {
|
||||
return errors.New("rootless container requires user namespaces")
|
||||
}
|
||||
|
||||
if len(config.UidMappings) == 0 {
|
||||
if len(config.UIDMappings) == 0 {
|
||||
return errors.New("rootless containers requires at least one UID mapping")
|
||||
}
|
||||
if len(config.GidMappings) == 0 {
|
||||
if len(config.GIDMappings) == 0 {
|
||||
return errors.New("rootless containers requires at least one GID mapping")
|
||||
}
|
||||
return nil
|
||||
@@ -68,7 +68,7 @@ func rootlessEUIDMount(config *configs.Config) error {
|
||||
// Ignore unknown mount options.
|
||||
continue
|
||||
}
|
||||
if !hasIDMapping(uid, config.UidMappings) {
|
||||
if !hasIDMapping(uid, config.UIDMappings) {
|
||||
return errors.New("cannot specify uid= mount options for unmapped uid in rootless containers")
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func rootlessEUIDMount(config *configs.Config) error {
|
||||
// Ignore unknown mount options.
|
||||
continue
|
||||
}
|
||||
if !hasIDMapping(gid, config.GidMappings) {
|
||||
if !hasIDMapping(gid, config.GIDMappings) {
|
||||
return errors.New("cannot specify gid= mount options for unmapped gid in rootless containers")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ func rootlessEUIDConfig() *configs.Config {
|
||||
{Type: configs.NEWUSER},
|
||||
},
|
||||
),
|
||||
UidMappings: []configs.IDMap{
|
||||
UIDMappings: []configs.IDMap{
|
||||
{
|
||||
HostID: 1337,
|
||||
ContainerID: 0,
|
||||
Size: 1,
|
||||
},
|
||||
},
|
||||
GidMappings: []configs.IDMap{
|
||||
GIDMappings: []configs.IDMap{
|
||||
{
|
||||
HostID: 7331,
|
||||
ContainerID: 0,
|
||||
@@ -52,7 +52,7 @@ func TestValidateRootlessEUIDUserns(t *testing.T) {
|
||||
|
||||
func TestValidateRootlessEUIDMappingUid(t *testing.T) {
|
||||
config := rootlessEUIDConfig()
|
||||
config.UidMappings = nil
|
||||
config.UIDMappings = nil
|
||||
if err := Validate(config); err == nil {
|
||||
t.Errorf("Expected error to occur if no uid mappings provided")
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func TestValidateRootlessEUIDMappingUid(t *testing.T) {
|
||||
|
||||
func TestValidateNonZeroEUIDMappingGid(t *testing.T) {
|
||||
config := rootlessEUIDConfig()
|
||||
config.GidMappings = nil
|
||||
config.GIDMappings = nil
|
||||
if err := Validate(config); err == nil {
|
||||
t.Errorf("Expected error to occur if no gid mappings provided")
|
||||
}
|
||||
@@ -93,15 +93,15 @@ func TestValidateRootlessEUIDMountUid(t *testing.T) {
|
||||
}
|
||||
|
||||
config.Mounts[0].Data = "uid=2"
|
||||
config.UidMappings[0].Size = 10
|
||||
config.UIDMappings[0].Size = 10
|
||||
if err := Validate(config); err != nil {
|
||||
t.Errorf("Expected error to not occur when setting uid=2 in mount options and UidMapping[0].size is 10")
|
||||
t.Errorf("Expected error to not occur when setting uid=2 in mount options and UIDMappings[0].size is 10")
|
||||
}
|
||||
|
||||
config.Mounts[0].Data = "uid=20"
|
||||
config.UidMappings[0].Size = 10
|
||||
config.UIDMappings[0].Size = 10
|
||||
if err := Validate(config); err == nil {
|
||||
t.Errorf("Expected error to occur when setting uid=20 in mount options and UidMapping[0].size is 10")
|
||||
t.Errorf("Expected error to occur when setting uid=20 in mount options and UIDMappings[0].size is 10")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,21 +130,21 @@ func TestValidateRootlessEUIDMountGid(t *testing.T) {
|
||||
}
|
||||
|
||||
config.Mounts[0].Data = "gid=5"
|
||||
config.GidMappings[0].Size = 10
|
||||
config.GIDMappings[0].Size = 10
|
||||
if err := Validate(config); err != nil {
|
||||
t.Errorf("Expected error to not occur when setting gid=5 in mount options and GidMapping[0].size is 10")
|
||||
t.Errorf("Expected error to not occur when setting gid=5 in mount options and GIDMappings[0].size is 10")
|
||||
}
|
||||
|
||||
config.Mounts[0].Data = "gid=11"
|
||||
config.GidMappings[0].Size = 10
|
||||
config.GIDMappings[0].Size = 10
|
||||
if err := Validate(config); err == nil {
|
||||
t.Errorf("Expected error to occur when setting gid=11 in mount options and GidMapping[0].size is 10")
|
||||
t.Errorf("Expected error to occur when setting gid=11 in mount options and GIDMappings[0].size is 10")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRootlessEUIDMount(b *testing.B) {
|
||||
config := rootlessEUIDConfig()
|
||||
config.GidMappings[0].Size = 10
|
||||
config.GIDMappings[0].Size = 10
|
||||
config.Mounts = []*configs.Mount{
|
||||
{
|
||||
Source: "devpts",
|
||||
|
||||
@@ -95,7 +95,7 @@ func namespaces(config *configs.Config) error {
|
||||
return errors.New("USER namespaces aren't enabled in the kernel")
|
||||
}
|
||||
} else {
|
||||
if config.UidMappings != nil || config.GidMappings != nil {
|
||||
if config.UIDMappings != nil || config.GIDMappings != nil {
|
||||
return errors.New("User namespace mappings specified, but USER namespace isn't enabled in the config")
|
||||
}
|
||||
}
|
||||
@@ -264,13 +264,13 @@ func checkIDMapMounts(config *configs.Config, m *configs.Mount) error {
|
||||
if config.RootlessEUID {
|
||||
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")
|
||||
}
|
||||
if len(config.UidMappings) == 0 || len(config.GidMappings) == 0 {
|
||||
if len(config.UIDMappings) == 0 || len(config.GIDMappings) == 0 {
|
||||
return fmt.Errorf("not yet supported to use gidMappings/uidMappings in a mount without also using a user namespace")
|
||||
}
|
||||
if !sameMapping(config.UidMappings, m.UIDMappings) {
|
||||
if !sameMapping(config.UIDMappings, m.UIDMappings) {
|
||||
return fmt.Errorf("not yet supported for the mount uidMappings to be different than user namespace uidMapping")
|
||||
}
|
||||
if !sameMapping(config.GidMappings, m.GIDMappings) {
|
||||
if !sameMapping(config.GIDMappings, m.GIDMappings) {
|
||||
return fmt.Errorf("not yet supported for the mount gidMappings to be different than user namespace gidMapping")
|
||||
}
|
||||
if !filepath.IsAbs(m.Source) {
|
||||
|
||||
@@ -192,7 +192,7 @@ func TestValidateUsernamespaceWithoutUserNS(t *testing.T) {
|
||||
uidMap := configs.IDMap{ContainerID: 123}
|
||||
config := &configs.Config{
|
||||
Rootfs: "/var",
|
||||
UidMappings: []configs.IDMap{uidMap},
|
||||
UIDMappings: []configs.IDMap{uidMap},
|
||||
}
|
||||
|
||||
err := Validate(config)
|
||||
@@ -405,8 +405,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
name: "idmap mount without bind opt specified",
|
||||
isErr: true,
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/abs/path/",
|
||||
@@ -422,8 +422,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
isErr: true,
|
||||
config: &configs.Config{
|
||||
RootlessEUID: true,
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/abs/path/",
|
||||
@@ -454,8 +454,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
name: "idmap mounts with different userns and mount mappings",
|
||||
isErr: true,
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/abs/path/",
|
||||
@@ -477,8 +477,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
name: "idmap mounts with different userns and mount mappings",
|
||||
isErr: true,
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/abs/path/",
|
||||
@@ -500,8 +500,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
name: "idmap mounts without abs source path",
|
||||
isErr: true,
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "./rel/path/",
|
||||
@@ -517,8 +517,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
name: "idmap mounts without abs dest path",
|
||||
isErr: true,
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/abs/path/",
|
||||
@@ -534,8 +534,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
{
|
||||
name: "simple idmap mount",
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/another-abs/path/",
|
||||
@@ -550,8 +550,8 @@ func TestValidateIDMapMounts(t *testing.T) {
|
||||
{
|
||||
name: "idmap mount with more flags",
|
||||
config: &configs.Config{
|
||||
UidMappings: mapping,
|
||||
GidMappings: mapping,
|
||||
UIDMappings: mapping,
|
||||
GIDMappings: mapping,
|
||||
Mounts: []*configs.Mount{
|
||||
{
|
||||
Source: "/another-abs/path/",
|
||||
|
||||
Reference in New Issue
Block a user