Skip to content

Commit b44eeb4

Browse files
committed
fix: expand AD user name filter
1 parent 86e38df commit b44eeb4

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

rust/user-info-fetcher/src/backend/active_directory.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const LDAP_FIELD_OBJECT_DISTINGUISHED_NAME: &str = "dn";
8989
const LDAP_FIELD_USER_NAME: &str = "userPrincipalName";
9090
const LDAP_FIELD_USER_PRIMARY_GROUP_RID: &str = "primaryGroupID";
9191
const LDAP_FIELD_GROUP_MEMBER: &str = "member";
92+
const LDAP_FIELD_SAM_ACCOUNT_NAME: &str = "sAMAccountName";
9293

9394
#[tracing::instrument(skip(
9495
tls,
@@ -133,9 +134,7 @@ pub(crate) async fn get_user_info(
133134
)
134135
)
135136
}
136-
UserInfoRequest::UserInfoRequestByName(username) => {
137-
format!("{LDAP_FIELD_USER_NAME}={}", ldap_escape(&username.username))
138-
}
137+
UserInfoRequest::UserInfoRequestByName(username) => user_name_filter(&username.username),
139138
};
140139
let requested_user_attrs = [
141140
LDAP_FIELD_OBJECT_SECURITY_ID,
@@ -179,6 +178,16 @@ pub(crate) async fn get_user_info(
179178
.await
180179
}
181180

181+
/// Constructs a user filter that searches both the UPN as well as the sAMAccountName attributes.
182+
/// See this issue for details: https://github.com/stackabletech/opa-operator/issues/702
183+
fn user_name_filter(username: &str) -> String {
184+
let escaped_username = ldap_escape(username);
185+
let realm = "SBLE.TEST"; // TODO: Replace with actual realm
186+
format!(
187+
"(|({LDAP_FIELD_USER_NAME}={escaped_username}@{realm})({LDAP_FIELD_USER_NAME}={escaped_username})({LDAP_FIELD_SAM_ACCOUNT_NAME}={escaped_username}))"
188+
)
189+
}
190+
182191
#[tracing::instrument(
183192
skip(
184193
ldap,

0 commit comments

Comments
 (0)