Skip to content

Commit

Permalink
Feature/4/self managed ssh keys (#5)
Browse files Browse the repository at this point in the history
* Support self-managed SSH keys plus file cleanup
* CHANGELOG.md bump
  • Loading branch information
jufemaiz authored Aug 2, 2019
1 parent 62aefdf commit cac085d
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 73 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v0.0.3 (2019-08-02)

* Self-managed SSH keys supported

## v0.0.2 (2019-08-01)

* Tags added!
Expand Down
20 changes: 20 additions & 0 deletions groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,24 @@ data "aws_iam_policy_document" "self_management" {
values = ["true"]
}
}

statement {
sid = "AllowUsersToSelfManageTheirSSHKeys"

actions = [
"iam:DeleteSSHPublicKey",
"iam:GetSSHPublicKey",
"iam:ListSSHPublicKeys",
"iam:UpdateSSHPublicKey",
"iam:UploadSSHPublicKey"
]

resources = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/&{aws:username}"]

condition {
test = "Bool"
variable = "aws:MultiFactorAuthPresent"
values = ["true"]
}
}
}
18 changes: 9 additions & 9 deletions groups/readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ cat << README > README.md
This module generates generic IAM roles as follows.
* Devops
* DevopsProd
* ReadOnly
* ReadOnlyProd
* Superuser
* SuperuserProd
* Support
* SupportProd
* UserSelfManagement
* `Devops`
* `DevopsProd`
* `ReadOnly`
* `ReadOnlyProd`
* `Superuser`
* `SuperuserProd`
* `Support`
* `SupportProd`
* `UserSelfManagement`
## Usage
Expand Down
1 change: 0 additions & 1 deletion groups/tagging.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ locals {
},
)
}

1 change: 0 additions & 1 deletion groups/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

terraform {
required_version = ">= 0.12"
}
12 changes: 6 additions & 6 deletions roles/readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ This module generates generic IAM roles as follows.
## Human roles
* Devops
* Readonly
* Superuser
* Support
* `Devops`
* `Readonly`
* `Superuser`
* `Support`
## Machine roles
* Metrics
* `Metrics`
## Miscellany
Since this module is recommended to be applied across all accounts, it comes
with some other goodies:-
* Password defaults
* Password defaults
## Usage
Expand Down
1 change: 0 additions & 1 deletion roles/tagging.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ locals {
},
)
}

1 change: 0 additions & 1 deletion roles/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ variable "tags" {
type = map(string)
default = {}
}

1 change: 0 additions & 1 deletion roles/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

terraform {
required_version = ">= 0.12"
}
100 changes: 50 additions & 50 deletions user/readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,79 @@ This module generates a single user, and adds them to appropriate groups.
# Usage instructions:
1. Generate a PGP key
1. Generate a PGP key
### Option A
### Option A
Use keybase.io. You can just feed your keybase.io username in to this module
and we'll do the rest.
Use keybase.io. You can just feed your keybase.io username in to this module
and we'll do the rest.
### Option B
### Option B
[Find some supported software for your platform](https://gnupg.org/download/)
[Find some supported software for your platform](https://gnupg.org/download/)
2. Use this module to create your user
2. Use this module to create your user
\`\`\`
module "stuart" {
source = "[email protected]:aceteknologi/terraform-iam.git//user?ref=v0.0.1"
\`\`\`
module "stuart" {
source = "[email protected]:aceteknologi/terraform-iam.git//user?ref=v0.0.1"
username = "[email protected]"
username = "[email protected]"
# if you used keybase.io this could be
# public_pgp_key = "keybase:<username>"
# if you used keybase.io this could be
# public_pgp_key = "keybase:<username>"
# or it could be something long-winded, like
# public_pgp_key = "mQINBFxre0gBEADEP8d8Lp9Yn6wMLhBuJxtTpEOivHkvxClBdz7neGz/t679LwbDIZJcbX3maFpH8+2LwRSFlV5OPJvv4Ldee2xKDxkSI7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QQNc3/xQVnopIGVAfDVADSGnnz510rAWVQV3QHG4acY5E2ArdCMWcktqa5kuyEzGT0tWrebH7eiTj9l2v46ypfvgSfxGFmaMgqQmT8Ug+fYo9RXUg3hpM8hseq4d+fdkIZXlKkKTMgv3wH9i86zjuVMAmOrEty6EFDC284gjmIunVxpIbZTYsEucrMYIBytfqLNmOC49utScOQWhpT3aXknpXHE0zVKxVcn/VM/dlWD9rKJKTp4RuWVKKv161360/0oMMzBb/CSiexsIJI2IEAjpw4n53RKRNZjX6RDeRnQqvAYEKG3qMUlEvMN2WtmVuKChmgg5Kc2qbTAa0FkY1SSH2QYt+ew+USabX6+Ni8UG7uKCht81Wo26ffkdSfiIj+jKJBS7A8llvNQpNU9r7fyOmlxvUxdqUBw2BDVX3RVul5jHEckJb6JpCZh9ik8TYo8TOAWM111Cwm5xTAaSBcqc7E4w5/RlGfQN4diC4FdsQicSiG05vnPrh/ROQYbge1ZwRN7w9hAJ8JMywYFN/GpzdroYJ"
# Maximum 10 groups!
groups = [
"\${module.groups.self_management_group_name}",
"\${module.groups.devops_group_name}",
"\${module.groups.devops_prod_group_name}",
"\${module.groups.superuser_group_name}",
"\${module.groups.superuser_prod_group_name}",
]
# Maximum 10 groups!
groups = [
"\${module.groups.self_management_group_name}",
"\${module.groups.devops_group_name}",
"\${module.groups.devops_prod_group_name}",
"\${module.groups.superuser_group_name}",
"\${module.groups.superuser_prod_group_name}",
]
tags = "\${local.tags}"
}
tags = "\${local.tags}"
}
output "stuart" {
value = <<EOF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Initial login details for \${module.stuart.name}
output "stuart" {
value = <<EOF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Initial login details for \${module.stuart.name}
Password: \${module.stuart.encrypted_password}
Password: \${module.stuart.encrypted_password}
Please decrypt this password with the PGP key with the fingerprint \${module.stuart.key_fingerprint}
Hint: \`echo "\${module.stuart.encrypted_password}" | base64 --decode | gpg\`
OR
\`echo "\${module.stuart.encrypted_password}" | base64 --decode | keybase pgp decrypt\`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EOF
}
\`\`\`
Please decrypt this password with the PGP key with the fingerprint \${module.stuart.key_fingerprint}
Hint: \`echo "\${module.stuart.encrypted_password}" | base64 --decode | gpg\`
OR
\`echo "\${module.stuart.encrypted_password}" | base64 --decode | keybase pgp decrypt\`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EOF
}
\`\`\`
3. Decode the output
3. Decode the output
\`echo "wcFMA/........." | base64 --decode | gpg\`
\`echo "wcFMA/........." | base64 --decode | gpg\`
4. Login to the [console!](https://console.aws.amazon.com/)
4. Login to the [console!](https://console.aws.amazon.com/)
# Enter your account ID
# Enter your username
# Enter your decrypted password
# Enter your account ID
# Enter your username
# Enter your decrypted password
5. Navigate to IAM » <Your User> » Security credentials
5. Navigate to IAM » <Your User> » Security credentials
6. Next to "Assigned MFA device", hit the "Manage" link and create yourself an
MFA device
6. Next to "Assigned MFA device", hit the "Manage" link and create yourself an
MFA device
7. Sign out
7. Sign out
8. Sign in (this time with MFA!)
8. Sign in (this time with MFA!)
9. Navigate back to IAM » <Your User> » Security credentials
9. Navigate back to IAM » <Your User> » Security credentials
10. Hit the create access key button! You now have keys. Rotate them often.
Expand Down
1 change: 0 additions & 1 deletion user/tagging.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ locals {
},
)
}

1 change: 0 additions & 1 deletion user/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ variable "tags" {

variable "username" {
}

1 change: 0 additions & 1 deletion user/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit cac085d

Please sign in to comment.