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

Activity logs #193

Merged
merged 50 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4ad4efe
Added a basic framework for activity logs
vmatsiiako Dec 16, 2022
9218d2a
Fixed the padding issue in the login page
vmatsiiako Dec 17, 2022
2e84b7e
Initial schema ideas for logging
dangtony98 Dec 17, 2022
fae27a0
Changed text for the activity page
vmatsiiako Dec 18, 2022
939826f
Merge branch 'logging' into activity-logs
vmatsiiako Dec 18, 2022
9d41f75
Added Intercom to Docs
vmatsiiako Dec 18, 2022
648e3e3
Continue developing log schema
dangtony98 Dec 18, 2022
7d280d4
Added event filter for logs
vmatsiiako Dec 19, 2022
72664c5
Merge branch 'activity-logs' of https://github.com/Infisical/infisica…
dangtony98 Dec 21, 2022
6e50adb
Fix merge conflicts
dangtony98 Dec 21, 2022
009f9c6
Continue developing activity logs backend
dangtony98 Dec 21, 2022
019e90d
Fix merge conflicts
dangtony98 Dec 27, 2022
9497a26
Add v1 audit log backend models and wiring to push secrets
dangtony98 Dec 27, 2022
16f2405
Add audit logs to pulls, still need to refactor
dangtony98 Dec 27, 2022
6fa84bf
Fix merge conflicts
vmatsiiako Dec 28, 2022
3c349b1
Merge remote-tracking branch 'origin' into activity-logs
dangtony98 Jan 1, 2023
4dac65e
Begin action route for getting an action by id
dangtony98 Jan 1, 2023
ce66e55
Merge remote-tracking branch 'origin' into activity-logs
dangtony98 Jan 1, 2023
9c83808
Added populate statement
vmatsiiako Jan 1, 2023
4576e8f
Merge branch 'activity-logs' of https://github.com/Infisical/infisica…
dangtony98 Jan 1, 2023
0167342
Improved frontend for activity logs
vmatsiiako Jan 2, 2023
a8f0c39
Finish v1 audit logs, secret versioning, version all unversioned secrets
dangtony98 Jan 2, 2023
0294431
Modularize prepareDatabasse into initSecretVersioning
dangtony98 Jan 2, 2023
1c2a43c
Clean unecessary imports
dangtony98 Jan 2, 2023
4af8390
Patch actionNames on getWorkspacelogs
dangtony98 Jan 2, 2023
03b7d3a
Wired frontend for logs
vmatsiiako Jan 2, 2023
ae5320e
Finished activity logs V1
vmatsiiako Jan 2, 2023
1428679
Merge branch 'activity-logs' of https://github.com/Infisical/infisica…
dangtony98 Jan 3, 2023
0ff8194
Modify getWorkspaceLogs to accept sortBy query param
dangtony98 Jan 3, 2023
6845e91
Updated icon for activity logs
vmatsiiako Jan 3, 2023
d0949b2
Fixed the sorting buf with version history
vmatsiiako Jan 3, 2023
679db32
Begin docs for secret versioning, snapshots, and audit logs
dangtony98 Jan 3, 2023
fe0c466
Moved the delete button to the sidebar
vmatsiiako Jan 3, 2023
92ab29f
Merge branch 'activity-logs' of https://github.com/Infisical/infisica…
vmatsiiako Jan 3, 2023
9d0e269
Moved project id from dashboard to settings
vmatsiiako Jan 3, 2023
c7c5a94
Modify secret snapshots to point to secret versions
dangtony98 Jan 3, 2023
9727075
Resolve merge conflicts
dangtony98 Jan 3, 2023
fb394de
Remove unecessary imports
dangtony98 Jan 3, 2023
5967a5c
Add endpoint to return count of secret snapshots for a workspace
dangtony98 Jan 4, 2023
15db792
Patch requireAuth middleware in getting secret snapshot by id
dangtony98 Jan 4, 2023
df7340e
Fix merge conflicts
dangtony98 Jan 4, 2023
347b720
Finished secret snapshots
vmatsiiako Jan 5, 2023
6c88c4d
Updated the image for signup invites
vmatsiiako Jan 5, 2023
9cf28fe
Service tokens update on frontend
vmatsiiako Jan 5, 2023
8b48205
Fixed the service token bugs
vmatsiiako Jan 5, 2023
cc408d8
Update channel in workspace v2 controller
dangtony98 Jan 5, 2023
3f0eefb
Merge branch 'main' into activity-logs
vmatsiiako Jan 5, 2023
6e125b9
Merge remote-tracking branch 'origin' into activity-logs
dangtony98 Jan 5, 2023
85cb3a1
Fix frontend endpoints for service tokens and patch secret index.d.ts…
dangtony98 Jan 5, 2023
db36b81
Update package-lock.json
dangtony98 Jan 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { apiLimiter } from './helpers/rateLimiter';

import {
workspace as eeWorkspaceRouter,
secret as eeSecretRouter
secret as eeSecretRouter,
secretSnapshot as eeSecretSnapshotRouter,
action as eeActionRouter
} from './ee/routes/v1';
import {
signup as v1SignupRouter,
Expand Down Expand Up @@ -70,7 +72,9 @@ if (NODE_ENV === 'production') {

// (EE) routes
app.use('/api/v1/secret', eeSecretRouter);
app.use('/api/v1/secret-snapshot', eeSecretSnapshotRouter);
app.use('/api/v1/workspace', eeWorkspaceRouter);
app.use('/api/v1/action', eeActionRouter);

// v1 routes
app.use('/api/v1/signup', v1SignupRouter);
Expand Down
8 changes: 6 additions & 2 deletions backend/src/controllers/v1/secretController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export const pullSecrets = async (req: Request, res: Response) => {
secrets = await pull({
userId: req.user._id.toString(),
workspaceId,
environment
environment,
channel: channel ? channel : 'cli',
ipAddress: req.ip
});

key = await Key.findOne({
Expand Down Expand Up @@ -188,7 +190,9 @@ export const pullSecretsServiceToken = async (req: Request, res: Response) => {
secrets = await pull({
userId: req.serviceToken.user._id.toString(),
workspaceId,
environment
environment,
channel: 'cli',
ipAddress: req.ip
});

key = {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/v2/secretController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import to from "await-to-js";
import { Request, Response } from "express";
import mongoose, { Types } from "mongoose";
import Secret, { ISecret } from "../../models/secret";
import { CreateSecretRequestBody, ModifySecretRequestBody, SanitizedSecretForCreate, SanitizedSecretModify } from "../../types/secret/types";
import { CreateSecretRequestBody, ModifySecretRequestBody, SanitizedSecretForCreate, SanitizedSecretModify } from "../../types/secret";
const { ValidationError } = mongoose.Error;
import { BadRequestError, InternalServerError, UnauthorizedRequestError, ValidationError as RouteValidationError } from '../../utils/errors';
import { AnyBulkWriteOperation } from 'mongodb';
Expand Down
15 changes: 7 additions & 8 deletions backend/src/controllers/v2/workspaceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import {
ServiceToken,
ServiceTokenData
} from '../../models';
import {
createWorkspace as create,
deleteWorkspace as deleteWork
} from '../../helpers/workspace';
import {
v2PushSecrets as push,
pullSecrets as pull,
Expand Down Expand Up @@ -50,7 +46,6 @@ interface V2PushSecret {
*/
export const pushWorkspaceSecrets = async (req: Request, res: Response) => {
// upload (encrypted) secrets to workspace with id [workspaceId]

try {
let { secrets }: { secrets: V2PushSecret[] } = req.body;
const { keys, environment, channel } = req.body;
Expand All @@ -70,7 +65,9 @@ export const pushWorkspaceSecrets = async (req: Request, res: Response) => {
userId: req.user._id,
workspaceId,
environment,
secrets
secrets,
channel: channel ? channel : 'cli',
ipAddress: req.ip
});

await pushKeys({
Expand Down Expand Up @@ -136,7 +133,9 @@ export const pullSecrets = async (req: Request, res: Response) => {
secrets = await pull({
userId,
workspaceId,
environment
environment,
channel: channel ? channel : 'cli',
ipAddress: req.ip
});

if (channel !== 'cli') {
Expand Down Expand Up @@ -196,7 +195,7 @@ export const getWorkspaceServiceTokenData = async (
) => {
let serviceTokenData;
try {
const { workspaceId } = req.query;
const { workspaceId } = req.params;

serviceTokenData = await ServiceTokenData
.find({
Expand Down
31 changes: 31 additions & 0 deletions backend/src/ee/controllers/v1/actionController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Request, Response } from 'express';
import * as Sentry from '@sentry/node';
import { Action, SecretVersion } from '../../models';
import { ActionNotFoundError } from '../../../utils/errors';

export const getAction = async (req: Request, res: Response) => {
let action;
try {
const { actionId } = req.params;

action = await Action
.findById(actionId)
.populate([
'payload.secretVersions.oldSecretVersion',
'payload.secretVersions.newSecretVersion'
]);

if (!action) throw ActionNotFoundError({
message: 'Failed to find action'
});

} catch (err) {
throw ActionNotFoundError({
message: 'Failed to find action'
});
}

return res.status(200).send({
action
});
}
6 changes: 5 additions & 1 deletion backend/src/ee/controllers/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as stripeController from './stripeController';
import * as secretController from './secretController';
import * as secretSnapshotController from './secretSnapshotController';
import * as workspaceController from './workspaceController';
import * as actionController from './actionController';

export {
stripeController,
secretController,
workspaceController
secretSnapshotController,
workspaceController,
actionController
}
1 change: 1 addition & 0 deletions backend/src/ee/controllers/v1/secretController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SecretVersion } from '../../models';
secretVersions = await SecretVersion.find({
secret: secretId
})
.sort({ createdAt: -1 })
.skip(offset)
.limit(limit);

Expand Down
27 changes: 27 additions & 0 deletions backend/src/ee/controllers/v1/secretSnapshotController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Request, Response } from 'express';
import * as Sentry from '@sentry/node';
import { SecretSnapshot } from '../../models';

export const getSecretSnapshot = async (req: Request, res: Response) => {
let secretSnapshot;
try {
const { secretSnapshotId } = req.params;

secretSnapshot = await SecretSnapshot
.findById(secretSnapshotId)
.populate('secretVersions');

if (!secretSnapshot) throw new Error('Failed to find secret snapshot');

} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
return res.status(400).send({
message: 'Failed to get secret snapshot'
});
}

return res.status(200).send({
secretSnapshot
});
}
81 changes: 79 additions & 2 deletions backend/src/ee/controllers/v1/workspaceController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Request, Response } from 'express';
import e, { Request, Response } from 'express';
import * as Sentry from '@sentry/node';
import { SecretSnapshot } from '../../models';
import {
SecretSnapshot,
Log
} from '../../models';

/**
* Return secret snapshots for workspace with id [workspaceId]
Expand All @@ -18,6 +21,7 @@ import { SecretSnapshot } from '../../models';
secretSnapshots = await SecretSnapshot.find({
workspace: workspaceId
})
.sort({ createdAt: -1 })
.skip(offset)
.limit(limit);

Expand All @@ -32,4 +36,77 @@ import { SecretSnapshot } from '../../models';
return res.status(200).send({
secretSnapshots
});
}

/**
* Return count of secret snapshots for workspace with id [workspaceId]
* @param req
* @param res
*/
export const getWorkspaceSecretSnapshotsCount = async (req: Request, res: Response) => {
let count;
try {
const { workspaceId } = req.params;
count = await SecretSnapshot.countDocuments({
workspace: workspaceId
});
} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
return res.status(400).send({
message: 'Failed to count number of secret snapshots'
});
}

return res.status(200).send({
count
});
}

/**
* Return (audit) logs for workspace with id [workspaceId]
* @param req
* @param res
* @returns
*/
export const getWorkspaceLogs = async (req: Request, res: Response) => {
let logs
try {
const { workspaceId } = req.params;

const offset: number = parseInt(req.query.offset as string);
const limit: number = parseInt(req.query.limit as string);
const sortBy: string = req.query.sortBy as string;
const userId: string = req.query.userId as string;
const actionNames: string = req.query.actionNames as string;

logs = await Log.find({
workspace: workspaceId,
...( userId ? { user: userId } : {}),
...(
actionNames
? {
actionNames: {
$in: actionNames.split(',')
}
} : {}
)
})
.sort({ createdAt: sortBy === 'recent' ? -1 : 1 })
.skip(offset)
.limit(limit)
.populate('actions')
.populate('user');

} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
return res.status(400).send({
message: 'Failed to get workspace logs'
});
}

return res.status(200).send({
logs
});
}
Loading