7 from invirt.config import structs as config
10 # expandOwner and expandAdmin form the API that needs to be exported
11 # for all authz modules.
14 # TODO: Make expandOwner and expandAdmin deal with acquiring tokens
15 # and encrypting the connection to the prdb as necessary/requested by
17 def expandOwner(name):
18 """Expand an owner to a list of authorized users.
20 For the locker authz module, an owner is an Athena locker. Those
21 users who have been given the administrator ('a') bit on the root
22 of a locker are given access to any VM owned by that locker,
23 unless they also have been given a negative administrator bit.
25 If a locker doesn't exist, or we can't access the permissions, we
26 assume the ACL is empty.
29 path = _lockerPath(name)
30 cell = fs.whichcell(path)
31 a = acl.ACL.retrieve(path)
35 if a.pos[ent] & acl.ADMINISTER:
36 allowed.update(_expandGroup(ent, cell))
38 if a.neg[ent] & acl.ADMINISTER:
39 allowed.difference_update(_expandGroup(ent, cell))
43 if e.errno in (errno.ENOENT, errno.EACCES):
49 def expandAdmin(name, owner):
50 """Expand an administrator to a list of authorized users.
52 Because the interpretation of an administrator might depend on the
53 owner, the owner is passed in as an argument.
55 However, in the case of locker-based authentication, the
56 administrator is always interpreted as an AFS entry (either a user
57 or a group) in the home cell (athena.mit.edu for XVM).
59 return _expandGroup(name)
63 # These are helper functions, and aren't part of the authz API
66 def _expandGroup(name, cell=None):
67 """Expand an AFS group into a list of its members.
69 Because groups are not global, but can vary from cell to cell,
70 this function accepts as an optional argument the cell in which
71 this group should be resolved.
73 If no cell is specified, it is assumed that the default cell (or
74 ThisCell) should be used.
76 If the name is a user, not a group, then a single-element set with
77 the same name is returned.
79 As with expandOwner, if a group doesn't exist or if we're unable
80 to retrieve its membership, we assume it's empty.
83 ent = pts.PTS(cell).getEntry(name)
85 return set([ent.name])
87 return set([x.name for x in ent.members])
89 if e.errno in (errno.ENOENT, errno.EACCESS):
95 def _lockerPath(owner):
96 """Given the name of a locker, return a path to that locker.
98 This turns out to be pretty simple, thanks to the /mit
101 return '/mit/%s' % owner