Changeset 5a721ed
- Timestamp:
- Sep 15, 2010 1:45:58 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master
- Children:
- af25848
- Parents:
- 9cce15a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/access_to_abac.py
r9cce15a r5a721ed 62 62 [attribute(p, x) for x in (gp, gu) if x is not None]) 63 63 creds.add(c) 64 if a in to_id: to_id[a].append(c)65 else: to_id[ a] = [ c ]64 if (project, user) in to_id: to_id[(project,user)].append(c) 65 else: to_id[(project,user)] = [ c ] 66 66 else: 67 67 raise parse_error("Badly formatted local mapping: %s" % l) 68 68 69 70 def parse_protogeni(l, creds, me, to_id, p, gp, gu): 71 right_side_str = '\s*,\s*\(\s*(%s)\s*,\s*(%s)\s*,\s*(%s)\s*,\s*(%s)\s*\)' \ 72 % (path_str, id_str, path_str, id_str) 73 74 m = re.match(right_side_str, l) 75 if m: 76 cert, user, key, pw = m.group(1,2,3,4) 77 acert = re.sub('/', '_', cert) 78 79 a = "cert_%s_user_%s" % (acert, user) 80 c = credential(me, a, 81 [attribute(p, x) for x in (gp, gu) if x is not None]) 82 creds.add(c) 83 if (cert, user, key, pw) in to_id: 84 to_id[(cert, user, key, pw)].append(c) 85 else: 86 to_id[(cert, user, key, pw)] = [ c ] 87 else: 88 raise parse_error("Badly formatted local mapping: %s" % l) 69 89 70 90 def parse_dragon(l, creds, me, to_id, p, gp, gu): … … 94 114 'internal': parse_internal, 95 115 'skel': parse_skel, 116 'protogeni': parse_protogeni, 96 117 } 97 118 … … 110 131 self.add_option('--key', dest='key', default=None, 111 132 help='key for the certificate') 133 self.add_option('--dir', dest='dir', default=None, 134 help='Output directory for credentials') 112 135 self.add_option('--type', action='callback', nargs=1, type='str', 113 136 callback=access_opts.parse_mapper, … … 116 139 ", ".join(access_opts.mappers.keys()) + \ 117 140 'Omit for generic parsing.') 141 self.add_option('--quiet', dest='quiet', action='store_true', 142 default=False, 143 help='Do not print credential to local attribute map') 144 self.add_option('--create-creds', action='store_true', 145 dest='create_creds', default=False, 146 help='create credentials for rules. Requires ' + \ 147 '--cert, --key, and --dir to be given.') 118 148 self.set_defaults(mapper=None) 119 149 120 150 def create_creds(creds, cert, key, dir, creddy='/usr/local/bin/creddy'): 151 def attrs(r): 152 if r.principal and r.attr: 153 return ['--subject-id=%s' % r.principal, 154 '--subject-role=%s' %r.attr] 155 elif r.principal: 156 return ['--subject-id=%s' % r.prinicpal] 157 else: 158 raise parse_error('Attribute without a principal?') 159 160 for i, c in enumerate(creds): 161 cmd = [creddy, '--attribute', '--issuer=%s' % cert, '--key=%s' % key, 162 '--role=%s' % c.attr, '--out=%s/cred%d' % (dir, i)] 163 for r in c.req: 164 cmd.extend(attrs(r)) 165 print " ".join(cmd) 121 166 122 167 comment_re = re.compile('^\s*#|^$') 123 168 fedid_str = 'fedid:([0-9a-fA-F]{40})' 124 169 id_str = '[a-zA-Z][\w_-]*' 170 path_str = '[a-zA-Z_/\.-]+' 125 171 id_any_str = '(%s|<any>)' % id_str 126 172 id_same_str = '(%s|<same>)' % id_str … … 144 190 print >>sys.stderr, 'No --cert, using dummy fedid' 145 191 me = fedid(hexstr='0123456789012345678901234567890123456789') 192 193 if opts.key and not os.access(opts.key, os.R_OK): 194 sys.exit('Cannot read key (%s)' % opts.key) 195 196 if opts.dir: 197 if not os.path.isdir(opts.dir): 198 sys.exit('%s is not a directory' % opts.dir) 199 elif not os.access(opts.dir, os.W_OK): 200 sys.exit('%s is not writable' % opts.dir) 146 201 147 202 mapper = opts.mapper … … 185 240 continue 186 241 187 for c in creds: 188 print "%s" % c 189 190 for k, c in to_id.items(): 191 print "%s: %s" % ( k , ", ".join(set(["%s.%s" % (x.principal, x.attr) \ 192 for x in c]))) 242 if opts.create_creds: 243 if all([opts.cert, opts.key, opts.dir]): 244 create_creds([c for c in creds if c.principal == me], 245 opts.cert, opts.key, opts.dir) 246 else: 247 print >>sys.stderr, 'Cannot create credentials. Missing parameter' 248 249 if not opts.quiet: 250 for k, c in to_id.items(): 251 for a in set(["%s.%s" % (x.principal, x.attr) for x in c]): 252 print "%s -> (%s)" % ( a, ", ".join(k))
Note: See TracChangeset
for help on using the changeset viewer.