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

[ATOM-2] Moving Access control from AKO to management-lib #59

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
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
519 changes: 519 additions & 0 deletions accesscontrol/access_control.go

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions accesscontrol/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package accesscontrol

// PrivilegeScope enumerates valid scopes for privileges.
type PrivilegeScope int

const (
// Global scoped privileges.
Global PrivilegeScope = iota

// NamespaceSet is namespace and optional set scoped privilege.
NamespaceSet
)

// Privileges are all privilege string allowed in the spec and associated scopes.
var Privileges = map[string][]PrivilegeScope{
"read": {Global, NamespaceSet},
"write": {Global, NamespaceSet},
"read-write": {Global, NamespaceSet},
"read-write-udf": {Global, NamespaceSet},
"data-admin": {Global},
"sys-admin": {Global},
"user-admin": {Global},
"truncate": {Global, NamespaceSet},
"sindex-admin": {Global},
"udf-admin": {Global},
}

// Post6Privileges are post version 6.0 privilege strings allowed in the spec and associated scopes.
var Post6Privileges = map[string][]PrivilegeScope{
"truncate": {Global, NamespaceSet},
"sindex-admin": {Global},
"udf-admin": {Global},
}
10 changes: 10 additions & 0 deletions deployment/aeroinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ func GetInfoOnHosts(log logr.Logger, policy *aero.ClientPolicy,

return c.infoOnHosts(getHostIDsFromHostConns(allHosts), cmd)
}

func GetNamespaceStats(hostConns []*HostConn, policy *aero.ClientPolicy,
namespace string) (map[string]InfoResult, error) {
clHosts, err := getHostsFromHostConns(hostConns, policy)
if err != nil {
return nil, err
}

return getNamespaceStats(clHosts, namespace)
}
83 changes: 1 addition & 82 deletions deployment/strong_consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func validateSCClusterNsState(scNamespacesPerHost map[*host][]string, ignorableN
continue
}

kvMap, err := getNamespaceStats(clHost, ns)
kvMap, err := getNamespaceStatsPerHost(clHost, ns)
if err != nil {
return err
}
Expand Down Expand Up @@ -256,21 +256,6 @@ func recluster(clHost *host) error {
return nil
}

func getNamespaceStats(clHost *host, namespace string) (map[string]string, error) {
cmd := fmt.Sprintf("namespace/%s", namespace)

res, err := clHost.asConnInfo.asInfo.RequestInfo(cmd)
if err != nil {
return nil, err
}

cmdOutput := res[cmd]

clHost.log.V(1).Info("Run info command", "cmd", cmd)

return ParseInfoIntoMap(cmdOutput, ";", "=")
}

func setRoster(clHost *host, namespace, observedNodes string) error {
cmd := fmt.Sprintf("roster-set:namespace=%s;nodes=%s", namespace, observedNodes)

Expand Down Expand Up @@ -305,36 +290,6 @@ func getRoster(clHost *host, namespace string) (map[string]string, error) {
return ParseInfoIntoMap(cmdOutput, ":", "=")
}

func getNamespaces(clHost *host) ([]string, error) {
cmd := CmdNamespaces

res, err := clHost.asConnInfo.asInfo.RequestInfo(cmd)
if err != nil {
return nil, err
}

cmdOutput := res[cmd]

clHost.log.V(1).Info("Run info command", "cmd", cmd, "output", cmdOutput)

if cmdOutput != "" {
return strings.Split(cmdOutput, ";"), nil
}

return nil, nil
}

// ContainsString check whether list contains given string
func containsString(list []string, ele string) bool {
for _, listEle := range list {
if strings.EqualFold(ele, listEle) {
return true
}
}

return false
}

func isNodeInRoster(clHost *host, ns string) (bool, error) {
nodeID, err := getNodeID(clHost)
if err != nil {
Expand All @@ -360,39 +315,3 @@ func isNodeInRoster(clHost *host, ns string) (bool, error) {

return false, nil
}

func getNodeID(clHost *host) (string, error) {
cmd := "node"

res, err := clHost.asConnInfo.asInfo.RequestInfo(cmd)
if err != nil {
return "", err
}

return res[cmd], nil
}

// ParseInfoIntoMap parses info string into a map.
func ParseInfoIntoMap(str, del, sep string) (map[string]string, error) {
m := map[string]string{}
if str == "" {
return m, nil
}

items := strings.Split(str, del)

for _, item := range items {
if item == "" {
continue
}

kv := strings.Split(item, sep)
if len(kv) < 2 {
return nil, fmt.Errorf("error parsing info item %s", item)
}

m[kv[0]] = strings.Join(kv[1:], sep)
}

return m, nil
}
91 changes: 91 additions & 0 deletions deployment/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,94 @@ func getHostsFromHostConns(hostConns []*HostConn, policy *as.ClientPolicy) ([]*h

return hosts, nil
}

func getNamespaceStats(hosts []*host, namespace string) (map[string]InfoResult, error) {
stats := make(map[string]InfoResult, len(hosts))

for _, host := range hosts {
ir, err := getNamespaceStatsPerHost(host, namespace)
if err != nil {
return nil, err
}

stats[host.id] = ir
}

return stats, nil
}
func getNamespaceStatsPerHost(clHost *host, namespace string) (map[string]string, error) {
cmd := fmt.Sprintf("namespace/%s", namespace)

res, err := clHost.asConnInfo.asInfo.RequestInfo(cmd)
if err != nil {
return nil, err
}

cmdOutput := res[cmd]
clHost.log.V(1).Info("Run info command", "cmd", cmd)

return ParseInfoIntoMap(cmdOutput, ";", "=")
}
func getNodeID(clHost *host) (string, error) {
cmd := "node"

res, err := clHost.asConnInfo.asInfo.RequestInfo(cmd)
if err != nil {
return "", err
}

return res[cmd], nil
}

// ParseInfoIntoMap parses info string into a map.
func ParseInfoIntoMap(str, del, sep string) (map[string]string, error) {
m := map[string]string{}
if str == "" {
return m, nil
}

items := strings.Split(str, del)
for _, item := range items {
if item == "" {
continue
}

kv := strings.Split(item, sep)
if len(kv) < 2 {
return nil, fmt.Errorf("error parsing info item %s", item)
}

m[kv[0]] = strings.Join(kv[1:], sep)
}

return m, nil
}

// ContainsString check whether list contains given string
func containsString(list []string, ele string) bool {
for _, listEle := range list {
if strings.EqualFold(ele, listEle) {
return true
}
}

return false
}

func getNamespaces(clHost *host) ([]string, error) {
cmd := CmdNamespaces

res, err := clHost.asConnInfo.asInfo.RequestInfo(cmd)
if err != nil {
return nil, err
}

cmdOutput := res[cmd]
if cmdOutput != "" {
clHost.log.V(1).Info("Run info command", "cmd", cmd, "output", cmdOutput)

return strings.Split(cmdOutput, ";"), nil
}

return nil, nil
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aerospike/aerospike-management-lib
go 1.22

require (
github.com/aerospike/aerospike-client-go/v7 v7.1.0
github.com/aerospike/aerospike-client-go/v7 v7.4.0
github.com/deckarep/golang-set/v2 v2.3.1
github.com/docker/go-connections v0.4.0
github.com/go-logr/logr v1.4.1
Expand Down Expand Up @@ -54,6 +54,6 @@ require (
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/grpc v1.63.0 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/aerospike/aerospike-client-go/v7 v7.1.0 h1:yvCTKdbpqZxHvv7sWsFHV1j49jZcC8yXRooWsDFqKtA=
github.com/aerospike/aerospike-client-go/v7 v7.1.0/go.mod h1:AkHiKvCbqa1c16gCNGju3c5X/yzwLVvblNczqjxNwNk=
github.com/aerospike/aerospike-client-go/v7 v7.4.0 h1:g8/7v8RHhQhTArhW3C7Au7o+u8j8x5eySZL6MXfpHKU=
github.com/aerospike/aerospike-client-go/v7 v7.4.0/go.mod h1:pPKnWiS8VDJcH4IeB1b8SA2TWnkjcVLHwAAJ+BHfGK8=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
Expand Down Expand Up @@ -36,8 +36,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 h1:y3N7Bm7Y9/CtpiVkw/ZWj6lSlDF3F74SfKwfTCer72Q=
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF/w5E9CNxSwbpD6No=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYpldc7gVz2KMQwJ/QYCDIa7XU=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand All @@ -52,10 +52,10 @@ github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM=
github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk=
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
Expand Down Expand Up @@ -147,8 +147,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8=
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
14 changes: 0 additions & 14 deletions info/as_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1681,17 +1681,3 @@ func parseIntoDcMap(str, del, sep string) lib.Stats {

return m.ToParsedValues()
}

func contains(list []string, str string) bool {
if len(list) == 0 {
return false
}

for _, s := range list {
if s == str {
return true
}
}

return false
}
Loading