@adobe/helix-html-pipeline 5.1.3 → 5.2.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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/steps/authenticate.js +29 -10
- package/src/steps/utils.js +7 -0
- package/src/utils/json-filter.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [5.2.0](https://github.com/adobe/helix-html-pipeline/compare/v5.1.3...v5.2.0) (2023-11-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* implement partition specific auth ([#456](https://github.com/adobe/helix-html-pipeline/issues/456)) ([89fa4f1](https://github.com/adobe/helix-html-pipeline/commit/89fa4f1a7a8ddaecad3659f6eaa37416a4452744)), closes [#274](https://github.com/adobe/helix-html-pipeline/issues/274)
|
|
7
|
+
|
|
1
8
|
## [5.1.3](https://github.com/adobe/helix-html-pipeline/compare/v5.1.2...v5.1.3) (2023-11-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { getAuthInfo, makeAuthError } from '../utils/auth.js';
|
|
13
|
+
import { toArray } from './utils.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Checks if the given email is allowed.
|
|
@@ -27,6 +28,26 @@ export function isAllowed(email = '', allows = []) {
|
|
|
27
28
|
return allows.findIndex((a) => a === email || a === wild) >= 0;
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Returns the normalized access configuration for the current partition.
|
|
33
|
+
* @param state
|
|
34
|
+
* @return {{}}
|
|
35
|
+
*/
|
|
36
|
+
export function getAccessConfig(state) {
|
|
37
|
+
const { access } = state.config;
|
|
38
|
+
if (!access) {
|
|
39
|
+
return {
|
|
40
|
+
allow: [],
|
|
41
|
+
apiKeyId: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const { partition } = state;
|
|
45
|
+
return {
|
|
46
|
+
allow: toArray(access[partition]?.allow ?? access.allow),
|
|
47
|
+
apiKeyId: toArray(access[partition]?.apiKeyId ?? access.apiKeyId),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
/**
|
|
31
52
|
* Handles authentication
|
|
32
53
|
* @type PipelineStep
|
|
@@ -43,8 +64,11 @@ export async function authenticate(state, req, res) {
|
|
|
43
64
|
return;
|
|
44
65
|
}
|
|
45
66
|
|
|
67
|
+
// get partition relative auth info
|
|
68
|
+
const access = getAccessConfig(state);
|
|
69
|
+
|
|
46
70
|
// if not protected, do nothing
|
|
47
|
-
if (!
|
|
71
|
+
if (!access.allow.length) {
|
|
48
72
|
return;
|
|
49
73
|
}
|
|
50
74
|
|
|
@@ -77,20 +101,15 @@ export async function authenticate(state, req, res) {
|
|
|
77
101
|
|
|
78
102
|
// validate jti
|
|
79
103
|
if (jti) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
: [state.config.access.apiKeyId];
|
|
83
|
-
if (ids.indexOf(jti) < 0) {
|
|
84
|
-
state.log.warn(`[auth] invalid jti ${jti}: does not match configured id ${state.config.access.apiKeyId}`);
|
|
104
|
+
if (access.apiKeyId.indexOf(jti) < 0) {
|
|
105
|
+
state.log.warn(`[auth] invalid jti ${jti}: does not match configured id ${access.apiKeyId}`);
|
|
85
106
|
makeAuthError(state, req, res, 'invalid-jti');
|
|
86
107
|
}
|
|
87
108
|
}
|
|
88
109
|
|
|
89
110
|
// check profile is allowed
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!isAllowed(email, allows)) {
|
|
93
|
-
state.log.warn(`[auth] profile not allowed for ${allows}`);
|
|
111
|
+
if (!isAllowed(email, access.allow)) {
|
|
112
|
+
state.log.warn(`[auth] profile not allowed for ${access.allow}`);
|
|
94
113
|
makeAuthError(state, req, res, 'forbidden', 403);
|
|
95
114
|
}
|
|
96
115
|
}
|
package/src/steps/utils.js
CHANGED
package/src/utils/json-filter.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { PipelineStatusError } from '../PipelineStatusError.js';
|
|
13
|
+
import { toArray } from '../steps/utils.js';
|
|
13
14
|
|
|
14
15
|
const TYPE_KEY = ':type';
|
|
15
16
|
|
|
@@ -78,7 +79,7 @@ export default function jsonFilter(state, res, query) {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
state.timer?.update('json-filter');
|
|
81
|
-
const requestedSheets =
|
|
82
|
+
const requestedSheets = toArray(sheet);
|
|
82
83
|
if (requestedSheets.length === 0 && 'default' in json) {
|
|
83
84
|
requestedSheets.push('default');
|
|
84
85
|
}
|