screwdriver-api 8.0.204 → 8.0.206
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 => {
|
|
@@ -48,16 +48,26 @@ async function batchUpdatePipelineAdmins(pipelineConfigs, user, isSDAdmin, serve
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if (!isSDAdmin) {
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
if (pipeline.scmContext !== user.scmContext) {
|
|
52
|
+
throw boom.forbidden(
|
|
53
|
+
`User ${user.username} and pipeline (id=${pipeline.id}) have different SCM contexts`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let permissions;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
permissions = await user.getPermissions(pipeline.scmUri);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw boom.boomify(error, { statusCode: error.statusCode });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// check if user has admin access
|
|
66
|
+
if (!permissions.admin) {
|
|
67
|
+
throw boom.forbidden(
|
|
68
|
+
`User ${user.username} does not have admin permission for the pipeline (id=${pipeline.id}) repo and is not allowed to update admins`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
72
|
|
|
63
73
|
// check if pipeline is being deleted
|
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`);
|