|
| 1 | +# n8n-gw |
| 2 | + |
| 3 | +OIDC gateway for n8n Community Edition. |
| 4 | + |
| 5 | +`n8n-gw` is a reverse proxy that adds OIDC login to n8n Community Edition without patching n8n itself. Browser users authenticate with an OIDC provider, then the gateway maps that identity to an existing n8n account stored in Vault, performs the n8n UI login server-side, and forwards the resulting browser session to n8n. |
| 6 | + |
| 7 | +Public execution endpoints such as webhooks and forms bypass OIDC so external services can continue calling n8n normally. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- OIDC authentication for n8n console access |
| 12 | +- Vault-backed mapping from OIDC users to n8n credentials |
| 13 | +- Server-side n8n `/rest/login` bridge |
| 14 | +- Redis-backed gateway sessions and OIDC state |
| 15 | +- Pass-through routing for `/webhook/*`, `/form/*`, and related public execution paths |
| 16 | +- External `POST /rest/login` blocking |
| 17 | +- Health and readiness endpoints |
| 18 | +- Prometheus metrics |
| 19 | + |
| 20 | +## Container Image |
| 21 | + |
| 22 | +```bash |
| 23 | +docker pull ghcr.io/yangs1202/n8n-gw:latest |
| 24 | +docker pull ghcr.io/yangs1202/n8n-gw:v1.0 |
| 25 | +``` |
| 26 | + |
| 27 | +## Required Configuration |
| 28 | + |
| 29 | +```bash |
| 30 | +PUBLIC_BASE_URL=https://proxy.example.com |
| 31 | +N8N_UPSTREAM_URL=http://n8n:5678 |
| 32 | +OIDC_ISSUER_URL=https://idp.example.com |
| 33 | +OIDC_CLIENT_ID=n8n-gw |
| 34 | +OIDC_CLIENT_SECRET=change-me |
| 35 | +REDIS_URL=redis://redis:6379/0 |
| 36 | +VAULT_ADDR=https://vault.example.com |
| 37 | +VAULT_TOKEN=change-me |
| 38 | +``` |
| 39 | + |
| 40 | +Production deployments should prefer Vault AppRole instead of a long-lived Vault token: |
| 41 | + |
| 42 | +```bash |
| 43 | +VAULT_ROLE_ID=change-me |
| 44 | +VAULT_SECRET_ID=change-me |
| 45 | +``` |
| 46 | + |
| 47 | +Optional defaults: |
| 48 | + |
| 49 | +```bash |
| 50 | +OIDC_SCOPES="openid profile email" |
| 51 | +VAULT_KV_MOUNT=secret |
| 52 | +VAULT_KV_PREFIX=n8n-gw/users |
| 53 | +PUBLIC_BYPASS_PREFIXES=/webhook/,/webhook-test/,/webhook-waiting/,/form/,/form-test/,/forms/,/forms-test/ |
| 54 | +``` |
| 55 | + |
| 56 | +## Local Run |
| 57 | + |
| 58 | +Create a local `.env` file from the variables above, then run: |
| 59 | + |
| 60 | +```bash |
| 61 | +./scripts/run-local.sh |
| 62 | +``` |
| 63 | + |
| 64 | +## Security Notes |
| 65 | + |
| 66 | +- Do not expose the upstream n8n service directly to the public internet. |
| 67 | +- Do not commit `.env`, Vault tokens, OIDC client secrets, AppRole IDs, AppRole secrets, Kubernetes manifests, private ingress details, or production hostnames to this repository. |
| 68 | +- Public execution routes such as `/webhook/*` and `/form/*` bypass OIDC by design. Configure authentication at the n8n workflow or upstream edge layer when needed. |
| 69 | +- External `POST /rest/login` requests are blocked by the gateway. Only the gateway's internal n8n client calls upstream n8n login. |
| 70 | +- n8n `/rest/login` is an internal UI endpoint, not a stable public API. Re-test this bridge when upgrading n8n. |
| 71 | + |
| 72 | +## Documentation |
| 73 | + |
| 74 | +Implementation details are in [docs/README.md](docs/README.md). |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +# n8n-gw 한국어 |
| 79 | + |
| 80 | +n8n Community Edition을 수정하지 않고 OIDC 로그인을 붙이는 게이트웨이입니다. |
| 81 | + |
| 82 | +`n8n-gw`는 n8n 앞단에 위치하는 reverse proxy입니다. 브라우저 사용자는 OIDC로 인증하고, 게이트웨이는 OIDC 사용자를 Vault에 저장된 기존 n8n 계정 정보와 매핑합니다. 그 다음 게이트웨이가 서버 사이드에서 n8n UI 로그인을 수행하고, 발급된 n8n 브라우저 세션을 사용자에게 전달합니다. |
| 83 | + |
| 84 | +웹훅과 폼 같은 public execution endpoint는 OIDC로 리다이렉트하지 않고 그대로 n8n으로 전달합니다. |
| 85 | + |
| 86 | +## 주요 기능 |
| 87 | + |
| 88 | +- n8n 콘솔 접근에 OIDC 인증 추가 |
| 89 | +- Vault 기반 OIDC 사용자와 n8n 계정 매핑 |
| 90 | +- 서버 사이드 n8n `/rest/login` 브리지 |
| 91 | +- Redis 기반 gateway session 및 OIDC state 저장 |
| 92 | +- `/webhook/*`, `/form/*` 등 public execution path 바이패스 |
| 93 | +- 외부 `POST /rest/login` 차단 |
| 94 | +- health/readiness endpoint 제공 |
| 95 | +- Prometheus metrics 제공 |
| 96 | + |
| 97 | +## 컨테이너 이미지 |
| 98 | + |
| 99 | +```bash |
| 100 | +docker pull ghcr.io/yangs1202/n8n-gw:latest |
| 101 | +docker pull ghcr.io/yangs1202/n8n-gw:v1.0 |
| 102 | +``` |
| 103 | + |
| 104 | +## 필수 설정 |
| 105 | + |
| 106 | +```bash |
| 107 | +PUBLIC_BASE_URL=https://proxy.example.com |
| 108 | +N8N_UPSTREAM_URL=http://n8n:5678 |
| 109 | +OIDC_ISSUER_URL=https://idp.example.com |
| 110 | +OIDC_CLIENT_ID=n8n-gw |
| 111 | +OIDC_CLIENT_SECRET=change-me |
| 112 | +REDIS_URL=redis://redis:6379/0 |
| 113 | +VAULT_ADDR=https://vault.example.com |
| 114 | +VAULT_TOKEN=change-me |
| 115 | +``` |
| 116 | + |
| 117 | +운영 환경에서는 장기 Vault token보다 Vault AppRole 사용을 권장합니다. |
| 118 | + |
| 119 | +```bash |
| 120 | +VAULT_ROLE_ID=change-me |
| 121 | +VAULT_SECRET_ID=change-me |
| 122 | +``` |
| 123 | + |
| 124 | +## 보안 주의사항 |
| 125 | + |
| 126 | +- upstream n8n service를 public internet에 직접 노출하지 마세요. |
| 127 | +- `.env`, Vault token, OIDC client secret, AppRole ID, AppRole secret, Kubernetes manifest, private ingress 정보, 운영 hostname을 repository에 commit하지 마세요. |
| 128 | +- `/webhook/*`, `/form/*` 같은 public execution route는 의도적으로 OIDC를 우회합니다. 필요한 인증은 n8n workflow 또는 edge layer에서 설정하세요. |
| 129 | +- 외부 `POST /rest/login`은 gateway가 차단합니다. upstream n8n login은 gateway 내부 client만 호출합니다. |
| 130 | +- n8n `/rest/login`은 안정적인 public API가 아니라 UI 내부 endpoint입니다. n8n 업그레이드 시 반드시 integration test로 다시 확인하세요. |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +# n8n-gw 中文 |
| 135 | + |
| 136 | +用于 n8n Community Edition 的 OIDC 网关。 |
| 137 | + |
| 138 | +`n8n-gw` 是部署在 n8n 前面的反向代理。用户通过 OIDC 登录后,网关会把 OIDC 身份映射到 Vault 中保存的现有 n8n 账号和密码,然后在服务端调用 n8n UI 登录接口,并把生成的浏览器会话转发给用户。 |
| 139 | + |
| 140 | +Webhook、form 等公开执行路径不会触发 OIDC 重定向,因此外部服务可以继续正常调用 n8n。 |
| 141 | + |
| 142 | +## 功能 |
| 143 | + |
| 144 | +- 为 n8n 控制台访问添加 OIDC 认证 |
| 145 | +- 使用 Vault 保存 OIDC 用户到 n8n 账号的映射 |
| 146 | +- 服务端 n8n `/rest/login` 登录桥接 |
| 147 | +- 使用 Redis 保存网关会话和 OIDC state |
| 148 | +- 直通 `/webhook/*`、`/form/*` 等公开执行路径 |
| 149 | +- 阻止外部 `POST /rest/login` |
| 150 | +- 提供 health/readiness 接口 |
| 151 | +- 提供 Prometheus metrics |
| 152 | + |
| 153 | +## 容器镜像 |
| 154 | + |
| 155 | +```bash |
| 156 | +docker pull ghcr.io/yangs1202/n8n-gw:latest |
| 157 | +docker pull ghcr.io/yangs1202/n8n-gw:v1.0 |
| 158 | +``` |
| 159 | + |
| 160 | +## 必需配置 |
| 161 | + |
| 162 | +```bash |
| 163 | +PUBLIC_BASE_URL=https://proxy.example.com |
| 164 | +N8N_UPSTREAM_URL=http://n8n:5678 |
| 165 | +OIDC_ISSUER_URL=https://idp.example.com |
| 166 | +OIDC_CLIENT_ID=n8n-gw |
| 167 | +OIDC_CLIENT_SECRET=change-me |
| 168 | +REDIS_URL=redis://redis:6379/0 |
| 169 | +VAULT_ADDR=https://vault.example.com |
| 170 | +VAULT_TOKEN=change-me |
| 171 | +``` |
| 172 | + |
| 173 | +生产环境建议使用 Vault AppRole,而不是长期有效的 Vault token。 |
| 174 | + |
| 175 | +```bash |
| 176 | +VAULT_ROLE_ID=change-me |
| 177 | +VAULT_SECRET_ID=change-me |
| 178 | +``` |
| 179 | + |
| 180 | +## 安全注意事项 |
| 181 | + |
| 182 | +- 不要把上游 n8n 服务直接暴露到公网。 |
| 183 | +- 不要提交 `.env`、Vault token、OIDC client secret、AppRole ID、AppRole secret、Kubernetes manifest、私有 ingress 信息或生产域名。 |
| 184 | +- `/webhook/*`、`/form/*` 等公开执行路径会有意绕过 OIDC。需要认证时,请在 n8n workflow 或边缘网关层配置。 |
| 185 | +- 外部 `POST /rest/login` 会被网关阻止。只有网关内部的 n8n client 会调用上游 n8n 登录接口。 |
| 186 | +- n8n `/rest/login` 是 UI 内部接口,不是稳定的公开 API。升级 n8n 时必须重新运行集成测试。 |
0 commit comments