🔐 Permissions & Roles
Access control là critical cho production n8n. Bài này covers role-based permissions, workflow sharing, và credential management chi tiết.
N8N Role System
Built-in Roles:
Text
1ROLE HIERARCHY2──────────────3 4┌─────────────────────────────────────────────────┐5│ INSTANCE │6│ ┌─────────────────────────────────────────┐ │7│ │ GLOBAL OWNER │ │8│ │ • Full system access │ │9│ │ • User management │ │10│ │ • All settings │ │11│ └─────────────────────────────────────────┘ │12│ │ │13│ ┌─────────────────────────────────────────┐ │14│ │ GLOBAL ADMIN (Enterprise) │ │15│ │ • User management │ │16│ │ • Some settings │ │17│ │ • Access all workflows │ │18│ └─────────────────────────────────────────┘ │19│ │ │20│ ┌─────────────────────────────────────────┐ │21│ │ GLOBAL MEMBER │ │22│ │ • Create workflows │ │23│ │ • Own credentials │ │24│ │ • Personal settings │ │25│ └─────────────────────────────────────────┘ │26└─────────────────────────────────────────────────┘Workflow-Level Roles:
Text
1WORKFLOW PERMISSIONS2────────────────────3 4OWNER (per workflow)5├── Full access6├── Edit workflow7├── Execute8├── Share9├── Delete10└── Transfer ownership11 12EDITOR13├── View workflow14├── Edit workflow15├── Execute16└── Cannot delete/share17 18VIEWER (Enterprise)19├── View only20├── See executions21└── Cannot modifyWorkflow Sharing
Share Via UI:
Text
11. Open workflow22. Click "Share" button (top right)33. Select users to share with44. Set permission level:5 - Editor: Can modify6 - Viewer: Read only (Enterprise)75. Save changesSharing Best Practices:
Text
1SHARING MATRIX2──────────────3 4Workflow Type │ Share With │ Permission5────────────────────┼───────────────┼────────────6Production Critical │ Team leads │ Editor7 │ Team members │ Viewer8────────────────────┼───────────────┼────────────9Development │ Team members │ Editor10 │ Others │ None11────────────────────┼───────────────┼────────────12Utility/Tools │ All users │ Viewer13 │ Maintainer │ Editor14────────────────────┼───────────────┼────────────15Templates │ All users │ Viewer16 │ Template team │ EditorAPI Workflow Sharing:
Bash
1# Share workflow via API2curl -X POST \3 "https://n8n.yourdomain.com/rest/workflows/1/share" \4 -H "Content-Type: application/json" \5 -H "X-N8N-API-KEY: your_api_key" \6 -d '{7 "shareWith": {8 "userId": "user-uuid-here",9 "role": "editor"10 }11 }'12 13# List workflow shares14curl "https://n8n.yourdomain.com/rest/workflows/1/shares" \15 -H "X-N8N-API-KEY: your_api_key"Credential Sharing
Share Credentials:
Text
11. Settings → Credentials22. Select credential33. Click "Sharing"44. Add users/workflows55. Note: Secrets never shown to shared usersCredential Share Types:
Text
1CREDENTIAL SHARING OPTIONS2──────────────────────────3 4WORKFLOW-SPECIFIC5├── Credential only works in specific workflow6├── Cannot be used in other workflows7├── Recommended for sensitive data8└── Example: API key for specific integration9 10USER-SPECIFIC11├── Shared user can use in their workflows12├── Can create new workflows with this credential13├── Cannot see actual secrets14└── Example: Shared database connection15 16EVERYONE (Owner only)17├── All users can use18├── Useful for common services19├── Still cannot see secrets20└── Example: Company Slack tokenCredential Permission Matrix:
Text
1ACTION │ Owner │ Shared User2─────────────────────────┼───────┼─────────────3View credential name │ ✅ │ ✅4Use in workflows │ ✅ │ ✅5See secret values │ ✅ │ ❌6Edit credential │ ✅ │ ❌7Delete credential │ ✅ │ ❌8Re-share credential │ ✅ │ ❌Project/Team Setup (Enterprise)
Project Structure:
Text
1PROJECT ORGANIZATION2────────────────────3 4📁 Project: Marketing Automations5│6├── 👤 Project Admin7│ ├── Full project access8│ ├── Manage project members9│ └── All workflows & credentials10│11├── 👥 Project Members12│ ├── Access project resources13│ └── Create within project14│15├── 📋 Workflows16│ ├── Email Campaign Handler17│ ├── Social Media Poster18│ └── Lead Nurture Sequence19│20└── 🔑 Credentials21 ├── Marketing-Mailchimp22 ├── Marketing-Twitter23 └── Marketing-HubSpotProject Environment Config:
Bash
1# Enable projects (Enterprise)2N8N_ENTERPRISE_FEATURES_ENABLED=true3 4# Project isolation5N8N_PROJECT_ISOLATION_MODE=strict6 7# Project settings8N8N_DEFAULT_PROJECT_ID=default-project-idAccess Control Patterns
Pattern 1: Department Isolation
Text
1Marketing Department2├── Workflows: Marketing-*3├── Credentials: Marketing-*4├── Users: marketing-team@company.com5└── Isolation: Cannot access Sales workflows6 7Sales Department8├── Workflows: Sales-*9├── Credentials: Sales-*10├── Users: sales-team@company.com11└── Isolation: Cannot access Marketing workflows12 13Shared Resources14├── Workflows: Shared-*15├── Credentials: Common-*16├── Users: All departments17└── Read-only for mostPattern 2: Environment-Based
Text
1Production2├── Limited users (admins only)3├── Strict credential access4├── No experimental workflows5└── Full monitoring6 7Staging8├── More users9├── Test credentials only10├── Clone of production11└── Testing allowed12 13Development14├── All developers15├── Personal credentials16├── Experimentation encouraged17└── Less restrictionsPattern 3: Role-Based
Text
1Workflow Developers2├── Create/edit workflows3├── Use shared credentials4├── Cannot manage users5└── Cannot access admin settings6 7Integration Specialists8├── Full credential access9├── Setup external services10├── Document integrations11└── Support developers12 13Platform Admins14├── User management15├── Instance settings16├── Monitoring & logs17└── Backup managementSecurity Configurations
Restrict Dangerous Nodes:
Bash
1# Disable code execution2N8N_NODES_EXCLUDE="[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.code\"]"3 4# Disable file system access5N8N_NODES_EXCLUDE="[\"n8n-nodes-base.readBinaryFile\",\"n8n-nodes-base.writeBinaryFile\",\"n8n-nodes-base.readFile\",\"n8n-nodes-base.writeFile\"]"6 7# Disable SSH8N8N_NODES_EXCLUDE="[\"n8n-nodes-base.ssh\"]"9 10# Combined restrictions11N8N_NODES_EXCLUDE="[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.ssh\",\"n8n-nodes-base.readBinaryFile\"]"IP Allowlist (nginx):
nginx
1# Allow specific IPs for certain users2location /api/v1/workflows {3 # Restrict write operations to office IP4 limit_except GET {5 allow 203.0.113.0/24; # Office IP range6 deny all;7 }8 9 proxy_pass http://n8n:5678;10}Audit & Compliance
Permission Audit Script:
SQL
1-- List all workflow permissions2SELECT 3 w.name as workflow_name,4 u.email as owner_email,5 sw."userId" as shared_with,6 sw.role as permission7FROM workflow_entity w8JOIN "user" u ON w."userId" = u.id9LEFT JOIN shared_workflow sw ON sw."workflowId" = w.id10ORDER BY w.name;Credential Audit:
SQL
1-- List credential sharing2SELECT 3 c.name as credential_name,4 c.type as credential_type,5 u.email as owner,6 sc."userId" as shared_with7FROM credentials_entity c8JOIN "user" u ON c."userId" = u.id9LEFT JOIN shared_credentials sc ON sc."credentialsId" = c.id10ORDER BY c.name;Export Permissions Report:
Bash
1#!/bin/bash2# permissions-report.sh3 4REPORT_DIR="/opt/n8n-reports"5DATE=$(date +%Y%m%d)6 7# Workflow permissions8docker exec n8n-postgres psql -U n8n -d n8n -c "9COPY (10 SELECT 11 w.name,12 u.email as owner,13 string_agg(su.email, ', ') as shared_with14 FROM workflow_entity w15 JOIN \"user\" u ON w.\"userId\" = u.id16 LEFT JOIN shared_workflow sw ON sw.\"workflowId\" = w.id17 LEFT JOIN \"user\" su ON sw.\"userId\" = su.id18 GROUP BY w.id, u.id19) TO STDOUT WITH CSV HEADER;20" > "$REPORT_DIR/workflow_permissions_$DATE.csv"21 22echo "Report saved: $REPORT_DIR/workflow_permissions_$DATE.csv"Multi-Instance Strategy
Separate Instances by Security Level:
Text
1HIGH SECURITY (Finance/HR)2├── Isolated network3├── Admin access only4├── Strict credential handling5├── Full audit logging6└── Separate backups7 8STANDARD (General Business)9├── Team access10├── Department credentials11├── Standard monitoring12└── Regular backups13 14DEVELOPMENT (Sandbox)15├── All developers16├── Test credentials only17├── Relaxed policies18└── Optional backupsCross-Instance Communication:
yaml
1# webhook-based communication2# High-security instance exposes limited webhooks3# Standard instance calls these webhooks4 5# Example: HR workflow calls Finance for budget check6# HR Instance (caller)7- HTTP Request node8 - URL: https://finance.n8n.company.com/webhook/budget-check9 - Auth: Bearer token (shared secret)10 - Data: { "department": "HR", "amount": 5000 }11 12# Finance Instance (receiver)13- Webhook node14 - Auth: Header auth (validate token)15 - Respond with approval/denial onlyTroubleshooting Permissions
Cannot Access Workflow:
Text
1Error: "You don't have permission"2 3Check:41. Is workflow shared with you?52. What's your permission level?63. Is credential accessible?7 8Fix:9- Ask owner to share10- Check credential sharing11- Verify not disabled userCredential Not Working:
Text
1Error: "Credential not found"2 3Possible causes:41. Credential not shared52. Credential deleted63. Credential for different workflow7 8Fix:9- Request credential sharing10- Create personal credential11- Check workflow-specific credentialsPermission Check Query:
SQL
1-- Check user's accessible workflows2SELECT w.name, w.active3FROM workflow_entity w4WHERE w."userId" = 'user-uuid'5 OR EXISTS (6 SELECT 1 FROM shared_workflow sw 7 WHERE sw."workflowId" = w.id 8 AND sw."userId" = 'user-uuid'9 );Best Practices Summary
Security Guidelines
Permission Best Practices:
- Least Privilege - Give minimum necessary access
- Regular Audits - Review permissions monthly
- Prompt Deprovisioning - Remove access immediately when people leave
- Document Sharing - Record why access was granted
- Credential Rotation - Rotate after team changes
Bài Tập Thực Hành
Permission Setup Challenge
Implement access control:
- Define 3 user roles for your team
- Create workflow sharing policy document
- Set up credential sharing strategy
- Write audit query to list all permissions
- Document permission request process
- Test access controls work correctly
Build secure team access! 🔐
Key Takeaways
Remember
- 👤 Owner can do everything - Including transfer
- 🔑 Credentials stay secret - Shared users can use, not see
- 📊 Audit regularly - Permissions drift over time
- 🚫 Restrict dangerous nodes - Code, SSH, file access
- 📋 Document everything - Who has access and why
Tiếp Theo
Bài tiếp theo: Monitoring & Alerting - Track executions, performance metrics, và error alerting.
