Skip to content

Commit d046777

Browse files
author
U Cirello
authored
Merge pull request #4 from strongdm/development
bump python version
2 parents 9b2b924 + a30bf2b commit d046777

18 files changed

+1163
-1097
lines changed

dist/strongdm-1.0.0.tar.gz

-69.6 KB
Binary file not shown.

dist/strongdm-1.0.0.zip

-87.7 KB
Binary file not shown.

dist/strongdm-1.0.1.tar.gz

70.4 KB
Binary file not shown.

example/okta-sync/okta-sync.py

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2020 StrongDM Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
115
import yaml
216
import os
317
import strongdm
@@ -6,25 +20,32 @@
620
from okta.models.user.User import User
721
from okta.models.usergroup.UserGroup import UserGroup
822

23+
924
def load_matchers():
1025
f = open('matchers.yml')
11-
data = yaml.load(f, Loader = yaml.Loader)
26+
data = yaml.load(f, Loader=yaml.Loader)
1227
return data
1328

29+
1430
class OktaUser:
1531
def __init__(self, login, first_name, last_name, groups):
1632
self.login = login
1733
self.first_name = first_name
1834
self.last_name = last_name
1935
self.groups = groups
36+
2037
def __repr__(self):
21-
return "%s %s"%(self.login,self.groups)
38+
return "%s %s" % (self.login, self.groups)
39+
2240

2341
def load_okta_users():
2442
ret = []
25-
apiClient = ApiClient(pathname='/api/v1/users', base_url=os.getenv('OKTA_CLIENT_ORGURL'), api_token=os.getenv('OKTA_CLIENT_TOKEN'))
43+
apiClient = ApiClient(pathname='/api/v1/users',
44+
base_url=os.getenv('OKTA_CLIENT_ORGURL'),
45+
api_token=os.getenv('OKTA_CLIENT_TOKEN'))
2646
params = {
27-
'search': "profile.department eq \"Engineering\" and (status eq \"ACTIVE\")"
47+
'search':
48+
"profile.department eq \"Engineering\" and (status eq \"ACTIVE\")"
2849
}
2950
response = ApiClient.get_path(apiClient, '/', params=params)
3051
users = Utils.deserialize(response.text, User)
@@ -34,15 +55,18 @@ def load_okta_users():
3455
groups = []
3556
for ug in userGroups:
3657
groups.append(ug.profile.name)
37-
oktaUser = OktaUser(u.profile.login, u.profile.firstName, u.profile.lastName, groups)
58+
oktaUser = OktaUser(u.profile.login, u.profile.firstName,
59+
u.profile.lastName, groups)
3860
ret.append(oktaUser)
3961
return ret
4062

63+
4164
def main():
4265
try:
4366
okta_sync()
4467
except Exception as ex:
45-
print("okta sync failed:"+str(ex))
68+
print("okta sync failed:" + str(ex))
69+
4670

4771
def okta_sync():
4872
SDM_API_ACCESS_KEY = os.getenv('SDM_API_ACCESS_KEY')
@@ -52,23 +76,25 @@ def okta_sync():
5276

5377
if SDM_API_ACCESS_KEY is None or SDM_API_SECRET_KEY is None \
5478
or OKTA_CLIENT_TOKEN is None or OKTA_CLIENT_ORGURL is None:
55-
print("SDM_API_ACCESS_KEY, SDM_API_SECRET_KEY, OKTA_CLIENT_TOKEN, and OKTA_CLIENT_ORGURL must be set")
79+
print(
80+
"SDM_API_ACCESS_KEY, SDM_API_SECRET_KEY, OKTA_CLIENT_TOKEN, and OKTA_CLIENT_ORGURL must be set"
81+
)
5682
return
5783

5884
matchers = load_matchers()
5985
okta_users = load_okta_users()
6086

6187
client = strongdm.Client(SDM_API_ACCESS_KEY, SDM_API_SECRET_KEY)
6288

63-
accounts = {o.email:o.id for o in client.accounts.list("")}
89+
accounts = {o.email: o.id for o in client.accounts.list("")}
6490
permissions = [v for v in client.account_grants.list("")]
6591

6692
# define current state
6793
current = {}
6894
for p in permissions:
6995
if p.account_id not in current:
7096
current[p.account_id] = set()
71-
current[p.account_id].add((p.resource_id,p.id))
97+
current[p.account_id].add((p.resource_id, p.id))
7298

7399
# define desired state
74100
desired = {}
@@ -80,33 +106,35 @@ def okta_sync():
80106
if group["name"] in u.groups:
81107
if u.login not in accounts:
82108
continue
83-
overlapping+=1
109+
overlapping += 1
84110
aid = accounts[u.login]
85111
if aid not in desired:
86112
desired[aid] = set()
87113
desired[aid].add(res.id)
88114

89115
# revoke things
90116
revocations = 0
91-
for aid,curRes in current.items():
92-
desRes = desired.get(aid,set())
117+
for aid, curRes in current.items():
118+
desRes = desired.get(aid, set())
93119
for rid in curRes:
94120
if rid[0] not in desRes:
95-
revocations+=1
121+
revocations += 1
96122
client.account_grants.delete(rid[1])
97123

98124
# grant things
99125
grants = 0
100-
for aid,desRes in desired.items():
101-
curRes = current.get(aid,set())
126+
for aid, desRes in desired.items():
127+
curRes = current.get(aid, set())
102128
for rid in desRes:
103129
for cr in curRes:
104130
if rid != cr[0]:
105-
grants+=1
106-
client.account_grants.create(strongdm.AccountGrant(resource_id=rid, account_id=aid))
131+
grants += 1
132+
client.account_grants.create(
133+
strongdm.AccountGrant(resource_id=rid, account_id=aid))
107134

108135
print("{} Okta users, {} strongDM users, {} overlapping users, {} grants, {} revocations".format(\
109136
len(okta_users),len(accounts), overlapping, grants, revocations))
110137

138+
111139
if __name__ == '__main__':
112140
main()

example/panicButton.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121
import strongdm
2222

23+
2324
# panicButton.py suspends all users except for one admin,
2425
# in the fake use case of a critical break in or something
2526
# usage:
@@ -50,20 +51,28 @@ def main():
5051
client.accounts.update(user)
5152
for attachment in state['attachments']:
5253
try:
53-
client.account_attachments.create(strongdm.AccountAttachment(account_id=attachment["account_id"],role_id=attachment["role_id"]))
54+
client.account_attachments.create(
55+
strongdm.AccountAttachment(
56+
account_id=attachment["account_id"],
57+
role_id=attachment["role_id"]))
5458
except strongdm.errors.AlreadyExistsError:
5559
pass
5660
except Exception as ex:
57-
print("skipping creation of attachment due to error: ", str(ex))
61+
print("skipping creation of attachment due to error: ",
62+
str(ex))
5863
for grant in state['grants']:
5964
try:
60-
client.account_grants.create(strongdm.AccountGrant(account_id=grant["account_id"],resource_id=grant["resource_id"]))
65+
client.account_grants.create(
66+
strongdm.AccountGrant(
67+
account_id=grant["account_id"],
68+
resource_id=grant["resource_id"]))
6169
except strongdm.errors.AlreadyExistsError:
6270
pass
6371
except Exception as ex:
6472
print("skipping creation of grant due to error: ", str(ex))
6573
print("reinstated " + str(reinstated_count) + " users")
66-
print("recreated " + str(len(state['attachments'])) + " account attachments")
74+
print("recreated " + str(len(state['attachments'])) +
75+
" account attachments")
6776
print("recreated " + str(len(state['grants'])) + " account grants")
6877
return
6978

@@ -83,17 +92,24 @@ def main():
8392
account_grants = client.account_grants.list('')
8493

8594
state = {
86-
'attachments': [{"account_id":x.account_id,"role_id":x.role_id} for x in account_attachments if x.account_id != admin_user_id],
87-
'grants': [{"account_id":x.account_id,"resource_id":x.resource_id} for x in account_grants if x.account_id != admin_user_id and x.valid_until is None],
95+
'attachments': [{
96+
"account_id": x.account_id,
97+
"role_id": x.role_id
98+
} for x in account_attachments if x.account_id != admin_user_id],
99+
'grants': [{
100+
"account_id": x.account_id,
101+
"resource_id": x.resource_id
102+
} for x in account_grants
103+
if x.account_id != admin_user_id and x.valid_until is None],
88104
}
89105

90-
print("storing " + str(len(state['attachments'])) + " account attachments in state")
106+
print("storing " + str(len(state['attachments'])) +
107+
" account attachments in state")
91108
print("storing " + str(len(state['grants'])) + " account grants in state")
92109

93110
with open('state.json', 'w') as outfile:
94111
json.dump(state, outfile)
95112

96-
97113
suspended_count = 0
98114
users = client.accounts.list('')
99115
for user in users:
@@ -104,11 +120,11 @@ def main():
104120
client.accounts.update(user)
105121
suspended_count += 1
106122
except Exception as ex:
107-
print("skipping user " + user.id + " on account of error: " + str(ex))
108-
123+
print("skipping user " + user.id + " on account of error: " +
124+
str(ex))
109125

110126
print("suspended " + str(suspended_count) + " users ")
111127

112128

113129
if __name__ == "__main__":
114-
main()
130+
main()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
setup(
1717
name='strongdm',
1818
packages=['strongdm'],
19-
version='1.0.0',
19+
version='1.0.1',
2020
license='apache-2.0',
2121
description='strongDM SDK for the Python programming language.',
2222
author='strongDM Team',
2323
author_email='[email protected]',
2424
url='https://github.com/strongdm/strongdm-sdk-python',
25-
download_url='https://github.com/user/reponame/archive/v1.0.0.tar.gz',
25+
download_url='https://github.com/user/reponame/archive/v1.0.1.tar.gz',
2626
keywords=[
2727
'strongDM', 'sdm', 'api', 'automation', 'security', 'audit',
2828
'database', 'server', 'ssh', 'rdp'

0 commit comments

Comments
 (0)