Duo API目录Syn

2024-05-16 11:17:30 发布

您现在位置:Python中文网/ 问答频道 /正文

默认情况下,Duo-Sync每天运行一次,由于业务需要,需要每2小时运行一次。查看DUO API,有一个用于用户同步的命令:

python -m duo_client.client --ikey <> --skey <> --host api-<>.duosecurity.com --method POST --path /admin/v1/users username=<> /directorysync/<DIR SYNC>/syncuser

但是,我没有看到与Active Directory进行常规整体同步的API,因此为了解决这种问题,我希望从2FA组获得所有用户,并使用以下方法通过用户名通过循环进行同步:

import sys
import os
import duo_client
from ldap3 import Server, Connection, ALL, NTLM, ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES, AUTO_BIND_NO_TLS, SUBTREE
from ldap3.core.exceptions import LDAPCursorError

server_name = ''
domain_name = ''
user_name = ''
password = '!'

admin_api = duo_client.Admin(
    ikey= "",
    skey= "",
    host= "api-.duosecurity.com",)

format_string = '{:40}'
print(format_string.format('samaccountname'))

server = Server(server_name, get_info=ALL)
conn = Connection(server, user='{}\\{}'.format(domain_name, user_name), password=password, authentication=NTLM,
auto_bind=True)
conn.search('dc={},dc=int'.format(domain_name), '(&(objectCategory=user)(memberOf=CN=2FA,OU=,OU=,OU=,OU=,DC=,DC=int))',
attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES])

for e in sorted(conn.entries):
    print(e.samaccountname)
    os.system("python -m duo_client.client --ikey --skey --host api-.duosecurity.com --method POST --path /admin/v1/users username={}/directorysync//syncuser".format(e.samaccountname))"

上面的代码提供了一些有用的功能,但对于某些用户,它还将它们重新创建为以下内容:username/Dir/DIRAPI/usersync之类的用户id。如下图所示Duo APISyncing User


Tags: 用户nameimportclientapiformatserverou
1条回答
网友
1楼 · 发布于 2024-05-16 11:17:30

似乎用户名={}错了

下面是创建一个新用户,因此我看到username/…/。。。。你知道吗

Post/admin/v1/username={}

下面是使用API调用的正确方法。你知道吗

os.system("python -m duo_client.client  ikey  skey  host api-.duosecurity.com  method POST  path /admin/v1/users/directorysync/syncuser username={}".format(e.samaccountname))"

相关问题 更多 >