<div dir="ltr">Yes, no need to set init_uid in this situation (unprivileged container + setcap), <div>lxc.network.type = none --> CLONE_NEWNET is not set when clone --> when create raw socket, kernel cap_capable(), ns != cred->user_ns --> cap_raised() is not checked --> unprivileged testapp get EPERM error</div><div>Does cap_capable() need to be patched for this case?<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 16, 2017 at 1:07 AM Serge E. Hallyn <<a href="mailto:serge@hallyn.com">serge@hallyn.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Quoting Philip (<a href="mailto:ultrafit67@gmail.com" target="_blank">ultrafit67@gmail.com</a>):<br>
> Please ignore step 4, lxc.id_map only allow ONE uid/gid, so<br>
> lxc_switch_uid_gid will fail<br>
<br>
I'm not sure what you mean by that, but your id mapping makes<br>
uid 2000 on the host map to 0 in the container, and that is the<br>
only uid in the container.<br>
<br>
So lxc.init_uid would need to be 0 - the id in the container.<br>
<br>
> On Fri, Dec 15, 2017 at 10:17 AM Philip <<a href="mailto:ultrafit67@gmail.com" target="_blank">ultrafit67@gmail.com</a>> wrote:<br>
><br>
> > Hi,<br>
> ><br>
> > I want to use unprivileged container + setcap to set limited capabilities,<br>
> > but can not success, here is my test (lxc-1.0.8 and lxc-2.0.8):<br>
> ><br>
> > testapp:<br>
> > int ret = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);<br>
> > fprintf(stderr, "socket ret %d, %s\n", ret, strerror(errno));<br>
> ><br>
> > 1. add net_raw capability<br>
> > setcap cap_net_admin,cap_net_raw=eip ./testapp<br>
> ><br>
> > 2. switch to uid 2000, execute testapp<br>
> > $ ./testapp<br>
> > socket ret 3, Success<br>
> ><br>
> > 3. use unprivileged container to run testapp<br>
> > lxc config:<br>
> > lxc.network.type = none<br>
> > lxc.id_map = u 0 2000 1<br>
> > lxc.id_map = g 0 2000 1<br>
> ><br>
> > sudo lxc-execute -n testapp -f config -P /files/testapp<br>
> > ....<br>
> > socket ret -1, Operation not permitted<br>
> ><br>
> > 4. using lxc-2.0.8, add init_uid/init_gid<br>
> > lxc.init_uid = 2000<br>
> > lxc.init_gid = 2000<br>
> ><br>
> > lxc-execute: utils.c: lxc_switch_uid_gid: 2069 Invalid argument - Failed<br>
> > to switch to gid 2000.<br>
> ><br>
> > Can anyone help, what is going wrong?<br>
> ><br>
<br>
> _______________________________________________<br>
> lxc-users mailing list<br>
> <a href="mailto:lxc-users@lists.linuxcontainers.org" target="_blank">lxc-users@lists.linuxcontainers.org</a><br>
> <a href="http://lists.linuxcontainers.org/listinfo/lxc-users" rel="noreferrer" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a><br>
<br>
_______________________________________________<br>
lxc-users mailing list<br>
<a href="mailto:lxc-users@lists.linuxcontainers.org" target="_blank">lxc-users@lists.linuxcontainers.org</a><br>
<a href="http://lists.linuxcontainers.org/listinfo/lxc-users" rel="noreferrer" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a></blockquote></div>