Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grafana-alloy: add NixOS module #318306

Merged
merged 4 commits into from
Jun 10, 2024
Merged

Conversation

flokli
Copy link
Contributor

@flokli flokli commented Jun 8, 2024

cc @vunso @hbjydev @claudiiii

Description of changes

This adds a NixOS module for grafana-alloy.

I started from the grafana-agent, one but dropped all settings and
config management whatsoever.

grafana-alloy uses its own Alloy config format (similar to HCL), which
is not really possible to express in Nix.
Simply pointing to a path in `/etc`, and leaving it up to the user to configure
it via `environment.etc` allows the user to arrange config files however
it makes most sense for them.

It also adds a VM test, ensuring it starts up healthy (with empty config),
and adds it to the package passthru.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Copy link
Contributor

@hbjydev hbjydev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@flokli flokli marked this pull request as ready for review June 8, 2024 20:46
@flokli
Copy link
Contributor Author

flokli commented Jun 8, 2024

Deployed this to some of my infrastructure (using my old grafana flow configs). Also verified changes in the config file cause a reload (not restart), and are picked up successfully.

Copy link
Contributor

@hbjydev hbjydev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, on a second (more thorough) readthrough, I've got more stuff to add to this; as payment for being a PITA though I'm happy to also add myself to the maintainers list on this one :)

Apologies, just want to make sure it's got decent consistency with the upstream stuff, primarily for the sake of it being an easy transition for people coming from something like Ubuntu where the naming is all just alloy, not grafana-alloy.

Once these are addressed (even if they're dismissed), I'm happy for this to go through one more build-test cycle and then look to get it merged. I'll deploy it to my own machines later today if I can, but without binary cache it'll be a tad painful lol

nixos/modules/services/monitoring/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/modules/services/monitoring/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/modules/services/monitoring/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/modules/services/monitoring/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/modules/services/monitoring/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/modules/services/monitoring/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/tests/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/tests/grafana-alloy.nix Outdated Show resolved Hide resolved
nixos/tests/grafana-alloy.nix Outdated Show resolved Hide resolved
@flokli
Copy link
Contributor Author

flokli commented Jun 10, 2024

Hmmh, okay, their debian package also calls this alloy. I'd wish we could rename this alloy gloabbly, but that package already exist.

I'll push a new version shortly, updating the module, unit files etc.

This adds a NixOS module for Grafana Alloy.

I started from the grafana-agent one but dropped all settings and config
management whatsoever.

Grafana Alloy uses its own Alloy config format (similar to HCL), which
is not really possible to express in Nix.
Simply pointing to a path in `/etc`, and leaving it up to the user to configure
it via `environment.etc` allows the user to arrange config files however
it makes most sense for them.

The module, systemd unit etc is called "alloy", not "grafana-alloy" to
follow the way it's packaged on other distros, to follow POLA.
This adds a VM test, starting up Grafana Alloy and ensuring it comes
up healthy.
@flokli
Copy link
Contributor Author

flokli commented Jun 10, 2024

Everything done except for the adm group change. I propose we merge this in as-is.

if adding the group becomes necessary, we can still fix it in a followup. It wasn't necessary for grafana-agent to get systemd journal logs collected, so I'd be surprised it'd be necessary for alloy.

@flokli flokli requested a review from hbjydev June 10, 2024 10:42
@hbjydev
Copy link
Contributor

hbjydev commented Jun 10, 2024

@flokli it's not for journal, it's because adm has read access to most of /var/log, so it opens up syslog and stuff. I'd like to avoid removing groups from the user if it's not necessary personally.

flokli added a commit to flokli/alloy that referenced this pull request Jun 10, 2024
The systemd-journald group is sufficient to get system logs, at least
all systemd-journald provided ones.

See
https://www.freedesktop.org/software/systemd/man/latest/systemd-journald.service.html#Access%20Control
and NixOS/nixpkgs#318306 (comment)
for details, handing out `adm` is effectively giving `sudo` rights,
which is precisely what we don't want to do.
@flokli
Copy link
Contributor Author

flokli commented Jun 10, 2024

@flokli it's not for journal, it's because adm has read access to most of /var/log, so it opens up syslog and stuff. I'd like to avoid removing groups from the user if it's not necessary personally.

There's nothing in the tmpfiles shipped with NixOS granting access to /var/log, only /var/log/journal, so this has no effect in terms of allowing more log files to be read out of the box.

I'd prefer this to be opt in, due to the security implications and principle of least privilege, and adm being used to allow sudo in some cases.

After all, it's only a systemd.services.alloy.serviceConfig.SupplementaryGroups away, or even better, access be allowed on the logs themselves, by granting the alloy user access to log files through ACLs.

@flokli
Copy link
Contributor Author

flokli commented Jun 10, 2024

Okay, apparently it's admin, not to be confused with adm, which should not hand out sudo access. At least assuming stock sudoers files, and noone confusing it the other way round 😱 .

I still think there's very little on NixOS these days still logging to /var/log , which is not to the journal, so I'd prefer to not add this group to the alloy service by default.

Considering we don't configure ACLs for other files in /var/log, users need to do some work to make it available for the alloy service, so I'd rather keep it opt-in (and granting the alloy user access might be the cleaner choice).

@flokli flokli merged commit d2d2467 into NixOS:master Jun 10, 2024
24 of 25 checks passed
@flokli flokli deleted the grafana-alloy-module branch June 10, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants