|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
|
|
3
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
4
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
5
|
|
|
# this work for additional information regarding copyright ownership. |
|
6
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
8
|
|
|
# the License. You may obtain a copy of the License at |
|
9
|
|
|
# |
|
10
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
# |
|
12
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
# See the License for the specific language governing permissions and |
|
16
|
|
|
# limitations under the License. |
|
17
|
|
|
|
|
18
|
|
|
from st2actions.runners.pythonrunner import Action |
|
19
|
|
|
import duo_client |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
class Auth(Action): |
|
23
|
|
|
def run(self, username, factor, ipaddr, async, device, |
|
24
|
|
|
push_type, passcode, push_info): |
|
25
|
|
|
""" |
|
26
|
|
|
Auth against the Duo Platorm. |
|
27
|
|
|
|
|
28
|
|
|
Returns: An dict with info returned by Duo. |
|
29
|
|
|
|
|
30
|
|
|
Raises: |
|
31
|
|
|
ValueError: On Auth Failure. |
|
32
|
|
|
""" |
|
33
|
|
|
|
|
34
|
|
|
try: |
|
35
|
|
|
ikey = self.config['ikey'] |
|
36
|
|
|
skey = self.config['skey'] |
|
37
|
|
|
host = self.config['host'] |
|
38
|
|
|
except KeyError: |
|
39
|
|
|
raise ValueError("Duo config not found in config.") |
|
40
|
|
|
|
|
41
|
|
|
auth = duo_client.Auth(ikey=ikey, |
|
42
|
|
|
skey=skey, |
|
43
|
|
|
host=host) |
|
44
|
|
|
|
|
45
|
|
|
try: |
|
46
|
|
|
data = auth.auth(factor=factor, |
|
47
|
|
|
username=username, |
|
48
|
|
|
type=push_type, |
|
49
|
|
|
device=device) |
|
50
|
|
|
except: |
|
51
|
|
|
raise ValueError("Duo Auth request failed!") |
|
52
|
|
|
else: |
|
53
|
|
|
if data['status'] == "allow": |
|
54
|
|
|
return data |
|
55
|
|
|
elif data['status'] == "deny": |
|
56
|
|
|
print data['status_msg'] |
|
57
|
|
|
raise ValueError("Duo login denied! {}".format( |
|
58
|
|
|
data['status_msg'])) |
|
59
|
|
|
else: |
|
60
|
|
|
raise ValueError("Invalid status") |
|
61
|
|
|
|