-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AKS Service Target: Adds support for Azure RBAC when local user accou…
…nts are disabled (#3211) When a cluster is provisioned with Azure RBAC and local accounts are disabled azd will leverage kubelogin to use exec auth module with azd authentication.
- Loading branch information
Showing
7 changed files
with
200 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ javac | |
jmes | ||
jquery | ||
keychain | ||
kubelogin | ||
LASTEXITCODE | ||
ldflags | ||
lechnerc77 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package kubelogin | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/azure/azure-dev/cli/azd/pkg/exec" | ||
"github.com/azure/azure-dev/cli/azd/pkg/tools" | ||
) | ||
|
||
// Cli is a wrapper around the kubelogin CLI | ||
type Cli struct { | ||
commandRunner exec.CommandRunner | ||
} | ||
|
||
// NewCli creates a new instance of the kubelogin CLI wrapper | ||
func NewCli(commandRunner exec.CommandRunner) *Cli { | ||
return &Cli{ | ||
commandRunner: commandRunner, | ||
} | ||
} | ||
|
||
// Gets the name of the Tool | ||
func (cli *Cli) Name() string { | ||
return "kubelogin" | ||
} | ||
|
||
// Returns the installation URL to install the kubelogin CLI | ||
func (cli *Cli) InstallUrl() string { | ||
return "https://aka.ms/azure-dev/kubelogin-install" | ||
} | ||
|
||
// Checks whether or not the kubelogin CLI is installed and available within the PATH | ||
func (cli *Cli) CheckInstalled(ctx context.Context) error { | ||
if err := tools.ToolInPath("kubelogin"); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertKubeConfig converts a kubeconfig file to use the exec auth module | ||
func (c *Cli) ConvertKubeConfig(ctx context.Context, options *ConvertOptions) error { | ||
if options == nil { | ||
options = &ConvertOptions{} | ||
} | ||
|
||
if options.Login == "" { | ||
options.Login = "azd" | ||
} | ||
|
||
runArgs := exec.NewRunArgs("kubelogin", "convert-kubeconfig", "--login", options.Login) | ||
if options.KubeConfig != "" { | ||
runArgs = runArgs.AppendParams("--kubeconfig", options.KubeConfig) | ||
} | ||
|
||
if options.TenantId != "" { | ||
runArgs = runArgs.AppendParams("--tenant-id", options.TenantId) | ||
} | ||
|
||
if options.Context != "" { | ||
runArgs = runArgs.AppendParams("--context", options.Context) | ||
} | ||
|
||
if _, err := c.commandRunner.Run(ctx, runArgs); err != nil { | ||
return fmt.Errorf("converting kubeconfig: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertOptions are the options for converting a kubeconfig file | ||
type ConvertOptions struct { | ||
// Login method to use (defaults to azd) | ||
Login string | ||
// AAD tenant ID | ||
TenantId string | ||
// The name of the kubeconfig context to use | ||
Context string | ||
// KubeConfig is the path to the kube config file | ||
KubeConfig string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.