首页 > 解决方案 > 如何在 Github 组织插件中使用两个因素

问题描述

我们正在对 GitHub 组织中的所有用户强制执行两因素身份验证。

当我们启用它时,我们所有的 Jenkins 工作都很好,除了我们的“Github 组织”工作。

似乎这个插件只支持用户名/密码凭据,而不是 id_rsa 或 access_tokens,它们可以很好地与两因素身份验证配合使用。

如果您使用用户名/access_token 凭据,则会拒绝访问:

java.io.FileNotFoundException: 
[https://api.github.com/]
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
    at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
    at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
    at org.kohsuke.github.Requester.parse(Requester.java:612)
    at org.kohsuke.github.Requester.parse(Requester.java:594)
    at org.kohsuke.github.Requester._to(Requester.java:272)
Caused: org.kohsuke.github.GHFileNotFoundException: \{"message":"Must specify two-factor authentication OTP code.","documentation_url":"
[https://developer.github.com/v3/auth#working-with-two-factor-authentication]
"}
    at org.kohsuke.github.Requester.handleApiError(Requester.java:686)
    at org.kohsuke.github.Requester._to(Requester.java:293)
    at org.kohsuke.github.Requester.to(Requester.java:234)
    at org.kohsuke.github.GitHub.checkApiUrlValidity(GitHub.java:703)
    at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.checkApiUrlValidity(GitHubSCMSource.java:1348)
    at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.retrieve(GitHubSCMSource.java:1401)
    at jenkins.scm.api.SCMSource.fetch(SCMSource.java:564)
    at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:95)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:295)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

我在这里输入了一张票(我不确定这是一个错误还是有解决方法,因此我在这里交叉发布) https://issues.jenkins-ci.org/browse/JENKINS-51092

甚至帮助文本都说它只支持用户名/密码组合(附图片)。

这个项目的 config.xml 文件的顶部是这样的:

看起来这已经在其他地方修复了,但不是这个插件: https ://issues.jenkins-ci.org/browse/JENKINS-39477

标签: jenkinsjenkins-plugins

解决方案


推荐阅读