Medplum Bot access policies and run-as-user

Medplum Bot access is set by the identity a Bot runs as, its project membership and access policies. This page explains how to choose between runAsUser, client credentials and a dedicated integration identity on a self-hosted deployment.

On this page

How Medplum Bot access policies and run-as-user decide what a Bot can touch

A Bot's reach comes from the identity it runs under and the access policies applied to that identity. For a self-hosted team whose Bots read and write patient data, this is the control that limits blast radius. A Bot is not trusted because it is code you wrote. It is trusted only as far as the Medplum project membership it runs through allows. Medplum's documentation describes Bots as server-side logic that runs with a Bot profile, and a Bot membership ties that profile to a project and a set of access policies. Once you know which membership a Bot uses, you know which resource types, compartments and operations it can reach. The other half is runAsUser, a setting that makes a Bot act with the calling user's access instead of its own. Both settings change what a Bot can read or write, so they belong in the same review.

Make this decision before the first production Bot is deployed, and again every time a Bot's scope changes: a new resource type, a new Subscription trigger, a cron schedule, or a move from a developer project to production. Write down, for each Bot, the identity it uses, whether runAsUser is set, the access policy that applies, and the one or two resource types it genuinely needs. Then confirm the result in a non-production project by calling the Bot as the identity it will use in production and checking that out-of-scope reads and writes fail. Confirm exact policy syntax, membership fields and the current behavior of runAsUser against the version you run, because these details change between releases and the Medplum docs are the authority for your build.

Medplum's compliance documentation describes HIPAA, SOC 2 Type II and other obligations as a shared responsibility between Medplum and its customers. On a self-hosted deployment, the access model you design for Bots is part of your side of that split, and no vendor document will decide it for you. Your compliance lead should be able to see the Bot inventory, each identity and policy, and the evidence that the policies were tested. Independent auditors will judge whether the controls work, so plan the evidence as you build the policies, not after the audit request arrives. Review the Medplum compliance documentation with your compliance team before deciding which records each Bot identity may hold.

Choosing the identity a Bot runs as

Run-as-user lets a Bot act with the access of the identity that invoked it, so the Bot's reach follows the caller's own access policies. This fits Bots that perform work on behalf of a specific person, such as a clinician-facing operation where the result should be limited to what that clinician could already read or write. Because the Bot inherits access, it does not need a separate policy for every use case.

  • Access granted: Whatever the calling user can read and write, including compartments and patient scopes that user is allowed to reach.
  • Best fit: Interactive operations triggered by a signed-in user, where audit trails should name the person responsible.
  • Main risk: Any user who can invoke the Bot indirectly gains the Bot's capabilities, so a broad or poorly scoped caller widens the blast radius.
  • Operational risk: Scheduled or event-driven runs may have no meaningful caller, so confirm how the Bot behaves when no user is attached.
  • Review point: Confirm the exact runAsUser semantics, including which identity is recorded in AuditEvents, in the current Medplum docs before relying on them.

Before approving this pattern, list every role that can invoke the Bot and confirm each one should be allowed to exercise its full access through it.

Access options for Medplum Bots and when each fits

This table compares the main ways to control what a Medplum Bot can read and write, from project membership to scoped integration Bots. Read each row as a question: what does the option control, when does it fit, and what must you confirm in your own project before relying on it. The main takeaway is that a Bot's effective access comes from several settings together, so test the combination rather than any single option.

OptionWhat it controlsWhen it fitsWhat to confirm before relying on it
Bot project membershipWhich Medplum project the Bot runs in and which resources exist there at allAny Bot that needs data from one project only, and as the baseline boundary for every other optionWhich project each Bot belongs to, and whether dev and production Bots are kept in separate projects
Access policies on the Bot profileThe resource types and compartments the Bot's identity may read, create, update or deleteIntegration Bots that only touch a fixed set of resource types, such as writing Observations from a device feedThat the policy grants only the resource types and actions the Bot needs, and that it is tested with a sample request for each
runAsUserRuns the Bot with the calling user's own access rights rather than the Bot's standing permissionsBots invoked by clinicians or staff where results should match what that person could already do in the chartHow the Bot behaves when the caller has no rights, and whether audit records show the true caller and the Bot
Client credentials as triggersLets an external system call a Bot or operation with a machine identity, outside any human sessionServer-to-server calls from a registry, lab or billing system that needs a fixed, auditable identityWho holds the client secret, how it is rotated, and which access policy applies to that client identity
Scoped integration BotsA dedicated Bot identity with the narrowest policy for one job, with its own secrets and triggersSingle-purpose workflows such as one interface feed, where a separate identity limits blast radiusThat no shared or default access policy widens the scope, and that each integration Bot has a named owner and review date

Setting up least-privilege access for a Bot

This sequence gives each Medplum Bot an identity that can reach only the resources its job needs, and confirms the restriction works before the Bot touches production data. It ends with a tested trigger method and a record of what the Bot can and cannot read or write.

  1. Inventory the resources each Bot needs

    Before opening any permissions, list every FHIR resource type and operation the Bot must read, create, update or delete, along with the trigger that starts it (a Subscription, a cron schedule, a custom operation or an external call). The integration owner and the security reviewer should sign off on this list, because it becomes the baseline for every later check. Done means you have a written table that maps each Bot to its resource types and actions, and any resource type not on the table is treated as out of scope. Confirm the resource types and operations your Medplum version supports, since the field names and search parameters vary between releases.

  2. Create a dedicated Bot identity

    Create a separate Bot membership for each integration rather than reusing an administrator or a shared developer account, so that every execution can be traced to one purpose. Keep Bots that serve different data flows, such as lab results and billing, on separate identities. Done means each Bot has its own identity in the project, and the membership list shows no Bot sharing a login with a person or another integration. Check in your Medplum version how Bot memberships and their profile resources are created, because the exact steps differ between the admin console and the API.

  3. Write access policies limited to those resources

    Attach an access policy to the Bot identity that names only the resource types and compartments from your inventory, and grant only the read or write actions each one needs. Avoid wildcard resource types and project-wide admin rights, and keep the policy file in version control so changes are reviewed. Done means the policy reads as a direct copy of the inventory table with nothing added. Confirm how your version evaluates overlapping policies on the same identity, since a broad policy attached elsewhere can widen what the Bot reaches.

  4. Choose runAsUser or a client credential for the trigger

    Decide how each Bot is invoked. With runAsUser, the Bot executes with the access rights of the user who triggered it, which suits interactive operations where the caller's permissions should bound the result. For unattended runs such as Subscriptions, cron jobs or server-to-server calls, use the Bot's own identity or a client credential scoped to that Bot, so that it does not depend on a person's session. Done means each Bot has one written trigger method and the reason for it. Confirm in your version whether runAsUser is available on the trigger type you plan to use, and how it interacts with the Bot's own policy.

  5. Verify the Bot cannot reach out-of-scope resources

    Run the Bot against a non-production project and attempt reads and writes on resource types outside its policy, such as a Patient search when the Bot should only touch Observations. Each out-of-scope request should return an authorization error, and the attempt should appear in the audit log. Repeat the check with a caller who has broader rights to confirm that runAsUser cannot exceed the caller's own access. Done means you have a short test record listing each attempted action, the expected result and the actual result. Confirm where your version records these denials, since audit event structure differs between releases.

  6. Test the in-scope path and record the result

    Using the same non-production project, run the Bot through its normal inputs and confirm it completes every in-scope read and write without needing extra permissions. If a legitimate step fails, fix the policy by adding the narrowest permission that unblocks it, then rerun the out-of-scope checks. Done means the in-scope test passes, the out-of-scope test still fails, and both records are filed with the Bot's change ticket. Confirm the test procedure against your own Medplum version and project configuration before repeating it in production.

  7. Review and repeat the check on each change

    Schedule a review each time the Bot's code, trigger, policy or Medplum version changes, and rerun both the in-scope and out-of-scope tests. Compare the current policy with the inventory table and remove any permission that no longer matches a documented need. Done means the review record shows the policy, the inventory and the test results agree. Confirm your organization's change management and review requirements with your compliance lead, since these checks support but do not replace them.

How a Subscription, cron or client call reaches a Bot and its data

A trigger starts in one of three places: a FHIR Subscription firing on a resource change, a cron schedule, or a client credentials call. Each one reaches the Bot through the Medplum server, and the Bot then acts under one of two identities: the caller's own access through runAsUser, or a dedicated Bot identity with its own memberships. Check which identity each path uses, because the access policies evaluated on the Medplum server decide what the Bot can read and write in PostgreSQL.

Three triggers reach a Bot through the Medplum server, which applies access policies before any data is touched.

Security risks when Bots inherit or share broad access

Bots act with the access of the identity they run under, so a single broad grant or shared credential can reach far more data than the integration needs. The cards below cover the risks that most often appear when Bots inherit privileged access, share credentials, or write to one shared audit identity, and the control to apply to each.

runAsUser exceeds intended scope

When a Bot runs with runAsUser, it acts with the access of the caller, so a privileged administrator who triggers it can make the Bot reach records the Bot was never meant to touch. Decide per Bot whether it should inherit the caller's access at all, and test it with a low-privilege caller to see what actually comes back. Confirm the exact runAsUser behavior for your Medplum version in the docs before relying on it.

Medplum auth docs

Shared client credentials across Bots

When several Bots or integrations use the same client credentials, revoking or rotating one integration breaks all the others, and a leaked secret exposes every Bot's access at once. Give each integration its own client identity with the narrowest access policy it needs. Check how client credentials are issued and rotated in your project, and keep their values in project secrets rather than in Bot code.

Wildcard access policies

Access policies that grant broad or wildcard resource access let a Bot read and write resource types it never uses, which turns a small integration into a wide data exposure. Write each policy against the specific resource types and compartments the Bot requires, and review it whenever the Bot's function changes. Test each policy with real requests to confirm that denied operations are actually denied.

No separation of development and production

When Bots are tested in the same project that holds production patient data, a faulty test Bot or a copied secret can change live records. Keep separate development and production projects with distinct identities, secrets and access policies, and promote Bots through a controlled release. Confirm how your deployment isolates projects and whether test data can be kept out of production.

Audit gaps when Bots share one identity

If several Bots run under one shared identity, AuditEvents show activity under that identity but cannot tell you which Bot, schedule or caller produced a given change. Give each Bot or integration its own identity so every action traces back to a single owner. Check that AuditEvents capture Bot executions and Subscription triggers in your deployment, and that logs are retained and reviewed.

Medplum compliance docs

Human accounts without MFA

A person who can edit Bots, secrets or access policies can change what every Bot is allowed to do, so a weak human login becomes a path to the whole integration layer. Require multi-factor authentication on every account that can administer projects, and limit administrator roles to the people who need them. Confirm which MFA methods your identity provider supports and who holds project admin rights.

Medplum auth docs

Trade-offs between inherited access and dedicated integration identities

The core decision is whether a Bot should act with the permissions of the user who triggered it, through runAsUser, or with its own identity whose scope is set once and reviewed on its own. Inheriting the caller's access keeps behavior aligned with the person who started the work, so a clinician-facing Bot shows the same records that clinician could open by hand. It also avoids creating and maintaining a separate identity for every workflow. The cost is that the Bot's reach moves whenever that user's roles, access policies or project memberships change, so a Bot that works for one caller may fail or over-reach for another.

A dedicated integration identity gives predictable, reviewable scope. Its access policy and Bot membership can be read in one place, and audit records show a stable actor rather than a rotating list of people. The price is ongoing maintenance: when resource types, compartments or search parameters change in your data model, the identity's policy has to be checked and updated, or the Bot will quietly lose access it needs. Confirm with your team how often your data model changes and who owns the policy review, because that frequency decides how much maintenance the dedicated identity will take.

Decide per Bot, not per platform. For each Bot, record the data it reads and writes, whether any execution is triggered by a human session, whether it runs on a schedule or from a Subscription, and how often its scope is expected to change. Bots that act on behalf of a user and touch only that user's data are usually candidates for inheritance. Bots that run unattended, aggregate across patients or feed external systems are usually better served by a dedicated identity with the narrowest policy that works. Document each decision as a short record that names the Bot, its identity, the reason, the owner, the review interval and the test that proves the scope. Auditors will ask how a decision was made and whether it is still valid, so the record should be kept with the Bot's source code and updated when the Bot changes.

Limits to confirm in your Medplum environment

Bot access depends on details that change between Medplum versions and between deployments, so none of the patterns in this topic should be treated as settled until your own environment confirms them. The cards below list the behaviors to verify, how each one affects what a Bot can read and write, and where the official documentation answers the question.

Exact runAsUser behavior by version

Confirm how runAsUser resolves the caller's identity and permissions in the Medplum version you run, including which resources it can reach and whether it carries the caller's access policies or only the Bot's own. Behavior can differ between releases, so check it against the exact version in your upgrade plan, not against examples from newer documentation. Run a test Bot that reads a resource the caller cannot see and record the result.

Self-hosting docs

Access policy application to Bot profiles

Confirm how access policies attach to Bot profiles in your deployment, including whether a policy on a ClientApplication or ProjectMembership applies to a Bot, and how multiple policies combine. Verify this in a non-production project with a Bot that has only the permissions you intend to grant. Record which resource types and compartments the Bot can write to, since a broad policy is the most common source of over-privileged integrations.

Medplum auth docs

Per-project Subscription limits

Confirm the maximum number of Subscriptions a single project can hold in your version, because each Subscription that triggers a Bot counts against it. Plan the mapping of resource changes to Bots before build, so one project does not run out of capacity when integrations are added. Ask Medplum for the current limit and any change process if your design needs more than the default.

Client credential token lifetimes

Confirm the access token lifetime and refresh behavior for client credentials used by Bots and external callers, and whether you can change these values in a self-hosted configuration. Short lifetimes limit damage from a leaked token but add refresh traffic and may break long-running jobs. Document the value you accept, who owns rotation of the client secret, and how a revoked client is handled during an incident.

Auth token docs

Identity provider support for the chosen pattern

Confirm that your identity provider setup supports the pattern you chose, such as passing the signed-in user's identity through to a Bot or using a client credential for a service identity. Check whether your provider or domain-level configuration supports the claims and flows the pattern requires, and whether multi-factor policy applies to service identities. Test sign-in and token issuance with your real identity provider before relying on the design.

Questions teams ask about Medplum Bot access and run-as-user

What does a Medplum Bot access design cost, and what drives the effort?

The cost is mostly the time of the people doing the design, testing and review, so effort scales with how much data the Bots touch. The main drivers are the number of Bots, the number of data classes each one reads or writes (Patient, Observation, Binary, Communication and similar), the number of Medplum projects involved, and how much testing and audit evidence your compliance team expects. A single read-only Bot on one project is a small task. Ten write-capable Bots across production and a test project, each with its own identity and documented permissions, is a much larger one. Ask any quote to break the work down by Bot, by project and by evidence deliverable, and to state which items are one-time and which recur when Bots or data classes change. Medplum's own pricing page covers hosting plans and does not price this design work.

How long does a scoped Medplum Bot access design take?

The duration depends on how many Bots and data classes are in scope and how quickly decisions can be made. Work usually takes longer when the data owners have not defined who should see which records, when the Bots must be reviewed by security or privacy staff before they are approved, or when the team has to build a test project to check permissions before anything touches production. Access policies that mirror existing role definitions are faster to draft than policies built from scratch. Ask for a written schedule with explicit review gates, and confirm which of those gates depend on your own staff being available. No duration is given here because the scope has to be agreed first.

What does the client team need to provide for this work?

Three things determine whether the design moves at a steady pace. First, named data owners who can state which FHIR resource types each Bot may read or write and under what conditions. Second, a security review step that checks the proposed Bot identities, access policies and any use of runAsUser against your own standards. Third, a Medplum test project, separate from production, where Bots and their access policies can be run with realistic but non-patient data before promotion. The client should also provide access to the current Bot code, the list of client credentials in use and the Subscriptions that trigger each Bot. Confirm these needs before work starts so they appear in the scope.

Can an internal team design Medplum Bot access without outside help?

Yes, a capable internal team can do this, provided it has the skills to cover the whole chain. Those skills include working knowledge of FHIR resources and search, Medplum access policies and project membership, OAuth client credentials and how Bots are invoked, and enough security judgment to decide which Bot identity should hold which permission. Teams without this mix often underestimate how many Bots call the same resources or how a Subscription can trigger a Bot under an unexpected identity. An external partner is most useful for a short scoped design, an independent review of the access model, or a retest after changes. Decide based on your staff's current capacity and the evidence your auditors will request.

When should a Bot use runAsUser instead of its own identity?

Use runAsUser when the Bot's work must respect the permissions of the person or system that triggered it, so it cannot see or change anything that caller could not. Use a dedicated Bot identity with a narrow access policy when the Bot performs a fixed integration task that no human user should be needed for, such as posting results from a lab feed. The choice affects audit trails, because the actions appear under the identity that actually ran them. Test both paths in a non-production project and confirm the behavior in your Medplum version, since permission handling is part of what the design must verify.

How does Medplum Bot access design change after a Medplum upgrade?

Access design must be re-checked after each upgrade, because the server version determines how access policies, Bot execution and client credentials behave. Medplum ships major versions annually, minor versions two to three times a year and patch versions weekly, and self-hosted deployments must move through each minor version in sequence. Plan a regression pass on the test project after every upgrade step: confirm that each Bot still runs under its intended identity, that runAsUser returns the expected results, and that AuditEvents still record the executions. Security patches also carry deadlines in Medplum's policy, so keep the access review on the same calendar as your upgrade plan. Confirm the exact behavior for your target version with Medplum's release notes before you schedule the work.

What evidence should an access design produce for compliance reviews?

Medplum's compliance documentation describes compliance as a shared responsibility between Medplum and its customers, so the access design must produce evidence your own assessors can review. Useful artifacts include an inventory of Bots with their identities, a matrix mapping each Bot to the resource types and projects it can reach, records of data owner approvals, test results from the non-production project, and procedures for reviewing changes. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications. Independent auditors and certification bodies make those determinations, so confirm early which evidence format your assessor requires.

How DeployOpen scopes and delivers Bot access design

DeployOpen treats Bot access as a design decision made before any Bot is written. We map each Bot's trigger, the data it reads and writes, and the identity it runs under, then build and test the Bot memberships and access policies that enforce that map in your self-hosted Medplum deployment.

How we scope

  • Inventory every planned Bot, its trigger type, and the FHIR resource types it reads and writes.
  • Record which Bots need runAsUser inheritance and which need a dedicated integration identity.
  • Agree deliverables, environments and timelines in writing, since most engagements are fixed-scope.

How we build

  • Create Bot memberships and access policies that grant only the resource types and compartments each Bot needs.
  • Test runAsUser and client credential triggers against both allowed and denied records in a non-production project.
  • Run negative tests to confirm that a Bot cannot read or modify data outside its written scope.

How we hand over

  • Document each Bot's identity, permitted resources, trigger and owner in a reviewable access register.
  • Provide the policy definitions as versioned configuration so changes go through your review process.
  • Walk your security and platform teams through test results, open risks and the procedure for adding a new Bot.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover.
  • Re-review access policies when Medplum releases change Bot behavior or access evaluation in your version.
  • Retest access controls after new Bots, new integrations or changes to identity provider settings.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.