Skip to content

Commit 21d6ad4

Browse files
David GoetzTarmac
authored andcommitted
Refactor SWIFT_HASH_PATH_SUFFIX to be in a config file. Adding new conf file /etc/swift/swift.conf
2 parents fa961fe + 3749d8c commit 21d6ad4

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

doc/source/development_saio.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ virtual machine will emulate running a four node Swift cluster.
199199
[filter:cache]
200200
use = egg:swift#memcache
201201

202+
#. Create `/etc/swift/swift.conf`::
203+
204+
[swift-hash]
205+
# random unique string that can never change (DO NOT LOSE)
206+
swift_hash_path_suffix = changeme
207+
202208
#. Create `/etc/swift/account-server/1.conf`::
203209

204210
[DEFAULT]

etc/swift.conf-sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[swift-hash]
2+
swift_hash_path_suffix = changeme
3+

swift/common/daemon.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def run(self, once=False, capture_stdout=True, capture_stderr=True):
4545
sys.stderr = utils.LoggerFileObject(self.logger)
4646

4747
utils.drop_privileges(self.conf.get('user', 'swift'))
48+
utils.validate_configuration()
4849

4950
try:
5051
os.setsid()

swift/common/utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import ctypes.util
3232
import fcntl
3333
import struct
34-
from ConfigParser import ConfigParser
34+
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
3535
from tempfile import mkstemp
3636
import cPickle as pickle
3737

@@ -56,12 +56,25 @@
5656
# Used by hash_path to offer a bit more security when generating hashes for
5757
# paths. It simply appends this value to all paths; guessing the hash a path
5858
# will end up with would also require knowing this suffix.
59-
HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap')
59+
hash_conf = ConfigParser()
60+
HASH_PATH_SUFFIX = ''
61+
if hash_conf.read('/etc/swift/swift.conf'):
62+
try:
63+
HASH_PATH_SUFFIX = hash_conf.get('swift-hash',
64+
'swift_hash_path_suffix')
65+
except (NoSectionError, NoOptionError):
66+
pass
6067

6168
# Used when reading config values
6269
TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes', 'on', 'On'))
6370

6471

72+
def validate_configuration():
73+
if HASH_PATH_SUFFIX == '':
74+
sys.exit("Error: [swift-hash]: swift_hash_path_suffix missing "
75+
"from /etc/swift/swift.conf")
76+
77+
6578
def load_libc_function(func_name):
6679
"""
6780
Attempt to find the function in libc, otherwise return a no-op func.

swift/common/wsgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from eventlet.green import socket, ssl
3535

3636
from swift.common.utils import get_logger, drop_privileges, \
37-
LoggerFileObject, NullLogger
37+
validate_configuration, LoggerFileObject, NullLogger
3838

3939

4040
def monkey_patch_mimetools():
@@ -112,6 +112,7 @@ def run_wsgi(conf_file, app_section, *args, **kwargs): # pragma: no cover
112112
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600)
113113
worker_count = int(conf.get('workers', '1'))
114114
drop_privileges(conf.get('user', 'swift'))
115+
validate_configuration()
115116

116117
def run_server():
117118
wsgi.HttpProtocol.default_request_version = "HTTP/1.0"

0 commit comments

Comments
 (0)