-
Notifications
You must be signed in to change notification settings - Fork 1
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
KO-251: Added auth sub-command to grant RBAC access #6
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c62e6f
Added auth sub-command to grant RBAC access
abhishekdwivedi3060 f4fc4fa
Sorted events as per CreationTimeStamp
abhishekdwivedi3060 1ac3b67
Added test-cases
abhishekdwivedi3060 c9cb0ba
Added License entry in go files
abhishekdwivedi3060 365143c
Fixed yaml pkg
abhishekdwivedi3060 29e366d
Merge branch 'main' into KO-251
abhishekdwivedi3060 3b40fe1
Added namespace lookup check
abhishekdwivedi3060 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -15,3 +15,5 @@ | |
# vendor/ | ||
|
||
dist/ | ||
bin/ | ||
.idea/ |
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 |
---|---|---|
@@ -1,41 +1,21 @@ | ||
# Aerospike-kubernetes-operator-ctl | ||
|
||
This is a command line tool for Aerospike kubernetes operator. | ||
|
||
## Aerospike Kubernetes Operator Log Collector | ||
|
||
### Overview | ||
|
||
collectinfo command collects all the required info from kubernetes cluster, which are available at the time of command being executed. | ||
|
||
There are certain flags associated with command: | ||
* **all-namespaces** - (shorthand -A, type bool) Collect info from all namespaces present in cluster. | ||
* **namespaces** - (shorthand -n, type string) Comma separated list of namespaces from which data needs to be collected. | ||
* **kubeconfig** - (type string) Absolute path to the kubeconfig file. | ||
* **path** - (type string) Absolute path to save output tar file. | ||
* **cluster-scope** - (type bool) Permission to collect cluster scoped objects info. Default true. | ||
|
||
### Requirements | ||
* Current user should have the list and get permission for all the objects collected by the command. | ||
* If **cluster-scope** flag is set, along with permission mentioned above, user should have list and get permission for cluster-scoped resources like(nodes and storageclasses). | ||
* **Kubectl** binary should be available in **PATH** environment variable. | ||
This is a command line tool for Aerospike Kubernetes Operator. It provides multiple sub-commands to perform different functions related to Aerospike Kubernetes Operator and Aerospike Kubernetes Cluster. | ||
|
||
Available sub-commands: | ||
1. [`collectinfo`](#aerospike-kubernetes-operator-log-collector) | ||
2. [`auth`](#grant-aerospike-kubernetes-cluster-rbac) | ||
### Building and quick start | ||
|
||
#### Building akoctl binary | ||
#### Building akoctl binary for local testing | ||
```sh | ||
make build | ||
``` | ||
|
||
#### Collect cluster info | ||
```sh | ||
./bin/akoctl collectinfo -n aerospike,olm --path ~/abc/ | ||
``` | ||
|
||
#### Install via krew plugin manager | ||
#### Install via Krew plugin manager | ||
[Krew](https://krew.sigs.k8s.io) is the plugin manager for kubectl command-line tool. Here `akoctl` has been added as a custom plugin to krew. | ||
|
||
##### Install krew | ||
##### Install Krew | ||
To install krew on any platform, follow [this](https://krew.sigs.k8s.io/docs/user-guide/setup/install/). | ||
##### Install akoctl | ||
```sh | ||
|
@@ -57,7 +37,25 @@ Installed plugin: akoctl | |
| Documentation: | ||
| https://github.com/aerospike/aerospike-kubernetes-operator-ctl | ||
/ | ||
``` | ||
|
||
## Aerospike Kubernetes Operator Log Collector | ||
|
||
### Overview | ||
|
||
`collectinfo` command collects all the required info from kubernetes cluster, which are available at the time of command being executed. | ||
|
||
Flag associated with this command: | ||
* **path** - (type string) Absolute path to save output tar file. | ||
|
||
### Requirements | ||
* Current user should have the list and get permission for all the objects collected by the command. | ||
* If **cluster-scope** flag is set, along with permissions mentioned above, user should have list and get permission for cluster-scoped resources like(nodes and storageclasses). | ||
* * **Kubectl** binary should be available in **PATH** environment variable. | ||
|
||
#### Collect cluster info using local binary | ||
```sh | ||
./bin/akoctl collectinfo -n aerospike,olm --path ~/abc/ | ||
``` | ||
|
||
#### Collect cluster info using krew | ||
|
@@ -123,4 +121,40 @@ akoctl_collectinfo | |
│ ├── events.txt | ||
└────────────────────────── | ||
|
||
``` | ||
``` | ||
|
||
## Grant Aerospike Kubernetes Cluster RBAC | ||
|
||
### Overview | ||
|
||
`auth` command creates/deletes RBAC resources for Aerospike cluster for the given namespaces. | ||
It creates/deletes ServiceAccount, RoleBinding or ClusterRoleBinding as per given scope of operation. | ||
|
||
There are 2 sub-commands associated with this command: | ||
* `create` - It creates/updates RBAC resources for the given namespaces. | ||
* `delete` - It deletes RBAC resources for the given namespaces. | ||
|
||
If `cluster-scope` is set (Default true), auth command grants cluster level RBAC whereas in case of `cluster-scope` false, it grants namespace level RBAC. | ||
|
||
### Permission required | ||
* Current user should have the CREATE, GET, UPDATE and DELETE permission for ServiceAccount and RoleBinding. | ||
* If **cluster-scope** flag is set, user should have the CREATE, GET, UPDATE and DELETE permission for ServiceAccount and ClusterRoleBinding. | ||
|
||
#### Collect cluster info | ||
```sh | ||
./bin/akoctl auth create -n aerospike,olm | ||
./bin/akoctl auth delete -n aerospike,olm | ||
``` | ||
|
||
#### Collect cluster info using krew | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change heading |
||
```sh | ||
kubectl akoctl auth create -n aerospike,olm | ||
kubectl akoctl auth delete -n aerospike,olm | ||
``` | ||
|
||
## Global Flags: | ||
There are certain global flags associated with akoctl: | ||
* **all-namespaces** - (shorthand -A, type bool) Specify all namespaces present in cluster. | ||
* **namespaces** - (shorthand -n, type string) Comma separated list of namespaces to perform operation in. | ||
* **kubeconfig** - (type string) Absolute path to the kubeconfig file. | ||
* **cluster-scope** - (type bool) Permission to work in cluster scoped mode (operate on cluster scoped resources like ClusterRoleBinding). Default true. |
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,74 @@ | ||
/* | ||
Copyright 2023 The aerospike-operator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/aerospike/aerospike-kubernetes-operator-ctl/pkg/auth" | ||
"github.com/aerospike/aerospike-kubernetes-operator-ctl/pkg/configuration" | ||
) | ||
|
||
// authCmd represents the auth command | ||
var authCmd = &cobra.Command{ | ||
Use: "auth", | ||
Short: "auth command is used to create or delete RBAC resources for Aerospike cluster for the given namespaces", | ||
Long: `This command has subcommands that will create or delete RBAC resources for Aerospike cluster for the given | ||
namespaces. | ||
It creates/deletes ServiceAccount, RoleBinding or ClusterRoleBinding as per given scope`, | ||
} | ||
|
||
var authCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "create command is used to create or update RBAC resources for Aerospike cluster for the given namespaces", | ||
Long: `This command will create RBAC resources for Aerospike cluster for the given | ||
namespaces. | ||
It creates ServiceAccount, RoleBinding or ClusterRoleBinding as per given scope`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.TODO() | ||
params, err := configuration.NewParams(ctx, namespaces, allNamespaces, clusterScope) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return auth.Create(ctx, params) | ||
}, | ||
} | ||
|
||
var authDeleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "delete command is used to delete RBAC resources for Aerospike cluster for the given namespaces", | ||
Long: `This command will delete RBAC resources for Aerospike cluster for the given | ||
namespaces. | ||
It deletes ServiceAccount, RoleBinding or ClusterRoleBinding as per given scope`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.TODO() | ||
params, err := configuration.NewParams(ctx, namespaces, allNamespaces, clusterScope) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return auth.Delete(ctx, params) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(authCmd) | ||
authCmd.AddCommand(authCreateCmd) | ||
authCmd.AddCommand(authDeleteCmd) | ||
} |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change heading