Security, Governance and PlatformPlatform contracts and execution isolationPrincipal
How should a queued agent job preserve the authenticated requester’s identity and authority?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
An authenticated API request enqueues user_id, tenant_id and an action. A privileged worker later trusts those fields, while other internal producers can also write to the queue. Explain the impersonation risk, design an authoritative job record and submit-time checks, and compare signed messages with server-issued references under tampering, replay and revocation.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Authentication establishes who made a request at one boundary. A queue message later containing that user’s name does not automatically carry the same assurance. The worker needs evidence linking the job to authenticated intake and a current decision about the requested effect.
The API authenticates a request and enqueues {user_id, tenant_id, action}. A worker reads it later and uses a service credential to call a privileged tool. If the worker treats those two IDs as authority just because they came through a queue, it has moved trust from an authenticated request into editable task data. A bug in a producer, an overly broad queue-write permission or an internal test publisher can claim another user. The queue proves that a permitted producer sent bytes, not that the named user authorized the action. This is a confused-deputy shape. AWS's IAM guidance explains the general problem, while SQS least-privilege guidance addresses which producers can write to a queue.
At intake, bind the authenticated principal to an action record that the producer cannot arbitrarily rewrite. Store the requester, tenant, allowed operation, resource, parameters, approval version and expiration under a server-issued job ID. Enqueue the opaque ID and a minimal routing hint. The worker reads the authoritative record, verifies its integrity and current eligibility, then asks the policy service whether this action may execute now. The privileged tool should also enforce the target tenant and action, rather than accepting a free-form user ID from the model or message body.
If someone argues that a signed queue message is enough, ask who signs it and what it attests. A signature from an overprivileged producer proves which service submitted the claim, not whether that service bound it to the authenticated user correctly. Signatures can protect transit and detect tampering, but they do not substitute for the authorization decision. Audit the original principal, producer identity, job ID and execution decision so the chain can be reconstructed.
Test a producer trying to enqueue a different tenant's job, a modified message after intake and a legitimate job whose user loses access before execution. The last case may require fresh approval or a fail-closed stop under the product's policy. The agent's task was approved yesterday. The employee loses access today. Does the scheduled action run? covers revocation of a scheduled task. This case asks how the worker knows whose task it received in the first place.
For example, intake can create job J under Alice’s authorized tenant A with a canonical order and amount. A message containingJis a request to process that stored intent, not permission to replace its requester with Bob. The worker readsJfrom a store whose write permissions and mutation rules protect those fields, then uses an atomic state transition or equivalent coordination to claim the next execution attempt. Duplicate delivery should return to the same operation identity instead of creating another business action.
An opaque job ID alone is not a security control. Another producer might learn or guess it. The worker must enforce producer permissions, job eligibility and any binding between the job and allowed processing lane. If a self-contained signed envelope is used instead, define the trusted issuer, audience, immutable action fields, expiry and replay handling. A signature from a service allowed to invent any subject still authenticates an unsafe claim.
Test the intake service and worker as separate trust boundaries. Try modifying requester fields, publishing an existing job onto the wrong lane and replaying a completed job. Then revoke the legitimate requester while a job is waiting. Identity integrity explains whose request this was. Current policy explains whether it may execute now. Both must hold before the worker spends its privileged credential.
Related questions
Keep practising security, governance and platform
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux