You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by as...@apache.org on 2012/02/14 11:22:40 UTC

svn commit: r1243859 - in /whirr/trunk: ./ CHANGES.txt core/src/main/java/org/apache/whirr/ClusterSpec.java core/src/test/java/org/apache/whirr/ClusterSpecTest.java

Author: asavu
Date: Tue Feb 14 10:22:40 2012
New Revision: 1243859

URL: http://svn.apache.org/viewvc?rev=1243859&view=rev
Log:
WHIRR-463. Fail fast when running as root (asavu)

Modified:
    whirr/trunk/   (props changed)
    whirr/trunk/CHANGES.txt
    whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java
    whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java

Propchange: whirr/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Feb 14 10:22:40 2012
@@ -5,3 +5,4 @@
 .settings
 target
 whirr.log*
+classes

Modified: whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/whirr/trunk/CHANGES.txt?rev=1243859&r1=1243858&r2=1243859&view=diff
==============================================================================
--- whirr/trunk/CHANGES.txt (original)
+++ whirr/trunk/CHANGES.txt Tue Feb 14 10:22:40 2012
@@ -56,6 +56,8 @@ Trunk (unreleased changes)
     WHIRR-347. Support provider-independent environment variables for 
     cloud credentials (asavu)
 
+    WHIRR-463. Fail fast when running as root (asavu)
+
   BUG FIXES
 
     WHIRR-367. Wrong groupId for zookeeper (Joe Crobak via asavu)

Modified: whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java
URL: http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java?rev=1243859&r1=1243858&r2=1243859&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java (original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java Tue Feb 14 10:22:40 2012
@@ -33,7 +33,6 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.configuration.CompositeConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
@@ -44,6 +43,7 @@ import org.jclouds.predicates.validators
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
@@ -205,7 +205,7 @@ public class ClusterSpec {
     return withTemporaryKeys(new PropertiesConfiguration());
   }
   @VisibleForTesting
-  public static ClusterSpec withTemporaryKeys(Configuration conf) 
+  public static ClusterSpec withTemporaryKeys(Configuration conf)
   throws ConfigurationException, JSchException, IOException {
     if (!conf.containsKey(Property.PRIVATE_KEY_FILE.getConfigName())) {
       Map<String, File> keys = org.apache.whirr.util.KeyPair.generateTemporaryFiles();
@@ -766,8 +766,7 @@ public class ClusterSpec {
     /*
      * http://stackoverflow.com/questions/2494645#2494645
      */
-    checkArgument(checkNotNull(publicKey, "publicKey")
-            .startsWith("ssh-rsa AAAAB3NzaC1yc2EA"),
+    checkArgument(checkNotNull(publicKey, "publicKey").startsWith("ssh-rsa AAAAB3NzaC1yc2EA"),
         "key should start with ssh-rsa AAAAB3NzaC1yc2EA");
   }
   
@@ -834,6 +833,7 @@ public class ClusterSpec {
   }
 
   public void setClusterUser(String user) {
+    checkArgument(user == null || !user.equals("root"), "cluster-user != root or do not run as root");
     this.clusterUser = user;
   }
 

Modified: whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java?rev=1243859&r1=1243858&r2=1243859&view=diff
==============================================================================
--- whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java (original)
+++ whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java Tue Feb 14 10:22:40 2012
@@ -376,4 +376,12 @@ public class ClusterSpecTest {
 
     ClusterSpec.withTemporaryKeys(conf);
   }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testFailIfRunningAsRootOrClusterUserIsRoot() throws ConfigurationException {
+    PropertiesConfiguration conf = new PropertiesConfiguration("whirr-core-test.properties");
+    conf.setProperty("whirr.cluster-user", "root");
+
+    ClusterSpec.withNoDefaults(conf);
+  }
 }