Skip to content

Commit

Permalink
Use sudoers file to allow prometheus user to run lnetctl
Browse files Browse the repository at this point in the history
  • Loading branch information
RDruon committed Aug 2, 2023
1 parent 7501241 commit b8cbf0f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions debian/install
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/usr/bin/prometheus-lustrefs-exporter
/etc/sudoers.d/prometheus
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ override_dh_auto_build:
override_dh_auto_install:
install -v -d debian/tmp/usr/bin
install -v -T target/release/lustrefs-exporter debian/tmp/usr/bin/prometheus-lustrefs-exporter
install -v -T sudoers_file/prometheus debian/tmp/etc/sudoers.d/prometheus


override_dh_auto_clean:
Expand Down
3 changes: 3 additions & 0 deletions lustrefs_exporter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ cargo build --release
%install
install -v -d %{buildroot}%{_bindir}
install -v -d %{buildroot}%{_unitdir}
install -v -d %{buildroot}%{_sysconfdir}/sudoers.d/
install -v -m 0644 lustrefs_exporter.service %{buildroot}%{_unitdir}
install -v target/release/lustrefs-exporter %{buildroot}%{_bindir}
install -v -m 0644 sudoers_file/prometheus %{buildroot}%{_sysconfdir}/sudoers.d/
%{__ln_s} lustrefs-exporter %{buildroot}%{_bindir}/lustrefs_exporter

%files
%{_bindir}/lustrefs-exporter
%{_bindir}/lustrefs_exporter
%{_unitdir}/lustrefs_exporter.service
%{_sysconfdir}/sudoers.d/prometheus

%pre
getent group prometheus >/dev/null || groupadd -r prometheus
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ async fn main() {
let mut lctl_output = parse_lctl_output(&lctl.stdout)?;
output.append(&mut lctl_output);

let lnetctl = Command::new("lnetctl")
.args(["net", "show", "-v", "4"])
let lnetctl = Command::new("sudo")
.args(["lnetctl", "net", "show", "-v", "4"])
.kill_on_drop(true)
.output()
.await?;
Expand All @@ -46,8 +46,8 @@ async fn main() {
let mut lnetctl_output = parse_lnetctl_output(lnetctl_stats)?;
output.append(&mut lnetctl_output);

let lnetctl_stats_output = Command::new("lnetctl")
.args(["stats", "show"])
let lnetctl_stats_output = Command::new("sudo")
.args(["lnetctl", "stats", "show"])
.kill_on_drop(true)
.output()
.await?;
Expand Down
1 change: 1 addition & 0 deletions sudoers_file/prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prometheus ALL=(ALL) NOPASSWD: /usr/sbin/lnetctl

0 comments on commit b8cbf0f

Please sign in to comment.