Skip to content

Commit e882217

Browse files
committed
Merge pull request #347 from noobaa/eran_alpha_updates
quick and very dirty fix for s3 and web server separation
2 parents f735928 + d270155 commit e882217

File tree

15 files changed

+118
-28
lines changed

15 files changed

+118
-28
lines changed

src/api/system_api.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,13 @@ module.exports = {
320320
item: {
321321
$ref: '/system_api/definitions/access_keys'
322322
}
323-
}
323+
},
324+
ssl_port: {
325+
type: 'string'
326+
},
327+
web_port: {
328+
type: 'string'
329+
},
324330
}
325331
},
326332

@@ -378,7 +384,5 @@ module.exports = {
378384
}
379385
}
380386
}
381-
382-
383387
}
384388
};

src/client/nb_console.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ nb_console.controller('OverviewCtrl', [
205205
function rest_server_information() {
206206
var scope = $scope.$new();
207207
scope.access_keys = nbSystem.system.access_keys;
208-
scope.rest_endpoint = $window.location.host + '/s3';
208+
209+
var rest_host = ($window.location.host).replace(':'+nbSystem.system.web_port,'').replace(':'+nbSystem.system.ssl_port,':443');
210+
console.log('SYS3:'+nbSystem.system.web_port+' host:'+rest_host);
211+
scope.rest_endpoint = rest_host ;
209212
scope.bucket_name = $scope.nbSystem.system.buckets[0].name;
210213
scope.rest_package = download_rest_server_package;
211214
console.log('rest_server_information', scope.rest_package, scope.rest_endpoint);
@@ -504,7 +507,7 @@ nb_console.controller('BucketViewCtrl', [
504507
return init_only ? nbSystem.init_system : nbSystem.reload_system();
505508
})
506509
.then(function() {
507-
nbFiles.set_access_keys(nbSystem.system.access_keys);
510+
nbFiles.set_access_keys(nbSystem.system.access_keys,nbSystem.system.web_port,nbSystem.system.ssl_port);
508511
$scope.bucket = _.find(nbSystem.system.buckets, function(bucket) {
509512
return bucket.name === $routeParams.bucket_name;
510513
});
@@ -553,7 +556,10 @@ nb_console.controller('BucketViewCtrl', [
553556
function rest_server_information() {
554557
var scope = $scope.$new();
555558
scope.access_keys = nbSystem.system.access_keys;
556-
scope.rest_endpoint = $window.location.host + '/s3';
559+
var rest_host = ($window.location.host).replace(':'+nbSystem.system.web_port,'').replace(':'+nbSystem.system.ssl_port,':443');
560+
console.log('SYS2:'+nbSystem.system.web_port+' host:'+rest_host);
561+
562+
scope.rest_endpoint = rest_host;
557563
scope.bucket_name = $routeParams.bucket_name;
558564
scope.rest_package = download_rest_server_package;
559565
console.log('rest_server_information', scope.rest_package, scope.rest_endpoint);
@@ -634,7 +640,7 @@ nb_console.controller('FileViewCtrl', [
634640
//Setting access keys.
635641
//TODO: consider separation to other object with only the keys
636642
// also, check better solution in terms of security.
637-
nbFiles.set_access_keys(nbSystem.system.access_keys);
643+
nbFiles.set_access_keys(nbSystem.system.access_keys,nbSystem.system.web_port,nbSystem.system.ssl_port);
638644

639645
$scope.bucket = _.find(nbSystem.system.buckets, function(bucket) {
640646
return bucket.name === $routeParams.bucket_name;

src/client/nb_files.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var streams = require('stream');
1313

1414

1515
nb_api.factory('nbFiles', [
16-
'$http', '$q', '$window', '$timeout', '$sce', 'nbAlertify', '$rootScope', 'nbClient','$location',
17-
function($http, $q, $window, $timeout, $sce, nbAlertify, $rootScope, nbClient,$location) {
16+
'$http', '$q', '$window', '$timeout', '$sce', 'nbAlertify', '$rootScope', 'nbClient','$location','nbSystem',
17+
function($http, $q, $window, $timeout, $sce, nbAlertify, $rootScope, nbClient,$location,nbSystem) {
1818
var $scope = {};
1919

2020
$scope.list_files = list_files;
@@ -33,7 +33,8 @@ nb_api.factory('nbFiles', [
3333
$scope.downloads = [];
3434
$scope.transfers = [];
3535
$scope.s3 = null;
36-
36+
$scope.web_port = 0;
37+
$scope.ssl_port = 0;
3738
// call first time with empty keys to initialize s3
3839
set_access_keys();
3940

@@ -61,7 +62,9 @@ nb_api.factory('nbFiles', [
6162

6263
//update access keys.
6364
//TODO: find more secured approach
64-
function set_access_keys(access_keys) {
65+
function set_access_keys(access_keys,web_port,ssl_port) {
66+
$scope.web_port = web_port;
67+
$scope.ssl_port = ssl_port;
6568
if (!_.isEmpty(access_keys)) {
6669
AWS.config.update({
6770
accessKeyId: access_keys[0].access_key,
@@ -87,7 +90,13 @@ nb_api.factory('nbFiles', [
8790
// (rest_port ? ':' + rest_port : '')+'/s3';
8891
// var https_endpoint = 'https://127.0.0.1' +
8992
// (rest_ssl_port ? ':' + rest_ssl_port : '')+'/s3';
90-
var rest_endpoint = $window.location.protocol+'//' +$window.location.host+'/s3';
93+
//var rest_host = ($window.location.host).replace(':'+web_port,'').replace(':'+ssl_port,':443');
94+
var rest_host = ($window.location.host).replace(':'+web_port,'').replace(':'+ssl_port,'');
95+
96+
console.log('SYS1:'+web_port+' host:'+rest_host);
97+
98+
var rest_endpoint = $window.location.protocol+'//' +rest_host;
99+
rest_endpoint = rest_endpoint.replace('https','http');
91100
console.log('win:',$window.location,":",rest_endpoint);
92101
$scope.s3 = new AWS.S3({
93102
// endpoint: $window.location.protocol === 'https:' ?
@@ -119,7 +128,7 @@ nb_api.factory('nbFiles', [
119128
return nbClient.client.object_driver_lazy().get_object_md(params, cache_miss);
120129
})
121130
.then(function(res) {
122-
console.log('FILE', res);
131+
console.log('FILE', res,params.key);
123132
var file_info = make_file_info({
124133
key: params.key,
125134
info: res
@@ -129,6 +138,8 @@ nb_api.factory('nbFiles', [
129138
Bucket: params.bucket,
130139
Key: params.key
131140
});
141+
url = url.replace(':'+$scope.web_port,'').replace(':'+$scope.ssl_port,':443');
142+
132143
console.log('urlll:',url);
133144
file_info.url = url;
134145
return file_info;

src/client/nb_nodes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,21 @@ nb_api.factory('nbNodes', [
188188
bucket: 'files',
189189
root_path: './agent_storage/'
190190
};
191-
config_json.address = 'wss://noobaa.local';
191+
192+
config_json.address = 'wss://noobaa.local:'+nbSystem.system.ssl_port;
192193
config_json.system = nbSystem.system.name;
193194
config_json.access_key = nbSystem.system.access_keys[0].access_key;
194195
config_json.secret_key = nbSystem.system.access_keys[0].secret_key;
195196
var encodedData = $window.btoa(JSON.stringify(config_json));
196197
scope.encodedData = encodedData;
197-
config_json.address = 'wss://'+$window.location.host;
198+
var secured_host = ($window.location.host).replace(':'+nbSystem.system.web_port,':'+nbSystem.system.ssl_port);
199+
config_json.address = 'wss://'+secured_host;
198200
encodedData = $window.btoa(JSON.stringify(config_json));
199201
scope.encodedDataIP = encodedData;
200202
scope.current_host = $window.location.host;
201203
scope.typeOptions = [
202204
{ name: 'Use noobaa.local', value: scope.encodedData },
203-
{ name: 'Use '+$window.location.host, value: scope.encodedDataIP },
205+
{ name: 'Use '+secured_host, value: scope.encodedDataIP },
204206
];
205207
console.log('type options',scope.typeOptions);
206208
scope.encoding = {type : scope.typeOptions[0].value};

src/deploy/NVA_build/deploy_base.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ function setup_mongo {
139139
function general_settings {
140140
iptables -I INPUT 1 -i eth0 -p tcp --dport 443 -j ACCEPT
141141
iptables -I INPUT 1 -i eth0 -p tcp --dport 80 -j ACCEPT
142+
iptables -I INPUT 1 -i eth0 -p tcp --dport 8080 -j ACCEPT
143+
iptables -I INPUT 1 -i eth0 -p tcp --dport 8443 -j ACCEPT
144+
142145
/sbin/iptables -A INPUT -m limit --limit 15/minute -j LOG --log-level 2 --log-prefix "Dropped by firewall: "
143146
/sbin/iptables -A OUTPUT -m limit --limit 15/minute -j LOG --log-level 2 --log-prefix "Dropped by firewall: "
144147
service iptables save

src/deploy/NVA_build/env.orig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
DEV_MODE=false
22
DEBUG_MODE=false
33

4-
PORT=80
5-
SSL_PORT=443
4+
PORT=8080
5+
SSL_PORT=8443
66
ON_PREMISE=true
77

88
# address means the address of the server as reachable from the internet

src/deploy/NVA_build/noobaa_supervisor.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ autorestart=true
1616
[program:webserver]
1717
directory=/root/node_modules/noobaa-core
1818
command=/usr/local/bin/node src/server/web_server.js
19+
20+
[program:s3rver]
21+
directory=/root/node_modules/noobaa-core
22+
command=/usr/local/bin/node src/s3/s3rver_starter.js

src/deploy/NVA_build/upgrade.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function restart_webserver {
3131
${SUPERCTL} restart webserver
3232
}
3333

34+
function restart_s3rver {
35+
${SUPERCTL} restart s3rver
36+
}
37+
3438

3539
function check_latest_version {
3640
local current=$(grep CURRENT_VERSION $ENV_FILE | sed 's:.*=\(.*\):\1:')
@@ -98,6 +102,7 @@ function do_upgrade {
98102
#workaround - from some reason, without sleep + restart, the server starts with odd behavior
99103
#TODO: understand why and fix.
100104
sleep 5;
105+
restart_s3rver
101106
restart_webserver
102107
deploy_log "Upgrade finished successfully!"
103108
}

src/deploy/NVA_build/upgrade_wrapper.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function pre_upgrade {
1111
#TODO: CHECK if rules already exist, is so skip this part
1212
iptables -I INPUT 1 -i eth0 -p tcp --dport 80 -j ACCEPT
1313
iptables -I INPUT 1 -i eth0 -p tcp --dport 443 -j ACCEPT
14+
iptables -I INPUT 1 -i eth0 -p tcp --dport 8080 -j ACCEPT
15+
iptables -I INPUT 1 -i eth0 -p tcp --dport 8443 -j ACCEPT
1416
#/sbin/iptables -A INPUT -m limit --limit 15/minute -j LOG --log-level 2 --log-prefix "Dropped by firewall: "
1517
#/sbin/iptables -A OUTPUT -m limit --limit 15/minute -j LOG --log-level 2 --log-prefix "Dropped by firewall: "
1618
service iptables save
@@ -47,6 +49,15 @@ function pre_upgrade {
4749

4850
sysctl -w fs.file-max=102400
4951
sysctl -p
52+
agent_conf=${CORE_DIR}/agent_conf.json
53+
if [ -f "$agent_conf" ]
54+
then
55+
deploy_log "$agent_conf found. Save to /tmp and restore"
56+
rm -f /tmp/agent_conf.json
57+
cp ${agent_conf} /tmp/agent_conf.json
58+
else
59+
deploy_log "$agent_conf not found."
60+
fi
5061
}
5162

5263
function post_upgrade {
@@ -56,6 +67,11 @@ function post_upgrade {
5667
local curmd=$(md5sum /tmp/noobaa-NVA.tar.gz | cut -f 1 -d' ')
5768
local prevmd=$(grep "#packmd" /backup/.env | cut -f 2 -d' ')
5869

70+
cp -f ${CORE_DIR}/src/deploy/NVA_build/noobaa_supervisor.conf /etc/noobaa_supervisor.conf
71+
cat /etc/noobaa_supervisor.conf
72+
cp /tmp/agent_conf.json ${CORE_DIR}/agent_conf.json
73+
74+
5975
cp -f ${CORE_DIR}/src/deploy/NVA_build/env.orig ${CORE_DIR}/.env
6076

6177
local AGENT_VERSION_VAR=$(grep AGENT_VERSION /backup/.env)

src/rpc/rpc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var browser_ws = global.window && global.window.WebSocket;
3030
// in the browser we take the address as the host of the web page
3131
// just like any ajax request. for development we take localhost.
3232
// for any other case the RPC objects can set the base_address property.
33-
var DEFAULT_BASE_ADDRESS = 'ws://127.0.0.1:5001';
33+
var DEFAULT_BASE_ADDRESS = 'ws://127.0.0.1:'+process.env.web_port;
3434
if (browser_location) {
3535
if (browser_ws) {
3636
// use ws/s address

0 commit comments

Comments
 (0)