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
146 changes: 146 additions & 0 deletions app/Http/Controllers/Api/WorkerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers\Api;

use App\Contracts\AuthProvider;
use App\Http\Middleware\Authenticate;
use App\Models\WorkerBuildIdRollout;
use App\Models\WorkerRegistration;
use App\Support\AvroPayloadEnvelopeResolver;
Expand All @@ -18,9 +20,11 @@
use App\Support\PayloadCodecContract;
use App\Support\PollRequestTaskKindsConflict;
use App\Support\QueryTaskQueueUnavailableException;
use App\Support\RouteAuthorizationResource;
use App\Support\RuntimeExternalPayloadAudit;
use App\Support\RuntimeExternalPayloadException;
use App\Support\SearchAttributeValueValidator;
use App\Support\ServiceCallBoundary;
use App\Support\ServiceModeTimerDispatcher;
use App\Support\StreamClosedException;
use App\Support\StreamErroredException;
Expand Down Expand Up @@ -58,6 +62,7 @@
use Workflow\V2\Models\ActivityExecution;
use Workflow\V2\Models\WorkflowHistoryEvent;
use Workflow\V2\Models\WorkflowRun;
use Workflow\V2\Models\WorkflowServiceCall;
use Workflow\V2\Models\WorkflowTask;
use Workflow\V2\Support\StickyExecution;
use Workflow\V2\Support\WorkerProtocolVersion;
Expand Down Expand Up @@ -1506,6 +1511,31 @@ public function completeWorkflowTask(Request $request, string $taskId): JsonResp
'commands.*.condition_wait_occurrence_id' => ['nullable', 'string'],
'commands.*.signal_name' => ['nullable', 'string'],
'commands.*.timeout_seconds' => ['nullable', 'integer', 'min:0'],
'commands.*.endpoint_name' => ['nullable', 'string', 'max:191'],
'commands.*.service_name' => ['nullable', 'string', 'max:191'],
'commands.*.operation_name' => ['nullable', 'string', 'max:191'],
'commands.*.request_payload' => ['nullable'],
'commands.*.namespace' => ['nullable', 'string', 'max:191'],
'commands.*.caller_namespace' => ['nullable', 'string', 'max:191'],
'commands.*.service_call_id' => ['nullable', 'string', 'max:191'],
'commands.*.idempotency_key' => ['nullable', 'string', 'max:191'],
'commands.*.mode_override' => ['nullable', 'string', 'in:sync,async'],
'commands.*.wait_for' => ['nullable', 'string', 'in:accepted,completed'],
'commands.*.wait_timeout_seconds' => ['nullable', 'integer', 'min:0'],
'commands.*.target_workflow_instance_id' => ['nullable', 'string', 'max:191'],
'commands.*.target_workflow_run_id' => ['nullable', 'string', 'max:191'],
'commands.*.business_key' => ['nullable', 'string', 'max:191'],
'commands.*.labels' => ['nullable', 'array'],
'commands.*.memo' => ['nullable', 'array'],
'commands.*.search_attributes' => ['nullable', 'array'],
'commands.*.duplicate_start_policy' => ['nullable', 'string', 'in:reject_duplicate,return_existing_active'],
'commands.*.metadata' => ['nullable', 'array'],
'commands.*.request_payload_reference' => ['nullable', 'string', 'max:191'],
'commands.*.principal_subject' => ['prohibited'],
'commands.*.principal_method' => ['prohibited'],
'commands.*.principal_roles' => ['prohibited'],
'commands.*.principal_tenant' => ['prohibited'],
'commands.*.principal_claims' => ['prohibited'],
...WorkflowCommandNormalizer::parallelMetadataValidationRules(),
'commands.*.workflow_stream' => ['nullable', 'array'],
'commands.*.workflow_stream.operation' => ['required_with:commands.*.workflow_stream', 'string', 'in:append,close,error'],
Expand Down Expand Up @@ -1561,6 +1591,8 @@ public function completeWorkflowTask(Request $request, string $taskId): JsonResp
return $response;
}

$commands = $this->authorizeServiceOperationCommands($request, (string) $namespace, $commands);

if ($response = $this->guardWorkerSessionCommandsAvailable(
$request,
$taskId,
Expand Down Expand Up @@ -1731,6 +1763,7 @@ function () use (
return $response;
}

$this->authorizeServiceOperationReplays($request, (string) $namespace, $taskId, $commands);
$commands = $this->canonicalizeWorkflowStreamPayloadCodecs($commands);
$commands = app(WorkflowStreamCommandProcessor::class)->process(
$taskId,
Expand Down Expand Up @@ -2651,6 +2684,118 @@ private function promoteWorkflowFailureExceptionPayload(array $commands): array
* @param list<array<string, mixed>> $commands
* @return list<array<string, mixed>>
*/
private function authorizeServiceOperationCommands(Request $request, string $namespace, array $commands): array
{
foreach ($commands as $index => $command) {
if (($command['type'] ?? null) !== 'start_service_operation') {
continue;
}

$principal = Authenticate::principal($request);
$targetNamespace = strtolower(trim($command['namespace'] ?? $namespace));
$callerNamespace = strtolower(trim($command['caller_namespace'] ?? $namespace));
if ($callerNamespace !== $namespace) {
throw ValidationException::withMessages([
"commands.{$index}.caller_namespace" => 'The caller namespace must match the leased workflow namespace.',
]);
}

$resource = array_replace(app(RouteAuthorizationResource::class)->make($request, ['worker']), [
'operation_family' => 'service',
'operation_name' => 'execute_operation',
'target_namespace' => $targetNamespace,
'namespace_name' => $targetNamespace,
'caller_namespace' => $namespace,
'service_endpoint_name' => strtolower(trim($command['endpoint_name'])),
'service_name' => strtolower(trim($command['service_name'])),
'service_operation_name' => strtolower(trim($command['operation_name'])),
]);
abort_unless($principal !== null && app(AuthProvider::class)->authorize($principal, 'execute_operation', $resource), 403);

if (isset($command['search_attributes'])) {
$this->searchAttributeValues->validateForNamespace(
$targetNamespace,
$command['search_attributes'],
"commands.{$index}.search_attributes",
);
}

// A worker owns command intent, not the authenticated caller identity.
$commands[$index] = array_replace($command, [
'namespace' => $targetNamespace,
'caller_namespace' => $namespace,
'principal_subject' => $principal->subject(),
'principal_method' => $principal->method(),
'principal_roles' => $principal->roles(),
'principal_tenant' => $principal->tenant(),
'principal_claims' => $principal->claims(),
]);
}

return $commands;
}

/**
* @param list<array<string, mixed>> $commands
*/
private function authorizeServiceOperationReplays(Request $request, string $namespace, string $taskId, array $commands): void
{
foreach ($commands as $index => $command) {
if (($command['type'] ?? null) !== 'start_service_operation') {
continue;
}

$callId = $command['service_call_id'] ?? null;
$key = $command['idempotency_key'] ?? null;
if ($callId === null && $key === null) {
continue;
}

$query = WorkflowServiceCall::query()->where('target_namespace', $command['namespace']);
if ($callId !== null) {
$query->whereKey(trim($callId));
} else {
$query->where('endpoint_name', strtolower(trim($command['endpoint_name'])))
->where('service_name', strtolower(trim($command['service_name'])))
->where('operation_name', strtolower(trim($command['operation_name'])))
->where('idempotency_key', trim($key))
->oldest('created_at')->oldest('id');
}
$call = $query->first();
if ($call === null && $callId === null) {
continue;
}

$runId = WorkflowTask::query()->whereKey($taskId)->value('workflow_run_id');
$principal = Authenticate::principal($request);
abort_unless($call !== null && $principal !== null
&& $call->caller_namespace === $namespace
&& $call->caller_workflow_run_id === $runId
&& $call->endpoint_name === strtolower(trim($command['endpoint_name']))
&& $call->service_name === strtolower(trim($command['service_name']))
&& $call->operation_name === strtolower(trim($command['operation_name'])), 403);

// Existing call IDs and idempotency keys must not skip current boundary policy.
$operation = $call->operation;
abort_unless($operation !== null && $call->endpoint !== null && $call->service !== null, 403);
$rejection = app(ServiceCallBoundary::class)->replayRejectionFor(
principal: $principal,
callerNamespace: $namespace,
operation: $operation,
endpointName: $call->endpoint_name,
serviceName: $call->service_name,
callerWorkflowInstanceId: $call->caller_workflow_instance_id,
callerWorkflowRunId: $runId,
idempotencyKey: $key,
operationModeOverride: $command['mode_override'] ?? null,
endpointBoundaryPolicy: $call->endpoint->boundary_policy ?? [],
serviceBoundaryPolicy: $call->service->boundary_policy ?? [],
operationBoundaryPolicy: $operation->boundary_policy ?? [],
);
abort_if($rejection !== null, 403);
}
}

private function normalizeWorkflowTaskCommandIntegerFields(array $commands): array
{
$integerFields = [
Expand All @@ -2668,6 +2813,7 @@ private function normalizeWorkflowTaskCommandIntegerFields(array $commands): arr
'min_supported',
'max_supported',
'timeout_seconds',
'wait_timeout_seconds',
];

foreach ($commands as $index => $command) {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": "^8.2",
"apache/avro": "^1.12",
"durable-workflow/workflow": "2.0.3",
"durable-workflow/workflow": "2.0.6",
"laravel/framework": "^13.0",
"laravel/tinker": "^3.0",
"league/flysystem-aws-s3-v3": "^3.35.3"
Expand Down Expand Up @@ -48,7 +48,7 @@
},
"extra": {
"durable-workflow": {
"product-train": "2.3.0"
"product-train": "2.3.1"
},
"laravel": {
"dont-discover": []
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docker-compose.dedicated-matching.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ name: durable-workflow-server
# daemon reports `shape: dedicated`.

# Generated by scripts/ci/sync-source-release.mjs. Do not edit the fallback.
x-server-image: &server-image ${DW_SERVER_IMAGE:-durableworkflow/server:${DW_SERVER_TAG:-2.3.0}}
x-server-image: &server-image ${DW_SERVER_IMAGE:-durableworkflow/server:${DW_SERVER_TAG:-2.3.1}}

x-server-environment: &server-environment
APP_NAME: "Durable Workflow Server"
APP_ENV: ${APP_ENV:-local}
DW_SERVER_KEY: ${DW_SERVER_KEY:-}
APP_VERSION: ${APP_VERSION:-${DW_SERVER_TAG:-2.3.0}}
APP_VERSION: ${APP_VERSION:-${DW_SERVER_TAG:-2.3.1}}
APP_DEBUG: ${APP_DEBUG:-false}
DB_CONNECTION: mysql
DB_HOST: mysql
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.memo-rolling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ services:
command: ["server-bootstrap"]
environment:
<<: *runtime-environment
APP_VERSION: ${APP_VERSION:-2.3.0}
APP_VERSION: ${APP_VERSION:-2.3.1}

successor:
image: ${DW_MEMO_SUCCESSOR_IMAGE:-durable-workflow/server-memo-rolling:local}
ports: !override []
environment:
<<: *runtime-environment
APP_VERSION: ${APP_VERSION:-2.3.0}
APP_VERSION: ${APP_VERSION:-2.3.1}
DW_SERVER_ID: memo-successor
DW_SERVER_TOPOLOGY_SHAPE: standalone_server
DW_SERVER_PROCESS_CLASS: server_http_node
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.published.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: durable-workflow-server

# Generated by scripts/ci/sync-source-release.mjs. Do not edit the fallback.
x-server-image: &server-image ${DW_SERVER_IMAGE:-durableworkflow/server:${DW_SERVER_TAG:-2.3.0}}
x-server-image: &server-image ${DW_SERVER_IMAGE:-durableworkflow/server:${DW_SERVER_TAG:-2.3.1}}

x-server-environment: &server-environment
APP_NAME: "Durable Workflow Server"
APP_ENV: ${APP_ENV:-local}
DW_SERVER_KEY: ${DW_SERVER_KEY:-}
APP_VERSION: ${APP_VERSION:-${DW_SERVER_TAG:-2.3.0}}
APP_VERSION: ${APP_VERSION:-${DW_SERVER_TAG:-2.3.1}}
APP_DEBUG: ${APP_DEBUG:-false}
LOG_CHANNEL: ${LOG_CHANNEL:-stderr}
LOG_LEVEL: ${LOG_LEVEL:-info}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.small-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ x-server-build: &server-build
x-server-environment: &server-environment
APP_NAME: "Durable Workflow Server"
APP_ENV: testing
APP_VERSION: ${APP_VERSION:-2.3.0}
APP_VERSION: ${APP_VERSION:-2.3.1}
APP_DEBUG: "false"
DW_SERVER_KEY: ${DW_SERVER_KEY:-base64:5Zt4nUhlCm3DD0nLXZJQdHiwPfb56yGo9gNV/g3jYbY=}
DB_CONNECTION: ${DW_SMALL_CLUSTER_DB:-mysql}
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
DW_SERVER_KEY: "${DW_SERVER_KEY:-}"
DW_SERVER_TOPOLOGY_SHAPE: standalone_server
DW_SERVER_PROCESS_CLASS: server_http_node
APP_VERSION: "${APP_VERSION:-2.3.0}"
APP_VERSION: "${APP_VERSION:-2.3.1}"
APP_DEBUG: "false"
DB_CONNECTION: mysql
DB_HOST: mysql
Expand Down Expand Up @@ -62,7 +62,7 @@ services:
APP_NAME: "Durable Workflow Server"
APP_ENV: local
DW_SERVER_KEY: "${DW_SERVER_KEY:-}"
APP_VERSION: "${APP_VERSION:-2.3.0}"
APP_VERSION: "${APP_VERSION:-2.3.1}"
APP_DEBUG: "false"
DB_CONNECTION: mysql
DB_HOST: mysql
Expand Down Expand Up @@ -123,7 +123,7 @@ services:
DW_SERVER_KEY: "${DW_SERVER_KEY:-}"
DW_SERVER_TOPOLOGY_SHAPE: standalone_server
DW_SERVER_PROCESS_CLASS: worker_node
APP_VERSION: "${APP_VERSION:-2.3.0}"
APP_VERSION: "${APP_VERSION:-2.3.1}"
DB_CONNECTION: mysql
DB_HOST: mysql
DB_PORT: 3306
Expand Down Expand Up @@ -176,7 +176,7 @@ services:
DW_SERVER_KEY: "${DW_SERVER_KEY:-}"
DW_SERVER_TOPOLOGY_SHAPE: standalone_server
DW_SERVER_PROCESS_CLASS: scheduler_node
APP_VERSION: "${APP_VERSION:-2.3.0}"
APP_VERSION: "${APP_VERSION:-2.3.1}"
DB_CONNECTION: mysql
DB_HOST: mysql
DB_PORT: 3306
Expand Down
10 changes: 5 additions & 5 deletions k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ The checked-in manifests are synchronized with the repository's stable source
release and pin its Docker Hub tag:

```text
durableworkflow/server:2.3.0
durableworkflow/server:2.3.1
```

Before production use, patch every workload image to the exact published tag or
digest you intend to run:

```bash
kubectl set image -n durable-workflow deploy/durable-workflow-server \
server=durableworkflow/server:2.3.0
server=durableworkflow/server:2.3.1
kubectl set image -n durable-workflow deploy/durable-workflow-worker \
worker=durableworkflow/server:2.3.0
worker=durableworkflow/server:2.3.1
kubectl set image -n durable-workflow cronjob/durable-workflow-scheduler \
scheduler=durableworkflow/server:2.3.0
scheduler=durableworkflow/server:2.3.1
```

GitHub Container Registry publishes the same release line at
`ghcr.io/durable-workflow/server:2.3.0`. Digest pinning is preferred for strict
`ghcr.io/durable-workflow/server:2.3.1`. Digest pinning is preferred for strict
change control.

The manifests expect you to provide:
Expand Down
Loading