Skip to content

Commit 13ae6f2

Browse files
rbac doc (#1037)
1 parent 9ed770a commit 13ae6f2

File tree

2 files changed

+172
-49
lines changed

2 files changed

+172
-49
lines changed

docs/user-guides/rbac.md

Lines changed: 171 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,53 @@
11
# RBAC
2-
alpha feature. now the feature is very simple in early stage. only has root account authentication
2+
Beta feature.
33

44
you can choose to enable RBAC feature, after enable RBAC, all request to service center must be authenticated
55

66
### Configuration file
7-
follow steps to enable this feature.
7+
Follow steps to enable this feature.
88

99
1.get rsa key pairs
1010
```sh
1111
openssl genrsa -out private.key 4096
1212
openssl rsa -in private.key -pubout -out public.key
1313
```
1414

15-
2.edit app.conf
16-
```ini
17-
rbac_enabled = true
18-
rbac_rsa_public_key_file = ./public.key # rsa key pairs
19-
rbac_rsa_private_key_file = ./private.key # rsa key pairs
20-
auth_plugin = buildin # must set to buildin
15+
2.edit app.yaml
16+
```yaml
17+
rbac:
18+
enable: true
19+
privateKeyFile: ./private.key # rsa key pairs
20+
publicKeyFile: ./public.key # rsa key pairs
21+
auth:
22+
kind: buildin # must set to buildin
2123
```
2224
3.root account
2325
24-
before you start server, you need to set env to set your root account password. Please note that password must conform to the [following set of rules](https://github.com/apache/servicecomb-service-center/blob/63722fadd511c26285e787eb2b4be516eab10b94/pkg/validate/matcher.go#L25): have at least 8 characters, have at most 32 characters, have at least one upper alpha, have at least one lower alpha, have at least one digit and have at lease one special character.
26+
before you start server, you need to set env to set your root account password.
27+
Please note that password must conform to the
28+
[following set of rules](https://github.com/apache/servicecomb-service-center/blob/63722fadd511c26285e787eb2b4be516eab10b94/pkg/validate/matcher.go#L25):
29+
have at least 8 characters, have at most 32 characters, have at least one upper alpha, have at least one lower alpha,
30+
have at least one digit and have at lease one special character.
2531
2632
```sh
2733
export SC_INIT_ROOT_PASSWORD='P4$$word'
2834
```
29-
at the first time service center cluster init, it will use this password to setup rbac module.
30-
you can revoke password by rest API after cluster started. but you can not use this env to revoke password after cluster started.
35+
At the first time service center cluster init, it will use this password to set up rbac module.
36+
you can revoke password by rest API after a cluster started. but you can not use **SC_INIT_ROOT_PASSWORD** to revoke password after a cluster started.
3137

32-
the root account name is "root"
38+
the initiated account name is fixed as "root"
3339

3440
To securely distribute your root account and private key,
3541
you can use kubernetes [secret](https://kubernetes.io/zh/docs/tasks/inject-data-application/distribute-credentials-secure/)
3642
### Generate a token
37-
token is the only credential to access rest API, before you access any API, you need to get a token
43+
Token is the only credential to access rest API, before you access any API, you need to get a token from service center
3844
```shell script
3945
curl -X POST \
4046
http://127.0.0.1:30100/v4/token \
4147
-d '{"name":"root",
4248
"password":"P4$$word"}'
4349
```
44-
will return a token, token will expired after 30m
50+
will return a token, token will expire after 30m
4551
```json
4652
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTI4MzIxODUsInVzZXIiOiJyb290In0.G65mgb4eQ9hmCAuftVeVogN9lT_jNg7iIOF_EAyAhBU"}
4753
```
@@ -59,19 +65,20 @@ curl -X GET \
5965
```
6066

6167
### Change password
62-
You must supply current password and token to update to new password
68+
You must supply a current password and token to update to new password
6369
```shell script
6470
curl -X POST \
6571
http://127.0.0.1:30100/v4/account/root/password \
6672
-H 'Authorization: Bearer {your_token}' \
6773
-d '{
6874
"currentPassword":"P4$$word",
69-
"password":"123"
75+
"password":"P4$$word1"
7076
}'
7177
```
7278

7379
### create a new account
74-
You can create new account named "peter", now peter has no any roles, also has no permission to operate resources. How to add roles and allocate resources please refer to next.
80+
You can create new account named "peter", and his role is developer.
81+
How to add roles and allocate resources please refer to next section.
7582
```shell script
7683
curl -X POST \
7784
http://127.0.0.1:30100/v4/account \
@@ -80,32 +87,131 @@ curl -X POST \
8087
-H 'Content-Type: application/json' \
8188
-d '{
8289
"name":"peter",
83-
"password":"{strong_password}"
90+
"roles":["developer"],
91+
"password":"{strong_password}"
8492
}'
8593
```
86-
### Roles
87-
Currently, two default roles are provided. You can also add new roles and assign resources.
8894

89-
### API and resources
90-
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 [here](https://github.com/apache/servicecomb-service-center/blob/master/server/service/rbac/resource.go).
91-
A new role named "tester" owns resources "service", "instance" and "rule".
92-
```json
95+
### Resource
96+
All APIs of the ServiceComb system is mapping to a **resource type**. resource is list as below:
97+
- service: permission to discover, register service and instance
98+
- governance: permission to manage traffic control policy, such as rate limiting
99+
- service/schema: permission to register and discover contract
100+
- account: permission to manage accounts
101+
- role: permission to manage roles
102+
- ops: permission to access admin API
103+
104+
declare a resource type that account can operate:
105+
```json
106+
{
107+
"resources": [
108+
{
109+
"type": "service"
110+
},
111+
{
112+
"type": "service/schema"
113+
}
114+
]
115+
}
116+
```
117+
### Label
118+
Define resource(only service resource) scope:
119+
- serviceName: specify service name
120+
- appId: specify which app that services belongs to
121+
- environment: specify env of the service
122+
123+
```json
124+
{
125+
"resources": [
126+
{
127+
"type": "service",
128+
"labels": {
129+
"serviceName": "order-service",
130+
"environment": "production"
131+
}
132+
},
133+
{
134+
"type": "service",
135+
"labels": {
136+
"serviceName": "order-service",
137+
"environment": "acceptance"
138+
}
139+
}
140+
]
141+
}
142+
```
143+
### Verbs
144+
Define what kind of action could be applied to a resource by an account, has 4 kinds:
145+
- get
146+
- delete
147+
- create
148+
- update
149+
150+
declare resource type and action:
151+
```json
93152
{
94-
"name": "tester",
95-
"perms": [
96-
{
97-
"resources": ["service","instance"],
98-
"verbs": ["get", "create", "update"]
99-
},
100-
{
101-
"resources": ["rule"],
102-
"verbs": ["get"]
103-
}
104-
]
153+
"resources": [
154+
{
155+
"type": "service"
156+
},
157+
{
158+
"type": "account"
159+
}
160+
],
161+
"verbs": [
162+
"get"
163+
]
105164
}
106165
```
107166

167+
### Roles
168+
Two default roles are provided after RBAC init:
169+
- admin: can operate account and role resource
170+
- developer: can operate any resource except account and role resource
171+
172+
each role include perms elements to indicates what kind of resource can be operated by this role, for example:
173+
174+
A role "TeamA" can get and create any services but can only delete or update "order-service"
175+
```json
176+
{
177+
"name": "TeamA",
178+
"perms": [
179+
{
180+
"resources": [
181+
{
182+
"type": "service"
183+
}
184+
],
185+
"verbs": [
186+
"get",
187+
"create"
188+
]
189+
},
190+
{
191+
"resources": [
192+
{
193+
"type": "service",
194+
"labels": {
195+
"serviceName": "order-service"
196+
}
197+
}
198+
],
199+
"verbs": [
200+
"update",
201+
"delete"
202+
]
203+
}
204+
]
205+
}
206+
```
207+
208+
209+
210+
108211
### create new role and how to use
212+
213+
You can also create a new role and give perms to this role.
214+
109215
1. You can add new role and allocate resources to new role. For example, a new role named "tester" and allocate resources to "tester".
110216
```shell script
111217
curl -X POST \
@@ -114,17 +220,34 @@ curl -X POST \
114220
-H 'Authorization: Bearer {your_token}' \
115221
-H 'Content-Type: application/json' \
116222
-d '{
117-
"name": "tester",
118-
"perms": [
119-
{
120-
"resources": ["service","instance"],
121-
"verbs": ["get", "create", "update"]
122-
},
123-
{
124-
"resources": ["rule"],
125-
"verbs": ["get"]
126-
}
127-
]
223+
"name": "TeamA",
224+
"perms": [
225+
{
226+
"resources": [
227+
{
228+
"type": "service"
229+
}
230+
],
231+
"verbs": [
232+
"get",
233+
"create"
234+
]
235+
},
236+
{
237+
"resources": [
238+
{
239+
"type": "service",
240+
"labels": {
241+
"serviceName": "order-service"
242+
}
243+
}
244+
],
245+
"verbs": [
246+
"update",
247+
"delete"
248+
]
249+
}
250+
]
128251
}'
129252
```
130253
2.then, assigning roles "tester" and "tester2" to user account "peter", "tester2" is a empty role has not any resources.
@@ -137,7 +260,7 @@ curl -X POST \
137260
-d '{
138261
"name":"peter",
139262
"password":"{strong_password}",
140-
"roles": ["tester", "tester2"]
263+
"roles": ["TeamA"]
141264
}'
142265
```
143266

@@ -151,7 +274,7 @@ curl -X POST \
151274
}'
152275
```
153276

154-
4.finally, user "peter" carry token to access the above allocated API resources would be permit, but access others API is not allowed.
277+
4.finally, user "peter" carry token to access resources.
155278

156279
for example
157280
```shell script

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/go-chassis/cari v0.4.1-0.20210601163026-bb6a506e336a
1919
github.com/go-chassis/foundation v0.3.1-0.20210513015331-b54416b66bcd
2020
github.com/go-chassis/go-archaius v1.5.1
21-
github.com/go-chassis/go-chassis/v2 v2.1.2-0.20210310004133-c9bc42149a18
21+
github.com/go-chassis/go-chassis/v2 v2.2.0
2222
github.com/go-chassis/kie-client v0.1.0
2323
github.com/golang/protobuf v1.4.3
2424
github.com/gorilla/websocket v1.4.2

0 commit comments

Comments
 (0)