aboutsummaryrefslogtreecommitdiff
path: root/ec2/spark_ec2.py
diff options
context:
space:
mode:
authorliuchang0812 <liuchang0812@gmail.com>2015-02-08 10:08:51 +0000
committerSean Owen <sowen@cloudera.com>2015-02-08 10:08:51 +0000
commit6fb141e2a9e728499f8782310560bfaef7a5ed6c (patch)
tree2cc1c57ba4e3bba72c42e111ddd63c9d242add68 /ec2/spark_ec2.py
parent5de14cc2763a8211f77eeb55940dec025822eb78 (diff)
downloadspark-6fb141e2a9e728499f8782310560bfaef7a5ed6c.tar.gz
spark-6fb141e2a9e728499f8782310560bfaef7a5ed6c.tar.bz2
spark-6fb141e2a9e728499f8782310560bfaef7a5ed6c.zip
[SPARK-5366][EC2] Check the mode of private key
Check the mode of private key file. Author: liuchang0812 <liuchang0812@gmail.com> Closes #4162 from Liuchang0812/ec2-script and squashes the following commits: fc37355 [liuchang0812] quota file name 01ed464 [liuchang0812] more output ce2a207 [liuchang0812] pep8 f44efd2 [liuchang0812] move code to real_main 8475a54 [liuchang0812] fix bug cd61a1a [liuchang0812] import stat c106cb2 [liuchang0812] fix trivis bug 89c9953 [liuchang0812] more output about checking private key 1177a90 [liuchang0812] remove commet 41188ab [liuchang0812] check the mode of private key
Diffstat (limited to 'ec2/spark_ec2.py')
-rwxr-xr-xec2/spark_ec2.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/ec2/spark_ec2.py b/ec2/spark_ec2.py
index 3f7242a53d..725b1e47e0 100755
--- a/ec2/spark_ec2.py
+++ b/ec2/spark_ec2.py
@@ -24,10 +24,12 @@ from __future__ import with_statement
import hashlib
import logging
import os
+import os.path
import pipes
import random
import shutil
import string
+from stat import S_IRUSR
import subprocess
import sys
import tarfile
@@ -349,6 +351,7 @@ def launch_cluster(conn, opts, cluster_name):
if opts.identity_file is None:
print >> stderr, "ERROR: Must provide an identity file (-i) for ssh connections."
sys.exit(1)
+
if opts.key_pair is None:
print >> stderr, "ERROR: Must provide a key pair name (-k) to use on instances."
sys.exit(1)
@@ -1007,6 +1010,18 @@ def real_main():
DeprecationWarning
)
+ if opts.identity_file is not None:
+ if not os.path.exists(opts.identity_file):
+ print >> stderr,\
+ "ERROR: The identity file '{f}' doesn't exist.".format(f=opts.identity_file)
+ sys.exit(1)
+
+ file_mode = os.stat(opts.identity_file).st_mode
+ if not (file_mode & S_IRUSR) or not oct(file_mode)[-2:] == '00':
+ print >> stderr, "ERROR: The identity file must be accessible only by you."
+ print >> stderr, 'You can fix this with: chmod 400 "{f}"'.format(f=opts.identity_file)
+ sys.exit(1)
+
if opts.ebs_vol_num > 8:
print >> stderr, "ebs-vol-num cannot be greater than 8"
sys.exit(1)