Skip to content
This repository was archived by the owner on May 31, 2023. It is now read-only.

Commit b343ad5

Browse files
Wout van Heeswijkpaulfantom
authored andcommitted
Enable the use of ports below 1024 (#122)
* add capability for ports lower then 1024 * fix some spelling and a typo * update documentation to include grafana_cap_net_bind_service
1 parent f2b136d commit b343ad5

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
3232
| `grafana_data_dir` | /var/lib/grafana | Path to database directory |
3333
| `grafana_address` | 0.0.0.0 | Address on which grafana listens |
3434
| `grafana_port` | 3000 | port on which grafana listens |
35+
| 'grafana_cap_net_bind_service' | false | Enables the use of ports below 1024 without root privilages by leveraging the 'capabilities' of the linux kernel. read: http://man7.org/linux/man-pages/man7/capabilities.7.html |
3536
| `grafana_url` | "http://{{ grafana_address }}:{{ grafana_port }}" | Full URL used to access Grafana from a web browser |
3637
| `grafana_api_url` | "{{ grafana_url }}" | URL used for API calls in provisioning if different from public URL. See [this issue](https://github.com/cloudalchemy/ansible-grafana/issues/70). |
3738
| `grafana_domain` | "{{ ansible_fqdn \| default(ansible_host) \| default('localhost') }}" | setting is only used in as a part of the `root_url` option. Useful when using GitHub or Google OAuth |

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ grafana_data_dir: "/var/lib/grafana"
1212

1313
grafana_address: "0.0.0.0"
1414
grafana_port: 3000
15+
# To enable the use of ports below 1024 for unprivileged processes linux needs to set CAP_NET_BIND_SERVICE.
16+
# This has some security implications, and should be a conscious choice.
17+
# Get informed by reading: http://man7.org/linux/man-pages/man7/capabilities.7.html
18+
grafana_cap_net_bind_service: false
1519

1620
# External Grafana address. Variable maps to "root_url" in grafana server section
1721
grafana_url: "http://{{ grafana_address }}:{{ grafana_port }}"

tasks/configure.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
- "{{ grafana_data_dir }}/dashboards"
4848
- "{{ grafana_data_dir }}/plugins"
4949

50+
- name: Enable grafana to ports lower than port 1024
51+
capabilities:
52+
path: /usr/sbin/grafana-server
53+
capability: CAP_NET_BIND_SERVICE+ep
54+
state: present
55+
when:
56+
- grafana_port <= 1024
57+
- grafana_cap_net_bind_service
58+
5059
- name: Enable and start Grafana systemd unit
5160
systemd:
5261
name: grafana-server

tasks/preflight.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@
7676
when:
7777
- grafana_version != 'latest'
7878
- grafana_version is version_compare('5.0', '<')
79+
80+
- name: Fail if grafana_port is lower than 1024 and grafana_cap_net_bind_service is not true
81+
fail:
82+
msg: Trying to use a port lower than 1024 without setting grafana_cap_net_bind_service.
83+
when:
84+
- grafana_port <= 1024
85+
- not grafana_cap_net_bind_service

0 commit comments

Comments
 (0)