【问题标题】:Force Azure DevOps Server 2019 to manually sync with ActiveDirectory强制 Azure DevOps Server 2019 与 ActiveDirectory 手动同步
【发布时间】:2020-06-18 11:24:10
【问题描述】:

我们有一个与企业 ActiveDirectory 配合使用的本地 Azure DevOps 服务器。添加新用户时,Azure DevOps Server 从 ActiveDirectory 中提取他们的信息。但后来在 ActiveDirectory 中更新了用户信息以解决一个问题 - 他们的电子邮件帐户丢失。

过去,我可以将用户删除并重新添加到 Azure DevOps Server 以解决问题,因为我的管理帐户具有访问权限并且可以在 ActiveDirectory 中查看用户的电子邮件。但是用户不再被 Azure DevOps Server 中的同步作业接收,因此他们的电子邮件地址仍然是空白的。 (用户已经添加了数周或数月而没有收到更新。)

我们已验证 Azure DevOps Server 服务帐户在登录服务器时可以看到 ActiveDirectory 中的电子邮件地址。所以这不是服务帐户的访问问题。

如何手动强制 Azure DevOps Server 运行 ActiveDirectory 同步?在以前的 TFS 版本中,曾经有一个 JobService 网络服务,我可以为此访问它,但该服务似乎不再可用,或者不再计划运行。

【问题讨论】:

  • 我仍在寻找解决此问题的方法。到目前为止,没有任何尝试过的工作。而且我们现在还有关于用户的其他部分,例如姓氏更改,也没有被拾取。

标签: azure-devops active-directory azure-devops-server-2019


【解决方案1】:

由于没有解决方案奏效,我决定从编码的角度看看可以做些什么。结果证明是直截了当的。 注意:请确保在编码方法之前检查下面提供的解决方案,因为 Azure DevOps Server 应该会自动刷新身份。

首先,我找到了一篇关于按名称查找用户的 Stack Overflow 文章:

TFS get user by name

这可用于使用 ReadIdentity 方法通过显示名称和其他属性来获取用户或组。

同样的 IIDentityServiceProvider 上还有一个名为 RefreshIdentity 的方法。当使用用户的 IdentityDescriptor 调用此方法时,会强制立即从其提供者刷新身份。请参阅此处的文档:

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/ff734945(v=vs.120)?redirectedfrom=MSDN

如果刷新成功,此方法返回 true,如果刷新失败,则返回 false。刷新也可能引发异常。例如,名为“Project Collection Build Service”的 Azure DevOps 标识在检索时被列为用户,但此标识在刷新时会引发异常。

使用这些方法,可以构建一个完整的工具来修复单个用户的身份,或者扫描“项目集合有效用户”组中的所有用户并刷新整个系统。使用此工具,我们能够修复 Azure DevOps Server 和 Active Directory 之间的同步问题。

下面是一些示例代码,展示了如何使用这些方法:

string rootSourceControlUrl = "TODO: Root URL of Azure DevOps";
string projectCollection = "TODO: Individual project collection within Azure DevOps";    

TfsTeamProjectCollection tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri($"{rootSourceControlUrl}/{projectCollection}"));
IIdentityManagementService ims = (IIdentityManagementService)tfsCollection.GetService(typeof(IIdentityManagementService));
TeamFoundationIdentity foundUser = ims.ReadIdentity(IdentitySearchFactor.DisplayName, 
                                       "TODO: Display name of user", MembershipQuery.Direct, 
                                       ReadIdentityOptions.ExtendedProperties);
if(foundUser != null)
{
    try
    {
        if (ims.RefreshIdentity(foundUser.Descriptor))
        {
            // Find the user by its original IdentityDescriptor, which shouldn't change during the refresh
            TeamFoundationIdentity refreshedUser = ims.ReadIdentity(foundUser.Descriptor, 
                          MembershipQuery.Direct, ReadIdentityOptions.ExtendedProperties);

            // TODO : Display changes from foundUser to refreshedUser, using individual properties 
            //        and the method foundUser.GetProperties(), which returns an 
            //        IEnumerable<KeyValuePair<string, object>> collection.
        }
        else
        {
             // TODO : Notify that user failed to refresh
        }
    }
    catch(Exception exc)
    {
        // TODO : Notify that exception occurred
    }
}
else
{
    // TODO : Notify that user was not found
}

【讨论】:

    【解决方案2】:

    TFS/Azure DevOps 服务器使用后台同步作业(每小时安排一次)来查找 Active Directory 中的更改。因此,您对 Active Directory 组所做的更改不会立即反映在 TFS 中。相反,TFS 会定期(默认每小时)同步这些组。

    您可以尝试重新启动 TFS Job Agent 服务,看看是否有帮助。

    【讨论】:

    • 实际上,我们确实尝试过重启 TFS Job Agent 服务,但并没有解决问题。我们还多次重新启动 Azure DevOps Server 以将 Windows 补丁应用到机器上,因此该服务已多次停止和启动。如果没有直接的方法来强制工作,你能告诉我后台工作触发了什么以将更新应用到用户吗?几乎就像该作业没有看到用户在 Active Directory 中已更新,因此它认为它没有任何要更新的内容。
    • 能否尝试删除用户,等待一两个小时重新添加?
    • 我按照你的建议做了,但没有运气。我删除了用户并等待了 7 个多小时才将它们添加回来。即使在 Azure DevOps Server 作业运行额外等待 2 小时后,用户仍然没有同步。我确实在数据库中找到了适当的作业历史表,我可以看到定期同步作业正在更新表,所以它似乎正在运行。但它没有执行同步。我也尝试了再次回收服务,我早上检查一下,看看它是否有效果。 (没有立即改变。)
    • 我还应该提到,我们正在使用系统的最新版本 Azure DevOps Server 2019 的更新 1。
    • 我刚刚注意到昨天更新了 1.1。
    【解决方案3】:

    我尝试了以上所有建议,但没有一个有效!

    最后,这段代码解决了我的问题:

    update [Tfs_Configuration].dbo.tbl_Identity
    set 
        AccountName = 'New Name', 
        DistinguishedName = 'CN=*New Name*, OU=..., OU= ... ,OU=... ,OU=...,OU=...,DC=...,DC=...',
        MailAddress = 'New eMail'
    where *Your Condition*
    

    【讨论】:

    • 据我了解,不建议将数据库直接更新到 Azure DevOps (TFS),这会被视为违反许可/服务协议。
    猜你喜欢
    • 2020-08-06
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2021-04-28
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多