#47639 Possible to have duplicate values of attribute monitored by Attribute Uniqueness plugin
Closed: wontfix Opened by nkinder.

Ticket was cloned from Red Hat Bugzilla (product Red Hat Enterprise Linux 7): Bug 1035840

Description of problem:
Attribute uniqueness plugin monitors specified attributes and ensures, that
newly added entries have unique values for the monitored attributes. One
example is attribute uid - if user tries to add new entry with uid equal to uid
of already existing entry, the addition operation is refused by DS.
It is possible to configure Attribute Uniqueness plugin and still add entry
with duplicate attribute. Below are steps for case  when 'sn' attribute is
being monitored.
Version-Release number of selected component (if applicable):
389-ds-base-1.2.11.15-29.el6.x86_64  (RHEL64)
389-ds-base-1.3.1.6-8.el7.x86_64 (RHEL7)
How reproducible:
always
Steps to Reproduce:
1. Delete sn index:
ldapdelete -h $HOST -p $PORT -D "cn=directory manager" -w Secret123
"cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"
2. Configure attribute uniqueness on sn attribute:
ldapmodify -h $HOST -p $PORT -D "cn=directory manager" -w Secret123 -a <<EOF
dn: cn=attribute uniqueness,cn=plugins,cn=config
changetype: modify
replace: nsslapd-pluginEnabled
nsslapd-pluginEnabled: on
-
replace: nsslapd-pluginarg0
nsslapd-pluginarg0: sn
-
replace: nsslapd-pluginarg1
nsslapd-pluginarg1: dc=example,dc=com
EOF
3. Add user:
ldapmodify -h $HOST -p $PORT -D "cn=directory manager" -w Secret123 -a <<EOF
dn: cn=tuser1,ou=people,dc=example,dc=com
objectclass: person
objectclass: top
sn: tuser1
cn: tuser1
EOF
4. Restart server
5. Add user with value 'sn' equal to value of sn of cn=tuser1:
ldapmodify -h $HOST -p $PORT -D "cn=directory manager" -w Secret123 -a <<EOF
dn: cn=tuser2,ou=people,dc=example,dc=com
objectclass: person
objectclass: top
sn: tuser1
cn: tuser2
EOF
Actual results:
ldapsearch -LLL -h $HOST -p $PORT -D "cn=directory manager" -w Secret123 -b
"cn=tuser1,ou=people,dc=example,dc=com" sn
dn: cn=tuser1,ou=People,dc=example,dc=com
sn: tuser1
ldapsearch -LLL -h $HOST -p $PORT -D "cn=directory manager" -w Secret123 -b
"cn=tuser2,ou=people,dc=example,dc=com" sn
dn: cn=tuser2,ou=People,dc=example,dc=com
sn: tuser1
ldapsearch -LLL -h $HOST -p $PORT -D "cn=directory manager" -w Secret123 -b
"cn=attribute uniqueness,cn=plugins,cn=config"
dn: cn=attribute uniqueness,cn=plugins,cn=config
objectClass: top
objectClass: nsSlapdPlugin
objectClass: extensibleObject
cn: attribute uniqueness
nsslapd-pluginPath: libattr-unique-plugin
nsslapd-pluginInitfunc: NSUniqueAttr_Init
nsslapd-pluginType: betxnpreoperation
nsslapd-pluginEnabled: on
nsslapd-pluginarg0: sn
nsslapd-pluginarg1: dc=example,dc=com
nsslapd-plugin-depends-on-type: database
nsslapd-pluginId: NSUniqueAttr
nsslapd-pluginVersion: 1.3.1.6
nsslapd-pluginVendor: 389 Project
nsslapd-pluginDescription: Enforce unique attribute values
Expected results:
Addition of cn=tuser2 should be refused by Attribute Uniqueness plugin.
Additional info:
When steps 3 and 4 are reversed, i.e. instance is first restarted, then user
cn=tuser1 added, then addition of cn=tuser2 is refused with:
adding new entry "cn=tuser2,ou=people,dc=example,dc=com"
ldap_add: Constraint violation (19)
        additional info: Another entry with the same attribute value already
exists (attribute: "sn")

The issue is that the index that is removed (sn) is a default index. So at the next restart that index is essentially recreated by the backend. So when the next add takes place there is an "sn" index to use, but it's empty. The server uses this index to find any matching entries, but none are found because it's empty. This allows the duplicate "sn" valued entry to be added. Removing the default index configuration at the same time the backend index is deleted achieves the desired results.

Correct way to remove default index:

[1] ldapdelete -h $HOST -p $PORT -D "cn=directory manager" -w Secret123
"cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"

[2] ldapdelete -h $HOST -p $PORT -D "cn=directory manager" -w Secret123
"cn=sn,cn=default indexes,cn=config,cn=ldbm database,cn=plugins,cn=config"

This will not be fixed in the core server, instead a doc bug has been filed to document the correct way to remove an default user index.

https://bugzilla.redhat.com/show_bug.cgi?id=1108356

Metadata Update from @mreynolds:
- Issue assigned to mreynolds
- Issue set to the milestone: 1.3.3 backlog

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This issue has been cloned to Github and is available here:
- https://github.com/389ds/389-ds-base/issues/976

If you want to receive further updates on the issue, please navigate to the github issue
and click on subscribe button.

Thank you for understanding. We apologize for all inconvenience.

Metadata Update from @spichugi:
- Issue close_status updated to: wontfix (was: Invalid)

Metadata