|
| 1 | +--- |
| 2 | +custom_edit_url: "https://github.com/netdata/netdata/edit/master/docs/netdata-agent/configuration/secure-your-netdata-agent-with-bearer-token.md" |
| 3 | +sidebar_label: "Bearer Token Protection" |
| 4 | +learn_status: "Published" |
| 5 | +learn_rel_path: "Netdata Agent/Configuration/Securing Agents" |
| 6 | +sidebar_position: "20" |
| 7 | +learn_link: "https://learn.netdata.cloud/docs/netdata-agent/configuration/securing-agents/bearer-token-protection" |
| 8 | +slug: "/netdata-agent/configuration/securing-agents/bearer-token-protection" |
| 9 | +--- |
| 10 | + |
| 11 | +# Secure Your Netdata Agent with Bearer Token Protection |
| 12 | + |
| 13 | +Netdata provides native bearer token protection that integrates with Netdata Cloud Single Sign-On (SSO). With a single configuration setting, you can secure direct access to your Netdata Agents and Parents while inheriting the same permissions and roles your users have in Netdata Cloud. |
| 14 | + |
| 15 | +## Who Can Use This |
| 16 | + |
| 17 | +Bearer token protection is available to all Netdata Cloud users: |
| 18 | + |
| 19 | +- **Community plan** (free) |
| 20 | +- **Business plan** (paid) |
| 21 | + |
| 22 | +Your agent must be [claimed to Netdata Cloud](/docs/netdata-cloud/connect-agent) to use this feature. |
| 23 | + |
| 24 | +## How It Works |
| 25 | + |
| 26 | +When bearer token protection is enabled: |
| 27 | + |
| 28 | +1. Users visit your agent's dashboard directly (e.g., `http://your-server:19999`) |
| 29 | +2. The agent redirects them to Netdata Cloud for authentication |
| 30 | +3. After successful Cloud SSO login, users receive a time-limited bearer token |
| 31 | +4. The token grants access based on their Netdata Cloud role (Admin, Manager, Troubleshooter, etc.) |
| 32 | +5. Tokens expire after 24 hours and are automatically renewed through Cloud |
| 33 | + |
| 34 | +This means: |
| 35 | + |
| 36 | +- **Single Sign-On**: Users authenticate once via Netdata Cloud |
| 37 | +- **Role-Based Access**: Cloud roles and permissions apply to direct agent access |
| 38 | +- **Centralized Control**: Manage access through Netdata Cloud, not per-agent configurations |
| 39 | +- **No Password Files**: No htpasswd files or reverse proxy auth configuration needed |
| 40 | + |
| 41 | +## Enable Bearer Token Protection |
| 42 | + |
| 43 | +Edit your `netdata.conf` using the [`edit-config`](/docs/netdata-agent/configuration#edit-configuration-files) script: |
| 44 | + |
| 45 | +```bash |
| 46 | +cd /etc/netdata |
| 47 | +sudo ./edit-config netdata.conf |
| 48 | +``` |
| 49 | + |
| 50 | +Add or modify the `[web]` section: |
| 51 | + |
| 52 | +```ini |
| 53 | +[web] |
| 54 | + bearer token protection = yes |
| 55 | +``` |
| 56 | + |
| 57 | +Restart Netdata to apply: |
| 58 | + |
| 59 | +```bash |
| 60 | +sudo systemctl restart netdata |
| 61 | +``` |
| 62 | + |
| 63 | +## What Gets Protected |
| 64 | + |
| 65 | +When enabled, bearer token protection secures **all data APIs**, including: |
| 66 | + |
| 67 | +- Metrics and charts (`/api/v3/data`, `/api/v3/allmetrics`) |
| 68 | +- Alerts (`/api/v3/alerts`, `/api/v3/alert_transitions`) |
| 69 | +- Contexts and nodes (`/api/v3/contexts`, `/api/v3/nodes`) |
| 70 | +- Functions (`/api/v3/function`, `/api/v3/functions`) |
| 71 | +- Dynamic configuration (`/api/v3/config`) |
| 72 | + |
| 73 | +## What Remains Public |
| 74 | + |
| 75 | +**Static web files** (HTML, CSS, JavaScript) in Netdata's web directory are **not protected**. This means: |
| 76 | + |
| 77 | +- Users can still download and view the dashboard UI |
| 78 | +- The dashboard will load but **won't display any data** |
| 79 | +- All API calls from the dashboard will fail until the user authenticates |
| 80 | + |
| 81 | +This is by design - it allows the dashboard to redirect users to Netdata Cloud for authentication. |
| 82 | + |
| 83 | +A small set of APIs also remain publicly accessible for operational reasons: |
| 84 | + |
| 85 | +| API | What it exposes | |
| 86 | +|-----|-----------------| |
| 87 | +| `/api/v3/info` | Agent version, OS, build info, capabilities | |
| 88 | +| `/api/v3/me` | Current user authentication status | |
| 89 | +| `/api/v3/claim` | Agent claiming endpoint (protected by separate security key) | |
| 90 | +| `/api/v3/stream_info` | Streaming connection statistics | |
| 91 | +| `/api/v2/claim` | Agent claiming endpoint (v2, protected by security key) | |
| 92 | +| `/api/v1/registry?action=hello` | Node list, machine GUIDs, cloud connection status | |
| 93 | +| `/api/v1/manage/health` | Alert silencing (protected by separate X-Auth-Token) | |
| 94 | + |
| 95 | +These APIs are required for the authentication flow and dashboard initialization. The registry `hello` action returns node identifiers and cloud connection status, which the dashboard needs to initiate the authentication redirect. |
| 96 | + |
| 97 | +**Note:** Other v1 and v2 APIs (like `/api/v2/info`, `/api/v3/versions`, `/api/v3/progress`) **are protected** by bearer token - only the specific endpoints listed above bypass protection. |
| 98 | + |
| 99 | +## Requirements |
| 100 | + |
| 101 | +- Agent must be claimed to Netdata Cloud |
| 102 | +- ACLK connection must be active (agent connected to Cloud) |
| 103 | +- Users must have a Netdata Cloud account with access to the space containing the agent |
| 104 | + |
| 105 | +## Comparison with Other Methods |
| 106 | + |
| 107 | +| Method | Setup Complexity | SSO | Centralized Management | Works Offline | |
| 108 | +|--------|-----------------|-----|----------------------|---------------| |
| 109 | +| **Bearer Token Protection** | Single setting | Yes | Yes | No | |
| 110 | +| Reverse Proxy + Basic Auth | High (proxy + htpasswd) | No | No | Yes | |
| 111 | +| IP-Based Restrictions | Medium | No | No | Yes | |
| 112 | +| Disable Dashboard | Single setting | N/A | N/A | N/A | |
| 113 | + |
| 114 | +Choose bearer token protection when you want the simplest setup with Cloud SSO integration. Choose reverse proxy if you need custom authentication, don't use Netdata Cloud, or require offline access. |
| 115 | + |
| 116 | +## Combining with Other Security Measures |
| 117 | + |
| 118 | +Bearer token protection can be combined with: |
| 119 | + |
| 120 | +- **TLS/SSL encryption**: Configure [TLS in Netdata](/docs/netdata-agent/configuration/securing-agents/web-server-reference#examples) for encrypted connections |
| 121 | +- **IP restrictions**: Add `allow connections from` to limit which IPs can even attempt to connect |
| 122 | +- **Firewall rules**: Block port 19999 from untrusted networks |
| 123 | + |
| 124 | +Example combining bearer token with IP restrictions: |
| 125 | + |
| 126 | +```ini |
| 127 | +[web] |
| 128 | + bearer token protection = yes |
| 129 | + allow connections from = 10.* 192.168.* localhost |
| 130 | +``` |
| 131 | + |
| 132 | +## Troubleshooting |
| 133 | + |
| 134 | +**Users can't authenticate:** |
| 135 | + |
| 136 | +- Verify the Agent is claimed and connected to Cloud: Check `http://your-server:19999/api/v3/info` and inspect the `cloud` section. Use `cloud.status` to verify whether the agent is connected to Netdata Cloud, and if it is not `online`, inspect `cloud.reason` for the failure details |
| 137 | +- If needed, run `sudo netdatacli aclk-state` to diagnose the ACLK connection |
| 138 | +- Ensure users have access to the same Cloud Space as the Agent |
| 139 | + |
| 140 | +**Token expired errors:** |
| 141 | + |
| 142 | +- Tokens automatically renew when users have an active Cloud session |
| 143 | +- If tokens expire, users simply re-authenticate through Cloud |
| 144 | + |
| 145 | +**Want to disable temporarily:** |
| 146 | + |
| 147 | +```ini |
| 148 | +[web] |
| 149 | + bearer token protection = no |
| 150 | +``` |
| 151 | + |
| 152 | +Or via API (requires Admin/Manager role via Cloud): |
| 153 | + |
| 154 | +``` |
| 155 | +POST /api/v3/bearer_protection |
| 156 | +``` |
0 commit comments