Skip to content

Commit 34cb335

Browse files
committed
fix #2812 - removed setting EXTRACTION_PATH as /root/node_modules/
on web_server start check if JWT_SECRET and MONGO_SSL_USER are missing from .env and present in process.env. if so then rewrite it to .env fix #2812 - regenerate missing JWT_SECRET and MONGO_SSL_USER added logs in upgrade_wrapper extract JWT_SECRET from old environment variabes look for JWT_SECRET in upgrade.sh vars fixed comment add logs add logs fix print to .env fix .env in web server instead of upgrade.sh removed log message moved set_process_name
1 parent b2d8e03 commit 34cb335

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

src/deploy/NVA_build/fix_mongo_ssl.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ if [ ! -d /etc/mongo_ssl/ ]; then
44
mkdir /etc/mongo_ssl/
55
. ${CORE_DIR}/src/deploy/NVA_build/setup_mongo_ssl.sh
66
chmod 400 -R /etc/mongo_ssl
7-
local client_subject=`openssl x509 -in /etc/mongo_ssl/client.pem -inform PEM -subject -nameopt RFC2253 | grep subject | awk '{sub("subject= ",""); print}'`
8-
echo "MONGO_SSL_USER=${client_subject}" >> ${CORE_DIR}/.env
7+
client_subject=`openssl x509 -in /etc/mongo_ssl/client.pem -inform PEM -subject -nameopt RFC2253 | grep subject | awk '{sub("subject= ",""); print}'`
98
# add bash script to run mongo shell with authentications
109
echo "mongo --ssl --sslPEMKeyFile /etc/mongo_ssl/client.pem --sslCAFile /etc/mongo_ssl/root-ca.pem --sslAllowInvalidHostnames -u \"${client_subject}\" --authenticationMechanism MONGODB-X509 --authenticationDatabase \"\\\$external\" \"\$@\"" > /usr/bin/mongors
1110
chmod +x /usr/bin/mongors
1211
fi
12+
13+
if grep -q MONGO_SSL_USER /root/node_modules/noobaa-core/.env; then
14+
client_subject=`openssl x509 -in /etc/mongo_ssl/client.pem -inform PEM -subject -nameopt RFC2253 | grep subject | awk '{sub("subject= ",""); print}'`
15+
echo "MONGO_SSL_USER=${client_subject}" >> /root/node_modules/noobaa-core/.env
16+
fi
17+

src/deploy/NVA_build/upgrade.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
# redirect the output log file to syslog (http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog)
44
exec 1> >(logger -t UPGRADE -p local0.warn) 2>&1
55

6+
EXTRACTION_PATH="/tmp/test/"
7+
8+
#TODO do we want to load base on /tmp/test? maybe load common_funcs differenetly
69
if [ -d /tmp/test/ ]; then
7-
EXTRACTION_PATH="/tmp/test/"
10+
COMMON_FUNCS_PATH="/tmp/test/"
811
else
9-
EXTRACTION_PATH="/root/node_modules"
12+
COMMON_FUNCS_PATH="/root/node_modules"
1013
fi
1114

12-
. ${EXTRACTION_PATH}/noobaa-core/src/deploy/NVA_build/deploy_base.sh
13-
. ${EXTRACTION_PATH}noobaa-core/src/deploy/NVA_build/common_funcs.sh
15+
16+
. ${COMMON_FUNCS_PATH}/noobaa-core/src/deploy/NVA_build/deploy_base.sh
17+
. ${COMMON_FUNCS_PATH}noobaa-core/src/deploy/NVA_build/common_funcs.sh
1418

1519
PACKAGE_FILE_NAME="new_version.tar.gz"
1620
WRAPPER_FILE_NAME="upgrade_wrapper.sh"
@@ -140,7 +144,6 @@ function check_latest_version {
140144
}
141145

142146
function extract_package {
143-
EXTRACTION_PATH="/root/node_modules"
144147
#Clean previous extracted package
145148
rm -rf ${EXTRACTION_PATH}*
146149
#Create path and extract package
@@ -174,6 +177,7 @@ function extract_package {
174177
# fi
175178
}
176179

180+
177181
function do_upgrade {
178182
#Update packages before we stop services, minimize downtime, limit run time for yum update so it won't get stuck
179183
timeout --signal=SIGINT 360 cat <( packages_upgrade )

src/server/web_server.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// load .env file before any other modules so that it will contain
55
// all the arguments even when the modules are loading.
66
console.log('loading .env file');
7-
require('../util/dotenv').load();
7+
const dotenv = require('../util/dotenv');
8+
dotenv.load();
89

910
//If test mode, use Istanbul for coverage
1011
for (let i = 0; i < process.argv.length; ++i) {
@@ -53,9 +54,39 @@ const rootdir = path.join(__dirname, '..', '..');
5354
const dev_mode = (process.env.DEV_MODE === 'true');
5455
const app = express();
5556

57+
dbg.set_process_name('WebServer');
58+
59+
// hacky fix for issue #2812 - check if JWT_SECRET and MONGO_SSL_USER are missing
60+
// in .env but exists in environment variables. if so write it to .env
61+
let env_obj = dotenv.parse();
62+
if (!env_obj.JWT_SECRET) {
63+
dbg.warn('JWT_SECRET is missing in .env file.');
64+
if (process.env.JWT_SECRET) {
65+
dbg.warn('JWT_SECRET found in process.env, writing to .env file. JWT_SECRET =', process.env.JWT_SECRET);
66+
dotenv.set({
67+
key: 'JWT_SECRET',
68+
value: process.env.JWT_SECRET
69+
});
70+
} else {
71+
dbg.error('JWT_SECRET is missing from .env and from process.env - users and agents will not be able to connect!!!!');
72+
}
73+
}
74+
if (!env_obj.MONGO_SSL_USER) {
75+
dbg.warn('MONGO_SSL_USER is missing in .env file.');
76+
if (process.env.MONGO_SSL_USER) {
77+
dbg.warn('MONGO_SSL_USER found in process.env, writing to .env file. MONGO_SSL_USER =', process.env.MONGO_SSL_USER);
78+
dotenv.set({
79+
key: 'MONGO_SSL_USER',
80+
value: process.env.MONGO_SSL_USER
81+
});
82+
} else {
83+
dbg.error('MONGO_SSL_USER is missing from .env and process.env - server will not be able to join or form a cluster');
84+
}
85+
}
86+
87+
5688
system_store.once('load', account_server.ensure_support_account);
5789

58-
dbg.set_process_name('WebServer');
5990
mongo_client.instance().connect();
6091

6192
//Set KeepAlive to all http/https agents in webserver

src/util/dotenv.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ module.exports = {
8282
* @param {String|Buffer} src - source to be parsed
8383
* @returns {Object}
8484
*/
85-
parse: function(src) {
85+
parse: function(src_param) {
86+
let src = src_param || fs.readFileSync('.env', {
87+
encoding: 'utf8'
88+
});
8689
var obj = {};
8790
var idx = 0;
8891

0 commit comments

Comments
 (0)