-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] ldap用户同步的code目前使用的是full_name #714
Comments
注意: 不能直接修复, 因为存量环境是通过code确定唯一的! 如果修复成sha256字符串, 会导致存量环境再次同步出现双份数据 |
如果没有找到方式可以兼容存量环境以及新装环境, 就不要动现有的逻辑 |
plugins/ldap/syncer.py def fetch_departments(self, restrict_types: List[str]):
"""获取 department 对象列表"""
groups, departments, _ = self._load()
results = []
for is_group, dept_meta in chain.from_iterable(iter([product([False], departments), product([True], groups)])):
if not dept_meta.get("dn"):
logger.warning("no dn field, skipping for %s:%s", ("group" if is_group else "department"), dept_meta)
continue
results.append(
department_adapter(
code=self._get_code(dept_meta),
dept_meta=dept_meta,
is_group=is_group,
restrict_types=restrict_types,
)
)
return results plugins/ldap/adaptor.py def department_adapter(code: str, dept_meta: Dict, is_group: bool, restrict_types: List[str]) -> LdapDepartment:
dn = dept_meta["dn"]
dn_values = parse_dn_value_list(dn, restrict_types=restrict_types)
parent_dept: Optional[LdapDepartment] = None
for dept_name in reversed(dn_values):
parent_dept = LdapDepartment(
name=dept_name,
parent=parent_dept,
is_group=is_group,
)
assert parent_dept is not None, "未从 dn 中提取到任何部门信息"
parent_dept.code = code
return parent_dept 这里相当于递归存了一条链路
|
分析的问题已全部注释标出来了, 需要考虑如何处理 bk-user/src/api/bkuser_core/categories/plugins/ldap/helper.py Lines 70 to 127 in b7a58c5
1, 全部用code, 那么需要所有部门链路都带 最困难的问题: 升级后如何保证存量数据正确 |
department full_name超长例如一级部门就超过 64 个字符, 那么所有都写不进来, 被截断了 所以, 无论如何是应该要改成hash的, 并且按目录区分 |
先看下有没有什么兼容方案, 确保同类的问题不再出现 |
ldap metas.py
使用的code 去做 |
没想明白原来的 line 114是为什么这么处理的 |
bk-user/src/api/bkuser_core/categories/plugins/ldap/helper.py Lines 64 to 127 in b7a58c5
输入:
|
临时解决方案:
alter table departments_department modify `code` varchar(256) DEFAULT NULL |
需要决策: 尽早在某个版本把department的code改成varchar 256, 可以减少大量的用户咨询 |
https://github.com/TencentBlueKing/bk-user/blob/v2.3.4-beta.28/src/api/bkuser_core/categories/plugins/ldap/helper.py#L82
正常情况下, 不会有问题, 因为每个部门的full_name是唯一的
带来的问题: 部门入库后的字段code=full_name, 而code又是唯一的
但是
此时, code冲突, 同步失败
The text was updated successfully, but these errors were encountered: