-
Notifications
You must be signed in to change notification settings - Fork 171
feat(audit-logging): Adds audit logging support #355
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
13a7fb2
add audit factory skeleton
msukkari cba10b8
add additional audit events
msukkari 584a8d1
add more audit logs
msukkari a66abf2
delete account join request when redeeming an invite
msukkari 3f7734d
Merge branch 'msukkarieh/stale_join_request' into msukkarieh/audit
msukkari e9f80f0
add audit event for account request removed
msukkari 0ba23c9
merge main
msukkari b00a429
Merge branch 'main' into msukkarieh/audit
msukkari 559633c
wip api to fetch audits
msukkari 9c97889
add check for audit with public access and entitlement
msukkari a38f2c4
merge main
msukkari 185fcfa
fix issues with merge
msukkari 47adbb4
add docs for audit logs
msukkari 4aa5923
add proper audit log for audit fetch and proper handling of api key h…
msukkari 85ce7ae
merge main
msukkari 51606f2
format nit
msukkari c9876e9
feedback
msukkari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| --- | ||
| title: Audit Logs | ||
| sidebarTitle: Audit logs | ||
| --- | ||
|
|
||
| import LicenseKeyRequired from '/snippets/license-key-required.mdx' | ||
|
|
||
| <LicenseKeyRequired /> | ||
|
|
||
| Audit logs are a collection of notable events performed by users within a Sourcebot deployment. Each audit log records information on the action taken, the user who performed the | ||
| action, and when the action took place. | ||
|
|
||
| This feature gives security and compliance teams the necessary information to ensure proper governance and administration of your Sourcebot deployment. | ||
|
|
||
| ## Enabling Audit Logs | ||
| Audit logs must be explicitly enabled by setting the `SOURCEBOT_EE_AUDIT_LOGGING_ENABLED` [environment variable](/docs/configuration/environment-variables) to `true` | ||
|
|
||
| ## Fetching Audit Logs | ||
| Audit logs are stored in the [postgres database](/docs/overview#architecture) connected to Sourcebot. To fetch all of the audit logs, you can use the following API: | ||
|
|
||
| ```bash icon="terminal" Fetch audit logs | ||
| curl --request GET '$SOURCEBOT_URL/api/ee/audit' \ | ||
| --header 'X-Org-Domain: ~' \ | ||
| --header 'X-Sourcebot-Api-Key: $SOURCEBOT_OWNER_API_KEY' | ||
| ``` | ||
|
|
||
| ```json icon="brackets-curly" wrap expandable Fetch audit logs example response | ||
| [ | ||
| { | ||
| "id": "cmc146k7m0003xgo2tri5t4br", | ||
| "timestamp": "2025-06-17T22:48:08.914Z", | ||
| "action": "api_key.created", | ||
| "actorId": "cmc12tnje0000xgn58jj8655h", | ||
| "actorType": "user", | ||
| "targetId": "205d1da1c6c3772b81d4ad697f5851fa11195176c211055ff0c1509772645d6d", | ||
| "targetType": "api_key", | ||
| "sourcebotVersion": "unknown", | ||
| "orgId": 1 | ||
| }, | ||
| { | ||
| "id": "cmc146c8r0001xgo2xyu0p463", | ||
| "timestamp": "2025-06-17T22:47:58.587Z", | ||
| "action": "query.code_search", | ||
| "actorId": "cmc12tnje0000xgn58jj8655h", | ||
| "actorType": "user", | ||
| "targetId": "1", | ||
| "targetType": "org", | ||
| "sourcebotVersion": "unknown", | ||
| "metadata": { | ||
| "message": "render branch:HEAD" | ||
| }, | ||
| "orgId": 1 | ||
| }, | ||
| { | ||
| "id": "cmc12vqgb0008xgn5nv5hl9y5", | ||
| "timestamp": "2025-06-17T22:11:44.171Z", | ||
| "action": "query.code_search", | ||
| "actorId": "cmc12tnje0000xgn58jj8655h", | ||
| "actorType": "user", | ||
| "targetId": "1", | ||
| "targetType": "org", | ||
| "sourcebotVersion": "unknown", | ||
| "metadata": { | ||
| "message": "render branch:HEAD" | ||
| }, | ||
| "orgId": 1 | ||
| }, | ||
| { | ||
| "id": "cmc12txwn0006xgn51ow1odid", | ||
| "timestamp": "2025-06-17T22:10:20.519Z", | ||
| "action": "query.code_search", | ||
| "actorId": "cmc12tnje0000xgn58jj8655h", | ||
| "actorType": "user", | ||
| "targetId": "1", | ||
| "targetType": "org", | ||
| "sourcebotVersion": "unknown", | ||
| "metadata": { | ||
| "message": "render branch:HEAD" | ||
| }, | ||
| "orgId": 1 | ||
| }, | ||
| { | ||
| "id": "cmc12tnjx0004xgn5qqeiv1ao", | ||
| "timestamp": "2025-06-17T22:10:07.101Z", | ||
| "action": "user.owner_created", | ||
| "actorId": "cmc12tnje0000xgn58jj8655h", | ||
| "actorType": "user", | ||
| "targetId": "1", | ||
| "targetType": "org", | ||
| "sourcebotVersion": "unknown", | ||
| "metadata": null, | ||
| "orgId": 1 | ||
| }, | ||
| { | ||
| "id": "cmc12tnjh0002xgn5h6vzu3rl", | ||
| "timestamp": "2025-06-17T22:10:07.086Z", | ||
| "action": "user.signed_in", | ||
| "actorId": "cmc12tnje0000xgn58jj8655h", | ||
| "actorType": "user", | ||
| "targetId": "cmc12tnje0000xgn58jj8655h", | ||
| "targetType": "user", | ||
| "sourcebotVersion": "unknown", | ||
| "metadata": null, | ||
| "orgId": 1 | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| ## Response schema | ||
|
|
||
| ```json icon="brackets-curly" expandable wrap Audit log fetch response schema | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "FetchAuditLogsResponse", | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "required": [ | ||
| "id", | ||
| "timestamp", | ||
| "action", | ||
| "actorId", | ||
| "actorType", | ||
| "targetId", | ||
| "targetType", | ||
| "sourcebotVersion", | ||
| "metadata", | ||
| "orgId" | ||
| ], | ||
| "properties": { | ||
| "id": { | ||
| "type": "string" | ||
| }, | ||
| "timestamp": { | ||
| "type": "string", | ||
| "format": "date-time" | ||
| }, | ||
| "action": { | ||
| "type": "string" | ||
| }, | ||
| "actorId": { | ||
| "type": "string" | ||
| }, | ||
| "actorType": { | ||
| "type": "string", | ||
| "enum": ["user", "api_key"] | ||
| }, | ||
| "targetId": { | ||
| "type": "string" | ||
| }, | ||
| "targetType": { | ||
| "type": "string", | ||
| "enum": ["user", "org", "file", "api_key", "account_join_request", "invite"] | ||
| }, | ||
| "sourcebotVersion": { | ||
| "type": "string" | ||
| }, | ||
| "metadata": { | ||
| "anyOf": [ | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "message": { "type": "string" }, | ||
| "api_key": { "type": "string" }, | ||
| "emails": { "type": "string" } | ||
| }, | ||
| "additionalProperties": false | ||
| }, | ||
| { | ||
| "type": "null" | ||
| } | ||
| ] | ||
| }, | ||
| "orgId": { | ||
| "type": "integer" | ||
| } | ||
| }, | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
|
|
||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/db/prisma/migrations/20250617031335_add_audit_table/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "Audit" ( | ||
| "id" TEXT NOT NULL, | ||
| "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "action" TEXT NOT NULL, | ||
| "actorId" TEXT NOT NULL, | ||
| "actorType" TEXT NOT NULL, | ||
| "targetId" TEXT NOT NULL, | ||
| "targetType" TEXT NOT NULL, | ||
| "sourcebotVersion" TEXT NOT NULL, | ||
| "metadata" JSONB, | ||
| "orgId" INTEGER NOT NULL, | ||
|
|
||
| CONSTRAINT "Audit_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "Audit_actorId_actorType_targetId_targetType_orgId_idx" ON "Audit"("actorId", "actorType", "targetId", "targetType", "orgId"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Audit" ADD CONSTRAINT "Audit_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.