Skip to content

Commit 4dd2e54

Browse files
Merge pull request #1865 from fatima99s/appService/VnetIntegrated
appService/VnetIntegrated
2 parents d55f872 + 4d9c382 commit 4dd2e54

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

exports.js

+1
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ module.exports = {
924924
'tlsVersionCheck' : require(__dirname + '/plugins/azure/appservice/tlsVersionCheck.js'),
925925
'remoteDebuggingDisabled' : require(__dirname + '/plugins/azure/appservice/remoteDebuggingDisabled.js'),
926926
'alwaysOnEnabled' : require(__dirname + '/plugins/azure/appservice/alwaysOnEnabled.js'),
927+
'vnetIntegrated' : require(__dirname + '/plugins/azure/appservice/vnetIntegrated.js'),
927928
'certificateExpiry' : require(__dirname + '/plugins/azure/appservice/certificateExpiry.js'),
928929
'scmSiteAccessRestriction' : require(__dirname + '/plugins/azure/appservice/scmSiteAccessRestriction.js'),
929930
'secureHttptriggerFunction' : require(__dirname + '/plugins/azure/appservice/secureHttptriggerFunction.js'),
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var async = require('async');
2+
var helpers = require('../../../helpers/azure');
3+
4+
module.exports = {
5+
title: 'Web Apps VNet Integrated',
6+
category: 'App Service',
7+
domain: 'Application Integration',
8+
description: 'Ensures that Azure Web Apps have virtual network integrated.',
9+
more_info: 'Enabling virtual network integration for apps allows outbound access to resources within the virtual network, ensuring enhanced security and operational control. This feature is crucial for proactively safeguarding your server against potential security threats and unauthorized access.',
10+
recommended_action: 'Ensure virtual network is integrated for all web apps.',
11+
link: 'https://learn.microsoft.com/en-us/azure/app-service/overview-vnet-integration',
12+
apis: ['webApps:list'],
13+
realtime_triggers: ['microsoftweb:sites:write', 'microsoftweb:sites:networkconfig:delete', 'microsoftweb:sites:delete'],
14+
15+
16+
run: function(cache, settings, callback) {
17+
var results = [];
18+
var source = {};
19+
var locations = helpers.locations(settings.govcloud);
20+
21+
async.each(locations.webApps, function(location, rcb) {
22+
const webApps = helpers.addSource(cache, source,
23+
['webApps', 'list', location]);
24+
25+
if (!webApps) return rcb();
26+
27+
if (webApps.err || !webApps.data) {
28+
helpers.addResult(results, 3, 'Unable to query for Web Apps: ' + helpers.addError(webApps), location);
29+
return rcb();
30+
}
31+
32+
if (!webApps.data.length) {
33+
helpers.addResult(results, 0, 'No existing Web Apps found', location);
34+
return rcb();
35+
}
36+
37+
webApps.data.forEach(function(webApp) {
38+
if (webApp && webApp.kind && webApp.kind === 'functionapp') {
39+
helpers.addResult(results, 0, 'Virtual Networks cannot be integrated with function apps', location, webApp.id);
40+
} else if (webApp && webApp.virtualNetworkSubnetId) {
41+
helpers.addResult(results, 0, 'App Service is integrated with a virtual network', location, webApp.id);
42+
} else {
43+
helpers.addResult(results, 2, 'App Service is not integrated with a virtual network', location, webApp.id);
44+
}
45+
});
46+
rcb();
47+
}, function() {
48+
// Global checking goes here
49+
callback(null, results, source);
50+
});
51+
}
52+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var expect = require('chai').expect;
2+
var vnetIntegrated = require('./vnetIntegrated');
3+
4+
const webApps = [
5+
{
6+
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
7+
'name': 'app1',
8+
'virtualNetworkSubnetId': '/subscriptions/12345/resourceGroups/cloudsploit-dev/providers/Microsoft.Network/virtualNetworks/test/subnets/default'
9+
},
10+
{
11+
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
12+
'name': 'app1',
13+
'virtualNetworkSubnetId': null
14+
}
15+
];
16+
17+
const createCache = (webApps) => {
18+
return {
19+
webApps: {
20+
list: {
21+
'eastus':{
22+
data: webApps
23+
}
24+
}
25+
}
26+
};
27+
};
28+
29+
const createErrorCache = () => {
30+
return {
31+
webApps: {
32+
list: {
33+
'eastus': {}
34+
}
35+
}
36+
};
37+
};
38+
39+
describe('vnetIntegrated', function() {
40+
describe('run', function() {
41+
it('should give passing result if no web apps', function(done) {
42+
const cache = createCache([]);
43+
vnetIntegrated.run(cache, {}, (err, results) => {
44+
expect(results.length).to.equal(1);
45+
expect(results[0].status).to.equal(0);
46+
expect(results[0].message).to.include('No existing Web Apps found');
47+
expect(results[0].region).to.equal('eastus');
48+
done();
49+
});
50+
});
51+
52+
it('should give unknown result if unable to query web app ', function(done) {
53+
const cache = createErrorCache();
54+
vnetIntegrated.run(cache, {}, (err, results) => {
55+
expect(results.length).to.equal(1);
56+
expect(results[0].status).to.equal(3);
57+
expect(results[0].message).to.include('Unable to query for Web Apps: ');
58+
expect(results[0].region).to.equal('eastus');
59+
done();
60+
});
61+
});
62+
63+
it('should give passing result if app service has Vnet Integrated', function(done) {
64+
const cache = createCache([webApps[0]]);
65+
vnetIntegrated.run(cache, {}, (err, results) => {
66+
expect(results.length).to.equal(1);
67+
expect(results[0].status).to.equal(0);
68+
expect(results[0].message).to.include('App Service is integrated with a virtual network');
69+
expect(results[0].region).to.equal('eastus');
70+
done();
71+
});
72+
});
73+
74+
it('should give failing result if app service app service does not have Vnet Integrated', function(done) {
75+
const cache = createCache([webApps[1]]);
76+
vnetIntegrated.run(cache, {}, (err, results) => {
77+
expect(results.length).to.equal(1);
78+
expect(results[0].status).to.equal(2);
79+
expect(results[0].message).to.include('App Service is not integrated with a virtual network');
80+
expect(results[0].region).to.equal('eastus');
81+
done();
82+
});
83+
});
84+
});
85+
});

0 commit comments

Comments
 (0)