Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Issue-42 Adding support for impersonating groups with flag --as-group #43

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/cmd/view-secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type CommandOpts struct {
secretKey string
quiet bool
impersonateAs string
impersonateAsGroups string
}

// NewCmdViewSecret creates the cobra command to be executed
Expand Down Expand Up @@ -94,6 +95,7 @@ func NewCmdViewSecret() *cobra.Command {
cmd.Flags().StringVarP(&res.customContext, "context", "c", res.customContext, "override the current context")
cmd.Flags().StringVarP(&res.kubeConfig, "kubeconfig", "k", res.kubeConfig, "explicitly provide the kubeconfig to use")
cmd.Flags().StringVar(&res.impersonateAs, "as", res.impersonateAs, "Username to impersonate for the operation. User could be a regular user or a service account in a namespace.")
cmd.Flags().StringVar(&res.impersonateAsGroups, "as-group", res.impersonateAsGroups, "Groups to impersonate for the operation. Multipe groups can be specified by comma separated.")

return cmd
}
Expand All @@ -119,6 +121,7 @@ func (c *CommandOpts) Retrieve(cmd *cobra.Command) error {
ctxOverride, _ := cmd.Flags().GetString("context")
kubeConfigOverride, _ := cmd.Flags().GetString("kubeconfig")
impersonateOverride, _ := cmd.Flags().GetString("as")
impersonateGroupOverride, _ := cmd.Flags().GetString("as-group")

var res, cmdErr bytes.Buffer
commandArgs := []string{"get", "secret", c.secretName, "-o", "json"}
Expand All @@ -138,6 +141,10 @@ func (c *CommandOpts) Retrieve(cmd *cobra.Command) error {
commandArgs = append(commandArgs, "--as", impersonateOverride)
}

if impersonateGroupOverride != "" {
commandArgs = append(commandArgs, "--as-group", impersonateGroupOverride)
}

out := exec.Command("kubectl", commandArgs...)
out.Stdout = &res
out.Stderr = &cmdErr
Expand Down