Skip to content

Commit

Permalink
adding kubeconfig command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasreed committed Oct 16, 2019
1 parent a63997c commit 16bb2cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -85,11 +85,12 @@ At this point this integration only supports standard IAM roles, and is not adva

## Flags Supported
```
--context string context to use for Kubernetes config
--gke enable GKE integration
-h, --help help for rbac-lookup
-k, --kind string filter by this RBAC subject kind (user, group, serviceaccount)
-o, --output string output format (normal, wide)
--context string context to use for Kubernetes config
--gke enable GKE integration
-h, --help help for rbac-lookup
-k, --kind string filter by this RBAC subject kind (user, group, serviceaccount)
--kubeconfig string config file location
-o, --output string output format (normal, wide)
```

## RBAC Manager
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Expand Up @@ -28,6 +28,7 @@ var (
commit string
outputFormat string
enableGke bool
kubeConfig string
kubeContext string
subjectKind string
)
Expand All @@ -44,12 +45,13 @@ var rootCmd = &cobra.Command{

subjectKind = strings.ToLower(subjectKind)

lookup.List(args, kubeContext, outputFormat, subjectKind, enableGke)
lookup.List(args, kubeConfig, kubeContext, outputFormat, subjectKind, enableGke)
},
}

func init() {
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "", "output format (normal, wide)")
rootCmd.PersistentFlags().StringVarP(&kubeConfig, "kubeconfig", "", "", "config file location")
rootCmd.PersistentFlags().StringVarP(&kubeContext, "context", "", "", "context to use for Kubernetes config")
rootCmd.PersistentFlags().StringVarP(&subjectKind, "kind", "k", "", "filter by this RBAC subject kind (user, group, serviceaccount)")
rootCmd.PersistentFlags().BoolVar(&enableGke, "gke", false, "enable GKE integration")
Expand Down
11 changes: 7 additions & 4 deletions lookup/list.go
Expand Up @@ -26,8 +26,9 @@ import (
)

// List outputs rbac bindings where subject names match given string
func List(args []string, kubeContext, outputFormat, subjectKind string, enableGke bool) {
clientConfig := getClientConfig(kubeContext)
func List(args []string, kubeConfig, kubeContext, outputFormat, subjectKind string, enableGke bool) {

clientConfig := getClientConfig(kubeConfig, kubeContext)

kubeconfig, err := clientConfig.ClientConfig()
if err != nil {
Expand Down Expand Up @@ -73,9 +74,11 @@ func List(args []string, kubeContext, outputFormat, subjectKind string, enableGk
l.printRbacBindings(outputFormat)
}

func getClientConfig(kubeContext string) clientcmd.ClientConfig {
func getClientConfig(kubeConfig, kubeContext string) clientcmd.ClientConfig {
configRules := clientcmd.NewDefaultClientConfigLoadingRules()
configRules.ExplicitPath = kubeConfig
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
configRules,
&clientcmd.ConfigOverrides{CurrentContext: kubeContext},
)
}

0 comments on commit 16bb2cc

Please sign in to comment.