Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow --no-rbac flag that allows users to not pass rbac config #9972

Merged
merged 5 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion go/cmd/vtadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
defaultClusterConfig cluster.Config

rbacConfigPath string
enableRbac bool
disableRbac bool
notfelineit marked this conversation as resolved.
Show resolved Hide resolved

traceCloser io.Closer = &noopCloser{}

Expand Down Expand Up @@ -101,14 +103,20 @@ func run(cmd *cobra.Command, args []string) {
}

var rbacConfig *rbac.Config
if rbacConfigPath != "" {
if !disableRbac && !enableRbac {
fatal("must explicitly enable or disable RBAC by passing --no-rbac or --rbac")
}
if enableRbac && !disableRbac && rbacConfigPath != "" {
cfg, err := rbac.LoadConfig(rbacConfigPath)
if err != nil {
fatal(err)
}

rbacConfig = cfg
}
if disableRbac && !enableRbac {
rbacConfig = rbac.DefaultConfig()
}

for i, cfg := range configs {
cluster, err := cfg.Cluster()
Expand Down Expand Up @@ -163,6 +171,8 @@ func main() {

// rbac flags
rootCmd.Flags().StringVar(&rbacConfigPath, "rbac-config", "rbac.yaml", "")
rootCmd.Flags().BoolVar(&enableRbac, "rbac", false, "whether to enable rbac")
rootCmd.Flags().BoolVar(&disableRbac, "no-rbac", false, "whether to disable rbac")
notfelineit marked this conversation as resolved.
Show resolved Hide resolved

// glog flags, no better way to do this
rootCmd.Flags().AddGoFlag(flag.Lookup("v"))
Expand Down
1 change: 1 addition & 0 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (api *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
api.Handler().ServeHTTP(w, r)
return
}

dynamicAPI := &API{
clusters: api.clusters,
clusterMap: api.clusterMap,
Expand Down
38 changes: 38 additions & 0 deletions go/vt/vtadmin/rbac/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,41 @@ func (c *Config) GetAuthenticator() Authenticator {
func (c *Config) GetAuthorizer() *Authorizer {
return c.authorizer
}

func DefaultConfig() *Config {
notfelineit marked this conversation as resolved.
Show resolved Hide resolved
log.Info("[rbac]: using default rbac configuration")
actions := []string{"get", "create", "delete", "put", "ping"}
notfelineit marked this conversation as resolved.
Show resolved Hide resolved
subjects := []string{"*"}
clusters := []string{"*"}

cfg := map[string][]*Rule{
"*": {
{
clusters: sets.NewString(clusters...),
actions: sets.NewString(actions...),
subjects: sets.NewString(subjects...),
},
},
}

return &Config{
Rules: []*struct {
Resource string
Actions []string
Subjects []string
Clusters []string
}{
{
Resource: "*",
Actions: actions,
Subjects: subjects,
Clusters: clusters,
},
},
cfg: cfg,
authorizer: &Authorizer{
policies: cfg,
},
authenticator: nil,
}
}