如何使用GO软件包配置OIDC配置-ithub.com/hashicorp/vult/api



我们能够使用以下代码初始化/解封并启用vault。

newres, err := client.Sys().Init(&intireq)
resseal, err := client.Sys().Unseal("xxxxxxxxxxxxxxxxxxxxx")
fmt.Println("resseal:", resseal)
enableopt := vault.MountInput{}
enableopt.Type = "oidc"
client.SetToken("xxxxxxxxxxxxxxxxxx")
err = client.Sys().EnableAuthWithOptions("oidc", &enableopt)

我们也可以在UI中看到启用了oidc。现在,我们需要配置oidc,如果从UI完成,它将使用下面的POST api和configs id:";oidc";,oidc_discovery_url:"xxxxxx";。。。。。。

https://vault.xxxxxx.com/v1/auth/oidc/config

我们需要从我们的GO代码中配置相同的内容,其中我们使用GO客户端保险库";github.com/hashicorp/vault/api";

无法获取身份验证配置的方法,需要有关正确方法的帮助。

API在Logical()结构中公开,因此您可以使用类似的东西

type oidcConfig struct {
OIDCDiscoveryURL string `json:"oidc_discovery_url"`
// ...snip...
}
// in function call
config := oidcConfig{
OIDCDiscoveryURL: "https://sample.url/oidc"
// ..snip..
}
resp, err := client.Logical().Write("auth/oidc/config", config)

当然,还有比这更好的设置配置键的方法,但希望能给您一个简单的例子。

最新更新