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:
[email protected]