Webhook icon
Script icon
Log icon
Sequential icon
Script icon
Request icon
Return icon

IDM User Provisioning Request via Webhook with Retries

Receive user provisioning requests via webhook, validate payloads in Python, and run PowerShell provisioning steps with automatic retries using Kestra.

Categories
Infrastructure

Give identity provisioning a real front door. An HR system, ITSM tool, or portal posts a JSON request to a secured webhook; the flow validates the payload, stamps it with a request id, and then executes the provisioning sequence: create the user, assign groups, register the account in the directory graph, and call downstream APIs. The whole provisioning block retries failed steps automatically, which the included addToGraph stub demonstrates by failing twice before succeeding on the third attempt.

How it works

  1. The user_provisioning_webhook trigger (io.kestra.plugin.core.trigger.Webhook) accepts a POST secured by the IDM_WEBHOOK_KEY secret; a payload JSON input with the same shape supports manual runs and testing.
  2. The validateRequest task (io.kestra.plugin.scripts.python.Script) parses {{ trigger.body ?? inputs.payload }}, rejects requests missing userPrincipalName or displayName, generates a requestId with uuid.uuid4(), and exposes every field as task outputs.
  3. The sendEmailProvisionRequest task is a Log placeholder for your notification of choice.
  4. The provisionUser task (io.kestra.plugin.core.flow.Sequential) wraps the provisioning steps with a constant retry policy (behavior: RETRY_FAILED_TASK, maxAttempts: 5, interval: PT2S), so only the failing step is retried, not the whole sequence.
  5. Inside it, createUser and addToGroup (io.kestra.plugin.scripts.powershell.Script) are stubs for your New-ADUser/Add-ADGroupMember or Microsoft Graph calls; addToGraph simulates a flaky directory API using taskrun.attemptsCount; callProvisionAPIs (io.kestra.plugin.core.http.Request) shows how to hit downstream systems; and sendProvisionDone returns the confirmation with the request id.

What you get

  • A validated, secured entry point for provisioning requests from any HTTP-capable system.
  • A generated request id that ties logs, outputs, and notifications together.
  • Step-level automatic retries that absorb transient directory and API failures.
  • PowerShell stubs positioned exactly where real AD or Graph calls belong.

Who it's for

  • IT and identity teams automating joiner workflows from HR or ticketing systems.
  • Platform engineers replacing email-driven account requests with an API.
  • Organizations that need provisioning steps to be retryable and fully logged.

Why orchestrate this with Kestra

Identity provisioning scripts tend to fail halfway: the user exists but has no groups, or the license call timed out silently. Kestra's RETRY_FAILED_TASK behavior retries exactly the failed step with its context intact, the webhook trigger provides a secured, standard entry point, payload validation happens before any change is made, and every request is an execution you can search by request id.

Prerequisites

  • A caller that can POST JSON to the webhook URL (HRIS, ITSM, or a portal).
  • For real provisioning, connectivity from the worker to your AD or Microsoft Graph endpoints.

Secrets

  • IDM_WEBHOOK_KEY: shared key guarding the Webhook trigger.

Quick start

  1. Add the IDM_WEBHOOK_KEY secret to your Kestra namespace.
  2. Execute manually with the default payload to watch validation, retries, and completion.
  3. Replace the PowerShell stubs with your real AD or Graph provisioning commands.
  4. Point your upstream system at the webhook URL with the configured key.

How to extend

  • Add a io.kestra.plugin.core.flow.Pause approval gate for privileged groups or license plans.
  • Send real notifications with io.kestra.plugin.email.MailSend or Slack.
  • Schedule deprovisioning at expirationDate by chaining a second flow.
  • Queue high volumes by setting flow concurrency limits and let Kestra backpressure requests.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.