* fix: [OCISDEV-1523] fix the LDAP master-ID filter for an empty base filter EnhanceFilterWithMasterID replaced an empty LDAP filter with a master-ID-only filter. This action restricted an unrestricted search to master-ID users only. The bug broke the cross-instance user search in multi-instance deployments. The function now keeps an empty filter unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix: [OCISDEV-1523] require an explicit LDAP user filter with a master ID EnhanceFilterWithMasterID in ocis-pkg/ldap/filter.go now keeps an empty LDAP filter unchanged instead of restricting it to master-ID users only. The auth-basic, users, groups, and graph services reuse this function to compute their default LDAP user filter at startup. An unset filter now means these services resolve or authenticate every user in the shared LDAP directory, not only master-ID users. This action is a behavior change for a deployment that sets OCIS_MULTI_INSTANCE_MASTER_ID without an explicit OCIS_LDAP_USER_FILTER. Each service now rejects startup when OCIS_MULTI_INSTANCE_MASTER_ID is set and its own user filter is empty. This action keeps a multi-instance deployment scoped to its own users by default. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * refactor: [OCISDEV-1523] simplify EnhanceFilterWithMasterID guard clauses The function collapses three early-return guards into one condition. This action removes a duplicated rationale comment between filter.go and filter_test.go. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * docs: [OCISDEV-1523] point the changelog entry at the master backport PR The changelog entry pointed at PR 13096, the stable-8.2 backport. This commit points the entry at the master-branch PR number instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package ldap
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/go-ldap/ldap/v3"
|
|
)
|
|
|
|
// EnhanceFilterWithMasterID adds master-ID match clauses to the given LDAP filter with OR.
|
|
// An empty filter means "no restriction". Do not OR an empty filter with a master-ID clause.
|
|
// This action would restrict an unrestricted search to the master ID only.
|
|
// The function returns the filter without a change when masterID is empty, when both
|
|
// attributes are empty, or when filter is empty.
|
|
func EnhanceFilterWithMasterID(filter, masterID, memberAttr, guestAttr string) string {
|
|
if masterID == "" || (memberAttr == "" && guestAttr == "") || filter == "" {
|
|
return filter
|
|
}
|
|
|
|
var masterIDParts []string
|
|
if memberAttr != "" {
|
|
masterIDParts = append(masterIDParts,
|
|
fmt.Sprintf("(%s=%s)", memberAttr, ldap.EscapeFilter(masterID)))
|
|
}
|
|
if guestAttr != "" {
|
|
masterIDParts = append(masterIDParts,
|
|
fmt.Sprintf("(%s=%s)", guestAttr, ldap.EscapeFilter(masterID)))
|
|
}
|
|
|
|
var masterIDFilter string
|
|
if len(masterIDParts) == 1 {
|
|
masterIDFilter = masterIDParts[0]
|
|
} else if len(masterIDParts) > 1 {
|
|
masterIDFilter = fmt.Sprintf("(|%s)", strings.Join(masterIDParts, ""))
|
|
}
|
|
|
|
return fmt.Sprintf("(|%s%s)", filter, masterIDFilter)
|
|
}
|