Skip to content

Commit 196dacb

Browse files
authored
Application Insights: CSP fixes for client-side and RBAC authentication for import web-job (#75)
2 parents 7594b3d + ffedea0 commit 196dacb

File tree

155 files changed

+24796
-28749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+24796
-28749
lines changed
2.47 KB
Binary file not shown.

src/AnalyticsEngine/App.ControlPanel.Engine/App.ControlPanel.Engine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
<ItemGroup>
7575
<Compile Include="BaseInstallProcessClasses.cs" />
7676
<Compile Include="InstallerLogs.cs" />
77-
<Compile Include="InstallerTasks\JobTasks\CreateOrUpdateRunbookConfigureTask.cs" />
7877
<Compile Include="InstallerTasks\JobTasks\ProfilingScriptsUploadToBlobStorageTask.cs" />
7978
<Compile Include="InstallerTasks\JobTasks\AutomationAccountTask.cs" />
8079
<Compile Include="ConfigureAzureComponentsTasks.cs" />
8180
<Compile Include="InstallerTasks\JobTasks\RunbookCreateOrUpdateTasks.cs" />
81+
<Compile Include="InstallerTasks\ResourceSecurityInstallJob.cs" />
8282
<Compile Include="InstallerTasks\RunbooksInstallJob.cs" />
8383
<Compile Include="Models\AzStorageConnectionInfo.cs" />
8484
<Compile Include="SolutionUninstaller.cs" />

src/AnalyticsEngine/App.ControlPanel.Engine/ConfigureAzureComponentsTasks.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ConfigureAzureComponentsTasks(SolutionInstallConfig config, ILogger logge
3838
/// Install configure & software on App Service, update target DB.
3939
/// </summary>
4040
public async Task RunPostCreatePaaSTasks(WebSiteResource webApp, DatabasePaaSInfo dbInfo, StorageAccountResource storage, AutomationAccountResource automationAccount,
41-
AppInsightsInfoWithApiAccess appInsights,
41+
AppInsightsInfo appInsights,
4242
RedisResource redis, CognitiveServicesInfo cognitiveServicesInfo,
4343
KeyVaultResource keyVault, string serviceBusConnectionString, SubscriptionResource subscription)
4444
{
@@ -130,7 +130,7 @@ async Task ConfigureWebApp(WebSiteResource webApp, DatabasePaaSInfo backendInfo,
130130
StorageAccountResource storage,
131131
RedisResource redis,
132132
CognitiveServicesInfo cognitiveServicesInfo,
133-
AppInsightsInfoWithApiAccess appInsights, string serviceBusConnectionString, KeyVaultResource keyVault)
133+
AppInsightsInfo appInsights, string serviceBusConnectionString, KeyVaultResource keyVault)
134134
{
135135
// App settings
136136
var url = $"https://{webApp.Data.HostNames.First()}/";
@@ -148,14 +148,6 @@ async Task ConfigureWebApp(WebSiteResource webApp, DatabasePaaSInfo backendInfo,
148148
{
149149
appSettings.Properties.Add("AppInsightsConnectionString", appInsights.ConnectionString);
150150
}
151-
if (!string.IsNullOrEmpty(appInsights?.ApiKey))
152-
{
153-
appSettings.Properties.Add("AppInsightsApiKey", appInsights.ApiKey);
154-
}
155-
if (!string.IsNullOrEmpty(appInsights?.AppId))
156-
{
157-
appSettings.Properties.Add("AppInsightsAppId", appInsights.AppId);
158-
}
159151

160152
if (this.Config.CognitiveServicesEnabled)
161153
{

src/AnalyticsEngine/App.ControlPanel.Engine/InstallerTasks/AzurePaaSInstallJob.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace App.ControlPanel.Engine.InstallerTasks
2121
/// </summary>
2222
public class AzurePaaSInstallJob : BaseAnalyticsSolutionInstallJob
2323
{
24+
private readonly GetOrCreateResourceGroupTask _rgCreateTask;
2425
private readonly AutomationAccountTask _automationAccountTask;
2526

2627
private readonly SqlServerTask _sqlServerTask;
@@ -37,14 +38,19 @@ public class AzurePaaSInstallJob : BaseAnalyticsSolutionInstallJob
3738

3839
private readonly LogAnalyticsInstallTask _logAnalyticsInstallTask;
3940
private readonly AppInsightsInstallTask _appInsightsInstallTask;
40-
private readonly AppInsightsConfigureApiTask _appInsightsConfigureApiTask;
4141
private readonly TextAnalyticsInstallTask _cognitiveServicesInstallTask;
4242

4343
/// <summary>
4444
/// Add tasks in order for execution, some being chained
4545
/// </summary>
4646
public AzurePaaSInstallJob(ILogger logger, SolutionInstallConfig config, SubscriptionResource subscription) : base(logger, config, subscription)
4747
{
48+
49+
var tagDic = config.Tags.ToDictionary();
50+
51+
_rgCreateTask = new GetOrCreateResourceGroupTask(TaskConfig.GetConfigForName(config.ResourceGroupName), logger, Location, tagDic, subscription);
52+
this.AddTask(_rgCreateTask);
53+
4854
// Performance levels
4955
var appPerfTier = AppServicePlanTask.PERF_TIER_BASIC1;
5056
var sqlPerfTier = SqlDatabaseTask.PERF_TIER_BASIC;
@@ -55,8 +61,6 @@ public AzurePaaSInstallJob(ILogger logger, SolutionInstallConfig config, Subscri
5561
appPerfTier = AppServicePlanTask.PERF_TIER_BASIC2;
5662
}
5763

58-
var tagDic = config.Tags.ToDictionary();
59-
6064
// Web
6165
var appServicePlanConfig = TaskConfig.GetConfigForName(config.AppServiceWebAppName).AddSetting(AppServicePlanTask.CONFIG_KEY_PERF_TIER, appPerfTier);
6266
_appServicePlanTask = new AppServicePlanTask(appServicePlanConfig, logger, Location, tagDic);
@@ -132,8 +136,7 @@ public AzurePaaSInstallJob(ILogger logger, SolutionInstallConfig config, Subscri
132136
var creds = new ClientSecretCredential(config.InstallerAccount.DirectoryId, config.InstallerAccount.ClientId, config.InstallerAccount.Secret);
133137
var appInsightsConfig = TaskConfig.GetConfigForName(config.AppInsightsName);
134138
_appInsightsInstallTask = new AppInsightsInstallTask(appInsightsConfig, logger, Location, tagDic, ResourceGroupName, config.Subscription.SubId, creds);
135-
_appInsightsConfigureApiTask = new AppInsightsConfigureApiTask(appInsightsConfig, logger, Location, creds, _config.Subscription.SubId, ResourceGroupName);
136-
this.AddTask(_logAnalyticsInstallTask, _appInsightsInstallTask, _appInsightsConfigureApiTask);
139+
this.AddTask(_logAnalyticsInstallTask, _appInsightsInstallTask);
137140

138141
// Cognitive
139142
if (config.CognitiveServicesEnabled)
@@ -166,7 +169,7 @@ public AzurePaaSInstallJob(ILogger logger, SolutionInstallConfig config, Subscri
166169
public DatabasePaaSInfo DatabasePaaSInfo => new DatabasePaaSInfo(CreatedSqlServer, CreatedSqlDatabase, _config);
167170
public RedisResource Redis => GetTaskResult<RedisResource>(_redisTask);
168171
public StorageAccountResource Storage => GetTaskResult<StorageAccountResource>(_storageAccountInstallTask);
169-
public AppInsightsInfoWithApiAccess AppInsights => GetTaskResult<AppInsightsInfoWithApiAccess>(_appInsightsConfigureApiTask);
172+
public AppInsightsInfo AppInsights => GetTaskResult<AppInsightsInfo>(_appInsightsInstallTask);
170173
public CognitiveServicesInfo CognitiveServicesInfo => _cognitiveServicesInstallTask != null ? GetTaskResult<CognitiveServicesInfo>(_cognitiveServicesInstallTask) : new CognitiveServicesInfo();
171174
public ServiceBusQueueResourceWithConnectionString SBQueueWithConnectionString => GetTaskResult<ServiceBusQueueResourceWithConnectionString>(_serviceBusQueueWithPolicyInstallTask);
172175
public KeyVaultResource KeyVault => GetTaskResult<KeyVaultResource>(_keyVaultTask);

src/AnalyticsEngine/App.ControlPanel.Engine/InstallerTasks/JobTasks/CreateOrUpdateRunbookConfigureTask.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Azure.ResourceManager.Authorization;
2+
using Azure.ResourceManager.Resources;
3+
using CloudInstallEngine;
4+
using CloudInstallEngine.Azure.InstallTasks;
5+
using Common.Entities.Installer;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace App.ControlPanel.Engine.InstallerTasks
9+
{
10+
/// <summary>
11+
/// Secures resources in the resource group by assigning RBAC roles.
12+
/// </summary>
13+
public class ResourceSecurityInstallJob : BaseAnalyticsSolutionInstallJob
14+
{
15+
private readonly RoleAssignmentTask _appInsightsReaderRoleTask;
16+
17+
public ResourceSecurityInstallJob(ILogger logger, SolutionInstallConfig config, SubscriptionResource subscription) : base(logger, config, subscription)
18+
{
19+
var tagDic = config.Tags.ToDictionary();
20+
21+
// Assign Reader role to the runtime account on the resource group (covers App Insights and all resources)
22+
var readerRoleConfig = TaskConfig.GetConfigForPropAndVal(RoleAssignmentTask.CONFIG_KEY_ROLE_NAME, "Reader")
23+
.AddSetting(RoleAssignmentTask.CONFIG_KEY_CLIENT_ID, config.RuntimeAccountOffice365.ClientId)
24+
.AddSetting(RoleAssignmentTask.CONFIG_KEY_CLIENT_SECRET, config.RuntimeAccountOffice365.Secret)
25+
.AddSetting(RoleAssignmentTask.CONFIG_KEY_TENANT_ID, config.RuntimeAccountOffice365.DirectoryId)
26+
.AddSetting(RoleAssignmentTask.CONFIG_KEY_PRINCIPAL_TYPE, "ServicePrincipal");
27+
28+
_appInsightsReaderRoleTask = new RoleAssignmentTask(readerRoleConfig, logger, Location, tagDic);
29+
this.AddTask(_appInsightsReaderRoleTask);
30+
}
31+
32+
public RoleAssignmentResource AppInsightsReaderRole => GetTaskResult<RoleAssignmentResource>(_appInsightsReaderRoleTask);
33+
}
34+
}

src/AnalyticsEngine/App.ControlPanel.Engine/SolutionInstaller.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public async Task InstallOrUpdate()
4848
var azureBackeEndCreationJob = new AzurePaaSInstallJob(_logger, Config, azureSub);
4949
await azureBackeEndCreationJob.Install();
5050

51+
// Secure resources with RBAC roles
52+
try
53+
{
54+
var resourceSecurityJob = new ResourceSecurityInstallJob(_logger, Config, azureSub);
55+
await resourceSecurityJob.Install();
56+
}
57+
catch (Exception ex)
58+
{
59+
_logger.LogError($"Failed to assign RBAC roles: {ex.Message}. Continuing installation...");
60+
}
61+
5162
// Run stuff now everything in Azure is created
5263
var tasks = new ConfigureAzureComponentsTasks(Config, _logger, _ftpConfig, InstalledByUsername, _softwareConfig, _configPassword);
5364
await tasks.RunPostCreatePaaSTasks(

src/AnalyticsEngine/App.ControlPanel.Engine/SqlExtentions/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ The scripts are run after the database schema has been updated with Entity Frame
1010

1111
Note: SQL server doesn't normally support "```GO```" statements in stored procedures ("GO" is a SQL Server Management Studio thing to separate scripts in a single file), so you should avoid using them in your scripts here.
1212
You *can* use the "GO" statement and the installer will split each segment by "GO" and then execute each segment (bit of a hack), but you should put the scripts in separate files or remove "GO" from any script here.
13+
14+
## Profiling Extensions
15+
These scripts setup the SQL Server profiling extensions but are run by PS scripts found in /src/AnalyticsEngine/WebJob.Office365ActivityImporter/AutomationPS/ProfilingJobs/.
16+
17+
The main logic is in "usp_CompileWeekly" - a stored procedure that compiles weekly profiling data from daily profiling data.

src/AnalyticsEngine/App.ControlPanel/App.ControlPanel.WinForms.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,6 @@
182182
<Compile Include="MainForm.Designer.cs">
183183
<DependentUpon>MainForm.cs</DependentUpon>
184184
</Compile>
185-
<Compile Include="NewSaltForm.cs">
186-
<SubType>Form</SubType>
187-
</Compile>
188-
<Compile Include="NewSaltForm.Designer.cs">
189-
<DependentUpon>NewSaltForm.cs</DependentUpon>
190-
</Compile>
191185
<Compile Include="Program.cs" />
192186
<Compile Include="Properties\AssemblyInfo.cs" />
193187
<Compile Include="ProxyConfigForm.cs">
@@ -248,9 +242,6 @@
248242
<EmbeddedResource Include="MainForm.resx">
249243
<DependentUpon>MainForm.cs</DependentUpon>
250244
</EmbeddedResource>
251-
<EmbeddedResource Include="NewSaltForm.resx">
252-
<DependentUpon>NewSaltForm.cs</DependentUpon>
253-
</EmbeddedResource>
254245
<EmbeddedResource Include="Properties\Resources.resx">
255246
<Generator>ResXFileCodeGenerator</Generator>
256247
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

src/AnalyticsEngine/App.ControlPanel/NewSaltForm.Designer.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)