Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(2700): Add audit log of operations on the Options page #2766

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/pipelines/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = () => ({
scmUri
};

logger.info(`[Audit] user ${user.username}:${scmContext} creates the pipeline for ${scmUri}.`);
pipeline = await pipelineFactory.create(pipelineConfig);

const collections = await collectionFactory.list({
Expand Down
8 changes: 7 additions & 1 deletion plugins/pipelines/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const idSchema = schema.models.pipeline.base.extract('id');

module.exports = () => ({
Expand Down Expand Up @@ -67,7 +68,12 @@ module.exports = () => ({
throw boom.boomify(error, { statusCode: error.statusCode });
})
// user has good permissions, remove the pipeline
.then(() => pipeline.remove())
.then(async () => {
logger.info(
`[Audit] user ${user.username}:${scmContext} deletes the pipeline pipelineId:${request.params.id}, scmUri:${pipeline.scmUri}.`
);
await pipeline.remove();
})
.then(() => h.response().code(204))
);
})
Expand Down
4 changes: 4 additions & 0 deletions plugins/pipelines/tokens/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const urlLib = require('url');
const pipelineIdSchema = schema.models.pipeline.base.extract('id');
const tokenCreateSchema = schema.models.token.create;
Expand Down Expand Up @@ -52,6 +53,9 @@ module.exports = () => ({
throw boom.conflict(`Token ${match.name} already exists`);
}

logger.info(
`[Audit] user ${username}:${scmContext} creates the token name:${request.payload.name} for pipelineId:${pipelineId}.`
);
const token = await tokenFactory.create({
name: request.payload.name,
description: request.payload.description,
Expand Down
4 changes: 4 additions & 0 deletions plugins/pipelines/tokens/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const tokenIdSchema = schema.models.token.base.extract('id');
const pipelineIdSchema = schema.models.pipeline.base.extract('id');
const { getUserPermissions, getScmUri } = require('../../helper');
Expand Down Expand Up @@ -52,6 +53,9 @@ module.exports = () => ({
throw boom.forbidden('Pipeline does not own token');
}

logger.info(
`[Audit] user ${username}:${scmContext} refreshes the token name:${token.name} for pipelineId:${pipelineId}.`
);
const refreshed = await token.refresh();

return h.response(refreshed.toJson()).code(200);
Expand Down
5 changes: 5 additions & 0 deletions plugins/pipelines/tokens/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const tokenIdSchema = schema.models.token.base.extract('id');
const pipelineIdSchema = schema.models.pipeline.base.extract('id');
const { getUserPermissions, getScmUri } = require('../../helper');
Expand Down Expand Up @@ -52,6 +53,10 @@ module.exports = () => ({
throw boom.forbidden('Pipeline does not own token');
}

logger.info(
`[Audit] user ${username}:${scmContext} deletes the token name:${token.name} for pipelineId:${pipeline.id}.`
);

return token.remove().then(() => h.response().code(204));
},
validate: {
Expand Down
7 changes: 7 additions & 0 deletions plugins/pipelines/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const idSchema = schema.models.pipeline.base.extract('id');
const { formatCheckoutUrl, sanitizeRootDir } = require('./helper');
const { getUserPermissions } = require('../helper');
Expand Down Expand Up @@ -138,6 +139,12 @@ module.exports = () => ({
oldPipeline.settings = { ...oldPipeline.settings, ...settings };
}

if (checkoutUrl || rootDir) {
logger.info(
`[Audit] user ${user.username}:${scmContext} updates the scmUri for pipelineID:${id} to ${oldPipeline.scmUri}.`
);
}

// update pipeline
const updatedPipeline = await oldPipeline.update();

Expand Down
4 changes: 4 additions & 0 deletions plugins/secrets/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const boom = require('@hapi/boom');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const urlLib = require('url');
const { getUserPermissions, getScmUri } = require('../helper');

Expand Down Expand Up @@ -56,6 +57,9 @@ module.exports = () => ({
throw boom.conflict(`Secret already exists with the ID: ${secret.id}`);
}

logger.info(
`[Audit] user ${user.username}:${scmContext} creates the secret key:${request.payload.name} for pipelineId:${request.payload.pipelineId}.`
);
const newSecret = await secretFactory.create(request.payload);

const location = urlLib.format({
Expand Down
8 changes: 7 additions & 1 deletion plugins/secrets/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const idSchema = schema.models.secret.base.extract('id');

module.exports = () => ({
Expand Down Expand Up @@ -32,7 +33,12 @@ module.exports = () => ({

// Make sure that user has permission before deleting
return canAccess(credentials, secret, 'admin', request.server.app)
.then(() => secret.remove())
.then(async () => {
logger.info(
`[Audit] user ${credentials.username}:${credentials.scmContext} deletes the secret key:${secret.name} from pipelineId:${secret.pipelineId}.`
);
await secret.remove();
})
.then(() => h.response().code(204));
})
.catch(err => {
Expand Down
5 changes: 5 additions & 0 deletions plugins/secrets/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const logger = require('screwdriver-logger');
const idSchema = schema.models.secret.base.extract('id');

module.exports = () => ({
Expand Down Expand Up @@ -36,6 +37,10 @@ module.exports = () => ({
secret[key] = request.payload[key];
});

logger.info(
`[Audit] user ${credentials.username}:${credentials.scmContext} updates the secret key:${secret.name} for pipelineId:${secret.pipelineId}.`
);

return secret.update();
})
.then(() => {
Expand Down