Ignore:
Timestamp:
Sep 23, 2010 5:44:47 PM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
835cf55
Parents:
09b1e9d
Message:

checkpoint: new works pretty well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/experiment_control.py

    r09b1e9d r7206e5a  
    3030from synch_store import synch_store
    3131from experiment_partition import experiment_partition
     32from authorizer import abac_authorizer
    3233
    3334import topdl
     
    282283                "ssh_privkey_file")
    283284        dt = config.get("experiment_control", "direct_transit")
     285        self.auth_type = config.get('experiment_control', 'auth_type') \
     286                or 'legacy'
     287        self.auth_dir = config.get('experiment_control', 'auth_dir')
    284288        if dt: self.direct_transit = [ tb.strip() for tb in dt.split(",")]
    285289        else: self.direct_transit = [ ]
     
    319323        self.local_access = { }
    320324
    321         if auth:
    322             self.auth = auth
    323         else:
    324             self.log.error(\
    325                     "[access]: No authorizer initialized, creating local one.")
    326             auth = authorizer()
     325        if self.auth_type == 'legacy':
     326            if auth:
     327                self.auth = auth
     328            else:
     329                self.log.error( "[access]: No authorizer initialized, " +\
     330                        "creating local one.")
     331                auth = authorizer()
     332        elif self.auth_type == 'abac':
     333            self.auth = abac_authorizer(load=self.auth_dir)
     334        else:
     335            raise service_error(service_error.internal,
     336                    "Unknown auth_type: %s" % self.auth_type)
    327337
    328338
     
    475485                eid = get_experiment_id(s)
    476486                if eid :
    477                     # Give the owner rights to the experiment
    478                     self.auth.set_attribute(s['owner'], eid)
    479                     # And holders of the eid as well
    480                     self.auth.set_attribute(eid, eid)
    481                     # allow overrides to control experiments as well
    482                     for o in self.overrides:
    483                         self.auth.set_attribute(o, eid)
    484                     # Set permissions to allow reading of the software repo, if
    485                     # any, as well.
    486                     for a in self.get_alloc_ids(s):
    487                         self.auth.set_attribute(a, 'repo/%s' % eid)
     487                    if self.auth_type == 'legacy':
     488                        # XXX: legacy
     489                        # Give the owner rights to the experiment
     490                        self.auth.set_attribute(s['owner'], eid)
     491                        # And holders of the eid as well
     492                        self.auth.set_attribute(eid, eid)
     493                        # allow overrides to control experiments as well
     494                        for o in self.overrides:
     495                            self.auth.set_attribute(o, eid)
     496                        # Set permissions to allow reading of the software
     497                        # repo, if any, as well.
     498                        for a in self.get_alloc_ids(s):
     499                            self.auth.set_attribute(a, 'repo/%s' % eid)
    488500                else:
    489501                    raise KeyError("No experiment id")
     
    546558
    547559        # Initialize the authorization attributes
    548         for fid in self.accessdb.keys():
    549             self.auth.set_attribute(fid, 'create')
    550             self.auth.set_attribute(fid, 'new')
     560        # XXX: legacy
     561        if self.auth_type == 'legacy':
     562            for fid in self.accessdb.keys():
     563                self.auth.set_attribute(fid, 'create')
     564                self.auth.set_attribute(fid, 'new')
    551565
    552566    def read_mapdb(self, file):
     
    589603        # Set the initial permissions on data in the store.  XXX: This ad hoc
    590604        # authorization attribute initialization is getting out of hand.
    591         for k in self.synch_store.all_keys():
    592             try:
    593                 if k.startswith('fedid:'):
    594                     fid = fedid(hexstr=k[6:46])
    595                     if self.state.has_key(fid):
    596                         for a in self.get_alloc_ids(self.state[fid]):
    597                             self.auth.set_attribute(a, k)
    598             except ValueError, e:
    599                 self.log.warn("Cannot deduce permissions for %s" % k)
     605        # XXX: legacy
     606        if self.auth_type == 'legacy':
     607            for k in self.synch_store.all_keys():
     608                try:
     609                    if k.startswith('fedid:'):
     610                        fid = fedid(hexstr=k[6:46])
     611                        if self.state.has_key(fid):
     612                            for a in self.get_alloc_ids(self.state[fid]):
     613                                self.auth.set_attribute(a, k)
     614                except ValueError, e:
     615                    self.log.warn("Cannot deduce permissions for %s" % k)
    600616
    601617
     
    13001316                if status and status == 'failed':
    13011317                    # remove the old access attribute
    1302                     self.auth.unset_attribute(fid, old_expid)
     1318                    self.auth.unset_attribute(fid, old_expid)
     1319                    self.auth.save()
    13031320                    overwrite = True
    13041321                    del self.state[eid]
     
    14971514                self.auth.set_attribute(tbparams[tb]['allocID']['fedid'],
    14981515                        "/%s/%s" % ( path, dest))
     1516            self.auth.save()
    14991517
    15001518        # Convert the software locations in the segments into the local
     
    15181536        to instantiate them and start it all up.
    15191537        """
     1538        req = req.get('NewRequestBody', None)
     1539        if not req:
     1540            raise service_error(service_error.req,
     1541                    "Bad request format (no NewRequestBody)")
     1542
     1543        if self.auth.import_credentials(data_list=req.get('credential', [])):
     1544            self.auth.save()
     1545       
    15201546        if not self.auth.check_attribute(fid, 'new'):
    15211547            raise service_error(service_error.access, "New access denied")
     
    15361562        gid = "dummy"
    15371563
    1538         req = req.get('NewRequestBody', None)
    1539         if not req:
    1540             raise service_error(service_error.req,
    1541                     "Bad request format (no NewRequestBody)")
    1542 
    15431564        # Generate an ID for the experiment (slice) and a certificate that the
    15441565        # allocator can use to prove they own it.  We'll ship it back through
    1545         # the encrypted connection.
    1546         (expid, expcert) = generate_fedid("test", dir=tmpdir, log=self.log)
     1566        # the encrypted connection.  If the requester supplied one, use it.
     1567        if 'experimentAccess' in req and 'X509' in req['experimentAccess']:
     1568            expcert = req['experimentAccess']['X509']
     1569            tf = tempfile.NamedTemporaryFile()
     1570            tf.write(expcert)
     1571            tf.flush()
     1572            expid = fedid(file=tf.name)
     1573            tf.close()
     1574            self.state_lock.acquire()
     1575            if expid in self.state:
     1576                self.state_lock.release()
     1577                raise service_error(service_error.req,
     1578                        'fedid %s identifies an existing experiment' % expid)
     1579            self.state_lock.release()
     1580        else:
     1581            (expid, expcert) = generate_fedid("test", dir=tmpdir, log=self.log)
    15471582
    15481583        #now we're done with the tmpdir, and it should be empty
     
    15571592
    15581593        # Let users touch the state
    1559         self.auth.set_attribute(fid, expid)
    1560         self.auth.set_attribute(expid, expid)
    1561         # Override fedids can manipulate state as well
    1562         for o in self.overrides:
    1563             self.auth.set_attribute(o, expid)
     1594        self.auth.set_attribute(fid, expid)
     1595        self.auth.set_attribute(expid, expid)
     1596        # Override fedids can manipulate state as well
     1597        for o in self.overrides:
     1598            self.auth.set_attribute(o, expid)
     1599        self.auth.save()
    15641600
    15651601        rv = {
     
    17931829                asignee = tbparams[tb]['allocID']['fedid']
    17941830                for f in ("hosts", gw_secretkey_base, gw_pubkey_base):
    1795                     self.auth.set_attribute(asignee, "%s/%s" % (configpath, f))
     1831                    self.auth.set_attribute(asignee, "%s/%s" % \
     1832                            (configpath, f))
    17961833
    17971834            part = experiment_partition(self.auth, self.store_url, tbmap,
     
    18091846                        self.auth.set_attribute(\
    18101847                                tbparams[tb]['allocID']['fedid'], sk)
     1848            self.auth.save()
    18111849
    18121850            self.wrangle_software(expid, top, topo, tbparams)
     
    18511889        # here on out, the state will stick around a while.
    18521890
    1853         # Let users touch the state
    1854         self.auth.set_attribute(fid, expid)
    1855         self.auth.set_attribute(expid, expid)
    1856         # Override fedids can manipulate state as well
    1857         for o in self.overrides:
    1858             self.auth.set_attribute(o, expid)
     1891        # Let users touch the state
     1892        self.auth.set_attribute(fid, expid)
     1893        self.auth.set_attribute(expid, expid)
     1894        # Override fedids can manipulate state as well
     1895        for o in self.overrides:
     1896            self.auth.set_attribute(o, expid)
     1897        self.auth.save()
    18591898
    18601899        # Create a logger that logs to the experiment's state object as well as
Note: See TracChangeset for help on using the changeset viewer.