Re[2]: ucred when euid/egid
Thanks all for comment. As i can understand all suggest to change primordial situation to suit direct use of seteuid/gid. I thought there is a cheat|hack|fix less expensive then redesign current permissions model in my project. So, if there is no way for seteuided program to gain access in accordance to euid group membership and it is not a bug, i'll give up. P.S. In terms of home directories it looked like this: rw-rw someone:filegroup~someone/thefile rw-rw someone:proggroup~someone/progdata rw-rw someone2:filegroup ~someone2/thefile rw-rw someone2:proggroup ~someone2/progdata rw-rw someone3:filegroup ~someone3/thefile rw-rw someone3:proggroup ~someone3/progdata ... Sunday, November 29, 2009, 11:13:40 PM, you wrote: CR> On Sun, Nov 29, 2009 at 01:19:02PM +0300, Anthony Pankov wrote: >> >> Thank you for reply. >> >> So, seteuid/gid isn't enough to gain group access as for real uid. >> But how i can achieve this? What functions should i call from >> 'theprog' to gain access for the groups euid user belongs to? >> >> May be i solve the problem in wrong way? >> >> The full problem is: >> >> There is a file owned by group filegroup: >> rw-rw someone:filegroupthefile >> >> There is a programs data owned by group proggroup: >> >> rw-rw someone2:proggroupprogdata >> >> I need a program (theprog) that can access 'thefile' and >> 'progdata' simultaneously. Program can be executed by anyone. CR> This is a clearer statement of the problem, in terms of what you're CR> trying to accomplish. CR> If you can make the program data owned by a special program user, and CR> require the users of the program to make their files group-accessible CR> by this special filegroup, then you can do it fairly simply, like this: CR> Make each users' "thefile" be owned by group filegroup, for example: CR> rw-rw someone:filegroup~someone/thefile CR> rw-rw someone2:filegroup ~someone2/thefile CR> rw-rw someone3:filegroup ~someone3/thefile CR> ... CR> Make the program's data file owned by *user* proguser: CR> rw-rw proguser:proggroupprogdata CR> Now you can make the program setuid proguser/setgid filegroup: CR> r-sr-sr-x proguser:filegrouptheprog CR> This lets it be executed by any user and access its own data (via the CR> suid) and the files the users have put into filegroup (via the sgid). CR> Note that the users should not themselves be members of filegroup CR> unless it's OK for them to read/write each others' data. You may need CR> either to provide an sgid utility which can be used to create or chown CR> that file to filegroup, or require them to be put in a shared directory CR> with filegroup gid and the directory sticky bit set. CR> Alteratively you could drop the sgid and simply require the file be group CR> readable/writable by the user's own group. In that case you have CR> r-sr-xr-x proguser:bin theprog CR> and CR> rw-rw someone:somegroup~someone/thefile >> My idea was to seteuid theprog to user who is memeber of one group >> (filegroup) and setegid theprog to another group (proggroup). In that >> way i was going to give theprog rights to work with both files. >> >> P.S. I don't want to use file ACLs. CR> The standard Unix permissions aren't really extensible in that way. CR> You can do it as I've outlined above; that's getting close to the CR> limits of what you can readily do with the standard permissions. If it CR> gets more complicated, you will need to either do ACLs or something CR> still more creative. CR> sudo, for instance, does allow you to set a vector of groups to match CR> the user you're executing as. It may be possible to leverage the sudo CR> command into doing something more elaborate if you need to, with a CR> suitably crafted sudoers config file; you could also look into the code CR> that sudo uses to set the group vector, but that will require you to CR> write a suid root utility which adds a lot of security risks. CR> Hope this helps, CR> -- Clifton -- Best regards, Anthonymailto:a...@mail.ru ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
Re: ucred when euid/egid
On Sun, 29 Nov 2009, Clifton Royston wrote: On Sun, Nov 29, 2009 at 01:19:02PM +0300, Anthony Pankov wrote: Thank you for reply. So, seteuid/gid isn't enough to gain group access as for real uid. But how i can achieve this? What functions should i call from 'theprog' to gain access for the groups euid user belongs to? May be i solve the problem in wrong way? The full problem is: There is a file owned by group filegroup: rw-rw someone:filegroupthefile There is a programs data owned by group proggroup: rw-rw someone2:proggroupprogdata I need a program (theprog) that can access 'thefile' and 'progdata' simultaneously. Program can be executed by anyone. This is a clearer statement of the problem, in terms of what you're trying to accomplish. If you can make the program data owned by a special program user, and require the users of the program to make their files group-accessible by this special filegroup, then you can do it fairly simply, like this: Make each users' "thefile" be owned by group filegroup, for example: rw-rw someone:filegroup~someone/thefile rw-rw someone2:filegroup ~someone2/thefile rw-rw someone3:filegroup ~someone3/thefile ... Make the program's data file owned by *user* proguser: rw-rw proguser:proggroupprogdata Now you can make the program setuid proguser/setgid filegroup: r-sr-sr-x proguser:filegrouptheprog This lets it be executed by any user and access its own data (via the suid) and the files the users have put into filegroup (via the sgid). If you can't make progdata owned by proguser, or if more groups are needed, you might be able to abuse newgrp(1), which will let you run a program with your real and effective gids set to any specified group of which your real uid is a member. This would require, though, that you break the code that requires access to those files into separate programs. (Though maybe they are as simple as cat'ing a file into a pipe or something.) Example: setuid(proguser); FILE *data = popen("echo \"cat progdata\" | newgrp proggroup", "r"); /* read data */ etc. If your program needs to do something really elaborate with the files that can't be factored out into a separate program, you could use newgrp to run a program that opens the file and passes its fd over a unix socket. But then it's really becoming a hack. :) Caution: I haven't tested any of this. -- Nate Eldredge n...@thatsmathematics.com ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
Re: ucred when euid/egid
On Sun, Nov 29, 2009 at 01:19:02PM +0300, Anthony Pankov wrote: > > Thank you for reply. > > So, seteuid/gid isn't enough to gain group access as for real uid. > But how i can achieve this? What functions should i call from > 'theprog' to gain access for the groups euid user belongs to? > > May be i solve the problem in wrong way? > > The full problem is: > > There is a file owned by group filegroup: > rw-rw someone:filegroupthefile > > There is a programs data owned by group proggroup: > > rw-rw someone2:proggroupprogdata > > I need a program (theprog) that can access 'thefile' and > 'progdata' simultaneously. Program can be executed by anyone. This is a clearer statement of the problem, in terms of what you're trying to accomplish. If you can make the program data owned by a special program user, and require the users of the program to make their files group-accessible by this special filegroup, then you can do it fairly simply, like this: Make each users' "thefile" be owned by group filegroup, for example: rw-rw someone:filegroup~someone/thefile rw-rw someone2:filegroup ~someone2/thefile rw-rw someone3:filegroup ~someone3/thefile ... Make the program's data file owned by *user* proguser: rw-rw proguser:proggroupprogdata Now you can make the program setuid proguser/setgid filegroup: r-sr-sr-x proguser:filegrouptheprog This lets it be executed by any user and access its own data (via the suid) and the files the users have put into filegroup (via the sgid). Note that the users should not themselves be members of filegroup unless it's OK for them to read/write each others' data. You may need either to provide an sgid utility which can be used to create or chown that file to filegroup, or require them to be put in a shared directory with filegroup gid and the directory sticky bit set. Alteratively you could drop the sgid and simply require the file be group readable/writable by the user's own group. In that case you have r-sr-xr-x proguser:bin theprog and rw-rw someone:somegroup~someone/thefile > My idea was to seteuid theprog to user who is memeber of one group > (filegroup) and setegid theprog to another group (proggroup). In that > way i was going to give theprog rights to work with both files. > > P.S. I don't want to use file ACLs. The standard Unix permissions aren't really extensible in that way. You can do it as I've outlined above; that's getting close to the limits of what you can readily do with the standard permissions. If it gets more complicated, you will need to either do ACLs or something still more creative. sudo, for instance, does allow you to set a vector of groups to match the user you're executing as. It may be possible to leverage the sudo command into doing something more elaborate if you need to, with a suitably crafted sudoers config file; you could also look into the code that sudo uses to set the group vector, but that will require you to write a suid root utility which adds a lot of security risks. Hope this helps, -- Clifton -- Clifton Royston -- clift...@iandicomputing.com / clift...@lava.net President - I and I Computing * http://www.iandicomputing.com/ Custom programming, network design, systems and network consulting services ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
Re[2]: ucred when euid/egid
Thank you for reply. So, seteuid/gid isn't enough to gain group access as for real uid. But how i can achieve this? What functions should i call from 'theprog' to gain access for the groups euid user belongs to? May be i solve the problem in wrong way? The full problem is: There is a file owned by group filegroup: rw-rw someone:filegroupthefile There is a programs data owned by group proggroup: rw-rw someone2:proggroupprogdata I need a program (theprog) that can access 'thefile' and 'progdata' simultaneously. Program can be executed by anyone. My idea was to seteuid theprog to user who is memeber of one group (filegroup) and setegid theprog to another group (proggroup). In that way i was going to give theprog rights to work with both files. P.S. I don't want to use file ACLs. Saturday, November 28, 2009, 9:28:03 PM, you wrote: >> >> Hello, >> >> I face some misunderstood situation related to the access permissions. >> >> >> There is a program(script) with the suid/sgid (mode 6555): >> >> r-sr-sr-x fuser:proggroup theprog >> >> There is a file: >> rw-rw someone:filegroupthefile >> >> >> User 'fuser' (==program euid) have primary group 'filegroup'(==group, >> who can read/write thefile). >> >> Program try to read(write) thefile and fail with permissions. >> >> I don't fully understand why. CR> There is no bug; when you use the suid/sgid facility, the program CR> gains the effective user ID and/or the effective GID of the executable. CR> It does *not* gain any gids which the effective user is added to at CR> login. CR> man seteuid for more info. CR> In what you have shown, theprog has neither the same user (fuser vs. CR> someone) nor the same group (proggroup vs. filegroup) as the file you CR> want it to modify. CR> For what you want to do to work correctly, you would need to either CR> make theprog's ownership be: CR> anyuser:filegroup CR> or CR> fuser:proggroup CR> -- Clifton -- Best regards, Anthonymailto:a...@mail.ru ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
Re: ucred when euid/egid
> Date: Fri, 27 Nov 2009 19:56:59 +0300 > From: Anthony Pankov > Subject: ucred when euid/egid > To: freebsd-hackers@freebsd.org > Message-ID: <15434604890.20091127195...@mail.ru> > Content-Type: text/plain; charset=us-ascii > > Hello, > > I face some misunderstood situation related to the access permissions. > > > There is a program(script) with the suid/sgid (mode 6555): > > r-sr-sr-x fuser:proggroup theprog > > There is a file: > rw-rw someone:filegroupthefile > > > User 'fuser' (==program euid) have primary group 'filegroup'(==group, > who can read/write thefile). > > Program try to read(write) thefile and fail with permissions. > > I don't fully understand why. There is no bug; when you use the suid/sgid facility, the program gains the effective user ID and/or the effective GID of the executable. It does *not* gain any gids which the effective user is added to at login. man seteuid for more info. In what you have shown, theprog has neither the same user (fuser vs. someone) nor the same group (proggroup vs. filegroup) as the file you want it to modify. For what you want to do to work correctly, you would need to either make theprog's ownership be: anyuser:filegroup or fuser:proggroup -- Clifton -- Clifton Royston -- clift...@iandicomputing.com / clift...@lava.net President - I and I Computing * http://www.iandicomputing.com/ Custom programming, network design, systems and network consulting services ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
ucred when euid/egid
Hello, I face some misunderstood situation related to the access permissions. There is a program(script) with the suid/sgid (mode 6555): r-sr-sr-x fuser:proggroup theprog There is a file: rw-rw someone:filegroupthefile User 'fuser' (==program euid) have primary group 'filegroup'(==group, who can read/write thefile). Program try to read(write) thefile and fail with permissions. I don't fully understand why. According VOP_ACCESS(9) there is a check /* Otherwise, check the groups. */ for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) ... So, i have only one assumption: when seteuided program executed ucred struct and cred->cr_groups doesn't change accordingly to euid/egid and stay the same as for executor. Is this a bug (how can i fix it) or feature (how can i bypass it)? -- Best regards, Anthony mailto:a...@mail.ru ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"