Skip to content

Commit 3d0509b

Browse files
authored
fix: handle unencrypted secrets (#139)
1 parent a59da0d commit 3d0509b

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

modules/iam-user/outputs.tf

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
locals {
2+
has_encrypted_password = length(compact(aws_iam_user_login_profile.this.*.encrypted_password)) > 0
3+
has_encrypted_secret = length(compact(aws_iam_access_key.this.*.encrypted_secret)) > 0
4+
}
5+
16
output "this_iam_user_name" {
27
description = "The user's name"
38
value = element(concat(aws_iam_user.this.*.name, [""]), 0)
@@ -15,18 +20,12 @@ output "this_iam_user_unique_id" {
1520

1621
output "this_iam_user_login_profile_key_fingerprint" {
1722
description = "The fingerprint of the PGP key used to encrypt the password"
18-
value = element(
19-
concat(aws_iam_user_login_profile.this.*.key_fingerprint, [""]),
20-
0,
21-
)
23+
value = element(concat(aws_iam_user_login_profile.this.*.key_fingerprint, [""]), 0)
2224
}
2325

2426
output "this_iam_user_login_profile_encrypted_password" {
2527
description = "The encrypted password, base64 encoded"
26-
value = element(
27-
concat(aws_iam_user_login_profile.this.*.encrypted_password, [""]),
28-
0,
29-
)
28+
value = element(concat(aws_iam_user_login_profile.this.*.encrypted_password, [""]), 0)
3029
}
3130

3231
output "this_iam_access_key_id" {
@@ -37,7 +36,7 @@ output "this_iam_access_key_id" {
3736
aws_iam_access_key.this_no_pgp.*.id,
3837
[""],
3938
),
40-
0,
39+
0
4140
)
4241
}
4342

@@ -64,7 +63,7 @@ output "this_iam_access_key_ses_smtp_password_v4" {
6463
aws_iam_access_key.this_no_pgp.*.ses_smtp_password_v4,
6564
[""],
6665
),
67-
0,
66+
0
6867
)
6968
}
7069

@@ -76,7 +75,7 @@ output "this_iam_access_key_status" {
7675
aws_iam_access_key.this_no_pgp.*.status,
7776
[""],
7877
),
79-
0,
78+
0
8079
)
8180
}
8281

@@ -87,42 +86,36 @@ output "pgp_key" {
8786

8887
output "keybase_password_decrypt_command" {
8988
description = "Decrypt user password command"
90-
value = <<EOF
91-
echo "${element(
92-
concat(aws_iam_user_login_profile.this.*.encrypted_password, [""]),
93-
0,
94-
)}" | base64 --decode | keybase pgp decrypt
89+
value = !local.has_encrypted_password ? null : <<EOF
90+
echo "${element(concat(aws_iam_user_login_profile.this.*.encrypted_password, [""]), 0)}" | base64 --decode | keybase pgp decrypt
9591
EOF
9692

9793
}
9894

9995
output "keybase_password_pgp_message" {
10096
description = "Encrypted password"
101-
value = <<EOF
97+
value = !local.has_encrypted_password ? null : <<EOF
10298
-----BEGIN PGP MESSAGE-----
10399
Version: Keybase OpenPGP v2.0.76
104100
Comment: https://keybase.io/crypto
105101
106-
${element(
107-
concat(aws_iam_user_login_profile.this.*.encrypted_password, [""]),
108-
0,
109-
)}
102+
${element(concat(aws_iam_user_login_profile.this.*.encrypted_password, [""]), 0)}
110103
-----END PGP MESSAGE-----
111104
EOF
112105

113106
}
114107

115108
output "keybase_secret_key_decrypt_command" {
116109
description = "Decrypt access secret key command"
117-
value = <<EOF
110+
value = !local.has_encrypted_secret ? null : <<EOF
118111
echo "${element(concat(aws_iam_access_key.this.*.encrypted_secret, [""]), 0)}" | base64 --decode | keybase pgp decrypt
119112
EOF
120113

121114
}
122115

123116
output "keybase_secret_key_pgp_message" {
124117
description = "Encrypted access secret key"
125-
value = <<EOF
118+
value = !local.has_encrypted_secret ? null : <<EOF
126119
-----BEGIN PGP MESSAGE-----
127120
Version: Keybase OpenPGP v2.0.76
128121
Comment: https://keybase.io/crypto
@@ -135,14 +128,10 @@ EOF
135128

136129
output "this_iam_user_ssh_key_ssh_public_key_id" {
137130
description = "The unique identifier for the SSH public key"
138-
value = element(
139-
concat(aws_iam_user_ssh_key.this.*.ssh_public_key_id, [""]),
140-
0,
141-
)
131+
value = element(concat(aws_iam_user_ssh_key.this.*.ssh_public_key_id, [""]), 0)
142132
}
143133

144134
output "this_iam_user_ssh_key_fingerprint" {
145135
description = "The MD5 message digest of the SSH public key"
146136
value = element(concat(aws_iam_user_ssh_key.this.*.fingerprint, [""]), 0)
147137
}
148-

0 commit comments

Comments
 (0)