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

provider/aws: Added aws_iam_login_profile custom password setting #10734

Closed
wants to merge 2 commits into from

Conversation

Ninir
Copy link
Contributor

@Ninir Ninir commented Dec 14, 2016

Reasoning for this change

This is the continuation of #9605.

The previous PR introduced PGP-based keys, encrypting and decrypting using keybase.io.
As the login_profile password was generated, it was missing the ability to generate a custom password.
This allows to set it, making this even more flexible.

Real Configuration

 resource "aws_iam_user" "user" {
     name = "demo"
     path = "/"
     force_destroy = true
 }
 
 data "aws_caller_identity" "current" {}
 
 data "aws_iam_policy_document" "user" {
     statement {
         effect = "Allow"
         actions = ["iam:GetAccountPasswordPolicy"]
         resources = ["*"]
     }
     statement {
         effect = "Allow"
         actions = ["iam:ChangePassword"]
         resources = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/&{aws:username}"]
     }
 }
 
 resource "aws_iam_user_policy" "user" {
     name = "AllowChangeOwnPassword"
     user = "${aws_iam_user.user.name}"
     policy = "${data.aws_iam_policy_document.user.json}"
 }
 
 resource "aws_iam_access_key" "user" {
     user = "${aws_iam_user.user.name}"
 }
 
 resource "aws_iam_user_login_profile" "user" {
     user = "${aws_iam_user.user.name}"
     password = "test"
 }

Use cases

Demos, trainings or handsons.

Acceptance tests

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSUserLoginProfile_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/12/14 21:58:25 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSUserLoginProfile_ -timeout 120m
=== RUN   TestAccAWSUserLoginProfile_basic
--- PASS: TestAccAWSUserLoginProfile_basic (22.11s)
=== RUN   TestAccAWSUserLoginProfile_keybase
--- PASS: TestAccAWSUserLoginProfile_keybase (20.71s)
=== RUN   TestAccAWSUserLoginProfile_keybaseDoesntExist
--- PASS: TestAccAWSUserLoginProfile_keybaseDoesntExist (12.11s)
=== RUN   TestAccAWSUserLoginProfile_notAKey
--- PASS: TestAccAWSUserLoginProfile_notAKey (14.28s)
=== RUN   TestAccAWSUserLoginProfile_customPassword
--- PASS: TestAccAWSUserLoginProfile_customPassword (19.61s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	88.850s

@@ -90,7 +90,27 @@ func TestAccAWSUserLoginProfile_notAKey(t *testing.T) {
{
// We own this account but it doesn't have any key associated with it
Config: testAccAWSUserLoginProfileConfig(username, "/", "lolimnotakey"),
ExpectError: regexp.MustCompile(`Error encrypting password`),
ExpectError: regexp.MustCompile(`Error encrypting Password`),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a typo here for password, with error:

* aws_iam_user_login_profile.user: Error encrypting Password: Error parsing given PGP key: unexpected EOF

@@ -169,7 +189,7 @@ func testDecryptPasswordAndTest(nProfile, nAccessKey, key string) resource.TestC
NewPassword: aws.String(generatePassword(20)),
})
if err != nil {
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "InvalidClientTokenId" {
if awserr, ok := err.(awserr.Error); ok && (awserr.Code() == "InvalidClientTokenId" || awserr.Code() == "EntityTemporarilyUnmodifiable") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required since I encountered this error:

Check failed: Check 2/2 error: Error changing decrypted password: EntityTemporarilyUnmodifiable: Login Profile for User test-user-5423997845776594466 cannot be modified while login profile is being created.

@jen20
Copy link
Contributor

jen20 commented Dec 14, 2016

Hi @Ninir! The issue with setting a custom password is that it then appears in configuration unencrypted - is this the desired outcome?

@Ninir
Copy link
Contributor Author

Ninir commented Dec 14, 2016

Hi @jen20 !

It is. In my case, it is sometimes useful to provide sequence-based passwords, like "user1", "user2" etc (training purposes for instance).

Also, the variable can be passed using -var file, or using a Vault Provider in cases you really need to hide it.

@Ninir Ninir changed the title [WIP] provider/aws: Added aws_iam_login_profile custom password setting provider/aws: Added aws_iam_login_profile custom password setting Dec 14, 2016
@Ninir
Copy link
Contributor Author

Ninir commented Dec 14, 2016

If you try to change the password without impersonating the user, the following error will be thrown:

InvalidUserType: Only IAM Users can change their own password.

I am able to do the update stuff, but it will require to impersonate the user, and update the profile.
Do you think we should go this way?

@ghost
Copy link

ghost commented Apr 7, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants