github.com/containers/podman/v5@v5.1.0-rc1/docs/source/markdown/options/uidmap.container.md (about) 1 ####> This option file is used in: 2 ####> podman create, run 3 ####> If file is edited, make sure the changes 4 ####> are applicable to all of those. 5 #### **--uidmap**=*[flags]container_uid:from_uid[:amount]* 6 7 Run the container in a new user namespace using the supplied UID mapping. This 8 option conflicts with the **--userns** and **--subuidname** options. This 9 option provides a way to map host UIDs to container UIDs. It can be passed 10 several times to map different ranges. 11 12 The possible values of the optional *flags* are discussed further down on this page. 13 The *amount* value is optional and assumed to be **1** if not given. 14 15 The *from_uid* value is based upon the user running the command, either rootful or rootless users. 16 17 * rootful user: [*flags*]*container_uid*:*host_uid*[:*amount*] 18 * rootless user: [*flags*]*container_uid*:*intermediate_uid*[:*amount*] 19 20 `Rootful mappings` 21 22 23 When **podman <<subcommand>>** is called by a privileged user, the option **--uidmap** 24 works as a direct mapping between host UIDs and container UIDs. 25 26 host UID -> container UID 27 28 The _amount_ specifies the number of consecutive UIDs that is mapped. 29 If for example _amount_ is **4** the mapping looks like: 30 31 | host UID | container UID | 32 | ---------- | ---------------- | 33 | *from_uid* | *container_uid* | 34 | *from_uid* + 1 | *container_uid* + 1 | 35 | *from_uid* + 2 | *container_uid* + 2 | 36 | *from_uid* + 3 | *container_uid* + 3 | 37 38 `Rootless mappings` 39 40 When **podman <<subcommand>>** is called by an unprivileged user (i.e. running rootless), 41 the value *from_uid* is interpreted as an "intermediate UID". In the rootless 42 case, host UIDs are not mapped directly to container UIDs. Instead the mapping 43 happens over two mapping steps: 44 45 host UID -> intermediate UID -> container UID 46 47 The **--uidmap** option only influences the second mapping step. 48 49 The first mapping step is derived by Podman from the contents of the file 50 _/etc/subuid_ and the UID of the user calling Podman. 51 52 First mapping step: 53 54 | host UID | intermediate UID | 55 | -------- | ---------------- | 56 | UID for Podman user | 0 | 57 | 1st subordinate UID | 1 | 58 | 2nd subordinate UID | 2 | 59 | 3rd subordinate UID | 3 | 60 | nth subordinate UID | n | 61 62 To be able to use intermediate UIDs greater than zero, the user needs to have 63 subordinate UIDs configured in _/etc/subuid_. See **subuid**(5). 64 65 The second mapping step is configured with **--uidmap**. 66 67 If for example _amount_ is **5** the second mapping step looks like: 68 69 | intermediate UID | container UID | 70 | ------------------ | ---------------- | 71 | *from_uid* | *container_uid* | 72 | *from_uid* + 1 | *container_uid* + 1 | 73 | *from_uid* + 2 | *container_uid* + 2 | 74 | *from_uid* + 3 | *container_uid* + 3 | 75 | *from_uid* + 4 | *container_uid* + 4 | 76 77 When running as rootless, Podman uses all the ranges configured in the _/etc/subuid_ file. 78 79 The current user ID is mapped to UID=0 in the rootless user namespace. 80 Every additional range is added sequentially afterward: 81 82 | host | rootless user namespace | length | 83 | ------ | ----------------------- | ------ | 84 | $UID | 0 | 1 | 85 | 1 | $FIRST_RANGE_ID | $FIRST_RANGE_LENGTH | 86 | 1+$FIRST_RANGE_LENGTH | $SECOND_RANGE_ID | $SECOND_RANGE_LENGTH| 87 88 `Referencing a host ID from the parent namespace` 89 90 As a rootless user, the given host ID in **--uidmap** or **--gidmap** 91 is mapped from the *intermediate namespace* generated by Podman. Sometimes 92 it is desirable to refer directly at the *host namespace*. It is possible 93 to manually do so, by running `podman unshare cat /proc/self/gid_map`, 94 finding the desired host id at the second column of the output, and getting 95 the corresponding intermediate id from the first column. 96 97 Podman can perform all that by preceding the host id in the mapping 98 with the `@` symbol. For instance, by specifying `--gidmap 100000:@2000:1`, 99 podman will look up the intermediate id corresponding to host id `2000` and 100 it will map the found intermediate id to the container id `100000`. The 101 given host id must have been subordinated (otherwise it would not be mapped 102 into the intermediate space in the first place). 103 104 If the length is greater than one, for instance with `--gidmap 100000:@2000:2`, 105 Podman will map host ids `2000` and `2001` to `100000` and `100001`, respectively, 106 regardless of how the intermediate mapping is defined. 107 108 `Extending previous mappings` 109 110 Some mapping modifications may be cumbersome. For instance, a user 111 starts with a mapping such as `--gidmap="0:0:65000"`, that needs to be 112 changed such as the parent id `1000` is mapped to container id `100000` 113 instead, leaving container id `1` unassigned. The corresponding `--gidmap` 114 becomes `--gidmap="0:0:1" --gidmap="2:2:65534" --gidmap="100000:1:1"`. 115 116 This notation can be simplified using the `+` flag, that takes care of 117 breaking previous mappings removing any conflicting assignment with 118 the given mapping. The flag is given before the container id 119 as follows: `--gidmap="0:0:65000" --gidmap="+100000:1:1"` 120 121 122 Flag | Example | Description 123 -----------|---------------|------------- 124 `+` | `+100000:1:1` | Extend the previous mapping 125 126 This notation leads to gaps in the assignment, so it may be convenient to 127 fill those gaps afterwards: `--gidmap="0:0:65000" --gidmap="+100000:1:1" --gidmap="1:65001:1"` 128 129 One specific use case for this flag is in the context of rootless 130 users. A rootless user may specify mappings with the `+` flag as 131 in `--gidmap="+100000:1:1"`. Podman will then "fill the gaps" starting 132 from zero with all the remaining intermediate ids. This is convenient when 133 a user wants to map a specific intermediate id to a container id, leaving 134 the rest of subordinate ids to be mapped by Podman at will. 135 136 `Passing only one of --uidmap or --gidmap` 137 138 Usually, subordinated user and group ids are assigned simultaneously, and 139 for any user the subordinated user ids match the subordinated group ids. 140 For convenience, if only one of **--uidmap** or **--gidmap** is given, 141 podman assumes the mapping refers to both UIDs and GIDs and applies the 142 given mapping to both. If only one value of the two needs to be changed, 143 the mappings should include the `u` or the `g` flags to specify that 144 they only apply to UIDs or GIDs and should not be copied over. 145 146 flag | Example | Description 147 ---------|-----------------|----------------- 148 `u` | `u20000:2000:1` |The mapping only applies to UIDs 149 `g` | `g10000:1000:1` |The mapping only applies to GIDs 150 151 For instance given the command 152 153 podman <<subcommand>> --gidmap "0:0:1000" --gidmap "g2000:2000:1" 154 155 Since no **--uidmap** is given, the **--gidmap** is copied to **--uidmap**, 156 giving a command equivalent to 157 158 podman <<subcommand>> --gidmap "0:0:1000" --gidmap "2000:2000:1" --uidmap "0:0:1000" 159 160 The `--gidmap "g2000:2000:1"` used the `g` flag and therefore it was 161 not copied to **--uidmap**. 162 163 `Rootless mapping of additional host GIDs` 164 165 A rootless user may desire to map a specific host group that has already been 166 subordinated within _/etc/subgid_ without specifying the rest of the mapping. 167 168 This can be done with **--gidmap "+g*container_gid*:@*host_gid*"** 169 170 Where: 171 172 - The host GID is given through the `@` symbol 173 - The mapping of this GID is not copied over to **--usermap** thanks to the `g` flag. 174 - The rest of the container IDs will be mapped starting from 0 to n, 175 with all the remaining subordinated GIDs, thanks to the `+` flag. 176 177 For instance, if a user belongs to the group `2000` and that group is 178 subordinated to that user (with `usermod --add-subgids 2000-2000 $USER`), 179 the user can map the group into the container with: **--gidmap=+g100000:@2000**. 180 181 If this mapping is combined with the option, **--group-add=keep-groups**, the 182 process in the container will belong to group `100000`, and files belonging 183 to group `2000` in the host will appear as being owned by group `100000` 184 inside the container. 185 186 podman run --group-add=keep-groups --gidmap="+g100000:@2000" ... 187 188 `No subordinate UIDs` 189 190 Even if a user does not have any subordinate UIDs in _/etc/subuid_, 191 **--uidmap** can be used to map the normal UID of the user to a 192 container UID by running `podman <<subcommand>> --uidmap $container_uid:0:1 --user $container_uid ...`. 193 194 `Pods` 195 196 The **--uidmap** option cannot be called in conjunction with the **--pod** option as a uidmap cannot be set on the container level when in a pod.