Protect Workflow Payloads
In embedded Laravel, opt in per workflow with withPayloadProtection(). The application seals durable Avro values with authenticated encryption before recording them. Each frame identifies its key by ID. Callers and queue workers obtain keys from the application's namespace-specific provider.
Use V2 from Workflow 2.46.0 or later, PHP with ext-sodium, and the queue and database from the Laravel quickstart.
Configure application-owned keys
For this example, use the default namespace. Generate the first key in a local shell and keep it in the environment shared by your Tinker sessions and queue workers. Use a secret store to distribute keys in production. Run the example with uncached Laravel configuration so a new process reads the changed environment.
export WORKFLOW_DEMO_KEY_V1="$(php -r 'echo base64_encode(random_bytes(32));')"
export WORKFLOW_DEMO_ACTIVE_KEY=v1
Save the following as config/payload-protection.php.
<?php
return [
'active' => env('WORKFLOW_DEMO_ACTIVE_KEY', 'v1'),
'keys' => [
'v1' => env('WORKFLOW_DEMO_KEY_V1'),
'v2' => env('WORKFLOW_DEMO_KEY_V2'),
],
];
Add the binding and imports below to app/Providers/AppServiceProvider.php. If the provider already has a register method, add the binding inside that method.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
use Workflow\Serializers\PayloadProtection;
use Workflow\V2\Contracts\PayloadProtectionKeys;
final class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(PayloadProtectionKeys::class, function ($app) {
$settings = $app['config']->get('payload-protection');
$keys = [];
foreach ($settings['keys'] as $id => $encoded) {
if ($encoded === null) {
continue;
}
$key = base64_decode($encoded, true);
if ($key === false || strlen($key) !== 32) {
throw new InvalidArgumentException('Invalid workflow protection key.');
}
$keys[$id] = $key;
}
$protection = new PayloadProtection($keys, $settings['active']);
return new class($protection) implements PayloadProtectionKeys {
public function __construct(private readonly PayloadProtection $protection)
{
}
public function forNamespace(string $namespace): ?PayloadProtection
{
return $namespace === 'default' ? $this->protection : null;
}
};
});
}
}
Start a protected workflow
Save this class as app/Workflows/ProtectedOrder.php. The workflow waits for an application signal with one integer argument.
<?php
namespace App\Workflows;
use Workflow\V2\Attributes\Signal;
use Workflow\V2\Workflow;
use function Workflow\V2\await;
#[Signal('approve', [['name' => 'quantity', 'type' => 'int', 'allows_null' => false]])]
final class ProtectedOrder extends Workflow
{
public function handle(string $order): array
{
$quantity = await('approve');
return ['order' => $order, 'quantity' => $quantity];
}
}
Start php artisan queue:work with v1 active. In another process with the same key configuration, run php artisan tinker and enter the following. Wait for the run to reach waiting before rotating. Choose a fresh workflow ID when repeating the example.
use App\Workflows\ProtectedOrder;
use Workflow\V2\WorkflowStub;
$workflow = WorkflowStub::make(ProtectedOrder::class, 'payload-rotation-demo', 'default')
->withPayloadProtection();
$workflow->start('private order λ');
Rotate the key and resume
Stop the example worker. Keep WORKFLOW_DEMO_KEY_V1, add the second key, and start a fresh worker with v2 active. In production, distribute both keys to every caller and worker in the namespace before switching the active writer. Restart long-running processes after the switch.
export WORKFLOW_DEMO_KEY_V2="$(php -r 'echo base64_encode(random_bytes(32));')"
export WORKFLOW_DEMO_ACTIVE_KEY=v2
php artisan queue:work
Start a fresh Tinker session with the new configuration and send the signal. The worker opens the old workflow input with v1 and writes the new result with v2.
use App\Workflows\ProtectedOrder;
use Workflow\V2\WorkflowStub;
$workflow = WorkflowStub::make(ProtectedOrder::class, 'payload-rotation-demo', 'default');
$workflow->withRequestId('approve-once')->signal('approve', 7);
After the run completes, read its output from the same Tinker session.
$workflow->refresh()->output();
// ['order' => 'private order λ', 'quantity' => 7]
Protection and retention
Protected runs cover durable workflow and ordinary activity arguments and results, recorded side-effect results, and application signal and update values. Child runs and continue-as-new inherit protection. For external payload storage, the storage driver receives the encrypted bytes. Application queries use the keys to replay state in memory. Webhook ingress and control-plane queries refuse protected runs.
IDs, names, queues, search attributes, memo fields, and application error text stay visible. Keep sensitive data out of those fields and logs. Activity heartbeat details, checkpoints, and the hosted activity task bridge are outside this protection scope. Operator views can show a protected marker for opaque values.
Keep each old key until the histories, external objects and restore copies that need it have expired or have been removed. A missing key produces payload_key_unavailable and leaves the protected value unreadable. Rotation preserves the original ciphertext in retained history.