Skip to content

Commit 0a9945c

Browse files
authored
Don't run Grafana as root anymore, (#240)
* Don't run Grafana as root anymore, instead use the service to map port 80 to port 3000. Also, include the config hash so Grafana gets restarted when the config changes. Signed-off-by: Tom Wilkie <[email protected]> * make fmt Signed-off-by: Tom Wilkie <[email protected]>
1 parent 7cda4c2 commit 0a9945c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

prometheus-ksonnet/grafana/config.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
org_role: 'Admin',
77
},
88
server: {
9-
http_port: 80,
9+
http_port: 3000,
1010
root_url: $._config.grafana_root_url,
1111
},
1212
analytics: {

prometheus-ksonnet/grafana/deployment.libsonnet

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
grafana_container::
2828
container.new('grafana', $._images.grafana) +
29-
container.withPorts($.core.v1.containerPort.new('grafana-metrics', 80)) +
29+
container.withPorts($.core.v1.containerPort.new('grafana-metrics', 3000)) +
3030
container.withEnvMap({
3131
GF_PATHS_CONFIG: '/etc/grafana-config/grafana.ini',
3232
GF_INSTALL_PLUGINS: std.join(',', $.grafana_plugins),
@@ -49,8 +49,10 @@
4949

5050
grafana_deployment:
5151
deployment.new('grafana', 1, [$.grafana_container]) +
52-
deployment.mixin.spec.template.spec.securityContext.withRunAsUser(0) +
53-
$.util.configVolumeMount('grafana-config', '/etc/grafana-config') +
52+
// Use configMapVolumeMount to automatically include the hash of the config
53+
// as an annotation. No need to use for others, Grafana will pick up
54+
// changes there.
55+
$.util.configMapVolumeMount($.grafana_config_map, '/etc/grafana-config') +
5456
$.util.configVolumeMount('grafana-dashboard-provisioning', '%(grafana_provisioning_dir)s/dashboards' % $._config) +
5557
$.util.configVolumeMount('grafana-datasources', '%(grafana_provisioning_dir)s/datasources' % $._config) +
5658
$.util.configVolumeMount('grafana-notification-channels', '%(grafana_provisioning_dir)s/notifiers' % $._config) +
@@ -77,6 +79,16 @@
7779
) +
7880
$.util.podPriority('critical'),
7981

82+
local service = $.core.v1.service,
83+
local servicePort = service.mixin.spec.portsType,
84+
8085
grafana_service:
81-
$.util.serviceFor($.grafana_deployment),
86+
$.util.serviceFor($.grafana_deployment) +
87+
service.mixin.spec.withPortsMixin([
88+
servicePort.newNamed(
89+
name='http',
90+
port=80,
91+
targetPort=3000,
92+
),
93+
]),
8294
}

0 commit comments

Comments
 (0)