Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/docs/content/docs/platform/enterprise/audit-logs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ Events use identifiers such as `resource.action`. These categories are represent
| Organization | `organization.updated`, `org_member.added`, `org_member.role_changed`, `organization.sso_provider.updated` |
| Links | `sim_link.created`, `sim_link.updated`, `sim_link.deleted` |
| Exports and drains | `audit_logs.exported`, `data_drain.created`, `data_drain.updated`, `data_drain.ran`, `data_drain.tested` |
| Integration tools | `tool.executed` |

A built-in integration tool run directly through the v2 API or Sim's MCP server, for example from Claude Code or Cursor, records `tool.executed` unless the tool is read-only, for example when it sends a message or creates an issue. A failed call is recorded too, whether the provider rejected it or Sim refused it, for example because an admin denied the tool. Error text is not stored, because it can repeat the tool's input. The entry names the person, the tool (`resourceId`, such as `slack_message`), whether it succeeded or failed (`metadata.status`), and the credential used (`metadata.credentialId`), and its surface is `mcp` for calls made through the MCP server. Tool inputs, outputs, and error messages are not copied into the entry. Read-only tools are not recorded per call; the credential they use records `credential.accessed`.

Authentication failures and password-reset requests use an anonymous actor and record the target account separately. Impersonation and administrative session revocations identify the operator and target organization. Table-row mutations record summaries and counts without copying row contents. A workflow or workspace written from source by the CLI (`workflow.created`, `workflow.updated` or `workspace.updated`) records `metadata.client` as `cli` and, when the source directory is in a git repository and `git` can read them, `metadata.gitSha` (the commit checked out) and `metadata.repo` (the `origin` remote URL, with any credentials removed). Either may be absent, for example `repo` in a repository with no `origin`.

Expand Down
58 changes: 57 additions & 1 deletion apps/sim/lib/tool-execution/application/execute-tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createSessionPrincipal,
createWorkspaceApiKeyPrincipal,
} from '@sim/testing/factories/principal.factory'
import { auditMock } from '@sim/testing/mocks/audit.mock'
import { auditMock, auditMockFns } from '@sim/testing/mocks/audit.mock'
import {
billingAttributionMock,
billingAttributionMockFns,
Expand Down Expand Up @@ -117,6 +117,7 @@ const TOOL_METADATA: Record<string, Record<string, unknown>> = {
slack_message: {
id: 'slack_message',
name: 'Slack Send Message',
effect: 'write',
params: {
accessToken: { type: 'string', required: true, visibility: 'hidden' },
text: { type: 'string', required: true, visibility: 'user-or-llm' },
Expand All @@ -126,6 +127,7 @@ const TOOL_METADATA: Record<string, Record<string, unknown>> = {
firecrawl_scrape: {
id: 'firecrawl_scrape',
name: 'Firecrawl Scrape',
effect: 'read',
params: {
url: { type: 'string', required: true, visibility: 'user-or-llm' },
apiKey: { type: 'string', required: true, visibility: 'user-only' },
Expand Down Expand Up @@ -433,6 +435,60 @@ describe('executeToolForCaller', () => {
})
})

describe('audit trail', () => {
const sendSlack = () =>
run({ toolId: 'slack_message', credentialId: 'credential-1', input: { text: 'secret plan' } })

it('records a tool that changes something outside Sim, without copying its input', async () => {
await sendSlack()

expect(auditMockFns.mockRecordAudit).toHaveBeenCalledTimes(1)
const entry = auditMockFns.mockRecordAudit.mock.calls[0][0]
expect(entry).toMatchObject({
workspaceId: WORKSPACE_ID,
actorId: 'user-1',
action: 'tool.executed',
resourceType: 'tool',
resourceId: 'slack_message',
resourceName: 'Slack Send Message',
metadata: { toolId: 'slack_message', status: 'succeeded', credentialId: 'credential-1' },
})
expect(JSON.stringify(entry)).not.toContain('secret plan')
})

it.each([
['the provider rejected', 'channel_not_found'],
['Sim refused inside the run', 'Tool slack_message is not allowed by your permission group'],
['a parser echoed the input back', 'Invalid JSON near "secret plan"'],
])('records a write %s as failed, without its error text', async (_case, error) => {
mocks.executeRegistryTool.mockResolvedValue({ success: false, error })

await sendSlack()

const entry = auditMockFns.mockRecordAudit.mock.calls[0][0]
expect(entry).toMatchObject({
description: 'Ran Slack Send Message (failed)',
metadata: { status: 'failed' },
})
expect(JSON.stringify(entry)).not.toContain(error)
})

it('leaves reads to the credential trail', async () => {
await run({ input: { url: 'https://example.com' } })

expect(mocks.executeRegistryTool).toHaveBeenCalled()
expect(auditMockFns.mockRecordAudit).not.toHaveBeenCalled()
})

it('records nothing for a call refused before it dispatched', async () => {
await expect(run({ toolId: 'slack_message', input: { text: 'hi' } })).rejects.toMatchObject({
code: 'validation',
})

expect(auditMockFns.mockRecordAudit).not.toHaveBeenCalled()
})
})

it('refuses a credential from another workspace the caller can use', async () => {
credentialsAccessMockFns.mockGetCredentialActorContext.mockResolvedValue(
usableCredentialIn('workspace-a')
Expand Down
28 changes: 27 additions & 1 deletion apps/sim/lib/tool-execution/application/execute-tool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AuditAction, AuditResourceType } from '@sim/audit'
import { createLogger } from '@sim/logger'
import { getErrorMessage } from '@sim/utils/errors'
import { generateId } from '@sim/utils/id'
Expand Down Expand Up @@ -36,7 +37,6 @@ import { getTool } from '@/tools/utils'
const logger = createLogger('ExecuteToolUseCase')

const DEFAULT_TIMEOUT_SECONDS = 120

export interface ExecuteToolInput {
workspaceId: string
toolId: string
Expand Down Expand Up @@ -298,6 +298,15 @@ function assertRequiredCallerInputsPresent(
* under `enforceCredentialAccess`, injects a hosted API key where Sim supplies
* one, applies the `deniedTools` denylist against the resolved id, and projects
* secrets out of the result.
*
* A call that dispatched to a tool not marked read-only is audited as
* `tool.executed`, whether it succeeded or not: a write the provider rejected
* may have partly applied, and one Sim refused inside the run, such as a tool
* the admin denied, is an attempt an admin needs to see. The error text is not
* kept, since a provider or parser error can echo the caller's input. Reads are left to
* the credential's own `credential.accessed` trail, which keeps the audit log at
* human scale when a coding agent lists or searches in a loop. Inputs and outputs
* are never copied into the entry; they can hold message bodies and secrets.
*/
export const executeToolForCaller = defineAuthorizedWorkspaceUseCase({
operation: toolExecutionOperations.execute,
Expand Down Expand Up @@ -502,6 +511,23 @@ export const executeToolForCaller = defineAuthorizedWorkspaceUseCase({
error: result.success ? null : { message: result.error ?? `${toolId} did not succeed` },
}
},
projectAudit: ({ input, result }) => {
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
const tool = getTool(result.toolId)
if (tool?.effect === 'read') return []
const toolName = tool?.name ?? result.toolId
return {
action: AuditAction.TOOL_EXECUTED,
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
resourceType: AuditResourceType.TOOL,
resourceId: result.toolId,
resourceName: toolName,
description: `Ran ${toolName}${result.status === 'failed' ? ' (failed)' : ''}`,
metadata: {
toolId: result.toolId,
status: result.status,
...(input.credentialId ? { credentialId: input.credentialId } : {}),
},
}
},
})

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/audit/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export const AuditAction = {
DESKTOP_TOOL_CALL_CLAIMED: 'desktop_tool_call.claimed',
DESKTOP_TOOL_CALL_COMPLETED: 'desktop_tool_call.completed',

/**
* A built-in integration tool run directly for a person, through the v2 API or Sim's MCP
* server, outside any workflow or chat. Recorded for every tool not marked read-only.
*/
TOOL_EXECUTED: 'tool.executed',

DOCUMENT_UPLOADED: 'document.uploaded',
DOCUMENT_UPDATED: 'document.updated',
DOCUMENT_DELETED: 'document.deleted',
Expand Down Expand Up @@ -328,6 +334,8 @@ export const AuditResourceType = {
SKILL: 'skill',
SUBSCRIPTION: 'subscription',
TABLE: 'table',
/** Not a stored resource: a built-in integration tool, identified by its tool id. */
TOOL: 'tool',
USER: 'user',
WEBHOOK: 'webhook',
WORKFLOW: 'workflow',
Expand Down
2 changes: 2 additions & 0 deletions packages/testing/src/mocks/audit.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const AuditAction = {
ENTERPRISE_SUBSCRIPTION_PROVISIONED: 'subscription.enterprise_provisioned',
CONNECTOR_DOCUMENT_RESTORED: 'connector_document.restored',
CONNECTOR_DOCUMENT_EXCLUDED: 'connector_document.excluded',
TOOL_EXECUTED: 'tool.executed',
DOCUMENT_UPLOADED: 'document.uploaded',
DOCUMENT_UPDATED: 'document.updated',
DOCUMENT_DELETED: 'document.deleted',
Expand Down Expand Up @@ -279,6 +280,7 @@ const AuditResourceType = {
SKILL: 'skill',
SUBSCRIPTION: 'subscription',
TABLE: 'table',
TOOL: 'tool',
USER: 'user',
WEBHOOK: 'webhook',
WORKFLOW: 'workflow',
Expand Down
Loading