Skip to content
Closed
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
17 changes: 17 additions & 0 deletions frontend/src/lib/features/actions/ScriptConfigPanel.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<script>
import Input from '../../components/Input.svelte';
import Textarea from '../../components/Textarea.svelte';
import { t } from '../../stores/i18n.svelte.js';
import { permissionStore } from '../../stores/permissions.svelte.js';

let {
selectedNode,
flowStore,
} = $props();

const cfg = $derived(selectedNode?.data?.config || {});
const canExecuteScript = $derived(permissionStore.hasPermissionKey('action.execute_script'));

const sourceExample = `// The effective executor's identity and permissions apply.
// Call the v2 REST API synchronously:
Expand All @@ -21,6 +24,14 @@ return { comment_id: res.body?.id ?? null };`;
</script>

<div class="script-panel">
{#if !canExecuteScript}
<p
class="permission-warning border border-ds-border-warning bg-ds-warning-subtle text-ds-text-warning"
data-testid="execute-script-permission-warning"
>
{t('actions.nodes.scriptTrustRequired')}
</p>
{/if}
<div>
<label for="execute-script-source" class="block text-xs font-medium mb-1">JavaScript (function body)</label>
<Textarea
Expand Down Expand Up @@ -120,6 +131,12 @@ return { comment_id: res.body?.id ?? null };`;
font-size: 11px;
line-height: 1.4;
}
.permission-warning {
border-radius: 6px;
padding: 8px;
font-size: 11px;
line-height: 1.4;
}
.hint code,
.reference code {
font-family: var(--ds-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/de/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default {
roundRobinAssign: 'Round-Robin zuweisen',
createMilestone: 'Meilenstein erstellen',
executeScript: 'Skript ausführen',
scriptTrustRequired: 'Erfordert die globale Berechtigung action.execute_script. Ohne sie werden Speichern oder manuelles Ausführen dieser Aktion abgelehnt; die In-Process-Laufzeit hat keine Speichergrenze pro Skript.',
},

aiUpdated: 'Aktion durch KI aktualisiert',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/en/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default {
insertCannedResponse: 'Insert canned response',
adjustLabels: 'Adjust labels',
executeScript: 'Run script',
scriptTrustRequired: 'Requires the global action.execute_script permission. Saving this action or running it manually is refused without it; the in-process runtime has no per-script memory bound.',
createItem: 'Create work item',
},

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/en/adminOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ export default {
action_manage: { name: 'Manage Actions', description: 'Can create, edit, delete, and execute workspace actions' },
action_credential_manage: { name: 'Manage Action Credentials', description: 'Can create, rotate, and delete workspace-scoped action credentials' },
action_set_actor: { name: 'Set Action Actor', description: 'Can run an action as another user, including across workspaces' },
action_execute_script: { name: 'Run Action Scripts', description: 'Can save or manually run actions that execute author-supplied JavaScript; in-process scripts have no per-script memory bound' },
teams_manage: { name: 'Manage Teams', description: 'Can create, edit, and delete teams' },
public_board_manage: { name: 'Manage Public Boards', description: 'Can make collections public and configure public board sharing' },
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fa/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default {
"roundRobinAssign": "تخصیص نوبتی",
"createMilestone": "نقطه عطف ایجاد کنید",
"executeScript": "اجرای اسکریپت",
"scriptTrustRequired": "به مجوز سراسری action.execute_script نیاز دارد. بدون آن، ذخیره این کنش یا اجرای دستی آن رد می‌شود؛ زمان اجرای درون‌فرایندی محدودیت حافظه برای هر اسکریپت ندارد.",
"notifyCustomer": "به مشتری اطلاع دهید",
"insertCannedResponse": "درج پاسخ آماده",
"adjustLabels": "برچسب ها را تنظیم کنید",
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/locales/fa/adminOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ export default {
"name": "تنظیم اقدام‌کننده",
"description": "می‌تواند یک اقدام را به‌عنوان کاربر دیگر اجرا کند، از جمله در سراسر فضاهای کاری"
},
"action_execute_script": {
"name": "اجرای اسکریپت‌های کنش",
"description": "می‌تواند کنش‌هایی را که جاوااسکریپت ارائه‌شده توسط نویسنده را اجرا می‌کنند ذخیره یا به‌صورت دستی اجرا کند؛ اسکریپت‌های درون‌فرایندی محدودیت حافظه برای هر اسکریپت ندارند"
},
"teams_manage": {
"name": "مدیریت تیم ها",
"description": "می تواند تیم ها را ایجاد، ویرایش و حذف کند"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fr/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
roundRobinAssign: 'Attribution à tour de rôle',
createMilestone: 'Créer un jalon',
executeScript: 'Exécuter le script',
scriptTrustRequired: 'Nécessite la permission globale action.execute_script. Sans elle, l’enregistrement de cette action ou son exécution manuelle est refusé ; le moteur en processus n’a pas de limite de mémoire par script.',
},

// Toast shown when the AI chat updates the open action via update_action.
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fr/adminOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export default {
action_manage: { name: 'Gérer les actions', description: 'Peut créer, modifier, supprimer et exécuter des actions d’espace de travail' },
action_credential_manage: { name: 'Gérer les identifiants d’action', description: 'Peut créer, renouveler et supprimer des identifiants d’action restreints à l’espace de travail' },
action_set_actor: { name: 'Définir l’acteur de l’action', description: 'Peut exécuter une action en tant qu’autre utilisateur, y compris entre espaces de travail' },
action_execute_script: { name: 'Exécuter les scripts d’action', description: 'Peut enregistrer ou exécuter manuellement des actions qui exécutent du JavaScript fourni par l’auteur ; les scripts en processus n’ont pas de limite de mémoire par script' },
teams_manage: { name: 'Gérer les équipes', description: 'Peut créer, modifier et supprimer des équipes' },
public_board_manage: { name: 'Gérer les tableaux publics', description: 'Peut rendre des collections publiques et configurer le partage de tableaux publics' },
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/nl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default {
insertCannedResponse: 'Standaardantwoord invoegen',
adjustLabels: 'Labels aanpassen',
executeScript: 'Script uitvoeren',
scriptTrustRequired: 'Vereist de globale machtiging action.execute_script. Zonder deze wordt het opslaan of handmatig uitvoeren van deze actie geweigerd; de in-process runtime heeft geen geheugenlimiet per script.',
createItem: 'Werkitem aanmaken',
},

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/nl/adminOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ export default {
action_manage: { name: 'Acties beheren', description: 'Kan werkruimteacties aanmaken, bewerken, verwijderen en uitvoeren' },
action_credential_manage: { name: 'Actiereferenties beheren', description: 'Kan referenties met werkruimtebereik aanmaken, roteren en verwijderen' },
action_set_actor: { name: 'Actie-actor instellen', description: 'Kan een actie namens een andere gebruiker uitvoeren, ook tussen werkruimten' },
action_execute_script: { name: 'Actiescripts uitvoeren', description: 'Kan acties opslaan of handmatig uitvoeren die door de auteur aangeleverde JavaScript uitvoeren; in-process scripts hebben geen geheugenlimiet per script' },
teams_manage: { name: 'Teams beheren', description: 'Kan teams aanmaken, bewerken en verwijderen' },
public_board_manage: { name: 'Openbare borden beheren', description: 'Kan collecties openbaar maken en openbare borddeling configureren' },
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/pl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default {
roundRobinAssign: 'Przypisanie rotacyjne',
createMilestone: 'Utwórz kamień milowy',
executeScript: 'Uruchom skrypt',
scriptTrustRequired: 'Wymaga globalnego uprawnienia action.execute_script. Bez niego zapisanie tej akcji lub ręczne uruchomienie jest odrzucane; środowisko działające w procesie nie ma limitu pamięci na skrypt.',
notifyCustomer: 'Powiadom klienta',
insertCannedResponse: 'Wstaw gotową odpowiedź',
adjustLabels: 'Dostosuj etykiety',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/ru/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default {
roundRobinAssign: 'Назначить по очереди',
createMilestone: 'Создать этап',
executeScript: 'Запустить скрипт',
scriptTrustRequired: 'Требуется глобальное разрешение action.execute_script. Без него сохранение этого действия или его ручной запуск отклоняются; у внутрипроцессного рантайма нет ограничения памяти на скрипт.',
notifyCustomer: 'Уведомить клиента',
insertCannedResponse: 'Вставить шаблон ответа',
adjustLabels: 'Изменить метки',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/ru/adminOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ export default {
action_manage: { name: 'Управление действиями', description: 'Создание, изменение, удаление и запуск действий пространства' },
action_credential_manage: { name: 'Секреты действий', description: 'Создание, замена и удаление секретов действий рабочего пространства' },
action_set_actor: { name: 'Исполнитель действия', description: 'Запуск действия от имени другого пользователя, в том числе между пространствами' },
action_execute_script: { name: 'Запуск скриптов действий', description: 'Может сохранять или вручную запускать действия, выполняющие предоставленный автором JavaScript; у внутрипроцессных скриптов нет ограничения памяти на скрипт' },
teams_manage: { name: 'Управление командами', description: 'Создание, изменение и удаление команд' },
public_board_manage: { name: 'Публичные доски', description: 'Публикация коллекций и настройка общего доступа к доскам' },
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/zh-CN/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default {
roundRobinAssign: '轮询分配',
createMilestone: '创建里程碑',
executeScript: '运行脚本',
scriptTrustRequired: '需要全局 action.execute_script 权限。没有该权限将拒绝保存此操作或手动运行;进程内运行时对每个脚本没有内存上限。',
},
aiUpdated: 'AI 已更新动作',
addNodes: '添加节点',
Expand Down
4 changes: 2 additions & 2 deletions internal/aitools/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func init() {
TriggerConfig: def.TriggerConfig,
CreatedBy: &env.UserID,
}
definitions := services.NewActionDefinitionService(env.DB, repo, env.ActionService)
definitions := services.NewActionDefinitionService(env.DB, repo, env.ActionService, env.PermService)
created, validation, err := definitions.Create(action, def.Nodes, def.Edges, env.actionWriteMeta(logger.ActionAutomationCreate, map[string]any{"workspace_id": args.WorkspaceID}))
if len(validation) > 0 {
return map[string]any{"error": validation[0].Message, "validation_errors": validation}, nil
Expand Down Expand Up @@ -540,7 +540,7 @@ func init() {
existing.TriggerType = def.TriggerType
existing.TriggerConfig = def.TriggerConfig

definitions := services.NewActionDefinitionService(env.DB, repo, env.ActionService)
definitions := services.NewActionDefinitionService(env.DB, repo, env.ActionService, env.PermService)
meta := env.actionWriteMeta(logger.ActionAutomationUpdate, map[string]any{"workspace_id": args.WorkspaceID})
meta.AuthorizeActor = func(_ *int, effectiveActor *int, actorChanging bool) error {
if !actorChanging && effectiveActor == nil {
Expand Down
18 changes: 18 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3727,6 +3727,24 @@ END $$;
CREATE UNIQUE INDEX IF NOT EXISTS uq_priorities_single_default ON priorities(is_default) WHERE is_default = true;
`,
},
{
// Existing databases need the permission row inserted; fresh installs get
// it from permissions.sql, and the check then stamps this migration so it
// is not re-run.
Version: "20261204_action_execute_script_permission",
Name: "Add the global action.execute_script trust permission",
CheckSQLite: `SELECT CASE WHEN EXISTS (
SELECT 1 FROM permissions WHERE permission_key = 'action.execute_script'
) THEN 1 ELSE 0 END`,
CheckPostgres: `SELECT CASE WHEN EXISTS (
SELECT 1 FROM permissions WHERE permission_key = 'action.execute_script'
) THEN 1 ELSE 0 END`,
SQLite: `INSERT OR IGNORE INTO permissions (permission_key, permission_name, description, scope, is_system)
VALUES ('action.execute_script', 'Run Action Scripts', 'Can save or manually run actions that execute author-supplied JavaScript; in-process scripts have no per-script memory bound', 'global', 0)`,
Postgres: `INSERT INTO permissions (permission_key, permission_name, description, scope, is_system)
VALUES ('action.execute_script', 'Run Action Scripts', 'Can save or manually run actions that execute author-supplied JavaScript; in-process scripts have no per-script memory bound', 'global', false)
ON CONFLICT (permission_key) DO NOTHING`,
},
}

// domainEventClaimableIndexMigration adds the partial index the claim query
Expand Down
1 change: 1 addition & 0 deletions internal/database/schema/permissions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ INSERT OR IGNORE INTO permissions (permission_key, permission_name, description,
('action.manage', 'Manage Actions', 'Can create, edit, delete, and execute workspace actions', 'workspace', 0),
('action.credential.manage', 'Manage Action Credentials', 'Can create, rotate, and delete workspace-scoped action credentials (API tokens for HTTP capabilities)', 'workspace', 0),
('action.set_actor', 'Set Action Actor', 'Can configure an action to run as a specific user (impersonation); grants cross-workspace reach', 'global', 0),
('action.execute_script', 'Run Action Scripts', 'Can save or manually run actions that execute author-supplied JavaScript; in-process scripts have no per-script memory bound', 'global', 0),
('teams.manage', 'Manage Teams', 'Can create, edit, and delete teams', 'global', 0),
('public_board.manage', 'Manage Public Boards', 'Can make collections public and configure public board sharing', 'global', 0);

Expand Down
1 change: 1 addition & 0 deletions internal/database/schema/permissions_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ INSERT INTO permissions (permission_key, permission_name, description, scope, is
('action.manage', 'Manage Actions', 'Can create, edit, delete, and execute workspace actions', 'workspace', false),
('action.credential.manage', 'Manage Action Credentials', 'Can create, rotate, and delete workspace-scoped action credentials (API tokens for HTTP capabilities)', 'workspace', false),
('action.set_actor', 'Set Action Actor', 'Can configure an action to run as a specific user (impersonation); grants cross-workspace reach', 'global', false),
('action.execute_script', 'Run Action Scripts', 'Can save or manually run actions that execute author-supplied JavaScript; in-process scripts have no per-script memory bound', 'global', false),
('teams.manage', 'Manage Teams', 'Can create, edit, and delete teams', 'global', false),
('public_board.manage', 'Manage Public Boards', 'Can make collections public and configure public board sharing', 'global', false)
ON CONFLICT (permission_key) DO NOTHING;
Expand Down
4 changes: 4 additions & 0 deletions internal/models/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ const (
PermissionProjectManage = "project.manage"
PermissionCustomersManage = "customers.manage"
PermissionActionSetActor = "action.set_actor" // Configure an action's actor_user_id to impersonate any user at execution time
// PermissionActionExecuteScript gates authoring and running action nodes that
// execute author-supplied JavaScript. Sobek runs in-process without a hard
// per-script heap bound, so this is a global trust level, not a workspace one.
PermissionActionExecuteScript = "action.execute_script" // Save or manually run actions containing execute_script nodes

// Workspace permissions
PermissionWorkspaceAdmin = "workspace.admin" // Manage workspace (administer workspace)
Expand Down
5 changes: 5 additions & 0 deletions internal/operatorcontrols/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ customer instance retains its own application, database and storage boundary.
| Plugin CLI execution | Operator gate intersects persisted organization preference |
| LDAP writes, test and sync | Operator gate; existing records retained for migration |
| Script authoring/import/execution | Operator gate; read/remove definitions remains possible |
| Saving or manually running `execute_script` nodes | Global `action.execute_script` permission; `action.manage` alone is not sufficient |
| Attachment preference | Organization may tighten operator per-object ceiling |
| Bulk imports | Operator gate and optional host admission |
| Mail transports and AI connections | Operator gate; normal permissions still required |
Expand Down Expand Up @@ -147,4 +148,8 @@ Enabled condition and action scripts share the instance-wide `concurrent_scripts
admission pool. `script_timeout_ms` caps both runtimes and action-script REST
deadlines; node settings can only narrow the ceiling. Permits are released on
success, error and cancellation. These ceilings are not heap/process isolation.
Saving or manually running an action that contains an `execute_script` node also
requires the global `action.execute_script` permission: a workspace
`action.manage` holder cannot author a script node. Existing definitions still
run on triggers, so remove or rewrite them before revoking the permission.
Keep untrusted scripts disabled until a separately bounded worker design is available.
2 changes: 1 addition & 1 deletion internal/restapi/v1/handlers/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ActionHandler struct {
// low-volume admin tooling, slower than the cookie path).
func NewActionHandler(db database.Database, permissionService *services.PermissionService, actionService *services.ActionService) *ActionHandler {
repo := repository.NewActionRepository(db)
definitions := services.NewActionDefinitionService(db, repo, actionService)
definitions := services.NewActionDefinitionService(db, repo, actionService, permissionService)
return &ActionHandler{
BaseHandler: NewBaseHandler(db, permissionService),
repo: repo,
Expand Down
2 changes: 1 addition & 1 deletion internal/restapi/v2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func executeAction(actions actionApplication) jsonOperation[actionExecuteRequest
if input.ItemID <= 0 {
return actionExecuteResponse{}, newError(http.StatusBadRequest, "invalid_request", "item_id is required")
}
status, err := actions.Execute(user.ID, workspaceID, actionID, input.ItemID)
status, err := actions.Execute(user.ID, workspaceID, actionID, input.ItemID, auditActor(r, user))
return actionExecuteResponse{Status: status}, actionError(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/restapi/v2/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ type actionApplication interface {
Logs(int, int, int, int, int) ([]*models.ActionExecutionLog, int, error)
ListRevisions(int, int, int, int, int) ([]models.ActionDefinitionRevisionSummary, int, error)
GetRevision(int, int, int, int) (*models.ActionDefinitionRevision, error)
Execute(int, int, int, int) (models.ActionExecutionStatus, error)
Execute(int, int, int, int, services.AuditActor) (models.ActionExecutionStatus, error)
}

// Deps lists every required v2 dependency. Construction has no fallbacks.
Expand Down
Loading
Loading