diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-11-08 14:14:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-08 14:14:06 +0100 |
| commit | 908f67c4f5ed46a55aeee9744a913efecd06e358 (patch) | |
| tree | 77a276961fb0b6d5c375695ade6323e5d7281e45 /smoketest/scripts/cli | |
| parent | 936fd5a36131f6a8958f7236d19531206365cf59 (diff) | |
| parent | dd21c0efeaf91261c3688b42248a2dea263cae2d (diff) | |
| download | vyos-1x-908f67c4f5ed46a55aeee9744a913efecd06e358.tar.gz vyos-1x-908f67c4f5ed46a55aeee9744a913efecd06e358.zip | |
Merge pull request #5629 from natali-rs1985/T9569
telegraf: T9569: Pass InfluxDB token via a root-only environment file
Diffstat (limited to 'smoketest/scripts/cli')
| -rwxr-xr-x | smoketest/scripts/cli/test_service_monitoring_telegraf.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_service_monitoring_telegraf.py b/smoketest/scripts/cli/test_service_monitoring_telegraf.py index 65a1ece82..02e4654b1 100755 --- a/smoketest/scripts/cli/test_service_monitoring_telegraf.py +++ b/smoketest/scripts/cli/test_service_monitoring_telegraf.py @@ -19,11 +19,14 @@ import unittest from base_vyostest_shim import VyOSUnitTestSHIM from vyos.configsession import ConfigSessionError +from vyos.utils.process import cmdl from vyos.utils.process import process_named_running +from vyos.utils.file import file_permissions from vyos.utils.file import read_file PROCESS_NAME = 'telegraf' TELEGRAF_CONF = '/run/telegraf/telegraf.conf' +TELEGRAF_ENV = '/run/telegraf/telegraf.env' base_path = ['service', 'monitoring', 'telegraf'] prometheus_base_path = ['service', 'monitoring', 'prometheus'] org = 'log@in.local' @@ -277,5 +280,28 @@ class TestMonitoringTelegraf(VyOSUnitTestSHIM.TestCase): self.cli_commit() self.cli_discard() + def test_09_influxdb_token(self): + new_token = 'A' * 86 + '==' + + self.basic_influxdb_setup() + + # Token is only readable by root and not exposed by systemd + self.assertEqual(read_file(TELEGRAF_ENV, sudo=True), f'INFLUX_TOKEN={token}') + self.assertEqual(file_permissions(TELEGRAF_ENV), '0600') + self.assertNotIn( + token, cmdl(['systemctl', 'show', '-p', 'Environment', 'telegraf.service']) + ) + + pid = process_named_running(PROCESS_NAME) + + # A reload keeps the old environment, a new token needs a restart + self.cli_set(base_path + ['influxdb', 'authentication', 'token', new_token]) + self.cli_commit() + + new_pid = process_named_running(PROCESS_NAME, timeout=10) + self.assertNotEqual(pid, new_pid) + environ = read_file(f'/proc/{new_pid}/environ', sudo=True) + self.assertIn(f'INFLUX_TOKEN={new_token}', environ) + if __name__ == '__main__': unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on()) |
