8 """Send errors to default auth log"""
9 syslog.openlog(facility=syslog.LOG_AUTH)
11 syslog.syslog("libpam python Logged: " + msg)
15 def check_arvados_token(requested_username, token):
16 auth_log("%s %s" % (requested_username, token))
19 f=file('/etc/default/arvados_pam')
20 config=dict([l.split('=') for l in f.readlines() if not l.startswith('#') or l.strip()==""])
21 arvados_api_host=config['ARVADOS_API_HOST'].strip()
22 hostname=config['HOSTNAME'].strip()
23 except Exception as e:
24 auth_log("problem getting default values %s" % e)
28 arv = arvados.api('v1',host=arvados_api_host, token=token, cache=None)
29 except Exception as e:
34 matches = arv.virtual_machines().list(filters=[['hostname','=',hostname]]).execute()['items']
35 except Exception as e:
41 auth_log("libpam_arvados could not determine vm uuid for '%s'" % hostname)
44 this_vm_uuid = matches[0]['uuid']
45 auth_log("this_vm_uuid: %s" % this_vm_uuid)
46 client_user_uuid = arv.users().current().execute()['uuid']
49 ['link_class','=','permission'],
50 ['name','=','can_login'],
51 ['head_uuid','=',this_vm_uuid],
52 ['tail_uuid','=',client_user_uuid]]
54 for l in arv.links().list(filters=filters).execute()['items']:
55 if requested_username == l['properties']['username']:
60 def pam_sm_authenticate(pamh, flags, argv):
62 user = pamh.get_user()
63 except pamh.exception, e:
67 return pamh.PAM_USER_UNKNOWN
70 resp = pamh.conversation(pamh.Message(pamh.PAM_PROMPT_ECHO_OFF, ''))
71 except pamh.exception, e:
75 check = check_arvados_token(user, resp.resp)
76 except Exception as e:
81 auth_log("Auth failed Remote Host: %s (%s:%s)" % (pamh.rhost, user, resp.resp))
82 return pamh.PAM_AUTH_ERR
84 auth_log("Success! Remote Host: %s (%s:%s)" % (pamh.rhost, user, resp.resp))
85 return pamh.PAM_SUCCESS
87 def pam_sm_setcred(pamh, flags, argv):
88 return pamh.PAM_SUCCESS
90 def pam_sm_acct_mgmt(pamh, flags, argv):
91 return pamh.PAM_SUCCESS
93 def pam_sm_open_session(pamh, flags, argv):
94 return pamh.PAM_SUCCESS
96 def pam_sm_close_session(pamh, flags, argv):
97 return pamh.PAM_SUCCESS
99 def pam_sm_chauthtok(pamh, flags, argv):
100 return pamh.PAM_SUCCESS