Skip to content

Commit 7b6d1e7

Browse files
committed
saml2aws: init module
Adding module to configure saml2aws utility using home-manager
1 parent aa6936b commit 7b6d1e7

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed

modules/lib/maintainers.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,18 @@
381381
github = "mipmip";
382382
githubId = 658612;
383383
};
384+
mokrinsky = {
385+
name = "mokrinsky";
386+
email = "[email protected]";
387+
github = "mokrinsky";
388+
githubId = 463907;
389+
keys = [
390+
{
391+
longkeyid = "rsa4096/0x73CC011921471A15";
392+
fingerprint = "EA54 E892 D96C 779E 1FA6 4E0A 73CC 0119 2147 1A15";
393+
}
394+
];
395+
};
384396
msfjarvis = {
385397
email = "[email protected]";
386398
github = "msfjarvis";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
time = "2025-11-05T12:54:50+00:00";
3+
condition = true;
4+
message = ''
5+
A new module is available: 'programs.saml2aws'.
6+
7+
saml2aws is a CLI tool which enables you to login and retrieve AWS temporary credentials using a SAML IDP. It support a bunch of SAML providers, from cloud ones like Akamai, Okta or OneLogin, to corporate or self-hosted like Authentik, KeyCloak or ADFS.
8+
'';
9+
}

modules/programs/saml2aws.nix

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}:
7+
8+
let
9+
cfg = config.programs.saml2aws;
10+
iniFormat = pkgs.formats.ini { };
11+
inherit (lib) mkIf mkOption types;
12+
in
13+
{
14+
meta.maintainers = [ lib.maintainers.mokrinsky ];
15+
16+
options.programs.saml2aws = {
17+
enable = lib.mkEnableOption "saml2aws CLI tool";
18+
19+
package = lib.mkPackageOption pkgs "saml2aws" {
20+
default = "saml2aws";
21+
nullable = true;
22+
};
23+
24+
enableBashIntegration = lib.hm.shell.mkBashIntegrationOption {
25+
inherit config;
26+
extraDescription = ''If enabled, this will install autocompletion for bash.'';
27+
};
28+
29+
enableZshIntegration = lib.hm.shell.mkZshIntegrationOption {
30+
inherit config;
31+
extraDescription = ''If enabled, this will install autocompletion for zsh.'';
32+
};
33+
34+
configLocation = mkOption {
35+
default = "${config.home.homeDirectory}/.saml2aws";
36+
type = types.str;
37+
example = lib.literalExpression ''
38+
''${config.home.homeDirectory}/.config/.saml2aws
39+
'';
40+
description = ''
41+
Environment variable to specify the location of saml2aws configuration.
42+
'';
43+
};
44+
45+
credentials = mkOption {
46+
type = types.submodule { freeformType = iniFormat.type; };
47+
default = { };
48+
example = lib.literalExpression ''
49+
{
50+
aws = {
51+
name = "aws";
52+
url = "https://domain.tld/uri/of/your/auth/endpoint";
53+
username = "username";
54+
provider = "Authentik";
55+
mfa = "Auto";
56+
skip_verify = false;
57+
timeout = 0;
58+
aws_urn = "urn:amazon:webservices";
59+
aws_session_duration = 3600;
60+
aws_profile = "123456789000";
61+
saml_cache = false;
62+
disable_remember_device = false;
63+
disable_sessions = false;
64+
download_browser_driver = false;
65+
headless = false;
66+
};
67+
}
68+
'';
69+
description = ''
70+
Configuration written to {file}`$HOME/.saml2aws` or config.programs.saml2aws.configLocation.
71+
'';
72+
};
73+
};
74+
75+
config = mkIf cfg.enable {
76+
home = {
77+
packages = mkIf (cfg.package != null) [ cfg.package ];
78+
79+
sessionVariables.SAML2AWS_CONFIGFILE = cfg.configLocation;
80+
81+
file."${cfg.configLocation}" = mkIf (cfg.credentials != { }) {
82+
source = iniFormat.generate "saml2aws-credentials-${config.home.username}" cfg.credentials;
83+
};
84+
};
85+
86+
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
87+
eval "$(${lib.getExe cfg.package} --completion-script-bash)"
88+
'';
89+
90+
programs.zsh.initContent = mkIf cfg.enableZshIntegration ''
91+
eval "$(${lib.getExe cfg.package} --completion-script-zsh)"
92+
'';
93+
94+
};
95+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
saml2aws = ./saml2aws.nix;
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[aws]
2+
aws_profile=123456789000
3+
aws_session_duration=3600
4+
aws_urn=urn:amazon:webservices
5+
disable_remember_device=false
6+
disable_sessions=false
7+
download_browser_driver=false
8+
headless=false
9+
mfa=Auto
10+
name=aws
11+
provider=Authentik
12+
saml_cache=false
13+
skip_verify=false
14+
timeout=0
15+
url=https://domain.tld/uri/of/your/auth/endpoint
16+
username=username
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
programs = {
3+
saml2aws = {
4+
enable = true;
5+
credentials = {
6+
aws = {
7+
name = "aws";
8+
url = "https://domain.tld/uri/of/your/auth/endpoint";
9+
username = "username";
10+
provider = "Authentik";
11+
mfa = "Auto";
12+
skip_verify = false;
13+
timeout = 0;
14+
aws_urn = "urn:amazon:webservices";
15+
aws_session_duration = 3600;
16+
aws_profile = "123456789000";
17+
saml_cache = false;
18+
disable_remember_device = false;
19+
disable_sessions = false;
20+
download_browser_driver = false;
21+
headless = false;
22+
};
23+
24+
};
25+
};
26+
};
27+
28+
nmt.script = ''
29+
assertFileExists home-files/.saml2aws
30+
assertFileContent home-files/.saml2aws \
31+
${./saml2aws.conf}
32+
'';
33+
}

0 commit comments

Comments
 (0)