首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Terraform/rancher2auth_config_github:未经授权401:必须进行身份验证

Terraform/rancher2auth_config_github:未经授权401:必须进行身份验证
EN

Stack Overflow用户
提问于 2022-01-27 08:24:36
回答 1查看 407关注 0票数 1

我正在尝试为rancher2配置Github身份验证,下面的链接是:https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/auth_config_github

但是当我使用这个资源时,我得到了401个未经授权的响应。

这是我的代码:

代码语言:javascript
运行
复制
terraform {
  required_providers {
    rancher2 = {
      source = "rancher/rancher2"
      version = "1.21.0"
    }
  }
}

provider "rancher2" {
  api_url   = "https://{{ rancher_public_domain }}"
  bootstrap = true
}

resource "rancher2_bootstrap" "admin" {
  password = "{{ admin_password }}"
  telemetry = false
  ui_default_landing = "ember"
}

resource "rancher2_auth_config_github" "github" {
  client_id = "<MY_GITHUB_CLIENT_ID>"
  client_secret = "<MY_GITHUB_CLIENT_SECRET>"
  enabled = true
}

output "rancher_username" {
  value = rancher2_bootstrap.admin.user
}

output "rancher_token" {
  value = rancher2_bootstrap.admin.token
  sensitive = true
}

output "rancher_url" {
  value = rancher2_bootstrap.admin.url
}

错误是:

代码语言:javascript
运行
复制
Error: Bad response statusCode [401]. Status [401 Unauthorized]. Body: [message=Unauthorized 401: must authenticate] from [https://{{ rancher_public_domain }}]

  with rancher2_auth_config_github.github,
  on main.tf line 21, in resource "rancher2_auth_config_github" "github":
  21: resource "rancher2_auth_config_github" "github" {

当我不使用这个资源时,错误不会发生。我能帮忙吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-01-27 14:02:40

根据Rancher/RKE认证文档和Rancher提供者文档,rancher2_auth_config_github需要一个具有admin配置的提供者,而不是bootstrap。我们可以使用rancher2_bootstrap资源的导出资源属性token对此进行身份验证:

代码语言:javascript
运行
复制
provider "rancher2" {
  api_url   = rancher2_bootstrap.admin.url
  token_key = rancher2_bootstrap.admin.token
}

现在的问题是,第二个提供程序配置将与bootstrap提供程序配置发生冲突。为此,我们可以使用提供程序别名:

代码语言:javascript
运行
复制
provider "rancher2" {
  api_url   = rancher2_bootstrap.admin.url
  token_key = rancher2_bootstrap.admin.token
  alias     = "admin"
}

resource "rancher2_auth_config_github" "github" {
  provider = rancher2.admin

  client_id     = "<MY_GITHUB_CLIENT_ID>"
  client_secret = "<MY_GITHUB_CLIENT_SECRET>"
  enabled       = true
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70875381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档