Skip to content

Control who can call each function, by role

Declare roles in your project config, add allowRoles or denyRoles to a function, and Helix refuses anyone without the right role before your handler runs. Admins assign roles in the dashboard, with no redeploy.

Tray Helix

What you need: Update to @trayai/helix-sdk and @trayai/helix-cli 1.34.0 or later. Contributors and Admins assign roles on the project's Access Control tab.

continue with SSO your identity provider
enterprise sso every app

A sales team builds a deal desk on Helix. Reps submit discount requests, and the finance lead approves them. Everyone on the team can open the app. Only finance should be able to approve a discount, and Jon in sales should never be able to approve his own.

Role-based access is how the app says so. The project config lists a finance role. The approveDiscount function is marked allowRoles: ['finance']. Maya in finance is assigned the role on the project’s Access Control tab. When Jon calls the function, he gets a 403 and his handler never runs. When Maya calls it, it goes through.

What that gives IT and the people building:

  • The rule lives next to the function. Whoever reads approveDiscount sees who may call it, and the SDK enforces it before the handler runs.
  • Roles are managed outside the app. Admins add and remove roles per person in the dashboard. Nothing needs a redeploy.
  • Deny always wins. Block a role from one function, and holding another allowed role does not get around it.
  • A record of every change. Each role assignment and removal lands in the organization’s activity trail.

An example

The deal desk has three kinds of function: request a discount, view the queue, approve a discount. The team wants reps to do the first two and finance to do the third.

1. Declare the roles

In helix.config.ts, the team adds a roles map with finance and sales. The key is the role id used in code and the value is the name admins see in the dashboard. Roles are picked up on every deploy.

2. Put a rule on the function

approveDiscount exports an access rule that allows the finance role. The functions for requesting and viewing have no rule, so anyone who can open the app can use them.

3. Assign people

On the project’s Access Control tab, under Users, a Contributor or Admin picks the people and their roles. Maya gets finance. Jon and Lin get sales. Add people and their roles in one step, or edit roles later from the row.

4. Try it as someone else

Before the team deploys, a developer runs the app locally as a sales user, with helix dev --identity ./.helix/identities/sales.json. Calling approveDiscount returns the same 403 a rep would get in production.

What follows from how it works

  • Roles narrow access, they don’t grant it. A person still needs access to the app to use any role.
  • Anonymous callers hold no roles. allowRoles refuses them, and a function with only denyRoles lets them through.
  • It covers HTTP functions. Schedules and MCP tools are not checked by the access rule.
  • Removing a role from config keeps assignments. They grant nothing until the role is declared again, and the dashboard marks them.
  • Removing someone from the app removes their roles.

Before you start

Update the SDK and CLI. Roles need @trayai/helix-sdk and @trayai/helix-cli 1.34.0 or later.

Test deny rules with an identity file. The default helix dev user holds every role you declare, so allowRoles never blocks you locally. Use an identity file or the X-Helix-Dev-Roles header to try fewer roles.

Handle a real user in dev. Before 1.34.0, ctx.identity was null in helix dev. Code that assumed that now sees a real dev user.

Read more

Quick answers

Does a role let someone open an app they can't already open?

No. Access Control settings decide who can open the app, and roles only narrow what an allowed person can use. Someone without access never reaches the app, whatever roles they hold.

What happens when two rules disagree?

Deny wins. denyRoles is checked first, so a person with a denied role is refused even if they also hold an allowed one.

What does a refused caller see?

A 403 with a plain message. For allowRoles it names the roles that are needed. For denyRoles it says the caller does not have access to the endpoint.

Can I assign roles from the CLI?

No. Roles are assigned per person in the Users section of the project's Access Control tab, and every assignment and removal is recorded in the organization's activity trail.

Do scheduled functions and MCP tools check roles?

The access rule applies to HTTP functions. Schedules run without a user, so there is nothing to check. Tools served from the MCP endpoint don't enforce it, but they can read ctx.identity.user.roles and check it themselves.

Try it on your own app

Deploy an app you built with your AI assistant, and see what Helix does with it.