You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2018/05/24 14:09:27 UTC

[1/3] brooklyn-server git commit: disable jclouds authorizePublicKey for extra ssh public key data

Repository: brooklyn-server
Updated Branches:
  refs/heads/master dedaffd52 -> 59a0b9112


disable jclouds authorizePublicKey for extra ssh public key data

we install this ourselves in addition so no need, and if we ask jclouds to do it, it seems to break sometimes (eg when keyPair is set).
there is a system property that can be set to revert for legacy behaviour.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/1950baae
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/1950baae
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/1950baae

Branch: refs/heads/master
Commit: 1950baaec5e3be4a69382eeb91ce132257dc9129
Parents: dedaffd
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu May 24 11:03:38 2018 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu May 24 11:06:46 2018 +0100

----------------------------------------------------------------------
 .../ExtraPublicKeyDataToAuthOption.java         |  9 +++++-
 .../provider/AbstractJcloudsLocationTest.java   |  2 +-
 .../provider/AwsEc2LocationLiveTest.java        | 29 ++++++++++++++++++++
 .../util/internal/BrooklynSystemProperties.java | 16 +++++++++--
 4 files changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1950baae/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/ExtraPublicKeyDataToAuthOption.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/ExtraPublicKeyDataToAuthOption.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/ExtraPublicKeyDataToAuthOption.java
index 2ab0ff6..8a47320 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/ExtraPublicKeyDataToAuthOption.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/ExtraPublicKeyDataToAuthOption.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.location.jclouds.templates.customize;
 
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.internal.BrooklynSystemProperties;
 import org.jclouds.compute.options.TemplateOptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,6 +29,7 @@ import org.slf4j.LoggerFactory;
 class ExtraPublicKeyDataToAuthOption implements TemplateOptionCustomizer {
     private static final Logger LOG = LoggerFactory.getLogger(ExtraPublicKeyDataToAuthOption.class);
 
+    @SuppressWarnings("deprecation")
     @Override
     public void apply(TemplateOptions t, ConfigBag props, Object v) {
         // this is unreliable:
@@ -43,8 +45,13 @@ class ExtraPublicKeyDataToAuthOption implements TemplateOptionCustomizer {
         // we also do it here for legacy reasons though i (alex) can't think of any situations it's needed
         // --
         // also we warn on exceptions in case someone is dumping comments or something else
+        //
+        // TODO remove in 1.1 or later, if we confirm there is no need for this
         try {
-            t.authorizePublicKey(v.toString());
+            if (BrooklynSystemProperties.JCLOUDS_AUTHORIZE_EXTRA_SSH_PUBLIC_KEY_DATA.isEnabled()) {
+                // May 2018 - disabled this unless explicitly enabled as it breaks the use of key pairs
+                t.authorizePublicKey(v.toString());
+            }
         } catch (Exception e) {
             Exceptions.propagateIfFatal(e);
             LOG.warn("Error trying jclouds authorizePublicKey; will run later: " + e, e);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1950baae/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AbstractJcloudsLocationTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AbstractJcloudsLocationTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AbstractJcloudsLocationTest.java
index ab0a23e..0a87e4b 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AbstractJcloudsLocationTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AbstractJcloudsLocationTest.java
@@ -48,7 +48,7 @@ import com.google.common.collect.Maps;
 public abstract class AbstractJcloudsLocationTest {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractJcloudsLocationTest.class);
 
-    private final String provider;
+    protected final String provider;
 
     protected JcloudsLocation loc;
     protected List<SshMachineLocation> machines = MutableList.of();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1950baae/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
index 9ebd2e8..b8aff87 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.location.jclouds.provider;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -28,6 +30,8 @@ import org.testng.annotations.Test;
  */
 public class AwsEc2LocationLiveTest extends AbstractJcloudsLocationTest {
 
+    private static final Logger log = LoggerFactory.getLogger(AwsEc2LocationLiveTest.class);
+    
     private static final String PROVIDER = "aws-ec2";
     private static final String EUWEST_REGION_NAME = "eu-west-1";
     private static final String USEAST_REGION_NAME = "us-east-1";
@@ -68,4 +72,29 @@ public class AwsEc2LocationLiveTest extends AbstractJcloudsLocationTest {
 
     @Test(enabled = false)
     public void noop() { } /* just exists to let testNG IDE run the test */
+    
+    // outline of test which can be used to assert combos of keys etc
+    // currently uses my (alex's) hardcoded keys and preexisting pair;
+    // should refactor to generate keys and the keypair and make a real test,
+    // but for now keeping it commented out as a template for people to do manual testing
+//    @Test(groups = "Live")
+//    public void testProvisionVmAndAuthPublicKey() {
+//        String regionName = USEAST_REGION_NAME;
+//        loc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(provider + (regionName == null ? "" : ":" + regionName));
+//        SshMachineLocation machine = obtainMachine(MutableMap.of(
+//            JcloudsLocationConfig.KEY_PAIR, "alex-aws-2",
+//            JcloudsLocationConfig.LOGIN_USER_PRIVATE_KEY_FILE, "~/.ssh/alex-aws-2-id_rsa",
+//            
+//            JcloudsLocationConfig.PRIVATE_KEY_FILE, "~/.ssh/aws-cloudera_rsa",
+//            JcloudsLocationConfig.PUBLIC_KEY_FILE, "~/.ssh/aws-cloudera_rsa.pub",
+//            JcloudsLocationConfig.EXTRA_PUBLIC_KEY_DATA_TO_AUTH,
+//                aws-whirr
+//                "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAw9R7FG0pOpZ7MR+KYty+UzHerEtW9NVBJj+NmznT4zg57klqDAxitahe6cJpj8Nbt0Rmp9G4TZQzAWuoSH5ZUJpFpcVP75tMYWOP6ZymH7MZ5hXLjLHTicNyQ/EB9H2eXSK2xLnq/8oDnzKgnhIXL7tbcC7hOY9Yzu25UrO+xQDbzM3nuwlr38JJwo1fLsIiEVI3uutZW9ANZgcZg0USlFFvxGcAA2KZ322tqtQtP3YYE0IogYUjTSFj5xexFDzIcN5V2Z2tHYKW+Jl/jR98EAsq4By1L+whoX142NJGZsB1GKm4zZTh3vjfzpeGNmxrrHDGp2TOCGFJjk2seHqyyw== alex@almac.rocklynn.cognetics.org",
+//            JcloudsLocationConfig.IMAGE_ID, "us-east-1/ami-5492ba3c"
+//        ));
+//        
+//        log.info("Provisioned {} vm {}; checking if ssh'able", provider, machine);
+//        assertTrue(machine.isSshable());
+//    }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1950baae/utils/common/src/main/java/org/apache/brooklyn/util/internal/BrooklynSystemProperties.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/internal/BrooklynSystemProperties.java b/utils/common/src/main/java/org/apache/brooklyn/util/internal/BrooklynSystemProperties.java
index 58c27d9..a8b9809 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/internal/BrooklynSystemProperties.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/internal/BrooklynSystemProperties.java
@@ -23,11 +23,12 @@ package org.apache.brooklyn.util.internal;
  */
 public class BrooklynSystemProperties {
 
-    // TODO should these become ConfigKeys ?
-    
+    // FIXME not used
     public static BooleanSystemProperty DEBUG = new BooleanSystemProperty("brooklyn.debug");
+    // FIXME not used
     public static BooleanSystemProperty EXPERIMENTAL = new BooleanSystemProperty("brooklyn.experimental");
     
+    // FIXME not used
     /** controls how long jsch delays between commands it issues */
     // -Dbrooklyn.jsch.exec.delay=100
     public static IntegerSystemProperty JSCH_EXEC_DELAY = new IntegerSystemProperty("brooklyn.jsch.exec.delay");
@@ -39,4 +40,15 @@ public class BrooklynSystemProperties {
 
     /** Allows the use of YAML tags to create arbitrary types known to Java. */
     public static BooleanSystemProperty YAML_TYPE_INSTANTIATION = new BooleanSystemProperty("org.apache.brooklyn.unsafe.YamlTypeInstantiation");
+    
+    /** Since 1.0.0 we no longer ask jclouds to authorizePublicKey for data in extraSshPublicKeyData; we do this ourselves, and the jclouds behaviour
+     * interferes with the use of key pairs.
+     * <p> 
+     * Set -Dbrooklyn.jclouds.authorizePublicKey.extraSshPublicKeyData=true to enable the jclouds call and revert to previous behaviour.
+     * 
+     * @deprecated since introduction in 1.0.0, to be removed in 1.1 or later unless there is a need for this
+     */
+    @Deprecated
+    public static BooleanSystemProperty JCLOUDS_AUTHORIZE_EXTRA_SSH_PUBLIC_KEY_DATA = new BooleanSystemProperty("brooklyn.jclouds.authorizePublicKey.extraSshPublicKeyData");
+    
 }


[3/3] brooklyn-server git commit: This closes #963

Posted by he...@apache.org.
This closes #963


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/59a0b911
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/59a0b911
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/59a0b911

Branch: refs/heads/master
Commit: 59a0b911207d3abbf99118951f8e0bff8e763c7e
Parents: dedaffd 9737c1b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu May 24 15:09:04 2018 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu May 24 15:09:04 2018 +0100

----------------------------------------------------------------------
 .../ExtraPublicKeyDataToAuthOption.java         |  9 ++++-
 .../provider/AbstractJcloudsLocationTest.java   |  2 +-
 .../provider/AwsEc2LocationLiveTest.java        | 39 ++++++++++++++++++++
 .../util/internal/BrooklynSystemProperties.java | 16 +++++++-
 4 files changed, 62 insertions(+), 4 deletions(-)
----------------------------------------------------------------------



[2/3] brooklyn-server git commit: added nice proper test from @andreaturli - thanks!

Posted by he...@apache.org.
added nice proper test from @andreaturli - thanks!


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/9737c1b7
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9737c1b7
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9737c1b7

Branch: refs/heads/master
Commit: 9737c1b7cecc54327cb2a0779faff3a07f590b1d
Parents: 1950baa
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu May 24 15:04:06 2018 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu May 24 15:04:06 2018 +0100

----------------------------------------------------------------------
 .../provider/AwsEc2LocationLiveTest.java        | 56 ++++++++++++--------
 1 file changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9737c1b7/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
index b8aff87..fef207c 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
@@ -18,8 +18,18 @@
  */
 package org.apache.brooklyn.location.jclouds.provider;
 
+import java.util.Map;
+
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsLocationConfig;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.jclouds.ec2.EC2Api;
+import org.jclouds.ec2.domain.KeyPair;
+import org.jclouds.ssh.SshKeys;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testng.Assert;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -73,28 +83,28 @@ public class AwsEc2LocationLiveTest extends AbstractJcloudsLocationTest {
     @Test(enabled = false)
     public void noop() { } /* just exists to let testNG IDE run the test */
     
-    // outline of test which can be used to assert combos of keys etc
-    // currently uses my (alex's) hardcoded keys and preexisting pair;
-    // should refactor to generate keys and the keypair and make a real test,
-    // but for now keeping it commented out as a template for people to do manual testing
-//    @Test(groups = "Live")
-//    public void testProvisionVmAndAuthPublicKey() {
-//        String regionName = USEAST_REGION_NAME;
-//        loc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(provider + (regionName == null ? "" : ":" + regionName));
-//        SshMachineLocation machine = obtainMachine(MutableMap.of(
-//            JcloudsLocationConfig.KEY_PAIR, "alex-aws-2",
-//            JcloudsLocationConfig.LOGIN_USER_PRIVATE_KEY_FILE, "~/.ssh/alex-aws-2-id_rsa",
-//            
-//            JcloudsLocationConfig.PRIVATE_KEY_FILE, "~/.ssh/aws-cloudera_rsa",
-//            JcloudsLocationConfig.PUBLIC_KEY_FILE, "~/.ssh/aws-cloudera_rsa.pub",
-//            JcloudsLocationConfig.EXTRA_PUBLIC_KEY_DATA_TO_AUTH,
-//                aws-whirr
-//                "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAw9R7FG0pOpZ7MR+KYty+UzHerEtW9NVBJj+NmznT4zg57klqDAxitahe6cJpj8Nbt0Rmp9G4TZQzAWuoSH5ZUJpFpcVP75tMYWOP6ZymH7MZ5hXLjLHTicNyQ/EB9H2eXSK2xLnq/8oDnzKgnhIXL7tbcC7hOY9Yzu25UrO+xQDbzM3nuwlr38JJwo1fLsIiEVI3uutZW9ANZgcZg0USlFFvxGcAA2KZ322tqtQtP3YYE0IogYUjTSFj5xexFDzIcN5V2Z2tHYKW+Jl/jR98EAsq4By1L+whoX142NJGZsB1GKm4zZTh3vjfzpeGNmxrrHDGp2TOCGFJjk2seHqyyw== alex@almac.rocklynn.cognetics.org",
-//            JcloudsLocationConfig.IMAGE_ID, "us-east-1/ami-5492ba3c"
-//        ));
-//        
-//        log.info("Provisioned {} vm {}; checking if ssh'able", provider, machine);
-//        assertTrue(machine.isSshable());
-//    }
+    @Test(groups = "Live")
+    public void testProvisionVmAndAuthPublicKey() {
+        String regionName = USEAST_REGION_NAME;
+        loc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(provider + (regionName == null ? "" : ":" + regionName));
+
+        EC2Api api = loc.getComputeService().getContext().unwrapApi(EC2Api.class);
+        String primaryKeyName = "brooklyn-keypair-" + System.currentTimeMillis();
+        try {
+            Map<String, String> extra = SshKeys.generate();
+            KeyPair primary = api.getKeyPairApiForRegion(regionName).get().createKeyPairInRegion(regionName, primaryKeyName);
+            SshMachineLocation machine = obtainMachine(MutableMap.of(
+                    JcloudsLocationConfig.KEY_PAIR, primary.getKeyName(),
+                    JcloudsLocationConfig.LOGIN_USER_PRIVATE_KEY_DATA, primary.getKeyMaterial(),
+                    JcloudsLocationConfig.EXTRA_PUBLIC_KEY_DATA_TO_AUTH, extra.get("public"),
+                    JcloudsLocationConfig.IMAGE_ID, "us-east-1/ami-5492ba3c"
+            ));
 
+            log.info("Provisioned {} vm {}; checking if ssh'able; extra private key below\n{}", provider, machine, extra.get("private"));
+            Assert.assertTrue(machine.isSshable());
+        } finally {
+            api.getKeyPairApiForRegion(USEAST_REGION_NAME).get().deleteKeyPairInRegion(USEAST_REGION_NAME, primaryKeyName);
+        }
+    }
+    
 }