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