|
| 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 | +}; |
0 commit comments