Jump to content

Garage: Difference between revisions

From Official NixOS Wiki
Sapi (talk | contribs)
m Removed the mention of MinIO because it is abandon-ware now and possibly being removed
Nicof2000 (talk | contribs)
explain how to setup garage with sops secrets
Line 4: Line 4:
It is documented in the [https://nixos.org/manual/nixos/stable/#module-services-garage NixOS manual].
It is documented in the [https://nixos.org/manual/nixos/stable/#module-services-garage NixOS manual].


==== Setup ====
You have to explicitly set the [https://search.nixos.org/options?query=services.garage&type=options#show=option%253Aservices.garage.package package option]. You can choose between the [https://search.nixos.org/packages?query=garage_ garage_1 and garage_2] packages.
For a minimal setup you need to configure rpc_bind_addr, s3_api.s3_region, replication_factor and rpc_secret_file.
The Garage [https://github.com/NixOS/nixpkgs/blob/0dc498bfe49baeb18b0f9891e800b53bb2603193/nixos/modules/services/web-servers/garage.nix#L145 systemd service has DynamicUser configured], which prevents you from setting the owner property of the secret.
Adding the secret without it like this:<syntaxhighlight lang="nixos">
{ config, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage.settings.rpc_secret_file = config.sops.secrets."garage/rpc_secret".path;
}
</syntaxhighlight>Results in: Error: Failed to read secret file /run/secrets/garage/rpc_secret: Permission denied (os error 13)
You can use [https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Credentials systemd LoadCredential] to make it accessible for the dynamic user running the service:<syntaxhighlight lang="nixos">
{ config, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage.settings.rpc_secret_file = "/run/credentials/garage.service/rpc_secret";
  systemd.services.garage.serviceConfig.LoadCredential =
    "rpc_secret:${config.sops.secrets."garage/rpc_secret".path}";
}
</syntaxhighlight>However this results in another error in the Garage service:<syntaxhighlight lang="bash">
2026-11-24T00:20:43.071157Z  INFO garage::server: Loading configuration from /etc/garage.toml...
Error: File /run/credentials/garage.service/rpc_secret is world-readable! (mode: 0100440, expected 0600)
Refusing to start until this is fixed, or environment variable GARAGE_ALLOW_WORLD_READABLE_SECRETS is set to true.
</syntaxhighlight>This is because garage expects the file to have a umask of 600, not 440. To accept this umask (which is secure, as you can see in the following codeblock) you can set the allow_world_readable_secrets setting.<syntaxhighlight lang="bash"># systemctl start garage; getfacl /run/credentials/garage.service/rpc_secret
getfacl: Removing leading '/' from absolute path names
# file: run/credentials/garage.service/rpc_secret
# owner: root
# group: root
user::r--
user:garage:r--
group::---
mask::r--
other::---</syntaxhighlight>The final configuration looks like this:<syntaxhighlight lang="nixos" line="1">{ config, pkgs, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage = {
    enable = true;
    package = pkgs.garage_2;
    settings = {
      rpc_bind_addr = "[::]:3901";
      rpc_secret_file = "/run/credentials/garage.service/rpc_secret";
      allow_world_readable_secrets = true;
      s3_api.s3_region = "garage";
      replication_factor = 3;
    };
  };
  systemd.services.garage.serviceConfig.LoadCredential =
    "rpc_secret:${config.sops.secrets."garage/rpc_secret".path}";
}</syntaxhighlight>
[[Category:Server]]
[[Category:Server]]
[[Category:NixOS Manual]]
[[Category:NixOS Manual]]

Revision as of 00:49, 24 November 2026

Garage is an open-source, self-hostable S3 store, for geodistributed stores.

It is documented in the NixOS manual.

Setup

You have to explicitly set the package option. You can choose between the garage_1 and garage_2 packages.

For a minimal setup you need to configure rpc_bind_addr, s3_api.s3_region, replication_factor and rpc_secret_file.

The Garage systemd service has DynamicUser configured, which prevents you from setting the owner property of the secret.

Adding the secret without it like this:

{ config, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage.settings.rpc_secret_file = config.sops.secrets."garage/rpc_secret".path;
}

Results in: Error: Failed to read secret file /run/secrets/garage/rpc_secret: Permission denied (os error 13) You can use systemd LoadCredential to make it accessible for the dynamic user running the service:

{ config, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage.settings.rpc_secret_file = "/run/credentials/garage.service/rpc_secret";
  systemd.services.garage.serviceConfig.LoadCredential =
    "rpc_secret:${config.sops.secrets."garage/rpc_secret".path}";
}

However this results in another error in the Garage service:

2026-11-24T00:20:43.071157Z  INFO garage::server: Loading configuration from /etc/garage.toml...
Error: File /run/credentials/garage.service/rpc_secret is world-readable! (mode: 0100440, expected 0600)
Refusing to start until this is fixed, or environment variable GARAGE_ALLOW_WORLD_READABLE_SECRETS is set to true.

This is because garage expects the file to have a umask of 600, not 440. To accept this umask (which is secure, as you can see in the following codeblock) you can set the allow_world_readable_secrets setting.

# systemctl start garage; getfacl /run/credentials/garage.service/rpc_secret
getfacl: Removing leading '/' from absolute path names
# file: run/credentials/garage.service/rpc_secret
# owner: root
# group: root
user::r--
user:garage:r--
group::---
mask::r--
other::---

The final configuration looks like this:

{ config, pkgs, ... }:
{
  sops.secrets."garage/rpc_secret" = { };

  services.garage = {
    enable = true;
    package = pkgs.garage_2;
    settings = {
      rpc_bind_addr = "[::]:3901";
      rpc_secret_file = "/run/credentials/garage.service/rpc_secret";
      allow_world_readable_secrets = true;
      s3_api.s3_region = "garage";
      replication_factor = 3;
    };
  };

  systemd.services.garage.serviceConfig.LoadCredential =
    "rpc_secret:${config.sops.secrets."garage/rpc_secret".path}";
}