【问题标题】:GitLab: How to find the owner of an SSH keyGitLab:如何找到 SSH 密钥的所有者
【发布时间】:2019-06-09 01:41:40
【问题描述】:

给定一个已在 GitLab 注册的 SSH 公钥或指纹,我如何找出与该密钥关联的帐户?

请注意,该密钥可能已注册为“部署密钥”,在这种情况下,我想知道注册它的帐户。

我更希望了解使用标准 Web UI(如果可能)和通过 REST API 以编程方式执行此操作的方法。如果这些都不可能,如有必要,我将采取涉及挖掘 GitLab 内部的答案(例如,通过对 GitLab 数据库的查询)。

【问题讨论】:

    标签: gitlab ssh-keys


    【解决方案1】:

    如果可以访问 postgres 控制台:

    root@gitlab:/# gitlab-psql
        psql (9.6.8)
        Type "help" for help.
    
        gitlabhq_production=#
        gitlabhq_production=# select a.name,a.username,b.fingerprint 
    from users a, keys b where a.id=b.user_id;
    
             name      | username |                   fingerprint                   
        ---------------+----------+-------------------------------------------------
         Administrator | root     | f4:cc:ec:76:d0:1c:86:1d:45:6d:a7:6e:b3:df:32:7c
        (1 row)
    

    【讨论】:

    • 这被标记为接受,因为它是迄今为止最好的解决方案,但如果有任何更简单的解决方案,我愿意接受。 (听起来好像没有。)
    • select a.name,a.username,b.key from users a, keys b where a.id=b.user_id and b.key like '%your_key%';
    【解决方案2】:

    通过 GitLab 综合安装,您可以使用 rails 控制台:

    gitlab-rails console
    > User.find(Key.find_by(fingerprint: '00:00:00:00...').user_id)
    

    将指纹的值替换为密钥的md5指纹。

    【讨论】:

      【解决方案3】:

      我没有看到任何将 SSH 密钥指纹作为参数的公共 API(例如在 User API 中)。

      我认为它仅用作内部 API,以检索实际的 SSH 密钥:merge request 250

      That code 可以为您提供有关如何编写自己的搜索代码的线索。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多