You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/11/03 14:04:31 UTC
[GitHub] [servicecomb-service-center] hityc2019 opened a new pull request #736: [SCB-2093]Add roles to control access to API resources
hityc2019 opened a new pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736
Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SCB) filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
- [ ] Each commit in the pull request should have a meaningful subject line and body.
- [ ] Format the pull request title like `[SCB-XXX] Fixes bug in ApproximateQuantiles`, where you replace `SCB-XXX` with the appropriate JIRA issue.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Run `go build` `go test` `go fmt` `go vet` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
---
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r526568101
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,74 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
Review comment:
现在pr的内容较多,支持多role的功能会在下一次提交中补全功能
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] SmartsYoung commented on pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
SmartsYoung commented on pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#issuecomment-730101800
现在pr的内容较多,支持多role的功能会在下一次提交中补全功能
| |
yangcong
|
|
yangcong_hit@163.com
|
签名由网易邮箱大师定制
On 11/18/2020 18:42,Shawn<no...@github.com> wrote:
@tianxiaoliang requested changes on this pull request.
In pkg/rbacframe/role.go:
> + */
+
+package rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Permissions []*Permission `json:"permissions,omitempty"`
+}
+
+type Permission struct {
+ Resources []string
这里没有进行tag定义
In pkg/rbacframe/role.go:
> + * 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 rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Permissions []*Permission `json:"permissions,omitempty"`
简化为perms
In pkg/rbacframe/resource_dao.go:
> @@ -35,3 +35,12 @@ func GetResource(api string) string {
func MapResource(api, resource string) {
resourceMap[api] = resource
}
+
+//AddResourceType join the resource to an array
+func AddResourceType(resourceType ...string) []string {
没看到rt用在哪了
In docs/user-guides/rbac.md:
> + ]
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
这个多role还没支持
In datasource/role.go:
> +
+import (
+ "context"
+ "errors"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+var (
+ ErrRoleDuplicated = errors.New("role is duplicated")
+ ErrRoleCanNotEdit = errors.New("role can not be edited")
+)
+
+// RoleManager contains the RBAC CRUD
+type RoleManager interface {
+ CreateRole(ctx context.Context, r *rbacframe.Role) error
+ RoleExist(ctx context.Context, key string) (bool, error)
input就别叫key了,改成name
In datasource/role.go:
> + "context"
+ "errors"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+var (
+ ErrRoleDuplicated = errors.New("role is duplicated")
+ ErrRoleCanNotEdit = errors.New("role can not be edited")
+)
+
+// RoleManager contains the RBAC CRUD
+type RoleManager interface {
+ CreateRole(ctx context.Context, r *rbacframe.Role) error
+ RoleExist(ctx context.Context, key string) (bool, error)
+ GetRole(ctx context.Context, key string) (*rbacframe.Role, error)
+ ListRole(ctx context.Context, key string) ([]*rbacframe.Role, int64, error)
list不需要name作为入参
In datasource/etcd/role.go:
> + return nil, err
+ }
+ if resp.Count != 1 {
+ return nil, client.ErrNotUnique
+ }
+ role := &rbacframe.Role{}
+ err = json.Unmarshal(resp.Kvs[0].Value, role)
+ if err != nil {
+ log.Errorf(err, "role info format invalid")
+ return nil, err
+ }
+ return role, nil
+}
+func (ds *DataSource) ListRole(ctx context.Context, key string) ([]*rbacframe.Role, int64, error) {
+ resp, err := client.Instance().Do(ctx, client.GET,
+ client.WithStrKey(kv.GenerateETCDRoleKey(key)), client.WithPrefix())
拿到role列表为何需要一个role的名字
In server/service/rbac/decision.go:
> - log.Warn("role is not allowed to access resource")
- return false, nil
+
+ for i := 0; i < len(ps); i++ {
+ pr := ps[i].Resources
+ contains := inStrSlice(pr, resource)
+ if contains {
+ return allowVerbs(ps[i].Verbs, verbs), nil
+ }
+ }
+
+ log.Warn("role is not allowed to operate resource")
+ return false, nil
+}
+
+func inStrSlice(haystack []string, needle string) bool {
inStrSlice方法名起的不够易懂,应该是ableToAccessResource
In server/service/rbac/decision.go:
> ps := r.Permissions
if len(ps) == 0 {
log.Warn("role has no any permissions")
return false, nil
}
- p, ok := ps[resource]
- if !ok || p == nil {
- log.Warn("role is not allowed to access resource")
- return false, nil
+
+ for i := 0; i < len(ps); i++ {
+ pr := ps[i].Resources
+ contains := inStrSlice(pr, resource)
+ if contains {
+ return allowVerbs(ps[i].Verbs, verbs), nil
allowVerbs不要最后返回这个方法的结果,虽然结果正确,但是代码不易读,应该是一个大方法判断resource和verbs,比如叫ableToOperateResource
In server/service/rbac/permission.go:
> +// AdminPerms allocate all resource permissions
+func AdminPerms() []*rbacframe.Permission {
+ resources := rbacframe.AddResourceType(ResourceAccount, ResourceRole, ResourceService, ResourceInstance,
+ ResourceDep, ResourceTag, ResourceRule, ResourceGovern, ResourceAdminister, ResourceSchema)
+ perm := []*rbacframe.Permission{
+ {
+ Resources: resources,
+ Verbs: []string{"*"},
+ },
+ }
+ return perm
+}
+
+// DevPerms allocate all resource permissions except account and role resources
+func DevPerms() []*rbacframe.Permission {
+ resources := rbacframe.AddResourceType(ResourceService, ResourceInstance,
我明白了AddResourceType是什么,你不如叫buildResourceList
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r525977030
##########
File path: pkg/rbacframe/role.go
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Permissions []*Permission `json:"permissions,omitempty"`
+}
+
+type Permission struct {
+ Resources []string
Review comment:
这里没有进行tag定义
##########
File path: pkg/rbacframe/role.go
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Permissions []*Permission `json:"permissions,omitempty"`
Review comment:
简化为perms
##########
File path: datasource/etcd/role.go
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 etcd
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "github.com/apache/servicecomb-service-center/datasource"
+ "github.com/apache/servicecomb-service-center/datasource/etcd/client"
+ "github.com/apache/servicecomb-service-center/datasource/etcd/kv"
+ "github.com/apache/servicecomb-service-center/pkg/etcdsync"
+ "github.com/apache/servicecomb-service-center/pkg/log"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+ "github.com/apache/servicecomb-service-center/pkg/util"
+ "github.com/apache/servicecomb-service-center/server/core"
+)
+
+func (ds *DataSource) CreateRole(ctx context.Context, r *rbacframe.Role) error {
+ lock, err := etcdsync.Lock("/role-creating/"+r.Name, -1, false)
+ if err != nil {
+ return fmt.Errorf("role %s is creating", r.Name)
+ }
+ defer func() {
+ err := lock.Unlock()
+ if err != nil {
+ log.Errorf(err, "can not release role lock")
+ }
+ }()
+ key := core.GenerateRoleKey(r.Name)
+ exist, err := datasource.Instance().RoleExist(ctx, r.Name)
+ if err != nil {
+ log.Errorf(err, "can not save role info")
+ return err
+ }
+ if exist {
+ return datasource.ErrRoleDuplicated
+ }
+ r.ID = util.GenerateUUID()
+ value, err := json.Marshal(r)
+ if err != nil {
+ log.Errorf(err, "role info is invalid")
+ return err
+ }
+ err = client.PutBytes(ctx, key, value)
+ if err != nil {
+ log.Errorf(err, "can not save account info")
+ return err
+ }
+ log.Info("create new role: " + r.ID)
+ return nil
+}
+
+func (ds *DataSource) RoleExist(ctx context.Context, key string) (bool, error) {
+ resp, err := client.Instance().Do(ctx, client.GET,
+ client.WithStrKey(kv.GenerateETCDRoleKey(key)))
+ if err != nil {
+ return false, err
+ }
+ if resp.Count == 0 {
+ return false, nil
+ }
+ return true, nil
+}
+func (ds *DataSource) GetRole(ctx context.Context, key string) (*rbacframe.Role, error) {
+ resp, err := client.Instance().Do(ctx, client.GET,
+ client.WithStrKey(kv.GenerateETCDRoleKey(key)))
+ if err != nil {
+ return nil, err
+ }
+ if resp.Count != 1 {
+ return nil, client.ErrNotUnique
+ }
+ role := &rbacframe.Role{}
+ err = json.Unmarshal(resp.Kvs[0].Value, role)
+ if err != nil {
+ log.Errorf(err, "role info format invalid")
+ return nil, err
+ }
+ return role, nil
+}
+func (ds *DataSource) ListRole(ctx context.Context, key string) ([]*rbacframe.Role, int64, error) {
+ resp, err := client.Instance().Do(ctx, client.GET,
+ client.WithStrKey(kv.GenerateETCDRoleKey(key)), client.WithPrefix())
Review comment:
拿到role列表为何需要一个role的名字
##########
File path: datasource/role.go
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 datasource
+
+import (
+ "context"
+ "errors"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+var (
+ ErrRoleDuplicated = errors.New("role is duplicated")
+ ErrRoleCanNotEdit = errors.New("role can not be edited")
+)
+
+// RoleManager contains the RBAC CRUD
+type RoleManager interface {
+ CreateRole(ctx context.Context, r *rbacframe.Role) error
+ RoleExist(ctx context.Context, key string) (bool, error)
+ GetRole(ctx context.Context, key string) (*rbacframe.Role, error)
+ ListRole(ctx context.Context, key string) ([]*rbacframe.Role, int64, error)
Review comment:
list不需要name作为入参
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,74 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
Review comment:
这个多role还没支持
##########
File path: pkg/rbacframe/resource_dao.go
##########
@@ -35,3 +35,12 @@ func GetResource(api string) string {
func MapResource(api, resource string) {
resourceMap[api] = resource
}
+
+//AddResourceType join the resource to an array
+func AddResourceType(resourceType ...string) []string {
Review comment:
没看到rt用在哪了
##########
File path: datasource/role.go
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 datasource
+
+import (
+ "context"
+ "errors"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+var (
+ ErrRoleDuplicated = errors.New("role is duplicated")
+ ErrRoleCanNotEdit = errors.New("role can not be edited")
+)
+
+// RoleManager contains the RBAC CRUD
+type RoleManager interface {
+ CreateRole(ctx context.Context, r *rbacframe.Role) error
+ RoleExist(ctx context.Context, key string) (bool, error)
Review comment:
input就别叫key了,改成name
##########
File path: server/service/rbac/decision.go
##########
@@ -19,26 +19,53 @@ package rbac
import (
"context"
+ "github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/server/service/rbac/dao"
)
func Allow(ctx context.Context, role, project, resource, verbs string) (bool, error) {
- r := dao.GetRole(ctx, role)
+ r, err := datasource.Instance().GetRole(ctx, role)
+ if err != nil {
+ log.Error("get role list errors", err)
+ return false, err
+ }
if r == nil {
log.Warn("empty role info")
return false, nil
}
+ //TODO check project
+
ps := r.Permissions
if len(ps) == 0 {
log.Warn("role has no any permissions")
return false, nil
}
- p, ok := ps[resource]
- if !ok || p == nil {
- log.Warn("role is not allowed to access resource")
- return false, nil
+
+ for i := 0; i < len(ps); i++ {
+ pr := ps[i].Resources
+ contains := inStrSlice(pr, resource)
+ if contains {
+ return allowVerbs(ps[i].Verbs, verbs), nil
+ }
+ }
+
+ log.Warn("role is not allowed to operate resource")
+ return false, nil
+}
+
+func inStrSlice(haystack []string, needle string) bool {
Review comment:
inStrSlice方法名起的不够易懂,应该是ableToAccessResource
##########
File path: server/service/rbac/permission.go
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbac
+
+import "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+
+// method to verbs
+var (
+ MethodToVerbs = map[string]string{
+ "GET": "get",
+ "POST": "create",
+ "UPDATE": "update",
+ "DELETE": "delete",
+ }
+)
+
+// AdminPerms allocate all resource permissions
+func AdminPerms() []*rbacframe.Permission {
+ resources := rbacframe.AddResourceType(ResourceAccount, ResourceRole, ResourceService, ResourceInstance,
+ ResourceDep, ResourceTag, ResourceRule, ResourceGovern, ResourceAdminister, ResourceSchema)
+ perm := []*rbacframe.Permission{
+ {
+ Resources: resources,
+ Verbs: []string{"*"},
+ },
+ }
+ return perm
+}
+
+// DevPerms allocate all resource permissions except account and role resources
+func DevPerms() []*rbacframe.Permission {
+ resources := rbacframe.AddResourceType(ResourceService, ResourceInstance,
Review comment:
我明白了AddResourceType是什么,你不如叫buildResourceList
##########
File path: server/service/rbac/decision.go
##########
@@ -19,26 +19,53 @@ package rbac
import (
"context"
+ "github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/server/service/rbac/dao"
)
func Allow(ctx context.Context, role, project, resource, verbs string) (bool, error) {
- r := dao.GetRole(ctx, role)
+ r, err := datasource.Instance().GetRole(ctx, role)
+ if err != nil {
+ log.Error("get role list errors", err)
+ return false, err
+ }
if r == nil {
log.Warn("empty role info")
return false, nil
}
+ //TODO check project
+
ps := r.Permissions
if len(ps) == 0 {
log.Warn("role has no any permissions")
return false, nil
}
- p, ok := ps[resource]
- if !ok || p == nil {
- log.Warn("role is not allowed to access resource")
- return false, nil
+
+ for i := 0; i < len(ps); i++ {
+ pr := ps[i].Resources
+ contains := inStrSlice(pr, resource)
+ if contains {
+ return allowVerbs(ps[i].Verbs, verbs), nil
Review comment:
allowVerbs不要最后返回这个方法的结果,虽然结果正确,但是代码不易读,应该是一个大方法判断resource和verbs,比如叫ableToOperateResource
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531816695
##########
File path: docs/user-guides/rbac.md
##########
@@ -70,21 +70,111 @@ curl -X PUT \
}'
```
-### create a new account by account which has admin role
+### create a new account
```shell script
curl -X POST \
http://127.0.0.1:30100/v4/account \
-H 'Accept: */*' \
- -H 'Authorization: Bearer {your_token}' \
+ -H 'Authorization: Bearer {root_token}' \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
Review comment:
等你的标题是create new role,然后里面介绍就是创建账号
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] SmartsYoung removed a comment on pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
SmartsYoung removed a comment on pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#issuecomment-730101800
现在pr的内容较多,支持多role的功能会在下一次提交中补全功能
| |
yangcong
|
|
yangcong_hit@163.com
|
签名由网易邮箱大师定制
On 11/18/2020 18:42,Shawn<no...@github.com> wrote:
@tianxiaoliang requested changes on this pull request.
In pkg/rbacframe/role.go:
> + */
+
+package rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Permissions []*Permission `json:"permissions,omitempty"`
+}
+
+type Permission struct {
+ Resources []string
这里没有进行tag定义
In pkg/rbacframe/role.go:
> + * 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 rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Permissions []*Permission `json:"permissions,omitempty"`
简化为perms
In pkg/rbacframe/resource_dao.go:
> @@ -35,3 +35,12 @@ func GetResource(api string) string {
func MapResource(api, resource string) {
resourceMap[api] = resource
}
+
+//AddResourceType join the resource to an array
+func AddResourceType(resourceType ...string) []string {
没看到rt用在哪了
In docs/user-guides/rbac.md:
> + ]
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
这个多role还没支持
In datasource/role.go:
> +
+import (
+ "context"
+ "errors"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+var (
+ ErrRoleDuplicated = errors.New("role is duplicated")
+ ErrRoleCanNotEdit = errors.New("role can not be edited")
+)
+
+// RoleManager contains the RBAC CRUD
+type RoleManager interface {
+ CreateRole(ctx context.Context, r *rbacframe.Role) error
+ RoleExist(ctx context.Context, key string) (bool, error)
input就别叫key了,改成name
In datasource/role.go:
> + "context"
+ "errors"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+var (
+ ErrRoleDuplicated = errors.New("role is duplicated")
+ ErrRoleCanNotEdit = errors.New("role can not be edited")
+)
+
+// RoleManager contains the RBAC CRUD
+type RoleManager interface {
+ CreateRole(ctx context.Context, r *rbacframe.Role) error
+ RoleExist(ctx context.Context, key string) (bool, error)
+ GetRole(ctx context.Context, key string) (*rbacframe.Role, error)
+ ListRole(ctx context.Context, key string) ([]*rbacframe.Role, int64, error)
list不需要name作为入参
In datasource/etcd/role.go:
> + return nil, err
+ }
+ if resp.Count != 1 {
+ return nil, client.ErrNotUnique
+ }
+ role := &rbacframe.Role{}
+ err = json.Unmarshal(resp.Kvs[0].Value, role)
+ if err != nil {
+ log.Errorf(err, "role info format invalid")
+ return nil, err
+ }
+ return role, nil
+}
+func (ds *DataSource) ListRole(ctx context.Context, key string) ([]*rbacframe.Role, int64, error) {
+ resp, err := client.Instance().Do(ctx, client.GET,
+ client.WithStrKey(kv.GenerateETCDRoleKey(key)), client.WithPrefix())
拿到role列表为何需要一个role的名字
In server/service/rbac/decision.go:
> - log.Warn("role is not allowed to access resource")
- return false, nil
+
+ for i := 0; i < len(ps); i++ {
+ pr := ps[i].Resources
+ contains := inStrSlice(pr, resource)
+ if contains {
+ return allowVerbs(ps[i].Verbs, verbs), nil
+ }
+ }
+
+ log.Warn("role is not allowed to operate resource")
+ return false, nil
+}
+
+func inStrSlice(haystack []string, needle string) bool {
inStrSlice方法名起的不够易懂,应该是ableToAccessResource
In server/service/rbac/decision.go:
> ps := r.Permissions
if len(ps) == 0 {
log.Warn("role has no any permissions")
return false, nil
}
- p, ok := ps[resource]
- if !ok || p == nil {
- log.Warn("role is not allowed to access resource")
- return false, nil
+
+ for i := 0; i < len(ps); i++ {
+ pr := ps[i].Resources
+ contains := inStrSlice(pr, resource)
+ if contains {
+ return allowVerbs(ps[i].Verbs, verbs), nil
allowVerbs不要最后返回这个方法的结果,虽然结果正确,但是代码不易读,应该是一个大方法判断resource和verbs,比如叫ableToOperateResource
In server/service/rbac/permission.go:
> +// AdminPerms allocate all resource permissions
+func AdminPerms() []*rbacframe.Permission {
+ resources := rbacframe.AddResourceType(ResourceAccount, ResourceRole, ResourceService, ResourceInstance,
+ ResourceDep, ResourceTag, ResourceRule, ResourceGovern, ResourceAdminister, ResourceSchema)
+ perm := []*rbacframe.Permission{
+ {
+ Resources: resources,
+ Verbs: []string{"*"},
+ },
+ }
+ return perm
+}
+
+// DevPerms allocate all resource permissions except account and role resources
+func DevPerms() []*rbacframe.Permission {
+ resources := rbacframe.AddResourceType(ResourceService, ResourceInstance,
我明白了AddResourceType是什么,你不如叫buildResourceList
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang merged pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang merged pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r530826693
##########
File path: server/service/rbac/resource.go
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbac
+
+import "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+
+const (
+ ResourceAccount = "account"
+ ResourceRole = "role"
+ ResourceService = "service"
+ ResourceInstance = "instance"
+ ResourceDep = "dependencies"
+ ResourceRule = "rule"
+ ResourceTag = "tag"
+ ResourceGovern = "governance"
+ ResourceSchema = "schema"
+ ResourceAdminister = "administer"
+)
+
+var (
+ Health = "/v4/:project/registry/health"
+ Version = "/v4/:project/registry/version"
+ TokenGranter = "/v4/token"
+
+ AccountList = "/v4/account"
Review comment:
已修改
##########
File path: pkg/rbacframe/api.go
##########
@@ -74,3 +76,27 @@ func Authenticate(tokenStr string, pub *rsa.PublicKey) (interface{}, error) {
}
return claims, nil
}
+
+// TypeOfRole return role list string
+func TypeOfRole(v interface{}) ([]string, error) {
Review comment:
在authr_plugin.go中66行,
```
tokenStr, err := token.Sign(map[string]interface{}{
rbacframe.ClaimsUser: user,
rbacframe.ClaimsRole: account.Roles,
},
```
传tokenStr中accountRoles对应了interface{},之前role是字符串,现在改成roles是字符串切片,得到tokenStr时,传入函数时, Authenticate(tokenStr string, pub *rsa.PublicKey)(interface{}, error) 又返回了interface{},因此string仍对应interface{},而[]string对应的是[]interface{}。引入反射是因为若只角色字段参数只传递一次,角色信息断言仍是[]string
##########
File path: docs/user-guides/rbac.md
##########
@@ -80,11 +80,104 @@ curl -X POST \
-d '{
"name":"peter",
"password":"{strong_password}",
- "role":"developer"
+ "roles": ["developer"]
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "roles": ["tester", "tester2"]
+}'
+```
+2.then, allocate resources to new role "tester"
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/role \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}'
+```
+and continue allocate resources to new role "tester2".
+
+3.Next, generate a token for the user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/token \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "roles": ["tester", "tester2"]
Review comment:
产生token不是必须带角色的,已删除
##########
File path: datasource/etcd/path/key_generator.go
##########
@@ -68,6 +68,14 @@ func GetProjectRootKey(domain string) string {
}, SPLIT)
}
+func GenerateETCDRoleKey(name string) string {
Review comment:
这部分是为了对应上下文统一格式,已更改为 GenerateRBACRoleKey删除
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r527515269
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,74 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
Review comment:
已经补全此部分内容
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#issuecomment-732890580
> 冲突
已解决冲突
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r530946448
##########
File path: pkg/rbacframe/api.go
##########
@@ -74,3 +76,27 @@ func Authenticate(tokenStr string, pub *rsa.PublicKey) (interface{}, error) {
}
return claims, nil
}
+
+// TypeOfRole return role list string
+func TypeOfRole(v interface{}) ([]string, error) {
Review comment:
没问题,改吧,不能用反射做断言
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r517092871
##########
File path: server/resource/register.go
##########
@@ -31,6 +31,7 @@ func init() {
func initRouter() {
if rbac.Enabled() {
roa.RegisterServant(&v4.AuthResource{})
+ roa.RegisterServant(&v4.RBACRole{})
Review comment:
风格保持一致,role resource
##########
File path: pkg/rbacframe/resource.go
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbacframe
+
+const (
+ ResourceAccount = "account"
+ ResourceRole = "role"
+ ResourceService = "service"
+ ResourceInstance = "instance"
+ ResourceDep = "dependencies"
+ ResourceRule = "rule"
+ ResourceTag = "tag"
+ ResourceGovern = "governance"
+ ResourceSchema = "schema"
+ ResourceAdminister = "administer"
+)
+
+// HTTP METHODS
+var (
+ GET = "GET"
+ POST = "POST"
+ UPDATE = "PUT"
+ DELETE = "DELETE"
+)
+
+var (
+ // WhiteList API's
+ Health = "/v4/:project/registry/health"
Review comment:
rbacframe包是给sc,kie共用的通用开发库,所以这些特性的API,应该挪到server/service/rbac/resource.go
##########
File path: server/service/rbac/decision.go
##########
@@ -21,24 +21,35 @@ import (
"context"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/server/service/rbac/dao"
+ "strings"
)
-func Allow(ctx context.Context, role, project, resource, verbs string) (bool, error) {
- r := dao.GetRole(ctx, role)
+func Allow(ctx context.Context, role, project, api, verbs string) (bool, error) {
Review comment:
api参数,更准确的命名是apiPattern
##########
File path: server/service/rbac/permission.go
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbac
+
+import "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+
+// verbs
+var (
+ GET = "GET"
Review comment:
verbs不应该是http的,而是get, create, delete, update
##########
File path: pkg/rbacframe/role.go
##########
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbacframe
+
+type RoleResponse struct {
+ Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Project []string `json:"project,omitempty"`
Review comment:
role不该属于一个project
##########
File path: server/resource/v4/rbac_role.go
##########
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 v4
+
+import (
+ "context"
+ "encoding/json"
+ errorsEx "github.com/apache/servicecomb-service-center/pkg/errors"
+ "github.com/apache/servicecomb-service-center/pkg/log"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+ "github.com/apache/servicecomb-service-center/pkg/rest"
+ "github.com/apache/servicecomb-service-center/server/rest/controller"
+ "github.com/apache/servicecomb-service-center/server/scerror"
+ "github.com/apache/servicecomb-service-center/server/service/rbac/dao"
+ "io/ioutil"
+ "net/http"
+)
+
+type RBACRole struct {
+}
+
+//URLPatterns define htp pattern
+func (r *RBACRole) URLPatterns() []rest.Route {
+ return []rest.Route{
+ {Method: http.MethodGet, Path: "/v4/permission/account/role", Func: r.GetRolePermission},
Review comment:
简化为 /v4/role
##########
File path: server/service/rbac/decision.go
##########
@@ -21,24 +21,35 @@ import (
"context"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/server/service/rbac/dao"
+ "strings"
)
-func Allow(ctx context.Context, role, project, resource, verbs string) (bool, error) {
- r := dao.GetRole(ctx, role)
+func Allow(ctx context.Context, role, project, api, verbs string) (bool, error) {
+ r, err := dao.GetRole(ctx, role)
Review comment:
如果每次校验都要查数据库,太慢了,做缓存
##########
File path: pkg/rbacframe/resource.go
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbacframe
+
+const (
+ ResourceAccount = "account"
+ ResourceRole = "role"
+ ResourceService = "service"
+ ResourceInstance = "instance"
+ ResourceDep = "dependencies"
+ ResourceRule = "rule"
+ ResourceTag = "tag"
+ ResourceGovern = "governance"
+ ResourceSchema = "schema"
+ ResourceAdminister = "administer"
+)
+
+// HTTP METHODS
+var (
+ GET = "GET"
Review comment:
用户定义时看到的方法应该是create,get,delete,update,而不是原生的http method,所以也要做映射
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#issuecomment-732734601
冲突
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531926325
##########
File path: docs/user-guides/rbac.md
##########
@@ -79,12 +80,100 @@ curl -X POST \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
Review comment:
该用户除了访问白名单和修改自己的密码之外,没有其它任何权限
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r519689528
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,74 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, <u>_/v4/account/:name_</u> belong to resource type of **account**, has the permission to create or delete user account, <u>_/v4/account/:name/password_</u> belong to resource type of **account**, has the permission to change user password, <u>_/v4/:project/registry/microservices_</u> belong to resource type of **service**, has the permission to create, add or delete microservices. For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/pkg/rbacframe/resource.go]()
+
+```json
+{
+ "resources": [ "account", "service"],
+ "permissions": {
+ "/v4/account/:name": "get,delete",
+ "/v4/account/:name/password": "create",
Review comment:
这部分应该是设计文档,不是用户使用文档
api对应什么resource是内置的代码,没有对最终用户接口,用户不可自定义resource
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,74 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, <u>_/v4/account/:name_</u> belong to resource type of **account**, has the permission to create or delete user account, <u>_/v4/account/:name/password_</u> belong to resource type of **account**, has the permission to change user password, <u>_/v4/:project/registry/microservices_</u> belong to resource type of **service**, has the permission to create, add or delete microservices. For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/pkg/rbacframe/resource.go]()
+
+```json
+{
+ "resources": [ "account", "service"],
+ "permissions": {
+ "/v4/account/:name": "get,delete",
+ "/v4/account/:name/password": "create",
+ "/v4/:project/registry/microservices": "get,create,delete"
+ }
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
+}'
+```
+then, allocate resources to new role
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/role \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name": "tester",
+ "resources": ["services", "instance"],
+ "permissions": {
+ "/v4/:project/registry/microservices/:serviceId/instances": "get,create",
+ "/v4/:project/registry/microservices/:serviceId/instances/:instanceId": "get, delete",
+ "/v4/:project/registry/microservices/:serviceId/instances/:instanceId/heartbeat": "update",
Review comment:
这样的定义也不太符合我的预期,role应该只对应resource的action权限,不会涉及API定义
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r530740998
##########
File path: datasource/etcd/path/key_generator.go
##########
@@ -68,6 +68,14 @@ func GetProjectRootKey(domain string) string {
}, SPLIT)
}
+func GenerateETCDRoleKey(name string) string {
Review comment:
没必要在方法签名增加ETCD这种多余信息
##########
File path: docs/user-guides/rbac.md
##########
@@ -80,11 +80,104 @@ curl -X POST \
-d '{
"name":"peter",
"password":"{strong_password}",
- "role":"developer"
+ "roles": ["developer"]
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "roles": ["tester", "tester2"]
+}'
+```
+2.then, allocate resources to new role "tester"
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/role \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}'
+```
+and continue allocate resources to new role "tester2".
+
+3.Next, generate a token for the user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/token \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "roles": ["tester", "tester2"]
Review comment:
为何gen token要填写role
##########
File path: server/service/rbac/resource.go
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 rbac
+
+import "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+
+const (
+ ResourceAccount = "account"
+ ResourceRole = "role"
+ ResourceService = "service"
+ ResourceInstance = "instance"
+ ResourceDep = "dependencies"
+ ResourceRule = "rule"
+ ResourceTag = "tag"
+ ResourceGovern = "governance"
+ ResourceSchema = "schema"
+ ResourceAdminister = "administer"
+)
+
+var (
+ Health = "/v4/:project/registry/health"
+ Version = "/v4/:project/registry/version"
+ TokenGranter = "/v4/token"
+
+ AccountList = "/v4/account"
Review comment:
这类以API开头
##########
File path: pkg/rbacframe/api.go
##########
@@ -74,3 +76,27 @@ func Authenticate(tokenStr string, pub *rsa.PublicKey) (interface{}, error) {
}
return claims, nil
}
+
+// TypeOfRole return role list string
+func TypeOfRole(v interface{}) ([]string, error) {
Review comment:
为何引入反射?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531575013
##########
File path: docs/user-guides/rbac.md
##########
@@ -70,21 +70,111 @@ curl -X PUT \
}'
```
-### create a new account by account which has admin role
+### create a new account
```shell script
curl -X POST \
http://127.0.0.1:30100/v4/account \
-H 'Accept: */*' \
- -H 'Authorization: Bearer {your_token}' \
+ -H 'Authorization: Bearer {root_token}' \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
Review comment:
这个是创建用户时为用户添加了两个空角色,这两个空角色还没有任何资源,第二步才是为角色分配资源;对于
1. 先创建角色并分配资源,然后再为用户添加角色;
2. 先为用户添加空角色,再为角色分配资源;
个人理解这两种方式都是可以的
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531827923
##########
File path: docs/user-guides/rbac.md
##########
@@ -70,21 +70,111 @@ curl -X PUT \
}'
```
-### create a new account by account which has admin role
+### create a new account
```shell script
curl -X POST \
http://127.0.0.1:30100/v4/account \
-H 'Accept: */*' \
- -H 'Authorization: Bearer {your_token}' \
+ -H 'Authorization: Bearer {root_token}' \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
Review comment:
已更改
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531816695
##########
File path: docs/user-guides/rbac.md
##########
@@ -70,21 +70,111 @@ curl -X PUT \
}'
```
-### create a new account by account which has admin role
+### create a new account
```shell script
curl -X POST \
http://127.0.0.1:30100/v4/account \
-H 'Accept: */*' \
- -H 'Authorization: Bearer {your_token}' \
+ -H 'Authorization: Bearer {root_token}' \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
Review comment:
等你的标题是create new role,然后里面介绍就是创建账号,创建账号应该在独立章节介绍,然后才是role manage ment
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r530943868
##########
File path: pkg/rbacframe/api.go
##########
@@ -74,3 +76,27 @@ func Authenticate(tokenStr string, pub *rsa.PublicKey) (interface{}, error) {
}
return claims, nil
}
+
+// TypeOfRole return role list string
+func TypeOfRole(v interface{}) ([]string, error) {
Review comment:
这里面确实是roles啊!应该是ClaimsRole改成ClaimsRoles更准确
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r530939136
##########
File path: pkg/rbacframe/api.go
##########
@@ -74,3 +76,27 @@ func Authenticate(tokenStr string, pub *rsa.PublicKey) (interface{}, error) {
}
return claims, nil
}
+
+// TypeOfRole return role list string
+func TypeOfRole(v interface{}) ([]string, error) {
Review comment:
不要搞复杂,这里面就是roles,没有role
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r526635881
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,62 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": {
+ "account": "create, update, delete",
+ "service": "*"
+ }
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
Review comment:
下一次提交中添加此功能
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#issuecomment-731888963
@tianxiaoliang
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r525646678
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,62 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": {
+ "account": "create, update, delete",
+ "service": "*"
+ }
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
+}'
+```
+then, allocate resources to new role
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/role \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name": "tester",
+ "permissions": {
+ "service": "get, delete",
Review comment:
这个要考虑下扩展性
```
perms:
- resources: ["service","instance"]
verbs: ["get", "list", "create"]
- resources: ["account"]
verbs: ["get"]
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531529543
##########
File path: docs/user-guides/rbac.md
##########
@@ -70,21 +70,111 @@ curl -X PUT \
}'
```
-### create a new account by account which has admin role
+### create a new account
```shell script
curl -X POST \
http://127.0.0.1:30100/v4/account \
-H 'Accept: */*' \
- -H 'Authorization: Bearer {your_token}' \
+ -H 'Authorization: Bearer {root_token}' \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
-- admin: able to do anything, including manage account, even change other account password
-- developer: able to call most of API except account management. except account management
+currently, two default roles are provided. rbac feature is in early development stage.
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "perms": [
+ {
+ "resources": ["service","instance"],
+ "verbs": ["get", "create", "update"]
+ },
+ {
+ "resources": ["rule"],
+ "verbs": ["get"]
+ }
+ ]
+}
+```
+
+### create new role
+1. You can add new role for user. Now, a user can be own more roles.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
Review comment:
account 路径写错了,创建角色不该是创建账户,另外这个body体也不对
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r525646678
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,62 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": {
+ "account": "create, update, delete",
+ "service": "*"
+ }
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
+}'
+```
+then, allocate resources to new role
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/role \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name": "tester",
+ "permissions": {
+ "service": "get, delete",
Review comment:
这个要考虑下扩展性
```
perms:
- resources: ["service","instance"]
verbs: ["get", "list", "watch"]
- resources: ["account"]
verbs: ["get"]
```
##########
File path: docs/user-guides/rbac.md
##########
@@ -85,6 +85,62 @@ curl -X POST \
}'
```
### Roles
-currently, you can not custom and manage any role and role policy. there is only 2 build in roles. rbac feature is in early development stage.
+currently, two default roles are provided. rbac feature is in early development stage.
- admin: able to do anything, including manage account, even change other account password
- developer: able to call most of API except account management. except account management
+You can also create new role and allocate resources to new role.
+
+### API and resources
+All APIs of the system are divided according to their attributes. For example, resource account has the permission to create or update or delete user account when assign the corresponding permissions, resource service has all permission to create, get, add or delete microservices when permissions equal to "*". For more details to see [https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go]()
+
+ ```json
+{
+ "name": "tester",
+ "permissions": {
+ "account": "create, update, delete",
+ "service": "*"
+ }
+}
+```
+
+### create new role
+you can add new role for user.
+```shell script
+curl -X POST \
+ http://127.0.0.1:30100/v4/account \
+ -H 'Accept: */*' \
+ -H 'Authorization: Bearer {your_token}' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "name":"dev_test",
+ "password":"{strong_password}",
+ "role":"tester"
Review comment:
一个账户可以有多个角色
```json
{
"name":"dev_test",
"password":"{strong_password}",
"roles":["tester"]
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531938896
##########
File path: docs/user-guides/rbac.md
##########
@@ -79,12 +80,100 @@ curl -X POST \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
Review comment:
访问白名单是什么功能
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531941907
##########
File path: docs/user-guides/rbac.md
##########
@@ -79,12 +80,100 @@ curl -X POST \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
Review comment:
health, version, 以及生成token这三个api
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] hityc2019 commented on pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
hityc2019 commented on pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#issuecomment-734729526
@tianxiaoliang
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #736: [SCB-2093]Add roles to control access to API resources
Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #736:
URL: https://github.com/apache/servicecomb-service-center/pull/736#discussion_r531922485
##########
File path: docs/user-guides/rbac.md
##########
@@ -79,12 +80,100 @@ curl -X POST \
-H 'Content-Type: application/json' \
-d '{
"name":"peter",
- "password":"{strong_password}",
- "role":"developer"
-
+ "password":"{strong_password}"
Review comment:
如果不给用户角色,默认会如何
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org