[19cc408] | 1 | #!/usr/local/bin/python |
---|
| 2 | |
---|
[e2ff75d] | 3 | import sys |
---|
| 4 | |
---|
[3c6dbec] | 5 | import emulab_access |
---|
[23dec62] | 6 | import dragon_access |
---|
[9c2e4e1] | 7 | import protogeni_access |
---|
[175b444] | 8 | import deter_internal_access |
---|
[7888aee] | 9 | import skeleton_access |
---|
[175b444] | 10 | |
---|
[ec4fb42] | 11 | from experiment_control import experiment_control_local |
---|
[5f6929a] | 12 | from ns2topdl import ns2topdl_local |
---|
[05191a6] | 13 | from util import read_simple_accessdb |
---|
[73ded03] | 14 | from fedid import fedid |
---|
[19cc408] | 15 | |
---|
[73ded03] | 16 | from authorizer import authorizer, abac_authorizer |
---|
[3f6bc5f] | 17 | |
---|
[7454054] | 18 | class deter_impl: |
---|
[19cc408] | 19 | """ |
---|
| 20 | The implementation of access control based on mapping users to projects. |
---|
| 21 | |
---|
| 22 | Users can be mapped to existing projects or have projects created |
---|
| 23 | dynamically. This implements both direct requests and proxies. |
---|
| 24 | """ |
---|
| 25 | # Used by the SOAP caller |
---|
[e77c86e] | 26 | soap_namespaces = ('http://www.isi.edu/fedd.wsdl', |
---|
| 27 | 'http://www.isi.edu/fedd_internal.wsdl') |
---|
[19cc408] | 28 | |
---|
[72ed6e4] | 29 | def __init__(self, config=None): |
---|
[19cc408] | 30 | """ |
---|
[ec4fb42] | 31 | Initializer. Uses the parsed configuration to create appropriate |
---|
| 32 | components. |
---|
[19cc408] | 33 | """ |
---|
[72ed6e4] | 34 | self.soap_services = { } |
---|
| 35 | self.xmlrpc_services = { } |
---|
[73ded03] | 36 | self.auth = None |
---|
[72ed6e4] | 37 | |
---|
| 38 | if config: |
---|
| 39 | self.cert_file = config.get("globals", "cert_file"); |
---|
| 40 | self.cert_pwd = config.get("globals", "cert_pwd"); |
---|
| 41 | self.trusted_certs = config.get("globals", "trusted_certs"); |
---|
[3c6dbec] | 42 | self.access_type = config.get("globals", "access_type", "emulab") |
---|
[73ded03] | 43 | self.auth_type = config.get("globals", "auth_type", "legacy") |
---|
| 44 | |
---|
[e2ff75d] | 45 | for mp in config.get("globals", "module_path","").split(":"): |
---|
| 46 | sys.path.append(mp) |
---|
| 47 | |
---|
[73ded03] | 48 | if self.auth_type == 'legacy': |
---|
| 49 | self.auth = authorizer() |
---|
| 50 | elif self.auth_type == 'abac': |
---|
| 51 | auth_url = config.get('globals', 'auth_url') |
---|
| 52 | if not auth_url: |
---|
| 53 | raise RuntimeError("auth_url required for ABAC " + \ |
---|
| 54 | "authorization") |
---|
| 55 | if self.cert_file: |
---|
| 56 | me = fedid(file=self.cert_file) |
---|
| 57 | else: |
---|
| 58 | raise RuntimeError("ABAC authorization needs a " +\ |
---|
| 59 | "certificate file") |
---|
| 60 | self.auth= abac_authorizer(url=auth_url, |
---|
| 61 | cert_file=self.cert_file, cert_pwd=self.cert_pwd, |
---|
| 62 | trusted_certs=self.trusted_certs, me=me) |
---|
| 63 | else: |
---|
| 64 | raise RuntimeError("Unknown authorizer type %s" % \ |
---|
| 65 | self.auth_type) |
---|
[72ed6e4] | 66 | |
---|
[05191a6] | 67 | access_db = config.get("globals", "accessdb") |
---|
| 68 | |
---|
| 69 | if access_db: |
---|
| 70 | try: |
---|
| 71 | read_simple_accessdb(access_db, self.auth) |
---|
[d3c8759] | 72 | except EnvironmentError, e: |
---|
[0b4e272] | 73 | raise RuntimeError( |
---|
[05191a6] | 74 | "Error reading accessDB %s: %s" % (access_db, e)) |
---|
[cc8d8e9] | 75 | except ValueError, e: |
---|
[0b4e272] | 76 | raise RuntimeError("%s" % e) |
---|
[05191a6] | 77 | |
---|
[72ed6e4] | 78 | if config.has_section("access"): |
---|
[3c6dbec] | 79 | if self.access_type == "emulab": |
---|
| 80 | self.access = emulab_access.access(config, self.auth) |
---|
[23dec62] | 81 | elif self.access_type == "dragon": |
---|
| 82 | self.access = dragon_access.access(config, self.auth) |
---|
[9c2e4e1] | 83 | elif self.access_type == "protogeni": |
---|
| 84 | self.access = protogeni_access.access(config, self.auth) |
---|
[175b444] | 85 | elif self.access_type == "deter_internal": |
---|
| 86 | self.access = deter_internal_access.access(config, |
---|
| 87 | self.auth) |
---|
[7888aee] | 88 | elif self.access_type == "skel": |
---|
| 89 | self.access = skeleton_access.access(config, self.auth) |
---|
[3c6dbec] | 90 | else: |
---|
[e2ff75d] | 91 | try: |
---|
| 92 | exec 'from %s import access as plugin_access' \ |
---|
| 93 | % self.access_type |
---|
| 94 | self.access = plugin_access(config, self.auth) |
---|
| 95 | except ImportError, e: |
---|
| 96 | raise RuntimeError( |
---|
| 97 | "Unknown access_type: %s (import failed: %s)" \ |
---|
| 98 | % (self.access_type, e)) |
---|
[72ed6e4] | 99 | self.soap_services.update(self.access.soap_services) |
---|
| 100 | self.xmlrpc_services.update(self.access.xmlrpc_services) |
---|
[09b4dc4] | 101 | else: |
---|
| 102 | self.access = None |
---|
[72ed6e4] | 103 | |
---|
| 104 | if config.has_section("experiment_control"): |
---|
[3f6bc5f] | 105 | self.experiment = \ |
---|
[ec4fb42] | 106 | experiment_control_local(config, self.auth) |
---|
[5fffd82] | 107 | # Tell the experiment control where local access control is and |
---|
[5a6b75b] | 108 | # what testbeds it pertains to. |
---|
[c9318dc] | 109 | if getattr(self, 'access', None): |
---|
[5a6b75b] | 110 | for t in self.access.testbed: |
---|
| 111 | self.experiment.local_access[t] = self.access |
---|
[5fffd82] | 112 | |
---|
[72ed6e4] | 113 | self.soap_services.update(self.experiment.soap_services) |
---|
| 114 | self.xmlrpc_services.update(self.experiment.xmlrpc_services) |
---|
[81a7f3f] | 115 | self.get_handler = self.experiment.get_handler |
---|
| 116 | else: |
---|
[39ee3cc] | 117 | if self.access and getattr(self.access, 'get_handler', None): |
---|
[dac2316] | 118 | self.get_handler = self.access.get_handler |
---|
| 119 | else: |
---|
| 120 | self.get_handler = None |
---|
[72ed6e4] | 121 | |
---|
[5f6929a] | 122 | if config.has_section("ns2topdl"): |
---|
| 123 | self.ns2topdl = ns2topdl_local(config, self.auth) |
---|
| 124 | self.soap_services.update(self.ns2topdl.soap_services) |
---|
| 125 | self.xmlrpc_services.update(self.ns2topdl.xmlrpc_services) |
---|
[f4f4117] | 126 | |
---|
[72ed6e4] | 127 | def new_feddservice(config): |
---|
[7454054] | 128 | return deter_impl(config) |
---|