Repository navigation
Expand file tree
/
Copy path20-API-Key-RBAC.yaml
More file actions
70 lines (69 loc) · 1.7 KB
/
Copy path20-API-Key-RBAC.yaml
File metadata and controls
70 lines (69 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# yaml-language-server: $schema=https://www.membrane-api.io/v7.7.1.json
#
# Tutorial: API Key RBAC (Role-Based Access Control)
#
# API keys carry scopes that determine what a caller may access.
# Authentication is optional — callers without a key reach the public path.
#
# 1.) Start Membrane:
# with Docker:
# Linux/Mac:
# ./run-docker.sh -c 20-API-Key-RBAC.yaml
# Windows:
# run-docker.cmd -c 20-API-Key-RBAC.yaml
#
# or with Java:
# Linux/Mac:
# ./membrane.sh -c 20-API-Key-RBAC.yaml
# Windows:
# membrane.cmd -c 20-API-Key-RBAC.yaml
#
# 2.) No key → public path:
# curl localhost:2000
#
# Public area
#
# 3.) Finance key → finance path:
# curl localhost:2000 -H "X-Api-Key: key-finance"
#
# Finance area
#
# 4.) Admin key → admin path:
# curl localhost:2000 -H "X-Api-Key: key-admin"
#
# Admin area
api:
port: 2000
flow:
- apiKey:
required: false # unauthenticated callers are allowed through
stores:
- simple:
- secret:
value: key-finance
scopes: # scopes granted to this key
- finance
- secret:
value: key-admin
scopes:
- admin
extractors:
- header: X-Api-Key
- if:
test: hasScope('admin')
flow:
- template:
src: Admin area
- return:
status: 200
- if:
test: hasScope('finance')
flow:
- template:
src: Finance area
- return:
status: 200
- static:
src: Public area
- return:
status: 200