|
| 1 | +--- |
| 2 | +title: Audit Logs |
| 3 | +sidebarTitle: Audit logs |
| 4 | +--- |
| 5 | + |
| 6 | +import LicenseKeyRequired from '/snippets/license-key-required.mdx' |
| 7 | + |
| 8 | +<LicenseKeyRequired /> |
| 9 | + |
| 10 | +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 |
| 11 | +action, and when the action took place. |
| 12 | + |
| 13 | +This feature gives security and compliance teams the necessary information to ensure proper governance and administration of your Sourcebot deployment. |
| 14 | + |
| 15 | +## Enabling Audit Logs |
| 16 | +Audit logs must be explicitly enabled by setting the `SOURCEBOT_EE_AUDIT_LOGGING_ENABLED` [environment variable](/docs/configuration/environment-variables) to `true` |
| 17 | + |
| 18 | +## Fetching Audit Logs |
| 19 | +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: |
| 20 | + |
| 21 | +```bash icon="terminal" Fetch audit logs |
| 22 | +curl --request GET '$SOURCEBOT_URL/api/ee/audit' \ |
| 23 | + --header 'X-Org-Domain: ~' \ |
| 24 | + --header 'X-Sourcebot-Api-Key: $SOURCEBOT_OWNER_API_KEY' |
| 25 | +``` |
| 26 | + |
| 27 | +```json icon="brackets-curly" wrap expandable Fetch audit logs example response |
| 28 | +[ |
| 29 | + { |
| 30 | + "id": "cmc146k7m0003xgo2tri5t4br", |
| 31 | + "timestamp": "2025-06-17T22:48:08.914Z", |
| 32 | + "action": "api_key.created", |
| 33 | + "actorId": "cmc12tnje0000xgn58jj8655h", |
| 34 | + "actorType": "user", |
| 35 | + "targetId": "205d1da1c6c3772b81d4ad697f5851fa11195176c211055ff0c1509772645d6d", |
| 36 | + "targetType": "api_key", |
| 37 | + "sourcebotVersion": "unknown", |
| 38 | + "orgId": 1 |
| 39 | + }, |
| 40 | + { |
| 41 | + "id": "cmc146c8r0001xgo2xyu0p463", |
| 42 | + "timestamp": "2025-06-17T22:47:58.587Z", |
| 43 | + "action": "query.code_search", |
| 44 | + "actorId": "cmc12tnje0000xgn58jj8655h", |
| 45 | + "actorType": "user", |
| 46 | + "targetId": "1", |
| 47 | + "targetType": "org", |
| 48 | + "sourcebotVersion": "unknown", |
| 49 | + "metadata": { |
| 50 | + "message": "render branch:HEAD" |
| 51 | + }, |
| 52 | + "orgId": 1 |
| 53 | + }, |
| 54 | + { |
| 55 | + "id": "cmc12vqgb0008xgn5nv5hl9y5", |
| 56 | + "timestamp": "2025-06-17T22:11:44.171Z", |
| 57 | + "action": "query.code_search", |
| 58 | + "actorId": "cmc12tnje0000xgn58jj8655h", |
| 59 | + "actorType": "user", |
| 60 | + "targetId": "1", |
| 61 | + "targetType": "org", |
| 62 | + "sourcebotVersion": "unknown", |
| 63 | + "metadata": { |
| 64 | + "message": "render branch:HEAD" |
| 65 | + }, |
| 66 | + "orgId": 1 |
| 67 | + }, |
| 68 | + { |
| 69 | + "id": "cmc12txwn0006xgn51ow1odid", |
| 70 | + "timestamp": "2025-06-17T22:10:20.519Z", |
| 71 | + "action": "query.code_search", |
| 72 | + "actorId": "cmc12tnje0000xgn58jj8655h", |
| 73 | + "actorType": "user", |
| 74 | + "targetId": "1", |
| 75 | + "targetType": "org", |
| 76 | + "sourcebotVersion": "unknown", |
| 77 | + "metadata": { |
| 78 | + "message": "render branch:HEAD" |
| 79 | + }, |
| 80 | + "orgId": 1 |
| 81 | + }, |
| 82 | + { |
| 83 | + "id": "cmc12tnjx0004xgn5qqeiv1ao", |
| 84 | + "timestamp": "2025-06-17T22:10:07.101Z", |
| 85 | + "action": "user.owner_created", |
| 86 | + "actorId": "cmc12tnje0000xgn58jj8655h", |
| 87 | + "actorType": "user", |
| 88 | + "targetId": "1", |
| 89 | + "targetType": "org", |
| 90 | + "sourcebotVersion": "unknown", |
| 91 | + "metadata": null, |
| 92 | + "orgId": 1 |
| 93 | + }, |
| 94 | + { |
| 95 | + "id": "cmc12tnjh0002xgn5h6vzu3rl", |
| 96 | + "timestamp": "2025-06-17T22:10:07.086Z", |
| 97 | + "action": "user.signed_in", |
| 98 | + "actorId": "cmc12tnje0000xgn58jj8655h", |
| 99 | + "actorType": "user", |
| 100 | + "targetId": "cmc12tnje0000xgn58jj8655h", |
| 101 | + "targetType": "user", |
| 102 | + "sourcebotVersion": "unknown", |
| 103 | + "metadata": null, |
| 104 | + "orgId": 1 |
| 105 | + } |
| 106 | +] |
| 107 | +``` |
| 108 | + |
| 109 | +## Audit action types |
| 110 | + |
| 111 | +| Action | Actor Type | Target Type | |
| 112 | +| :------- | :------ | :------| |
| 113 | +| `api_key.creation_failed` | `user` | `org` | |
| 114 | +| `api_key.created` | `user` | `api_key` | |
| 115 | +| `api_key.deletion_failed` | `user` | `org` | |
| 116 | +| `api_key.deleted` | `user` | `api_key` | |
| 117 | +| `user.creation_failed` | `user` | `user` | |
| 118 | +| `user.owner_created` | `user` | `org` | |
| 119 | +| `user.jit_provisioning_failed` | `user` | `org` | |
| 120 | +| `user.jit_provisioned` | `user` | `org` | |
| 121 | +| `user.join_request_creation_failed` | `user` | `org` | |
| 122 | +| `user.join_requested` | `user` | `org` | |
| 123 | +| `user.join_request_approve_failed` | `user` | `account_join_request` | |
| 124 | +| `user.join_request_approved` | `user` | `account_join_request` | |
| 125 | +| `user.join_request_removed` | `user` | `account_join_request` | |
| 126 | +| `user.invite_failed` | `user` | `org` | |
| 127 | +| `user.invites_created` | `user` | `org` | |
| 128 | +| `user.invite_accept_failed` | `user` | `invite` | |
| 129 | +| `user.invite_accepted` | `user` | `invite` | |
| 130 | +| `user.signed_in` | `user` | `user` | |
| 131 | +| `user.signed_out` | `user` | `user` | |
| 132 | +| `org.ownership_transfer_failed` | `user` | `org` | |
| 133 | +| `org.ownership_transferred` | `user` | `org` | |
| 134 | +| `query.file_source` | `user \| api_key` | `file` | |
| 135 | +| `query.code_search` | `user \| api_key` | `org` | |
| 136 | +| `query.list_repositories` | `user \| api_key` | `org` | |
| 137 | + |
| 138 | + |
| 139 | +## Response schema |
| 140 | + |
| 141 | +```json icon="brackets-curly" expandable wrap Audit log fetch response schema |
| 142 | +{ |
| 143 | + "$schema": "http://json-schema.org/draft-07/schema#", |
| 144 | + "title": "FetchAuditLogsResponse", |
| 145 | + "type": "array", |
| 146 | + "items": { |
| 147 | + "type": "object", |
| 148 | + "required": [ |
| 149 | + "id", |
| 150 | + "timestamp", |
| 151 | + "action", |
| 152 | + "actorId", |
| 153 | + "actorType", |
| 154 | + "targetId", |
| 155 | + "targetType", |
| 156 | + "sourcebotVersion", |
| 157 | + "metadata", |
| 158 | + "orgId" |
| 159 | + ], |
| 160 | + "properties": { |
| 161 | + "id": { |
| 162 | + "type": "string" |
| 163 | + }, |
| 164 | + "timestamp": { |
| 165 | + "type": "string", |
| 166 | + "format": "date-time" |
| 167 | + }, |
| 168 | + "action": { |
| 169 | + "type": "string" |
| 170 | + }, |
| 171 | + "actorId": { |
| 172 | + "type": "string" |
| 173 | + }, |
| 174 | + "actorType": { |
| 175 | + "type": "string", |
| 176 | + "enum": ["user", "api_key"] |
| 177 | + }, |
| 178 | + "targetId": { |
| 179 | + "type": "string" |
| 180 | + }, |
| 181 | + "targetType": { |
| 182 | + "type": "string", |
| 183 | + "enum": ["user", "org", "file", "api_key", "account_join_request", "invite"] |
| 184 | + }, |
| 185 | + "sourcebotVersion": { |
| 186 | + "type": "string" |
| 187 | + }, |
| 188 | + "metadata": { |
| 189 | + "anyOf": [ |
| 190 | + { |
| 191 | + "type": "object", |
| 192 | + "properties": { |
| 193 | + "message": { "type": "string" }, |
| 194 | + "api_key": { "type": "string" }, |
| 195 | + "emails": { "type": "string" } |
| 196 | + }, |
| 197 | + "additionalProperties": false |
| 198 | + }, |
| 199 | + { |
| 200 | + "type": "null" |
| 201 | + } |
| 202 | + ] |
| 203 | + }, |
| 204 | + "orgId": { |
| 205 | + "type": "integer" |
| 206 | + } |
| 207 | + }, |
| 208 | + "additionalProperties": false |
| 209 | + } |
| 210 | +} |
| 211 | + |
| 212 | +``` |
0 commit comments