Skip to content

Commit 93789fa

Browse files
committed
add native support for ssh keys for age
1 parent 6115430 commit 93789fa

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

modules/home-manager/sops.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ let
9898
gnupgHome = cfg.gnupg.home;
9999
sshKeyPaths = cfg.gnupg.sshKeyPaths;
100100
ageKeyFile = cfg.age.keyFile;
101+
ageSshKeyFile = cfg.age.sshKeyFile;
101102
ageSshKeyPaths = cfg.age.sshKeyPaths;
102103
placeholderBySecretName = cfg.placeholder;
103104
userMode = true;
@@ -250,11 +251,23 @@ in
250251
'';
251252
};
252253

254+
sshKeyFile = lib.mkOption {
255+
type = lib.types.nullOr pathNotInStore;
256+
default = null;
257+
example = "/home/someuser/.ssh/id_ed25519";
258+
description = ''
259+
Path to ssh key file that will be used by age for sops decryption.
260+
'';
261+
};
262+
253263
sshKeyPaths = lib.mkOption {
254264
type = lib.types.listOf lib.types.path;
255265
default = [ ];
256266
description = ''
257-
Paths to ssh keys added as age keys during sops description.
267+
Paths to ssh keys added as age keys during sops description. The ssh
268+
keys will be converted into age keys manually using ssh-to-age.
269+
270+
This option is deprecated and will be removed in the future. Use sops.age.sshKeyFile instead.
258271
'';
259272
};
260273
};
@@ -301,6 +314,7 @@ in
301314
|| cfg.gnupg.sshKeyPaths != [ ]
302315
|| cfg.gnupg.qubes-split-gpg.enable == true
303316
|| cfg.age.keyFile != null
317+
|| cfg.age.sshKeyFile != null
304318
|| cfg.age.sshKeyPaths != [ ];
305319
message = "No key source configured for sops. Either set services.openssh.enable or set sops.age.keyFile or sops.gnupg.home or sops.gnupg.qubes-split-gpg.enable";
306320
}

modules/nix-darwin/default.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,24 @@ in
300300
'';
301301
};
302302

303+
sshKeyFile = lib.mkOption {
304+
type = lib.types.nullOr pathNotInStore;
305+
default = null;
306+
example = "/etc/ssh/ssh_host_ed25519_key";
307+
description = ''
308+
Path to ssh key file that will be used by age for sops decryption.
309+
'';
310+
};
311+
303312
sshKeyPaths = lib.mkOption {
304313
type = lib.types.listOf lib.types.path;
305314
default = defaultImportKeys "ed25519";
306315
defaultText = lib.literalMD "The ed25519 keys from {option}`config.services.openssh.hostKeys`";
307316
description = ''
308-
Paths to ssh keys added as age keys during sops description.
317+
Paths to ssh keys added as age keys during sops description. The ssh
318+
keys will be converted into age keys manually using ssh-to-age.
319+
320+
This option is deprecated and will be removed in the future. Use sops.age.sshKeyFile instead.
309321
'';
310322
};
311323
};
@@ -345,6 +357,7 @@ in
345357
cfg.gnupg.home != null
346358
|| cfg.gnupg.sshKeyPaths != [ ]
347359
|| cfg.age.keyFile != null
360+
|| cfg.age.sshKeyFile != null
348361
|| cfg.age.sshKeyPaths != [ ];
349362
message = "No key source configured for sops. Either set services.openssh.enable or set sops.age.keyFile or sops.gnupg.home";
350363
}

modules/nix-darwin/manifest-for.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ writeTextFile {
1515
gnupgHome = cfg.gnupg.home;
1616
sshKeyPaths = cfg.gnupg.sshKeyPaths;
1717
ageKeyFile = cfg.age.keyFile;
18+
ageSshKeyFile = cfg.age.sshKeyFile;
1819
ageSshKeyPaths = cfg.age.sshKeyPaths;
1920
useTmpfs = false;
2021
placeholderBySecretName = cfg.placeholder;

modules/sops/default.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,24 @@ in
339339
'';
340340
};
341341

342+
sshKeyFile = lib.mkOption {
343+
type = lib.types.nullOr pathNotInStore;
344+
default = null;
345+
example = "/etc/ssh/ssh_host_ed25519_key";
346+
description = ''
347+
Path to ssh key file that will be used by age for sops decryption.
348+
'';
349+
};
350+
342351
sshKeyPaths = lib.mkOption {
343352
type = lib.types.listOf lib.types.path;
344353
default = defaultImportKeys "ed25519";
345354
defaultText = lib.literalMD "The ed25519 keys from {option}`config.services.openssh.hostKeys`";
346355
description = ''
347-
Paths to ssh keys added as age keys during sops description.
356+
Paths to ssh keys added as age keys during sops description. The ssh
357+
keys will be converted into age keys manually using ssh-to-age.
358+
359+
This option is deprecated and will be removed in the future. Use sops.age.sshKeyFile instead.
348360
'';
349361
};
350362
};
@@ -405,6 +417,7 @@ in
405417
cfg.gnupg.home != null
406418
|| cfg.gnupg.sshKeyPaths != [ ]
407419
|| cfg.age.keyFile != null
420+
|| cfg.age.sshKeyFile != null
408421
|| cfg.age.sshKeyPaths != [ ];
409422
message = "No key source configured for sops. Either set services.openssh.enable or set sops.age.keyFile or sops.gnupg.home";
410423
}

modules/sops/manifest-for.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ else
4040
gnupgHome = cfg.gnupg.home;
4141
sshKeyPaths = cfg.gnupg.sshKeyPaths;
4242
ageKeyFile = cfg.age.keyFile;
43+
ageSshKeyFile = cfg.age.sshKeyFile;
4344
ageSshKeyPaths = cfg.age.sshKeyPaths;
4445
useTmpfs = cfg.useTmpfs;
4546
placeholderBySecretName = cfg.placeholder;

pkgs/sops-install-secrets/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type manifest struct {
7979
SSHKeyPaths []string `json:"sshKeyPaths"`
8080
GnupgHome string `json:"gnupgHome"`
8181
AgeKeyFile string `json:"ageKeyFile"`
82+
AgeSSHKeyFile string `json:"ageSshKeyFile"`
8283
AgeSSHKeyPaths []string `json:"ageSshKeyPaths"`
8384
UseTmpfs bool `json:"useTmpfs"`
8485
UserMode bool `json:"userMode"`
@@ -1325,7 +1326,7 @@ func installSecrets(args []string) error {
13251326
}
13261327

13271328
// Import age keys
1328-
if len(manifest.AgeSSHKeyPaths) != 0 || manifest.AgeKeyFile != "" {
1329+
if (len(manifest.AgeSSHKeyPaths) != 0 || manifest.AgeKeyFile != "") && manifest.AgeSSHKeyFile == "" {
13291330
keyfile := filepath.Join(manifest.SecretsMountPoint, "age-keys.txt")
13301331
os.Setenv("SOPS_AGE_KEY_FILE", keyfile)
13311332
// Create the keyfile
@@ -1360,6 +1361,10 @@ func installSecrets(args []string) error {
13601361
}
13611362
}
13621363

1364+
if manifest.AgeSSHKeyFile != "" {
1365+
os.Setenv("SOPS_AGE_SSH_PRIVATE_KEY_FILE", manifest.AgeSSHKeyFile)
1366+
}
1367+
13631368
if err := decryptSecrets(manifest.Secrets); err != nil {
13641369
return err
13651370
}

0 commit comments

Comments
 (0)