-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permissions of deployed files and keep node.id #270
Changes from all commits
9eda9d3
4bff7aa
a4e091d
c38b7dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
from fabric.contrib import files | ||
from fabric.context_managers import settings | ||
from fabric.contrib.files import exists | ||
from fabric.operations import sudo, abort | ||
from fabric.api import env | ||
|
||
|
@@ -95,7 +96,7 @@ def deploy(confs, remote_dir): | |
sudo("mkdir -p " + remote_dir) | ||
for name, content in confs.iteritems(): | ||
write_to_remote_file(content, os.path.join(remote_dir, name), | ||
'presto') | ||
owner=PRESTO_STANDALONE_USER_GROUP, mode=644) | ||
|
||
|
||
def secure_create_file(filepath, user_group, mode=600): | ||
|
@@ -113,7 +114,27 @@ def secure_create_file(filepath, user_group, mode=600): | |
result = sudo(command) | ||
if result.return_code == missing_owner_code: | ||
abort("User %s does not exist. Make sure the Presto server RPM " | ||
"is installed and try again" % (user,)) | ||
"is installed and try again" % user) | ||
elif result.failed: | ||
abort("Failed to securely create file %s" % (filepath)) | ||
|
||
|
||
def secure_create_directory(filepath, user_group, mode=755): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the directory had to have permissions 644. Why is the default 755? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should have 755 permissions so that it is traversable. I'll fix the commit message |
||
user, group = user_group.split(':') | ||
missing_owner_code = 42 | ||
command = \ | ||
"( getent passwd {user} >/dev/null || exit {missing_owner_code} ) && " \ | ||
"mkdir -p {filepath} && " \ | ||
"chown {user_group} {filepath} && " \ | ||
"chmod {mode} {filepath} ".format( | ||
filepath=filepath, user=user, user_group=user_group, mode=mode, | ||
missing_owner_code=missing_owner_code) | ||
|
||
with settings(warn_only=True): | ||
result = sudo(command) | ||
if result.return_code == missing_owner_code: | ||
abort("User %s does not exist. Make sure the Presto server RPM " | ||
"is installed and try again" % user) | ||
elif result.failed: | ||
abort("Failed to securely create file %s" % (filepath)) | ||
|
||
|
@@ -122,7 +143,11 @@ def deploy_node_properties(content, remote_dir): | |
_LOGGER.info("Deploying node.properties configuration") | ||
name = "node.properties" | ||
node_file_path = (os.path.join(remote_dir, name)) | ||
secure_create_file(node_file_path, PRESTO_STANDALONE_USER_GROUP) | ||
if not exists(node_file_path, use_sudo=True): | ||
secure_create_file(node_file_path, PRESTO_STANDALONE_USER_GROUP, mode=644) | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to do this because the rpm doesn't set up the config files with correct ownership (see Teradata/presto#358) |
||
sudo('chown %(owner)s %(filepath)s && chmod %(mode)s %(filepath)s' | ||
% {'owner': PRESTO_STANDALONE_USER_GROUP, 'mode': 644, 'filepath': node_file_path}) | ||
node_id_command = ( | ||
"if ! ( grep -q -s 'node.id' " + node_file_path + " ); then " | ||
"uuid=$(uuidgen); " | ||
|
@@ -135,7 +160,7 @@ def deploy_node_properties(content, remote_dir): | |
|
||
|
||
def write_to_remote_file(text, filepath, owner, mode=600): | ||
secure_create_file(filepath, PRESTO_STANDALONE_USER_GROUP) | ||
secure_create_file(filepath, owner, mode) | ||
command = "echo '{text}' > {filepath}".format( | ||
text=escape_single_quotes(text), filepath=filepath) | ||
sudo(command) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ fudge==1.1.0 | |
PyYAML==3.11 | ||
overrides==0.5 | ||
setuptools==20.1.1 | ||
pip==7.1.2 | ||
pip==8.1.2 | ||
retrying==1.3.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment explaining why the mode for connectors is different than for regular config now that they're different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done