Skip to content

Commit

Permalink
TritonDataCenter#22 Want support for reverse proxy zones
Browse files Browse the repository at this point in the history
  • Loading branch information
arekinath committed May 22, 2020
1 parent 60f5fce commit 1a1583c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
20 changes: 18 additions & 2 deletions bin/cnsadm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2016, 2020, The University of Queensland
*/

var dashdash = require('dashdash');
Expand Down Expand Up @@ -291,7 +292,17 @@ function do_zones() {
return ((v || []).join(','));
}},
{field: 'hidden_primary', title: 'hidden primary',
type: 'boolean'}
type: 'boolean'},
{field: 'proxy_addr', title: 'proxy address',
type: 'string'},
{field: 'proxy_networks', stringify: function (v) {
v = v || [];
if (v.length === 1 && v[0] === '*')
return ('*');
if (v.length === 0)
return ('');
return (sprintf('(%d UUIDs)', v.length));
}}
];
var objs = Object.keys(config.forward_zones).map(function (z) {
var obj = config.forward_zones[z];
Expand Down Expand Up @@ -338,7 +349,12 @@ function do_zones() {
type: 'array',
items: {type: 'string'}
},
'hidden_primary': {type: 'boolean'}
'hidden_primary': {type: 'boolean'},
'proxy_addr': {type: 'string'},
'proxy_networks': {
type: 'array',
items: {type: 'string'}
}
}
};
if (args.length === 0 && !opts['delete']) {
Expand Down
11 changes: 11 additions & 0 deletions lib/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@
},
"hidden_primary": {
"type": "boolean"
},
"proxy_addr": {
"type": "string"
},
"proxy_networks": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"pattern": "^[*]$|^[a-f0-9-]+$"
}
}
},
"additionalProperties": false
Expand Down
31 changes: 27 additions & 4 deletions lib/vm-to-zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2016, 2020, The University of Queensland
*/

module.exports = buildZonesFromVm;
Expand Down Expand Up @@ -33,7 +34,8 @@ function buildZonesFromVm(vm, config, log) {
type: 'instance',
ip: ip,
zone: zone,
network: nic.network
network: nic.network,
network_pools: nic.network_pools
});
}
vm.services.forEach(function (svc) {
Expand All @@ -42,7 +44,8 @@ function buildZonesFromVm(vm, config, log) {
ip: ip,
zone: zone,
service: svc,
network: nic.network
network: nic.network,
network_pools: nic.network_pools
});
});
});
Expand Down Expand Up @@ -151,16 +154,33 @@ function isNetOwned(vm, netw) {
return ((netw.owner_uuids || []).indexOf(vm.owner.uuid) !== -1);
}

function isProxied(ent, config) {
var zoneConfig = config.forward_zones[ent.zone];
if (!zoneConfig.proxy_networks)
return (false);
if (zoneConfig.proxy_networks.indexOf(ent.network.uuid) !== -1)
return (true);
var pools = ent.network_pools;
for (var i = 0; i < pools.length; ++i) {
if (zoneConfig.proxy_networks.indexOf(pools[i]) !== -1)
return (true);
}
return (false);
}

function addInstance(zones, vm, ent, config) {
function addName(name) {
if (!zones[ent.zone])
zones[ent.zone] = {};
if (!zones[ent.zone][name])
zones[ent.zone][name] = [];
var recs = zones[ent.zone][name];
var ip = ent.ip;
if (isProxied(ent, config))
ip = config.forward_zones[ent.zone].proxy_addr;
recs.push({
constructor: ent.addrType,
args: [ent.ip]
args: [ip]
});
var hasTxt = false;
for (var i = 0; i < recs.length; ++i) {
Expand Down Expand Up @@ -274,6 +294,9 @@ function addService(zones, vm, ent, config) {
if (!zones[ent.zone][name])
zones[ent.zone][name] = [];
var recs = zones[ent.zone][name];
var ip = ent.ip;
if (isProxied(ent, config))
ip = config.forward_zones[ent.zone].proxy_addr;
var hasTxt = false;
for (var i = 0; i < recs.length; ++i) {
if (recs[i].constructor === 'TXT' &&
Expand All @@ -285,7 +308,7 @@ function addService(zones, vm, ent, config) {
if (vm.listServices) {
recs.push({
constructor: ent.addrType,
args: [ent.ip],
args: [ip],
src: vm.uuid
});
if (!hasTxt) {
Expand Down

0 comments on commit 1a1583c

Please sign in to comment.