Skip to content

Commit

Permalink
feat(kubeconfig_from_vault): Add --login-oidc param to automatically …
Browse files Browse the repository at this point in the history
…log in
  • Loading branch information
ondrejsika committed Feb 8, 2025
1 parent d98769d commit fae870e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/kubeconfig_from_vault/kubeconfig_from_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var FlagVaultAddr string
var FlagVaultSecretPath string
var FlagLoginOIDC bool

var Cmd = &cobra.Command{
Use: "kubeconfig-from-vault",
Expand Down Expand Up @@ -43,6 +44,12 @@ func init() {
"Vault Secret Path",
)
Cmd.MarkFlagRequired("path")
Cmd.Flags().BoolVar(
&FlagLoginOIDC,
"login-oidc",
false,
"Vault Login with OIDC",
)
}

func kubeconfigFromVault(vaultAddr, secretPath string) {
Expand All @@ -56,6 +63,10 @@ func kubeconfigFromVault(vaultAddr, secretPath string) {

caFilePath := createTmpFile(KUBERNETES_CA)

if FlagLoginOIDC {
sh([]string{"vault", "login", "-address", vaultAddr, "-method=oidc"})
}

sh([]string{"kubectl", "config", "set-cluster", KUBERNETES_CLUSTER_NAME, "--server=" + KUBERNETES_SERVER, "--certificate-authority=" + caFilePath, "--embed-certs=true"})
sh([]string{"kubectl", "config", "set-credentials", KUBERNETES_CLUSTER_NAME, "--token=" + KUBERNETES_TOKEN})
sh([]string{"kubectl", "config", "set-context", KUBERNETES_CLUSTER_NAME, "--cluster=" + KUBERNETES_CLUSTER_NAME, "--user=" + KUBERNETES_CLUSTER_NAME})
Expand Down

0 comments on commit fae870e

Please # to comment.