• FreeIPA ACI (Access Control Instructions) 访问控制说明


    FreeIPA ACI (Access Control Instructions) 访问控制说明

    一、ACI 位置

    Directory Server 将ACI存储在目录条目的多值属性中。设置ACI时,将aci添加到响应的目录条目。

    • 如果条目没有任何子条目,则ACI只应用于本条目
    • 如果有子条目,则会从最外层开始验证
    • Root DSE 条目的ACI只应用于该条目本身

    二、ACI 结构

    ACI属性使用以下语法:

    (target_rule) (version 3.0; acl "ACL_name"; permission_rule bind_rules;)
    
    • target_rule: 指定要设置访问控制的条目、属性或条目集、属性集。
    • version 3.0: 标识ACI版本的必须字段。
    • permission_rule: 定义权限。
    • bind_rules: 指定ACI的绑定规则

    三、ACI 局限性

    1. 如果LDAP分布在多台服务器上。
    • 使用groupdn关键字的组条目的ACI必须与组条目位于同一服务器上,同时动态组成员也必须在同一个服务器上,静态组成员可以位于远程服务器上。
    • 使用roledn关键字的ACI必须和角色定义条目在同一服务器上。
    1. 不能使用虚拟属性(例如CoS)在以下的字段属性中:
    • targetfilter
    • targetattrfilters
    • userattr
    1. 访问控制规则仅限于当前主机,如果在ACI关键字中指定的LDAP URLs不是本机地址,则URL将被忽略。

    四、复制拓扑中的ACI

    ACI存放在条目的aci属性中。如果包含ACI的条目是复制数据库的一部分,则ACI也会复制。

    五、操作ACI

    1. 查看ACI

    ldapsearch -D "cn=Directory Manager" -W -p 389 -h server.example.com -x 
         -b "dc=example,dc=com" -s sub '(aci=*)' aci
    

    2. 添加ACI

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=People,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr="userPassword") (version 3.0; acl "Allow users updating their password";
     allow (write) userdn= "ldap:///self";)
    

    3. 删除ACI

    // 删除所有aci
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=People,dc=example,dc=com
    changetype: delete
    delete: aci
    
    // 删除指定aci
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=People,dc=example,dc=com
    changetype: modify
    delete: aci
    aci: (targetattr="userPassword") (version 3.0; acl "Allow users
     updating their password"; allow (write) userdn= "ldap:///self";)
    

    六、定义目标(targets)

    如果没有定义目标,则ACI应用于当前条目及其子条目。

    在一个ACI中,以下加粗部分为目标规则:
    (target_rule)(version 3.0; acl "ACL_name"; permission_rule bind_rules;)

    1. Target 语法

    (keyword comparison_operator "expression")
    
    • keyword: 关键字,targettargetattrtargetfiltertargetattrfilters
    • comparison_operator: 有效值为==!=,表明目标是否是表达式指定的对象,不推荐使用!=
    • expression: 设置目标,必须用双引号引起来。表达式本身取决于使用的关键字。

    2. Target 关键字

    2.1 target

    基于DN以及子条目的访问控制,使用target关键字。使用target关键字的目标表达式:

    (target comparison_operator "ldap:///distinguished_name")
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=People,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (target = "ldap:///ou=People,dc=example,dc=com") (version 3.0;
     acl "Allow users to read and search attributes of own entry"; allow (search, read)
     (userdn = "userdn = "ldap:///self");)
    

    支持通配符,但是不支持DN后缀部分的通配符。

    # 支持
    (target = "ldap:///uid=user_name*,dc=example,dc=com")
    
    # 不支持
    (target = "ldap:///dc=*.com")
    

    2.2 targetattr

    访问条目的某些属性值。

    • read:返回给客户端的属性值。
    • search:可以被搜索的属性值。
    • write:条目中可以被修改的属性值。
    • add:创建新条目时,可以被添加的属性。

    可以使用||拼接多个属性。如下:

    (targetattr comparison_operator "attribute_1 || attribute_2 || ...")
    

    支持通配符*,基于安全考虑,在write权限上不允许使用通配符。

    2.3 targetfilter

    使用标准LDAP过滤器定位条目、属性。表达式:

    (targetfilter comparison_operator "LDAP_filter")
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetfilter = "(|(department=Engineering)(department=Sales)")
     (version 3.0; acl "Allow HR updating engineering and sales entries";
     allow (write) (groupdn = "ldap:///cn=Human Resources,dc=example,dc.com");)
    

    2.4 targetattrfilters

    通过目标的属性值来设置权限,基于属性值的ACI称为基于值(value-based)的ACI。

    # 对于具有一个属性和过滤器组合的授权
    (targetattrfilters="operation=attribute:filter")
    
    # 多个属性值和过滤器组合的授权
    (targetattrfilters="operation=attribute_1:filter_1 && attribute_2:filter_2 ... && attribute_m:filter_m")
    
    # 多个属性值和过滤器组合的多个授权
    (targetattrfilters="operation_1=attribute_1_1:filter_1_1 && attribute_1_2:filter_1_2 ... && attribute_1_m:filter_1_m , operation_2=attribute_2_1:filter_2_1 && attribute_2_2:filter_2_2 ... & attribute_2_n:filter_2_n ")
    

    operation可以设置为adddelattribute:filter为属性值和LDAP过滤器。
    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattrfilters="add=nsroledn:(!(nsroledn=cn=Admin)) &&
     telephoneNumber:(telephoneNumber=123*)") (version 3.0;
     acl "Allow adding roles and telephone";
     allow (add) (userdn = "ldap:///self");)
    

    2.5 target_from & target_to

    允许移动条目。
    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (target_from="ldap:///uid=*,cn=staging,dc=example,dc=com")
     (target_to="ldap:///cn=People,dc=example,dc=com")
     (version 3.0; acl "MODDN from"; allow (moddn))
     userdn="ldap:///uid=user,dc=example,dc=com";)
    

    3. 目标规则的高级用法

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (target = "ldap:///cn=*,ou=Groups,dc=example,dc=com")
     targetfilter="(&(objectClass=top)(objectClass=groupOfUniqueNames))")
     (targetattr="cn || uniqueMember || objectClass")
     (version 3.0; acl "example"; allow (read, search, write, add)
     (userdn = "ldap:///uid=test,ou=People,dc=example,dc=com");)
     
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (target="ldap:///cn=*,dc=example,dc=com")(targetattr="member" || "cn") (version 3.0;
     acl "Allow uid=user to search and read members of groups";
     allow (read, search) (userdn = "ldap:///uid=user,ou=People,dc=example,dc.com");)
     
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr = "jpegPhoto|| manager")
     (targetfilter = "(department=Engineering)") (version 3.0;
     acl "Allow engineering admins updating jpegPhoto and manager of department members";
     allow (write) (groupdn = "ldap:///cn=Engineering Admins,dc=example,dc.com");)
     
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=Engineering,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr = "ou || cn")
     (targetfilter = "(ou=Engineering)") (version 3.0;
     acl "Allow uid=user to search and read engineering attributes";
     allow (read, search) (userdn = "ldap:///uid=user,ou=People,dc=example,dc.com");)
    

    七、 定义权限

    权限规则指的是ACI关联的权限是允许或拒绝。

    在一个ACI中,以下加粗部分为权限规则:
    (target_rule) (version 3.0; acl "ACL_name";permission_rulebind_rules;)

    权限规则语法:
    permission (rights)

    • permission:设置允许(allow)还是拒绝(deny)
    • rights: 权限字段。

    1. 用户权限

    权限 描述
    read 设置用户是否可以读取目录,仅适用于LDAP的搜索操作。
    write 设置用户是否可以通过添加、修改和删除属性来修改条目。仅适用于LDAP中的modifymodrdn
    add 设置用户是否可以添加条目,仅适用于LDAP中的add操作
    delete 设置用户是否可以删除条目,仅适用于LDAP中的delete删除操作。
    search 设置用户是否可以搜索目录数据。查看作为搜索结果的一部分返回,则分配searchread权限。仅适用于LDAP中的搜索操作。
    compare 设置用户是否可以将其提供的数据与存储在目录中的数据进行比较,使用比较权限,目录返回成功或失败,但是无法看到用户条目或者属性的值。仅适用于LDAP中的比较操作。
    selfwrite 设置用户是否可以从组中添加或删除自己的DN,此权限仅限于组管理。
    proxy 设置指定的DN是否可以使用其他条目的权限访问目标。proxy权限在ACI授权范围内、用户或者租,可以像代理的用户、组一样执行命令。无法单独限制用户。
    all proxy之外的所有权限。

    2. LDAP操作所需权限

    针对LDAP操作必须要授权的用户权限类型。

    • 添加条目
      • add 添加条目
      • write 授予条目中的每个属性值的写入权限,默认情况下授予此权限,可以通过关键字targetattrfilters来授权指定的属性。
    • 删除条目
      • delete 允许删除条目
      • write 授予条目中的每个属性值的写入权限,默认情况下授予此权限,可以通过关键字targetattrfilters来授权指定的属性。
    • 更改条目属性
      • write 授予条目中的每个属性值的写入权限,默认情况下授予此权限,可以通过关键字targetattrfilters来授权指定的属性。
    • 搜索条目
      • search 在搜索过滤器中使用属性类型授予搜索权限
      • read 对条目中属性的读取权限。

    八、 绑定规则

    绑定规则定义必须满足绑定参数,以便LDAP应用ACI,绑定规则可以基于:DNs组成员或角色条目的具体位置绑定期间的身份验证类型绑定的时间和天数

    在一个ACI中,以下加粗部分为绑定规则:
    (target_rule) (version 3.0; acl "ACL_name"; permission_rulebind_rules;)

    绑定语法:
    keyword comparison_operator "expression"

    • keyword:设置绑定操作的类型。
    • comparison_operator: 比较运算符。==!=
    • expression: 设置表达式,必须用引号引起来,表达式本身取决于使用的关键字。

    1. 常用绑定规则

    1.1 userdn

    userdn关键字允许根据一个或多个DN设置权限。

    userdn comparison_operator "ldap:///distinguished_name || ldap:///distinguished_name || ..."
    

    表达式的值:

    • DN,支持*通配符。
    • LDAP过滤器
    • anyone 匿名访问,配置为ldap:///anyone
    • all 认证后即可访问,配置为ldap:///all
    • parent 当前绑定DN是目标条目的父级时的权限,配置为ldap:///parent

    1.2 groupdn

    基于组的ACI。使用groupdn关键字时,LDAP服务器将根据memberuniqueMembermemberURLmemberCertificateDescription属性验证组成员身份。

    groupdn comparison_operator "ldap:///distinguished_name || ldap:///distinguished_name || ..."
    

    表达式的值:

    • DN,组DN
    • LDAP 过滤器,经过身份验证的用户,必须是过滤器返回的至少一个组的成员。
      • 过滤器语法:groupdn comparison_operator "ldap:///distinguished_name??scope?(filter)"

    过滤器示例:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=People,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr="homePostalAddress") (version 3.0;
     acl "Allow manager=example setting homePostalAddress"; allow (write)
     userdn = "ldap:///dc=example,dc=com??sub?(manager=example)";)
    

    2. 不常用绑定规则

    2.1 基于值的定义访问(userattr)

    使用userattr关键字指定绑定条目与目标条目之间必须匹配的属性。

    userattr关键字使用语法:

    userattr comparison_operator "attribute_name#bind_type_or_attribute_value
    
    1) USERDN 绑定类型

    要在绑定用户DN与属性中存储的DN匹配时应用ACI。userattr关键字与USERDN绑定类型的语法:

    userattr comparison_operator "attribute_name#USERDN"
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=People,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr = "telephoneNumber")
     (version 3.0; acl "Manager: telephoneNumber";
     allow (all) userattr = "manager#USERDN";)
    
    2) GROUPDN 绑定类型

    要在绑定用户DN是属性中设置的组的成员时应用ACI。userattr关键字与GROUPDN绑定类型的语法:

    userattr comparison_operator "attribute_name#GROUPDN"
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=Social Committee,ou=Groups,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (target="ou=Social Committee,ou=Groups,dc=example,dc=com)
     (targetattrfilters="del=objectClass:(objectClass=groupOfNames)")
     (version 3.0; acl "Delete Group";
     allow (delete) userattr = "owner#GROUPDN";)
    

    如果使用静态组,并且和目标条目有相同的后缀,可以使用以下语法提高性能:

    userattr comparison_operator "ldap:///distinguished_name?attribute_name#GROUPDN"
    
    3) SELFDN 绑定类型

    当绑定用户的DN在目标条目的单值属性中时,SELFDN绑定类型允许授予权限。userattr关键字与SELFDN绑定类型的语法:

    userattr comparison_operator "attribute_name#SELFDN"
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=otp,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (target = "ldap:///ipatokenuniqueid=*,cn=otp,dc=example,dc=com")
     (targetfilter = "(objectClass=ipaToken)")(version 3.0;
     acl "token-add-delete"; allow (add) userattr = "ipatokenOwner#SELFDN";)
    
    4) LDAPURL 绑定类型

    绑定DN与目标条目属性中指定的过滤器匹配时,使用LDAPURL绑定类型。userattr关键字与LDAPURL绑定类型的语法:

    userattr comparison_operator "attribute_name#LDAPURL"
    

    Example:

    # ou=People,dc=example,dc=com条目的aciurl属性值为:ldap:///ou=People,dc=example,dc=com??one?(uid=user*)
    
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: ou=People,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr = "*")
     (version 3.0; acl "Allow read,search "; allow (read,search)
     (userattr = "aciurl#LDAPURL);)
    
    5) 绑定用户与目标条目具有相同属性值
    userattr comparison_operator "attribute_name#value"
    
    6) userattr 继承

    可以通过parent关键字并制定继承ACI目标的级数来实现。语法:

    userattr comparison_operator "parent[inheritance_level].attribute_name#bind_type_or_attribute_value
    
    • inheritance_level: 以逗号分隔的列表,表示目标条目下继承的级别,可以为(0,1,2,3,4)五个级别,0表示目标条目。
    • attribute_name:属性值
    • bind_type_or_attribute_value:设置属性值或者绑定类型
      Example:
    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: cn=Profiles,dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr="*") (version 3.0; acl "Profile access",
     allow (read,search) userattr="parent[0,1].owner#USERDN" ;)
    
    7) 指定特定IP地址或网段(ip)

    ip关键字可以设置特定IP地址或网段的访问权限。语法:

    ip comparison_operator "IP_address_or_range"
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr = "*") (version 3.0;acl "Deny 192.168.0.2/24"; deny (all)
     (userdn = "ldap:///anyone") and (ip != "192.0.2.");)
    
    8) 指定特定主机或域(dns)

    dns关键字设置特定主机或域的访问权限。语法:

    dns comparison_operator "host_name_or_domain_name"
    

    Example:

    ldapmodify -D "cn=Directory Manager" -W -p 389 -h server.example.com -x
    dn: dc=example,dc=com
    changetype: modify
    add: aci
    aci: (targetattr = "*") (version 3.0;acl "Deny example.com"; deny (all)
     (userdn = "ldap:///anyone") and (dns != "*.example.com");)
    

    参考链接

  • 相关阅读:
    UVA 712 STrees
    SGU 109 Magic of David Copperfield II
    SGU 108 Selfnumbers 2
    Go编程语言规范3表达式
    Go编程语言规范1 块,声明与作用域
    golang安装和部署
    Go编程语言规范2类型
    call web services from iPhone
    maximo 支援
    C#動態調用webservice  不加web引用
  • 原文地址:https://www.cnblogs.com/Orgliny/p/9565335.html
Copyright © 2020-2023  润新知