You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Vineet Saini <sw...@gmail.com> on 2014/07/08 20:04:04 UTC

How to create Winodows Compute with random or predefine password

I'm trying work with Jcloud ComputerServiceContext to create windows
compute in AWS.

>
> - Using image id to create node.
>
> Problem is when user is created I'm not able to get password for admin
> user. I tried example here (
> https://github.com/jclouds/jclouds-examples/blob/master/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/WindowsInstanceStarter.java)
> which seems to be based on 1.5.0 release. Not sure what to update it to
> work with 1.7x.
>
> Also if can point me how to set default password for administrator user.
> that would be helpful too.
>
> I want to grammatically create Compute based on OS and Cloud which map ti
> image and create node. This include Linux/Windows/Mac.
> Once Compute created, should be able to install a software independent of
> any third party tool or with open source tool that work across cloud
> service and OS.
>
> Thanks in advance.
>

Re: How to create Winodows Compute with random or predefine password

Posted by Vineet Saini <sw...@gmail.com>.
In this case I'm using image provided the cloud (understand can use custom
image but want to keep away from it for now).




On Tue, Jul 8, 2014 at 4:31 PM, Daniel Widdis <wi...@gmail.com> wrote:

>  Can you just create another user with sudo/admin permissions and a known
> password, and then save that image for later use?
>
>
> On 7/8/14, 11:04 AM, Vineet Saini wrote:
>
>>  Problem is when user is created I'm not able to get password for admin
>> user. I tried example here (
>> https://github.com/jclouds/jclouds-examples/blob/master/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/WindowsInstanceStarter.java)
>> which seems to be based on 1.5.0 release. Not sure what to update it to
>> work with 1.7x.
>>
>>
>>

Re: How to create Winodows Compute with random or predefine password

Posted by Daniel Widdis <wi...@gmail.com>.
Can you just create another user with sudo/admin permissions and a known 
password, and then save that image for later use?

On 7/8/14, 11:04 AM, Vineet Saini wrote:

    Problem is when user is created I'm not able to get password for
    admin user. I tried example here
    (https://github.com/jclouds/jclouds-examples/blob/master/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/WindowsInstanceStarter.java)
    which seems to be based on 1.5.0 release. Not sure what to update it
    to work with 1.7x.



RE: How to create Winodows Compute with random or predefine password

Posted by Zack Shoylev <za...@RACKSPACE.COM>.
Have you tried:
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginCredentials;
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginUser;

This is what I see in the example.




From: Vineet Saini [switchcodes2@gmail.com]

Sent: Wednesday, July 09, 2014 1:47 PM

To: user@jclouds.apache.org

Subject: Re: How to create Winodows Compute with random or predefine password















Zack,



Not sure where this method overrideLoginUser("username") exist or which library provide it, as getting error this method not found.




templateBuilder.options(overrideLoginUser(loginUser))




Thank you for help.




Vineet








On Wed, Jul 9, 2014 at 1:20 PM, Zack Shoylev 
<za...@rackspace.com> wrote:


You might want to try something like



templateBuilder.options(overrideLoginUser(loginUser))



before you call templateBuilder.build();



As per this example:

https://github.com/jclouds/jclouds-examples/blob/master/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java



In any case I am thinking the idea is that you should not be able to modify the template (or its options) after you call build().



Let me know if this helps or not.

-Zack



From: Vineet Saini [switchcodes2@gmail.com]



Sent: Wednesday, July 09, 2014 10:49 AM



To: 
user@jclouds.apache.org



Subject: Re: How to create Winodows Compute with random or predefine password






























Andrew,







Based on information you provided and using existing

example, I able to make some progress, but not able to resolved one thing, here is code snippet.











Iterable<Module> modules = ImmutableSet. of( new SshjSshClientModule(), new SLF4JLoggingModule(), new EnterpriseConfigurationModule(), new BouncyCastleCryptoModule();







ComputeServiceContext context = ContextBuilder.newBuilder("aws-ec2") .credentials(identity, credential ) .modules(modules).buildView(ComputeServiceContext.class);











// use image id for windows Server 2003 R2 base =  ami-9050a9f8



TemplateBuilder templateBuilder = context.getComputeService().templateBuilder();





templateBuilder.imageId("us-east-1/ami-9050a9f8") .smallest() .locationId("us-east-1").os64Bit(true);











// Get Template



Template template = templateBuilder.build();















// Here try to override administrator password with static password,



// This does not work







template.getOptions().overrideLoginUser("Administrator");



template.getOptions().overrideLoginPassword("test123");











// setup port for rdp







template.getOptions().inboundPorts(3389);











// Create Node: it wait for call to finish with admin user it setup. that take care of wait till ready.



Set<?extends NodeMetadata> nodes = computeService .createNodesInGroup("grouptest", 2, template);















NodeMetadata nodeMetadata = Iterables.getOnlyElement(nodes);









PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(



        context.unwrapApi(EC2Api.class).getWindowsApi().get().getPasswordDataInRegion(region, nodeMetadata.getId()), nodeMetadata.getCredentials().getPrivateKey());









WindowsLoginCredentialsFromEncryptedData f = context.utils().injector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);











// In this case it need parameter type to be EncryptedPasswordDataAndPrivateKey instead of PasswordDataAndPrivateKey, not sure how to resolve that.





LoginCredentials credentials = f.apply(dataAndKey);













// get decrypted pass



logger.info("Login name: %s", credentials.getUser());



logger.info("Password: %s", credentials.getPassword());















Thanks for all the help.































On Tue, Jul 8, 2014 at 3:53 PM, Andrew Phillips

<an...@apache.org> wrote:













Also if can point me how to set default password for administrator user.



that would be helpful too.













I am not sure if that is possible. The EC2 Windows Security guide [1] says that, during initial install, it "generates and sets a random password on the Administrator account", but with your own AMIs you may be able to do something different.







As regards retrieving the Administrator credentials: have you been able to try getting the WindowsApi [2] from the EC2Api [3] and using that? If you are working with a ComputeService view, you will need to "unwrap" the view to access the underlying API first

 [4].







Regards







ap







[1]

https://aws.amazon.com/articles/1767



[2]

http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/features/WindowsApi.html



[3]

http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/EC2Api.html#getWindowsApi()



[4]

http://jclouds.apache.org/start/concepts/#apis






























Re: How to create Winodows Compute with random or predefine password

Posted by Vineet Saini <sw...@gmail.com>.
Zack,

Not sure where this method overrideLoginUser("username") exist or which
library provide it, as getting error this method not found.

templateBuilder.options*(overrideLoginUser*(loginUser))

Thank you for help.

Vineet


On Wed, Jul 9, 2014 at 1:20 PM, Zack Shoylev <za...@rackspace.com>
wrote:

> You might want to try something like
>
> templateBuilder.options(overrideLoginUser(loginUser))
>
> before you call templateBuilder.build();
>
> As per this example:
>
> https://github.com/jclouds/jclouds-examples/blob/master/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java
>
> In any case I am thinking the idea is that you should not be able to
> modify the template (or its options) after you call build().
>
> Let me know if this helps or not.
> -Zack
>
> From: Vineet Saini [switchcodes2@gmail.com]
>
> Sent: Wednesday, July 09, 2014 10:49 AM
>
> To: user@jclouds.apache.org
>
> Subject: Re: How to create Winodows Compute with random or predefine
> password
>
>
>
>
>
>
>
>
>
>
>
>
>
> Andrew,
>
>
>
> Based on information you provided and using existing
> example, I able to make some progress, but not able to resolved one thing,
> here is code snippet.
>
>
>
>
>
> Iterable<Module> modules = ImmutableSet. of( new SshjSshClientModule(),
> new SLF4JLoggingModule(), new EnterpriseConfigurationModule(), new
> BouncyCastleCryptoModule();
>
>
>
> ComputeServiceContext context = ContextBuilder.newBuilder("aws-ec2")
> .credentials(identity, credential )
> .modules(modules).buildView(ComputeServiceContext.class);
>
>
>
>
>
> // use image id for windows Server 2003 R2 base =  ami-9050a9f8
>
> TemplateBuilder templateBuilder =
> context.getComputeService().templateBuilder();
>
>
> templateBuilder.imageId("us-east-1/ami-9050a9f8") .smallest()
> .locationId("us-east-1").os64Bit(true);
>
>
>
>
>
> // Get Template
>
> Template template = templateBuilder.build();
>
>
>
>
>
>
>
> // Here try to override administrator password with static password,
>
> // This does not work
>
>
>
> template.getOptions().overrideLoginUser("Administrator");
>
> template.getOptions().overrideLoginPassword("test123");
>
>
>
>
>
> // setup port for rdp
>
>
>
> template.getOptions().inboundPorts(3389);
>
>
>
>
>
> // Create Node: it wait for call to finish with admin user it setup. that
> take care of wait till ready.
>
> Set<?extends NodeMetadata> nodes = computeService
> .createNodesInGroup("grouptest", 2, template);
>
>
>
>
>
>
>
> NodeMetadata nodeMetadata = Iterables.getOnlyElement(nodes);
>
>
>
>
> PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(
>
>
> context.unwrapApi(EC2Api.class).getWindowsApi().get().getPasswordDataInRegion(region,
> nodeMetadata.getId()), nodeMetadata.getCredentials().getPrivateKey());
>
>
>
>
> WindowsLoginCredentialsFromEncryptedData f =
> context.utils().injector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);
>
>
>
>
>
> // In this case it need parameter type to be
> EncryptedPasswordDataAndPrivateKey instead of PasswordDataAndPrivateKey,
> not sure how to resolve that.
>
>
> LoginCredentials credentials = f.apply(dataAndKey);
>
>
>
>
>
>
> // get decrypted pass
>
> logger.info("Login name: %s", credentials.getUser());
>
> logger.info("Password: %s", credentials.getPassword());
>
>
>
>
>
>
>
> Thanks for all the help.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Tue, Jul 8, 2014 at 3:53 PM, Andrew Phillips
> <an...@apache.org> wrote:
>
>
>
>
>
>
> Also if can point me how to set default password for administrator user.
>
> that would be helpful too.
>
>
>
>
>
>
> I am not sure if that is possible. The EC2 Windows Security guide [1] says
> that, during initial install, it "generates and sets a random password on
> the Administrator account", but with your own AMIs you may be able to do
> something different.
>
>
>
> As regards retrieving the Administrator credentials: have you been able to
> try getting the WindowsApi [2] from the EC2Api [3] and using that? If you
> are working with a ComputeService view, you will need to "unwrap" the view
> to access the underlying API first
>  [4].
>
>
>
> Regards
>
>
>
> ap
>
>
>
> [1]
> https://aws.amazon.com/articles/1767
>
> [2]
>
> http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/features/WindowsApi.html
>
> [3]
>
> http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/EC2Api.html#getWindowsApi()
>
> [4]
> http://jclouds.apache.org/start/concepts/#apis
>
>
>
>
>
>
>
>
>
>

RE: How to create Winodows Compute with random or predefine password

Posted by Zack Shoylev <za...@RACKSPACE.COM>.
You might want to try something like

templateBuilder.options(overrideLoginUser(loginUser))

before you call templateBuilder.build();

As per this example:
https://github.com/jclouds/jclouds-examples/blob/master/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java

In any case I am thinking the idea is that you should not be able to modify the template (or its options) after you call build().

Let me know if this helps or not.
-Zack

From: Vineet Saini [switchcodes2@gmail.com]

Sent: Wednesday, July 09, 2014 10:49 AM

To: user@jclouds.apache.org

Subject: Re: How to create Winodows Compute with random or predefine password













Andrew,



Based on information you provided and using existing 
example, I able to make some progress, but not able to resolved one thing, here is code snippet.





Iterable<Module> modules = ImmutableSet. of( new SshjSshClientModule(), new SLF4JLoggingModule(), new EnterpriseConfigurationModule(), new BouncyCastleCryptoModule();



ComputeServiceContext context = ContextBuilder.newBuilder("aws-ec2") .credentials(identity, credential ) .modules(modules).buildView(ComputeServiceContext.class);





// use image id for windows Server 2003 R2 base =  ami-9050a9f8

TemplateBuilder templateBuilder = context.getComputeService().templateBuilder();


templateBuilder.imageId("us-east-1/ami-9050a9f8") .smallest() .locationId("us-east-1").os64Bit(true);





// Get Template

Template template = templateBuilder.build();







// Here try to override administrator password with static password,

// This does not work



template.getOptions().overrideLoginUser("Administrator");

template.getOptions().overrideLoginPassword("test123"); 





// setup port for rdp



template.getOptions().inboundPorts(3389);





// Create Node: it wait for call to finish with admin user it setup. that take care of wait till ready.

Set<?extends NodeMetadata> nodes = computeService .createNodesInGroup("grouptest", 2, template);







NodeMetadata nodeMetadata = Iterables.getOnlyElement(nodes);




PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(   

        context.unwrapApi(EC2Api.class).getWindowsApi().get().getPasswordDataInRegion(region, nodeMetadata.getId()), nodeMetadata.getCredentials().getPrivateKey());




WindowsLoginCredentialsFromEncryptedData f = context.utils().injector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);





// In this case it need parameter type to be EncryptedPasswordDataAndPrivateKey instead of PasswordDataAndPrivateKey, not sure how to resolve that.


LoginCredentials credentials = f.apply(dataAndKey);






// get decrypted pass

logger.info("Login name: %s", credentials.getUser());

logger.info("Password: %s", credentials.getPassword());







Thanks for all the help.















On Tue, Jul 8, 2014 at 3:53 PM, Andrew Phillips 
<an...@apache.org> wrote:






Also if can point me how to set default password for administrator user.

that would be helpful too.






I am not sure if that is possible. The EC2 Windows Security guide [1] says that, during initial install, it "generates and sets a random password on the Administrator account", but with your own AMIs you may be able to do something different.



As regards retrieving the Administrator credentials: have you been able to try getting the WindowsApi [2] from the EC2Api [3] and using that? If you are working with a ComputeService view, you will need to "unwrap" the view to access the underlying API first
 [4].



Regards



ap



[1] 
https://aws.amazon.com/articles/1767

[2] 
http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/features/WindowsApi.html

[3] 
http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/EC2Api.html#getWindowsApi()

[4] 
http://jclouds.apache.org/start/concepts/#apis










Re: How to create Winodows Compute with random or predefine password

Posted by Vineet Saini <sw...@gmail.com>.
Andrew,

Based on information you provided and using existing example
<https://github.com/jclouds/jclouds-examples/blob/master/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/WindowsInstanceStarter.java>,
I able to make some progress, but not able to resolved one thing, here is
code snippet.

Iterable<Module> modules = ImmutableSet. of( new SshjSshClientModule(), new
SLF4JLoggingModule(), new EnterpriseConfigurationModule(), new
BouncyCastleCryptoModule();

ComputeServiceContext context = ContextBuilder.newBuilder("aws-ec2")
.credentials(identity, credential )
.modules(modules).buildView(ComputeServiceContext.class);

// use image id for windows Server 2003 R2 base =  ami-9050a9f8
TemplateBuilder templateBuilder =
context.getComputeService().templateBuilder();
templateBuilder.imageId("us-east-1/ami-9050a9f8") .smallest()
.locationId("us-east-1").os64Bit(true);

// Get Template
Template template = templateBuilder.build();

// Here try to override administrator password with static password,
// *This does not work*
template.getOptions().overrideLoginUser("Administrator");
template.getOptions().overrideLoginPassword("test123");

// setup port for rdp
template.getOptions().inboundPorts(3389);

// Create Node:* it wait for call to finish with admin user it setup.* that
take care of wait till ready.
Set<?extends NodeMetadata> nodes = computeService
.createNodesInGroup("grouptest", 2, template);

NodeMetadata nodeMetadata = Iterables.getOnlyElement(nodes);

PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(

context.unwrapApi(EC2Api.class).getWindowsApi().get().getPasswordDataInRegion(region,
nodeMetadata.getId()), nodeMetadata.getCredentials().getPrivateKey());

WindowsLoginCredentialsFromEncryptedData f =
context.utils().injector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);


// In this case it need parameter type to be
EncryptedPasswordDataAndPrivateKey instead of PasswordDataAndPrivateKey,
not sure how to resolve that.
LoginCredentials credentials = f.apply(*dataAndKey*);


// get decrypted pass
logger.info("Login name: %s", credentials.getUser());
logger.info("Password: %s", credentials.getPassword());


Thanks for all the help.




On Tue, Jul 8, 2014 at 3:53 PM, Andrew Phillips <an...@apache.org> wrote:

> Also if can point me how to set default password for administrator user.
>>> that would be helpful too.
>>>
>>
> I am not sure if that is possible. The EC2 Windows Security guide [1] says
> that, during initial install, it "generates and sets a random password on
> the Administrator account", but with your own AMIs you may be able to do
> something different.
>
> As regards retrieving the Administrator credentials: have you been able to
> try getting the WindowsApi [2] from the EC2Api [3] and using that? If you
> are working with a ComputeService view, you will need to "unwrap" the view
> to access the underlying API first [4].
>
> Regards
>
> ap
>
> [1] https://aws.amazon.com/articles/1767
> [2] http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/
> features/WindowsApi.html
> [3] http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/
> EC2Api.html#getWindowsApi()
> [4] http://jclouds.apache.org/start/concepts/#apis
>

Re: How to create Winodows Compute with random or predefine password

Posted by Richard Downer <ri...@apache.org>.
Vineet,

You may find this information useful - it's a blog post I made a
couple years back, and it explains how to get the encrypted password
and then decrypt it to a plain text password, using your key:
http://www.frontiertown.co.uk/2012/03/java-administrator-password-windows-ec2-instance/

It's written against the official AWS EC2 Java SDK, but it should be a
simple process to change it to use the jclouds API instead.

You may also find this post useful, if you want to use SSH on your
Windows instances without needing the Administrator password or having
to build a custom image:
http://www.frontiertown.co.uk/2013/10/ssh-amazon-ec2-windows-servers/

Richard.


On 8 July 2014 23:32, Andrew Phillips <an...@apache.org> wrote:
>> account to use it to encrypt new windows password rather than generating
>> new keypair for encryption?
>
>
> You should be able to get a TemplateOptions object from the ComputeService.
> Since your underlying API is EC2, you can cast this to an EC2TemplateOptions
> instance (computeService.templateOptions().as(EC2TemplateOptions.class)) as
> then specify the desired key pair [1].
>
> Regards
>
> ap
>
> [1]
> http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/compute/options/EC2TemplateOptions.html#keyPair(java.lang.String)

Re: How to create Winodows Compute with random or predefine password

Posted by Andrew Phillips <an...@apache.org>.
> account to use it to encrypt new windows password rather than generating
> new keypair for encryption?

You should be able to get a TemplateOptions object from the  
ComputeService. Since your underlying API is EC2, you can cast this to  
an EC2TemplateOptions instance  
(computeService.templateOptions().as(EC2TemplateOptions.class)) as  
then specify the desired key pair [1].

Regards

ap

[1]  
http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/compute/options/EC2TemplateOptions.html#keyPair(java.lang.String)

Re: How to create Winodows Compute with random or predefine password

Posted by Vineet Saini <sw...@gmail.com>.
Also any way to tell ComputerServiceView to use existing keypair on my
account to use it to encrypt new windows password rather than generating
new keypair for encryption?

Thanks for help.


On Tue, Jul 8, 2014 at 3:53 PM, Andrew Phillips <an...@apache.org> wrote:

> Also if can point me how to set default password for administrator user.
>>> that would be helpful too.
>>>
>>
> I am not sure if that is possible. The EC2 Windows Security guide [1] says
> that, during initial install, it "generates and sets a random password on
> the Administrator account", but with your own AMIs you may be able to do
> something different.
>
> As regards retrieving the Administrator credentials: have you been able to
> try getting the WindowsApi [2] from the EC2Api [3] and using that? If you
> are working with a ComputeService view, you will need to "unwrap" the view
> to access the underlying API first [4].
>
> Regards
>
> ap
>
> [1] https://aws.amazon.com/articles/1767
> [2] http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/
> features/WindowsApi.html
> [3] http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/
> EC2Api.html#getWindowsApi()
> [4] http://jclouds.apache.org/start/concepts/#apis
>

Re: How to create Winodows Compute with random or predefine password

Posted by Andrew Phillips <an...@apache.org>.
>> Also if can point me how to set default password for administrator user.
>> that would be helpful too.

I am not sure if that is possible. The EC2 Windows Security guide [1]  
says that, during initial install, it "generates and sets a random  
password on the Administrator account", but with your own AMIs you may  
be able to do something different.

As regards retrieving the Administrator credentials: have you been  
able to try getting the WindowsApi [2] from the EC2Api [3] and using  
that? If you are working with a ComputeService view, you will need to  
"unwrap" the view to access the underlying API first [4].

Regards

ap

[1] https://aws.amazon.com/articles/1767
[2]  
http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/features/WindowsApi.html
[3]  
http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/EC2Api.html#getWindowsApi()
[4] http://jclouds.apache.org/start/concepts/#apis