workaround a problem with permissions on ~ec2-user/.ssh/authorized_keys

This commit is contained in:
John Morrison 2014-06-08 17:34:31 -07:00
Родитель 1d80315db9
Коммит 3484af09b2
2 изменённых файлов: 68 добавлений и 38 удалений

Просмотреть файл

@ -514,6 +514,8 @@ verbs.create = function(args) {
console.log(" ... public url will be:", config.public_url); console.log(" ... public url will be:", config.public_url);
ssh.ensureSshAccessPerms(deets.ipAddress, function(err) {
checkErr(err);
ssh.copyUpConfig(deets.ipAddress, config, function(err) { ssh.copyUpConfig(deets.ipAddress, config, function(err) {
checkErr(err); checkErr(err);
console.log(" ... victory! server is accessible and configured"); console.log(" ... victory! server is accessible and configured");
@ -574,6 +576,7 @@ verbs.create = function(args) {
}); });
}); });
}); });
});
}; };
verbs.create.doc = "create an EC2 instance, -h for help"; verbs.create.doc = "create an EC2 instance, -h for help";

Просмотреть файл

@ -12,6 +12,33 @@ function passthrough(cp) {
cp.stderr.pipe(process.stderr); cp.stderr.pipe(process.stderr);
} }
exports.ensureSshAccessPerms = function(host, cb) {
// Something, possibly cloud-init is resetting these permissions when we
// create the AMI. So this is a sad way to set them back for app@ has
// access to the EC2 instance.
var tries = 0;
var destination = 'ec2-user@' + host;
var cmd = "chmod go+x /home/ec2-user/.ssh";
var args = ['-o', 'StrictHostKeyChecking=no', destination, cmd];
function oneTry() {
child_process.execFile(ssh, args, function(err) {
if (err) {
if (++tries > MAX_TRIES) return cb("can't connect via SSH. stupid amazon");
process.stdout.write(tries <= 1 ? " ..." : ".");
setTimeout(oneTry, 3000);
} else {
cmd = "chmod go+r /home/ec2-user/.ssh/authorized_keys";
args = ['-o', 'StrictHostKeyChecking=no', destination, cmd];
child_process.execFile(ssh, args, function(err) {
if (err) return cb(err);
cb();
});
}
});
}
oneTry();
};
exports.copyUpConfig = function(host, configContents, cb) { exports.copyUpConfig = function(host, configContents, cb) {
var tries = 0; var tries = 0;
temp.open({}, function(err, r) { temp.open({}, function(err, r) {