bastillion-io / Bastillion-EC2

A web-based SSH console to execute commands and manage multiple EC2 instances simultaneously running on Amazon Web Services (AWS).
https://www.bastillion.io/features.html#ec2box
Other
424 stars 74 forks source link

Proxy Settings #4

Closed tompierce closed 10 years ago

tompierce commented 10 years ago

It would be great if we could use this from behind our corporate proxy. Any plans to include this?

skavanagh commented 10 years ago

Not quite sure why that wouldn't work. The way it's set now if there is no public DNS, it should fallback on the private

https://github.com/skavanagh/EC2Box/blob/master/src/main/java/com/ec2box/manage/action/SystemAction.java#L141

Would it be better if I made it configureable?? And do something like ..

if("true".equals(AppConfig.getProperty("usePublicDNS")) {
     if (StringUtils.isNotEmpty(instance.getPublicDnsName())) {
          hostSystem.setHost(instance.getPublicDnsName());
     } else  {
         hostSystem.setHost(instance.getPublicIpAddress());
     } 
} else {
     if (StringUtils.isNotEmpty(instance.getPrivateDnsName())) {
           hostSystem.setHost(instance.getPrivateDnsName());
      } else {
           hostSystem.setHost(instance.getPrivateIpAddress());
      }
}
tompierce commented 10 years ago

Ah, sorry. I should have explained better.

We can hit the web app no problem. But when I try to add my AWS credentials I get an "Invalid Credentials" error, which I assume is caused by EC2Box not being able to reach Amazon.

I believe you can supply proxy settings when you create an EC2Client. eg. in AWSCredAction.java

BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(), awsCred.getSecretKey());
AmazonEC2 service = new AmazonEC2Client(awsCredentials);

You can use the AmazonEC2Client constructor which also takes an AWSClientConfiguration.

I guess there might be other places where this configuration is necessary?

skavanagh commented 10 years ago

Gotcha! It's only in 2 or 3 places, so it should be easy. I'll just have a place for the proxy settings in the config file https://github.com/skavanagh/EC2Box/blob/master/src/main/resources/EC2BoxConfig.properties

skavanagh commented 10 years ago

This should do it. https://github.com/skavanagh/EC2Box/commit/5d68425c55520032046e62f1f5c22e71b3e47f80

tompierce commented 10 years ago

I noticed a typo in AWSClientConfig.java

    if (StringUtils.isNotEmpty(awsProxyPort)) {
        config.setProxyHost(awsProxyPort);
    }

should be

    if (StringUtils.isNotEmpty(awsProxyPort)) {
        config.setProxyPort(Integer.parseInt(awsProxyPort));
    }

(or similar)

With that change I'm able to set my AWS creds and my EC2 keys. However I get an error when I try to create an ssh terminal. The first time I tried I got an error box with "Unknown Host Exception". But subsequently I just get to the "No sessions could be created" page and lots of JdbcSQLException in the logs. eg.

org.h2.jdbc.JdbcSQLException: NULL not allowed for column "HOST"; SQL statement:
insert into system (display_nm, user, host, port, instance_id, key_id, region, state, instance_status, system_status) values (?,?,?,?,?,?,?,?,?,?) [23502-175]

I can fork and try and get a pull request together in the next few days if you'd like? I suspect that the SSHUtil stuff will also need to know about the proxy settings.

skavanagh commented 10 years ago

Whoops! Thanks!

Sounds like it's not getting anything back for the host info.

It should be right here...

https://github.com/skavanagh/EC2Box/blob/master/src/main/java/com/ec2box/manage/action/SystemAction.java#L145

Not sure what else to use.

skavanagh commented 10 years ago

try https://github.com/skavanagh/EC2Box/commit/2e849e9e06f08f646badbca6968555b30bc6f78f

I guess if it's in a VPC you have to get the private DNS from getNetworkInterfaces()

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/ec2/model/Instance.html#getNetworkInterfaces()

tompierce commented 10 years ago

I've realised I'm thinking about this wrong. I can sidestep the problem of deploying to our local network (which is behind a proxy server) by just deploying to an EC2 instance. I'll hopefully have some time to do it tomorrow. There might be some more work to do to support VPC's but I don't have much experience with those.

Thanks for all your help! I'll close this now.

skavanagh commented 10 years ago

No problem. I guess I was thinking you had already deployed it to your local network. Anyway you have it setup you need a value back for host, it won't work if it's null. I don't have any experience with VPC's either. And I'm not really sure the rules of when to set it to public DNS, private DNS or the private DNS off of the getNetworkInterfaces() method ..but it should be in that block of code somewhere, just needs a value for host. Thanks for making me think about it!