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

feat: add age plugin and fido2 hmac support #680

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ rec {

sops-import-keys-hook = pkgs.callPackage ./pkgs/sops-import-keys-hook { };

age-fido2-hmac = pkgs.callPackage ./pkgs/age-fido2-hmac {};
sops-fido2-hmac = pkgs.callPackage ./pkgs/sops-fido2-hmac {};

# backwards compatibility
inherit (pkgs) ssh-to-pgp;

Expand Down
9 changes: 9 additions & 0 deletions modules/sops/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ in
'';
};

plugins = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [];
description = ''
List of plugins to use for sops decryption.
'';
};
Copy link
Owner

Choose a reason for hiding this comment

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

Doesn't that also require age plugin support in sops?

Copy link
Author

Choose a reason for hiding this comment

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

I don't follow.

We should probably add the fido2-hmac plugin as a default in this option though.

Copy link
Owner

@Mic92 Mic92 Nov 23, 2024

Choose a reason for hiding this comment

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

Do we not need sops-nix to recognise these age plugin style age keys to not fail to run, even if they are not used?


generateKey = lib.mkOption {
type = lib.types.bool;
default = false;
Expand Down Expand Up @@ -431,6 +439,7 @@ in
sops.environment.SOPS_GPG_EXEC = lib.mkIf (cfg.gnupg.home != null || cfg.gnupg.sshKeyPaths != [ ]) (
lib.mkDefault "${pkgs.gnupg}/bin/gpg"
);
sops.environment.PATH= lib.makeBinPath cfg.age.plugins;

# When using sysusers we no longer are started as an activation script because those are started in initrd while sysusers is started later.
systemd.services.sops-install-secrets = lib.mkIf (regularSecrets != { } && useSystemdActivation) {
Expand Down
14 changes: 14 additions & 0 deletions pkgs/age-fido2-hmac/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ age-plugin-fido2-hmac
, runCommand
, makeWrapper
, lib
, age
}:

runCommand "age" {
nativeBuildInputs = [ makeWrapper ];
} ''
mkdir -p $out/bin
makeWrapper ${age}/bin/age $out/bin/age \
--prefix PATH : ${lib.makeBinPath [ age-plugin-fido2-hmac ]}
''
38 changes: 38 additions & 0 deletions pkgs/sops-fido2-hmac/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
sops,
fetchFromGitHub,
buildGoModule,
age-plugin-fido2-hmac,
makeWrapper
}:

let
version = "2024-11-23";
in
buildGoModule {
pname = "sops-fido2-hmac";
inherit version;
src = fetchFromGitHub {
owner = "brianmcgee";
repo = "sops";
rev = "0607eae847f1ae21205b5e2a919de6d5868f6395";
sha256 = "sha256-mWsIg9TXGlA8EuFD7Pb0w8PsD3LvCMCy1X9OTITxvsU=";
};
vendorHash = "sha256-NS0b25NQEJle///iRHAG3uTC5p6rlGSyHVwEESki3p4=";

subPackages = [ "cmd/sops" ];

ldflags = [
"-s"
"-w"
"-X github.com/getsops/sops/v3/version.Version=${version}"
];

nativeBuildInputs = [ makeWrapper ];

postInstall = ''
wrapProgram $out/bin/sops --prefix PATH : ${age-plugin-fido2-hmac}/bin
'';

inherit (sops) meta;
}