soajs.controller 4.2.42 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +43 -0
- package/.github/workflows/release.yml +94 -0
- package/ARCHITECTURE.md +193 -0
- package/Gruntfile.js +1 -1
- package/docs/configuration-custom-registry.md +421 -0
- package/docs/configuration-services-config.md +275 -0
- package/docs/data-flow.md +138 -0
- package/docs/deployment.md +205 -0
- package/docs/external-integrations.md +159 -0
- package/docs/gateway-routes.md +259 -0
- package/docs/maintenance-routes.md +308 -0
- package/docs/middleware/awareness.md +120 -0
- package/docs/middleware/cors.md +88 -0
- package/docs/middleware/enhancer.md +75 -0
- package/docs/middleware/favicon.md +36 -0
- package/docs/middleware/gotoService.md +146 -0
- package/docs/middleware/ip2ban.md +70 -0
- package/docs/middleware/key.md +196 -0
- package/docs/middleware/keyACL.md +139 -0
- package/docs/middleware/lastSeen.md +111 -0
- package/docs/middleware/maintenanceMode.md +81 -0
- package/docs/middleware/mt.md +568 -0
- package/docs/middleware/oauth.md +173 -0
- package/docs/middleware/response.md +106 -0
- package/docs/middleware/soajs.md +71 -0
- package/docs/middleware/traffic.md +190 -0
- package/docs/middleware/url.md +102 -0
- package/docs/multi-tenant-security.md +183 -0
- package/docs/request-flow.md +230 -0
- package/docs/service-discovery.md +167 -0
- package/mw/key/index.js +16 -1
- package/mw/mt/urac.js +21 -1
- package/mw/mt/utils.js +2 -0
- package/package.json +13 -13
- package/test/unit/mw/key/index.js +150 -0
- package/test/unit/mw/mt/urac.js +157 -4
- package/.travis.yml +0 -72
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Key ACL Middleware
|
|
2
|
+
|
|
3
|
+
**File:** `mw/keyACL/index.js`
|
|
4
|
+
|
|
5
|
+
**Order:** 12
|
|
6
|
+
|
|
7
|
+
The Key ACL middleware extracts and processes the Access Control List (ACL) from the tenant's key or package.
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
- Extracts ACL for the requested service
|
|
12
|
+
- Resolves ACL from application or package level
|
|
13
|
+
- Handles both old and new ACL schema formats
|
|
14
|
+
- Supports version-specific and method-specific ACL
|
|
15
|
+
|
|
16
|
+
## Flow
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Incoming Request (after key middleware)
|
|
20
|
+
│
|
|
21
|
+
▼
|
|
22
|
+
┌─────────────────┐
|
|
23
|
+
│ Have keyObj │ keyObj && packObj exist?
|
|
24
|
+
│ and packObj? │
|
|
25
|
+
└────────┬────────┘
|
|
26
|
+
│
|
|
27
|
+
├─── No ──▶ next()
|
|
28
|
+
│
|
|
29
|
+
▼
|
|
30
|
+
┌─────────────────────────┐
|
|
31
|
+
│ Extract ACL │ Priority:
|
|
32
|
+
│ for Service │ 1. keyObj.application.acl
|
|
33
|
+
└────────┬────────────────┘ 2. packObj.acl
|
|
34
|
+
│
|
|
35
|
+
▼
|
|
36
|
+
┌─────────────────────────┐
|
|
37
|
+
│ Detect Schema Type │ Old: apis/apisRegExp at root
|
|
38
|
+
│ │ New: versioned with methods
|
|
39
|
+
└────────┬────────────────┘
|
|
40
|
+
│
|
|
41
|
+
▼
|
|
42
|
+
┌─────────────────────────┐
|
|
43
|
+
│ Resolve Version │ Match requested version
|
|
44
|
+
│ (if versioned) │ or get latest from ACL
|
|
45
|
+
└────────┬────────────────┘
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
┌─────────────────────────┐
|
|
49
|
+
│ Extract Method- │ get, post, put, delete
|
|
50
|
+
│ Specific ACL │
|
|
51
|
+
└────────┬────────────────┘
|
|
52
|
+
│
|
|
53
|
+
▼
|
|
54
|
+
┌─────────────────────────┐
|
|
55
|
+
│ Store finalAcl │ req.soajs.controller.serviceParams.finalAcl
|
|
56
|
+
└────────┬────────────────┘
|
|
57
|
+
│
|
|
58
|
+
▼
|
|
59
|
+
next()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## ACL Resolution Priority
|
|
63
|
+
|
|
64
|
+
1. **Application ACL** - `keyObj.application.acl[serviceName]`
|
|
65
|
+
2. **Package ACL** - `packObj.acl[serviceName]`
|
|
66
|
+
|
|
67
|
+
## ACL Schema Formats
|
|
68
|
+
|
|
69
|
+
### Old Schema (Deprecated)
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
{
|
|
73
|
+
"serviceName": {
|
|
74
|
+
"access": true,
|
|
75
|
+
"apis": {
|
|
76
|
+
"/api/path": { "access": ["group1"] }
|
|
77
|
+
},
|
|
78
|
+
"apisRegExp": [
|
|
79
|
+
{ "regExp": /^\/api\/.*/, "access": ["group2"] }
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### New Schema (Versioned)
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
{
|
|
89
|
+
"serviceName": {
|
|
90
|
+
"1": { // Version
|
|
91
|
+
"access": true,
|
|
92
|
+
"apisPermission": "restricted",
|
|
93
|
+
"get": {
|
|
94
|
+
"apis": { "/user": {} }
|
|
95
|
+
},
|
|
96
|
+
"post": {
|
|
97
|
+
"apis": { "/user": { "access": ["admin"] } }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### New Schema (Method-Based, Non-Versioned)
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
{
|
|
108
|
+
"serviceName": {
|
|
109
|
+
"access": true,
|
|
110
|
+
"apisPermission": "restricted",
|
|
111
|
+
"get": {
|
|
112
|
+
"apis": { "/user": {} }
|
|
113
|
+
},
|
|
114
|
+
"post": {
|
|
115
|
+
"apis": { "/user": { "access": ["admin"] } }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Properties Set
|
|
122
|
+
|
|
123
|
+
| Property | Description |
|
|
124
|
+
|----------|-------------|
|
|
125
|
+
| `req.soajs.controller.serviceParams.finalAcl` | Processed ACL for the service |
|
|
126
|
+
|
|
127
|
+
## Error Codes
|
|
128
|
+
|
|
129
|
+
| Code | Description |
|
|
130
|
+
|------|-------------|
|
|
131
|
+
| 154 | Requested version not found in ACL |
|
|
132
|
+
|
|
133
|
+
## Usage Notes
|
|
134
|
+
|
|
135
|
+
- Runs after key middleware loads keyObj and packObj
|
|
136
|
+
- Application-level ACL overrides package ACL
|
|
137
|
+
- If no version specified, uses latest version from ACL
|
|
138
|
+
- Converts regex patterns for API matching
|
|
139
|
+
- Method-specific ACL inherits service-level `access` and `apisPermission`
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# LastSeen Middleware
|
|
2
|
+
|
|
3
|
+
**File:** `mw/lastSeen/index.js`
|
|
4
|
+
|
|
5
|
+
**Order:** 17
|
|
6
|
+
|
|
7
|
+
The LastSeen middleware asynchronously notifies a service (typically URAC) of user activity for tracking purposes.
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
- Tracks user activity (last seen time)
|
|
12
|
+
- Asynchronous notification (non-blocking)
|
|
13
|
+
- Configurable service endpoint
|
|
14
|
+
- Only tracks authenticated users
|
|
15
|
+
|
|
16
|
+
## Flow
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Incoming Request (after OAuth/MT)
|
|
20
|
+
│
|
|
21
|
+
▼
|
|
22
|
+
┌─────────────────┐
|
|
23
|
+
│ Call next() │ Continue immediately (non-blocking)
|
|
24
|
+
└────────┬────────┘
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
┌─────────────────────────┐
|
|
28
|
+
│ Have URAC Driver? │ req.soajs.uracDriver exists?
|
|
29
|
+
└────────┬────────────────┘
|
|
30
|
+
│
|
|
31
|
+
├─── No ──▶ (done)
|
|
32
|
+
│
|
|
33
|
+
▼
|
|
34
|
+
┌─────────────────────────┐
|
|
35
|
+
│ LastSeen Active? │ custom.gateway.value.lastSeen.active?
|
|
36
|
+
└────────┬────────────────┘
|
|
37
|
+
│
|
|
38
|
+
├─── No ──▶ (done)
|
|
39
|
+
│
|
|
40
|
+
▼
|
|
41
|
+
┌─────────────────────────┐
|
|
42
|
+
│ Get User ID │ From URAC profile
|
|
43
|
+
└────────┬────────────────┘
|
|
44
|
+
│
|
|
45
|
+
├─── No user ID ──▶ (done, log debug)
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
┌─────────────────────────┐
|
|
49
|
+
│ Resolve Service Host │ awareness.getHost()
|
|
50
|
+
└────────┬────────────────┘
|
|
51
|
+
│
|
|
52
|
+
├─── No host ──▶ (done, log debug)
|
|
53
|
+
│
|
|
54
|
+
▼
|
|
55
|
+
┌─────────────────────────┐
|
|
56
|
+
│ POST to LastSeen │ http://host:port/api
|
|
57
|
+
│ API (async) │ body: { network: ... }
|
|
58
|
+
└─────────────────────────┘
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
Located in `registry.custom.gateway.value.lastSeen`:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
{
|
|
67
|
+
"lastSeen": {
|
|
68
|
+
"active": true, // Enable tracking
|
|
69
|
+
"serviceName": "urac", // Target service
|
|
70
|
+
"serviceVersion": "3", // Service version
|
|
71
|
+
"api": "/user/last/seen", // API endpoint
|
|
72
|
+
"network": "internal" // Optional network identifier
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Field | Type | Default | Description |
|
|
78
|
+
|-------|------|---------|-------------|
|
|
79
|
+
| `active` | boolean | `false` | Enable/disable tracking |
|
|
80
|
+
| `serviceName` | string | `"urac"` | Service to notify |
|
|
81
|
+
| `serviceVersion` | string | `"3"` | Service version |
|
|
82
|
+
| `api` | string | `"/user/last/seen"` | API endpoint |
|
|
83
|
+
| `network` | string | - | Network identifier in request body |
|
|
84
|
+
|
|
85
|
+
## Request to URAC
|
|
86
|
+
|
|
87
|
+
**Method:** POST
|
|
88
|
+
|
|
89
|
+
**URL:** `http://{host}:{port}/user/last/seen`
|
|
90
|
+
|
|
91
|
+
**Headers:**
|
|
92
|
+
```
|
|
93
|
+
Content-Type: application/json
|
|
94
|
+
soajsinjectobj: <inject object from MT middleware>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Body:**
|
|
98
|
+
```javascript
|
|
99
|
+
{
|
|
100
|
+
"network": "internal" // If configured
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Usage Notes
|
|
105
|
+
|
|
106
|
+
- Non-blocking: calls `next()` immediately
|
|
107
|
+
- Only activates for authenticated users with URAC profile
|
|
108
|
+
- Errors are logged but don't affect the request
|
|
109
|
+
- Uses awareness for service host resolution
|
|
110
|
+
- Forwards `soajsinjectobj` header for authentication context
|
|
111
|
+
- Network identifier useful for tracking activity by location/network
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Maintenance Mode Middleware
|
|
2
|
+
|
|
3
|
+
**File:** `mw/maintenanceMode/index.js`
|
|
4
|
+
|
|
5
|
+
**Order:** 7
|
|
6
|
+
|
|
7
|
+
The Maintenance Mode middleware returns a configurable response when the gateway is in maintenance mode.
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
- Blocks all requests when maintenance mode is enabled
|
|
12
|
+
- Returns configurable status code and message
|
|
13
|
+
- Supports `Retry-After` header for clients
|
|
14
|
+
|
|
15
|
+
## Flow
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Incoming Request
|
|
19
|
+
│
|
|
20
|
+
▼
|
|
21
|
+
┌─────────────────────┐
|
|
22
|
+
│ Get Maintenance │ registry.custom.gateway.value.maintenanceMode
|
|
23
|
+
│ Mode Config │
|
|
24
|
+
└────────┬────────────┘
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
┌─────────────────────┐
|
|
28
|
+
│ Maintenance │ maintenanceMode.on === true?
|
|
29
|
+
│ Enabled? │
|
|
30
|
+
└────────┬────────────┘
|
|
31
|
+
│
|
|
32
|
+
├─── Yes ──▶ Return configured status/message
|
|
33
|
+
│ Set Retry-After header if configured
|
|
34
|
+
▼
|
|
35
|
+
next()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Located in `registry.custom.gateway.value.maintenanceMode`:
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
{
|
|
44
|
+
"maintenanceMode": {
|
|
45
|
+
"on": true, // Enable maintenance mode
|
|
46
|
+
"status": 503, // HTTP status code
|
|
47
|
+
"message": "System maintenance", // Response message
|
|
48
|
+
"retryAfter": 3600 // Retry-After header (seconds)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Field | Type | Default | Description |
|
|
54
|
+
|-------|------|---------|-------------|
|
|
55
|
+
| `on` | boolean | `false` | Enable/disable maintenance mode |
|
|
56
|
+
| `status` | number | `503` | HTTP status code |
|
|
57
|
+
| `message` | string | `"Maintenance mode is on, come back soon"` | Response message |
|
|
58
|
+
| `retryAfter` | number | - | Seconds until retry |
|
|
59
|
+
|
|
60
|
+
## Response
|
|
61
|
+
|
|
62
|
+
When maintenance mode is enabled:
|
|
63
|
+
```
|
|
64
|
+
HTTP/1.1 503 Service Unavailable
|
|
65
|
+
Content-Type: application/json
|
|
66
|
+
Retry-After: 3600
|
|
67
|
+
|
|
68
|
+
{
|
|
69
|
+
"result": false,
|
|
70
|
+
"errors": {
|
|
71
|
+
"codes": [xxx],
|
|
72
|
+
"details": [{ "code": xxx, "message": "System maintenance" }]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Usage Notes
|
|
78
|
+
|
|
79
|
+
- All requests blocked when enabled (no exceptions)
|
|
80
|
+
- Configure via Core DB custom registry
|
|
81
|
+
- Use maintenance port (5000) for health checks during maintenance
|