AI Agent Role-Based Access Control using Airtable and Telegram - n8n Workflow

Implement robust RBAC for your AI agents using this specialized n8n workflow. Manage user permissions (tools and roles) via Airtable and restrict access over Telegram.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Organizations deploying internal or external AI assistants that require differentiated access levels.
Developers looking for advanced LangChain integration, particularly tool filtering, within an n8n workflow.
System administrators who need a scalable way to manage user permissions for LLM tools using an n8n node structure.
Users seeking specialized n8n templates for secure, nested AI agent architecture.

Overview

This specialized n8n workflow provides a production-ready blueprint for implementing strong security boundaries around your AI agents. The primary challenge this n8n workflow solves is preventing unauthorized use of powerful tools (like database write access, file operations, or API calls) when an AI agent is exposed to multiple users via a platform like Telegram.

Instead of relying solely on the Large Language Model (LLM) to determine tool use, this n8n automation uses Airtable as a central access control list. When a user interacts with the system via the n8n trigger, the workflow retrieves their allowed tools. A crucial custom Code n8n node then dynamically wraps or disables unauthorized tools, ensuring the agent only interacts with approved functions. This approach significantly enhances the security and reliability of your AI services built with n8n templates.

How it Works

The entire process relies on two connected sub-workflows—the main agent handler and the nested weather agent—both leveraging the same RBAC checking mechanism.


  1. Incoming Request: The Telegram Trigger n8n node initiates the n8n workflow upon receiving a direct message.

  2. User Verification: The Get user permissions Airtable n8n node searches for the user's profile based on their Telegram username, retrieving fields like grantedroles and allowedtools.

  3. Authentication Branch: The Unknown user If n8n node checks the results. If the user is not found, the workflow stops and the Reply: unknown user Telegram n8n node sends an unauthorized message.

  4. Data Mapping: For authorized users, the Set input n8n node maps the user and permission data into variables for the primary agent.

  5. Main Agent Execution: The Main Agent (an Agent n8n node) is configured with memory (Simple Memory) and an LLM (OpenAI Chat Model). The user's query is passed to it.

  6. RBAC Enforcement: Before the agent decides which tool to use, the Check permissions Code n8n node executes. This custom n8n node compares the available connected tools against the user's allowedtools array. If a tool is not permitted (e.g., calculator is denied), the script replaces that tool's functionality with a function that explicitly returns an 'unauthorized' message to the LLM.

  7. Nested Agent Call: If the main agent needs a specialized function, such as weather data, it calls the weatheragent Tool Workflow n8n node, passing the required inputs and the user's allowedtools list.

  8. Sub-Agent RBAC: The sub-workflow starts via the When Executed by Another Workflow n8n trigger. The Weather Agent also runs its own permission check (Check permissions1) to ensure the user's permissions are respected for the sub-agent's specific tools (getcoordinates, get_weather).

  9. Final Response: The result from the Main Agent is sent back to the user via the Reply with results Telegram n8n node.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON data and paste it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Airtable Setup: Access the provided Airtable template (linked in the workflow's sticky note) and copy it to your workspace. Ensure your Airtable credentials are set up in n8n and linked to the Get user permissions n8n node.

  3. Credential Setup: Configure and link credentials for the following n8n nodes:

Telegram Trigger and Telegram nodes (Requires a Telegram Bot API key).
OpenAI Chat Model nodes (Requires an OpenAI API key).

  1. Airtable Base Configuration: In the Get user permissions Airtable n8n node, select your copied base and table ('Users') and ensure the filter formula correctly uses the Telegram username: ={username} = '{{ $json.message.from.username }}'.

  2. Workflow Linking (Tool Workflow): In the weather_agent Tool Workflow n8n node, ensure that the selected workflow ID points to the current n8n workflow itself, allowing for the nested execution pattern. This is crucial for the recursive RBAC to function correctly.

Node Details

This n8n workflow utilizes advanced features from the LangChain integration and core n8n nodes:

Telegram Trigger (n8n trigger): Listens for incoming messages sent directly to the configured bot. Key configuration: updates: [message].
Airtable (n8n node): Get user permissions. Searches the 'Users' table based on the Telegram username to retrieve allowedtools and grantedroles. Uses search operation with a formula filter.
If (n8n node): Unknown user. A flow control node that checks if the Airtable query returned any data, effectively acting as an authentication gate.
Set (n8n node): Set input. Formats the user data, specifically extracting the allowedtools array, which is essential for the RBAC enforcement steps later in the n8n workflow.
Agent (n8n node): Main Agent. The primary LLM orchestrator. It uses GPT-4o and includes a customized system message based on dynamic user data.
Code (n8n node): Check permissions. This critical custom n8n node implements the RBAC logic. It iterates through all available tools and dynamically replaces unpermitted tools with a placeholder function that returns an 'unauthorized' message. This ensures the agent is confined strictly by the user's permissions defined in Airtable.
Tool Workflow (n8n node): weatheragent. Demonstrates nesting, calling the current n8n workflow as a sub-agent, and passing the required allowedtools list down for continued permission enforcement within the nested context.
Tool Code (n8n node): list
allowedtools and listgranted_roles. Custom tools allowing the agent to inform the user of their own permissions, demonstrating self-awareness built into this n8n workflow.

Related n8n Workflows

Free

Nodes: 16 Nodes
Updated: December 26 2025
View all
Created by

Workflow Optimization Expert | Software Architect. Use my link to book an initial consultation for custom built workflows using n8n.

Featured*