This repository has been archived by the owner. It is now read-only.

Add GetPasswordData operation for EC2 instances #244

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@jen20

jen20 commented Mar 21, 2015

Description

This operation allows the user to obtain a copy of the auto-generated Administrator password for an instance running Windows, encrypted using the key-pair specified on instance launch.

A test has been added using the example from the documentation, but with the response updated to reflect the actual time format passed in current usage.

Example usage

package main

import (
    "fmt"
    "github.com/mitchellh/goamz/aws"
    "github.com/mitchellh/goamz/ec2"
    "log"
)

func main() {
    auth, err := aws.EnvAuth()
    if err != nil {
        log.Fatal(err)
    }

    client := ec2.New(auth, aws.USEast)

    resp, err := client.GetPasswordData("i-7435208e")
    if err != nil {
        log.Fatal(err)
    }

    log.Print(fmt.Sprintf("%+v", resp))
}

Example output (password available):

015/03/21 12:42:50 &{RequestId:ae0976ec-bf3e-4f29-8b76-b2909b53b55a InstanceId:i-7435208e Timestamp:2015-03-21 16:39:38 +0000 UTC PasswordData:
c1jbhR3b7cApaiPX2X8BdqqGo0LlY3jsFL5ods3yrp86UXhznv1Ae3rlNjxAKVFJOCGcbnDkV1dWU1CkOrc1proiWKJVefQsNXSKfVf/GW5eq+jag0C2jG2LITeKoio8jovhVMqQvtxP+DC+p21XWfBwXAuF5shAG+ULvx6dj1/7HJuDdcJwkptEswvIg95HOyfx29h6gTMDx1JwEHGDasWTJzrUp7tGESl+6LPS7SRI5SlrE1RrNn/3tsJstBi5yLKb7MjKlCHf6FNJYrlt1eXcA3gSAeBB699UjhXv1M5x6SSqmVmLcNlPeFfoOBbZ8vKS458p7Zj00OF3GJvGpA==
}

Example output (password not yet available):

2015/03/21 12:39:09 &{RequestId:a3df9040-beae-413c-862d-7833eb5de5e7 InstanceId:i-7435208e Timestamp:2015-03-21 16:38:16 +0000 UTC PasswordData:}
Add GetPasswordData operation for EC2 instances
This operation allows the user to obtain a copy of the auto-generated
Administrator password for an instance running Windows, encrypted using
the key-pair specified on instance launch.

jen20 added a commit to jen20/packer-windows-plugins that referenced this pull request Apr 1, 2015

Add GetPassword step to the EBS builder
This commit introduces a new build step which gets the automatically
generated password using the EC2 API and decrypts it using the generated
private key.

The following changes are necessary to support this:

- A key pair must be specified for the instance - similar to builders
  for other operating systems this can either be auto-generated if none
  is specified, or a specific key pair can be nominated.

- We rely on a function not yet merged into `mitchellh/goamz` in order to
  make the API call on EC2. There is currently an outstanding pull
  request for this (mitchellh/goamz#244), but
  for now it depends on the `jen20` fork of `goamz`.

This still needs adding to the instance builder, and also needs some
form of control to allow a password to be set explicitly if one has
already been set for the source AMI.

jen20 added a commit to jen20/packer-windows-plugins that referenced this pull request Apr 1, 2015

Add GetPassword step to the EBS builder
This commit introduces a new build step which gets the automatically
generated password using the EC2 API and decrypts it using the generated
private key.

The following changes are necessary to support this:

- A key pair must be specified for the instance - similar to builders
  for other operating systems this can either be auto-generated if none
  is specified, or a specific key pair can be nominated.

- We rely on a function not yet merged into `mitchellh/goamz` in order to
  make the API call on EC2. There is currently an outstanding pull
  request for this (mitchellh/goamz#244), but
  for now it depends on the `jen20` fork of `goamz`.

This still needs adding to the instance builder, and also needs some
form of control to allow a password to be set explicitly if one has
already been set for the source AMI.
@jen20

This comment has been minimized.

Show comment
Hide comment
@jen20

jen20 Apr 2, 2015

@mitchellh Is this likely to be accepted given the new libs? packer-community/packer-windows-plugins#39 depends on it - I can likely work around this if necessary though.

jen20 commented Apr 2, 2015

@mitchellh Is this likely to be accepted given the new libs? packer-community/packer-windows-plugins#39 depends on it - I can likely work around this if necessary though.

jen20 added a commit to jen20/packer-windows-plugins that referenced this pull request Apr 20, 2015

Add GetPassword step to the EBS builder
This commit introduces a new build step which gets the automatically
generated password using the EC2 API and decrypts it using the generated
private key.

The following changes are necessary to support this:

- A key pair must be specified for the instance - similar to builders
  for other operating systems this can either be auto-generated if none
  is specified, or a specific key pair can be nominated.

- We rely on a function not yet merged into `mitchellh/goamz` in order to
  make the API call on EC2. There is currently an outstanding pull
  request for this (mitchellh/goamz#244), but
  for now it depends on the `jen20` fork of `goamz`.

This still needs adding to the instance builder, and also needs some
form of control to allow a password to be set explicitly if one has
already been set for the source AMI.
@mefellows

This comment has been minimized.

Show comment
Hide comment
@mefellows

mefellows May 23, 2015

Hi @mitchellh, is this likely to be merged anytime soon? Looking to follow up on the above PR for Packer Windows Plugins. If not, we'll work on another strategy.

mefellows commented May 23, 2015

Hi @mitchellh, is this likely to be merged anytime soon? Looking to follow up on the above PR for Packer Windows Plugins. If not, we'll work on another strategy.

@davidneudorfer

This comment has been minimized.

Show comment
Hide comment

davidneudorfer commented Sep 22, 2015

+1

@jen20

This comment has been minimized.

Show comment
Hide comment
@jen20

jen20 Sep 22, 2015

You can now do this with the official AWS SDK:

resp, err := ec2conn.GetPasswordData(&ec2.GetPasswordDataInput{
    InstanceId: aws.String("instanceId"),
})

jen20 commented Sep 22, 2015

You can now do this with the official AWS SDK:

resp, err := ec2conn.GetPasswordData(&ec2.GetPasswordDataInput{
    InstanceId: aws.String("instanceId"),
})
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.