screwdriver-api 8.0.203 → 8.0.205
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/package.json
CHANGED
|
@@ -35,6 +35,13 @@ module.exports = () => ({
|
|
|
35
35
|
throw boom.notFound('Build does not exist');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// Ensure build scope tokens can only request secrets for their own build.
|
|
39
|
+
if (credentials.scope.includes('build')) {
|
|
40
|
+
if (parseInt(credentials.username, 10) !== parseInt(request.params.id, 10)) {
|
|
41
|
+
throw boom.forbidden('Token does not have permission to this secret');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
return build.secrets;
|
|
39
46
|
})
|
|
40
47
|
.then(secrets => {
|
|
@@ -161,7 +161,15 @@ module.exports = () => ({
|
|
|
161
161
|
|
|
162
162
|
// Apply state change and return early
|
|
163
163
|
applyStateChange(oldPipeline, state, username, stateChangeMessage);
|
|
164
|
-
|
|
164
|
+
let updatedPipeline;
|
|
165
|
+
|
|
166
|
+
// Screwdriver admins may not have valid pipeline-admin SCM credentials,
|
|
167
|
+
// so persist the state change without accessing SCM.
|
|
168
|
+
if (isScrewdriverAdmin) {
|
|
169
|
+
updatedPipeline = await (state === 'ACTIVE' ? oldPipeline.enable() : oldPipeline.disable());
|
|
170
|
+
} else {
|
|
171
|
+
updatedPipeline = await oldPipeline.update();
|
|
172
|
+
}
|
|
165
173
|
|
|
166
174
|
return h.response(updatedPipeline.toJson()).code(200);
|
|
167
175
|
}
|
|
@@ -200,7 +208,7 @@ module.exports = () => ({
|
|
|
200
208
|
}
|
|
201
209
|
|
|
202
210
|
applyStateChange(oldPipeline, state, username, stateChangeMessage);
|
|
203
|
-
const updatedPipeline = await oldPipeline.
|
|
211
|
+
const updatedPipeline = await (state === 'ACTIVE' ? oldPipeline.enable() : oldPipeline.disable());
|
|
204
212
|
|
|
205
213
|
return h.response(updatedPipeline.toJson()).code(200);
|
|
206
214
|
}
|
package/plugins/secrets/index.js
CHANGED
|
@@ -25,7 +25,6 @@ const secretsPlugin = {
|
|
|
25
25
|
* @param {Array} credentials.scope Scope of the credential (user, build, admin)
|
|
26
26
|
* @param {String} [credentials.pipelineId] If credential is a build, this is the pipeline ID
|
|
27
27
|
* @param {String} [credentials.configPipelineId] If credential is a build, this is the parent pipeline ID
|
|
28
|
-
* @param {String} [credentials.jobId] If credential is a build, this is the job ID
|
|
29
28
|
* @param {String} [credentials.isPR] If credential is a build, this is true if a PR
|
|
30
29
|
* @param {Object} secret Secret object from Hapi
|
|
31
30
|
* @param {String} permission Required permission level
|
|
@@ -33,7 +32,7 @@ const secretsPlugin = {
|
|
|
33
32
|
* @return {Boolean}
|
|
34
33
|
*/
|
|
35
34
|
server.expose('canAccess', async (credentials, secret, permission, app) => {
|
|
36
|
-
const { userFactory, pipelineFactory } = app;
|
|
35
|
+
const { buildFactory, userFactory, pipelineFactory, jobFactory } = app;
|
|
37
36
|
const { scmContext, scope, username } = credentials;
|
|
38
37
|
|
|
39
38
|
// Get secret pipeline
|
|
@@ -66,6 +65,27 @@ const secretsPlugin = {
|
|
|
66
65
|
return false;
|
|
67
66
|
}
|
|
68
67
|
|
|
68
|
+
// Check build scope
|
|
69
|
+
if (scope.includes('build')) {
|
|
70
|
+
const build = await buildFactory.get(username);
|
|
71
|
+
|
|
72
|
+
if (!build) {
|
|
73
|
+
throw boom.notFound(`Build ${username} does not exist`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const job = await jobFactory.get(build.jobId);
|
|
77
|
+
|
|
78
|
+
if (!job) {
|
|
79
|
+
throw boom.notFound(`Job ${build.jobId} does not exist`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const secrets = await job.secrets;
|
|
83
|
+
|
|
84
|
+
if (!secrets.some(jobSecret => jobSecret.id === secret.id)) {
|
|
85
|
+
throw boom.forbidden('Token does not have permission to this secret');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
69
89
|
// Check if secret belongs to current pipeline or parent pipeline
|
|
70
90
|
if (secret.pipelineId !== credentials.pipelineId && secret.pipelineId !== credentials.configPipelineId) {
|
|
71
91
|
throw boom.forbidden(`${username} is not allowed to access this secret`);
|