CodeCommitsIssuesPull requestsActionsInsightsSecurity
hrushikeshdeshpande-updating-semgrep-yml

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

DataConnectors/AzureStorage/Readme.md

57lines · modecode

1# Azure Function
2
3## Prerequisites
4* Ideally have access to Visual Studio or Visual Studio Code
5* Install dotnet core 3.1, https://dotnet.microsoft.com/download/dotnet-core
6* Install azure-cli, https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
7* Install azure-functions-core-tools, https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
8* Have the workspace ID and key of an Azure Log Analytics or Azure Sentinel workspace to hand. Details can be found here https://docs.microsoft.com/en-us/azure/azure-monitor/platform/agent-windows.
9
10## Setup
111. Create a new Azure Function, you can follow this https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-azure-function guide but don't proceed to create the function itself.
12 - You will also need to create a system identity for this function so that we can enable it to query the keyvault
13 - Platform features -> Identity -> User assigned -> Set status to On and click Save.
14 - Copy the Object ID, you will need to use this to allow authentication to the KeyVault
15
162. Create a new Azure Storage account or make use of an existing one.
17 - Create a new private container called 'statedata'
18 - Inside 'statedata' create a blob called 'state'. This is a semicolon separated file which contains the storage accounts to check and the time of last check.
19 - XXXX=YYYY;XXXX=YYYY
20 - For the first run create entries similar to test123=2020-01-01T01:01:01.8914445Z
21 - Obtain the Azure Storage connection string for the container. https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string
223. Create a new Azure Keyvault.
23 - Add the following secrets
24 - BlobStorageAccountKeys - A semi-colon ';' separated list of storage accounts to check ie NAME:KEY;NAME:KEY
25 - NAME is the name of the storage account
26 - KEY is the access key taken from the storage account's 'Access Keys' page.
27 - BlobStorageConnectionString - The connection string to blob storage that will hold state data
28 - LogAnalyticsWorkspace - LA workspace found in the previous step
29 - LogAnalyticsKey - LA key found in the previous step
30 - Add permissions for the Azure function (use the Object ID generated in step #1) to access the keyvault via Access Policies
31 - Access policies -> Add Access Policy -> Secret Management, Select your function as the service principle, Save -> Save
32 - Note down the URL for each of the KeyVault secrets created.
33
34## Publish the Azure Function
35You can publish an Azure Function with Visual Studio or Visual Studio Code. Alternatively the following commands will get you started.
36
37An important note on using the following commands, the Azure Function version must match what is defined in your codebase. Visual Studio will prompt to upgrade the function if this is different, the command below may not.
38
39Run the following commands
40``az login``
41followed by
42``func azure functionapp publish nameoffunction --csharp --force``
43
44## Configure
45In the Azure Function Application settings set up a configuration mapping from environment variable to keyvault entry.
46You can find these settings in Platform features -> Configuration -> Application settings -> New application setting.
47You can find the SECRETURI references below in the respective properies of the keyvault entries created earlier.
48* Name = BlobStorageAccountKeys Value = @Microsoft.KeyVault(SecretUri=https://SECRETURI)
49* Name = BlobStorageConnectionString Value = @Microsoft.KeyVault(SecretUri=https://SECRETURI)
50* Name = LogAnalyticsKey Value = @Microsoft.KeyVault(SecretUri=https://SECRETURI)
51* Name = LogAnalyticsWorkspace Value = @Microsoft.KeyVault(SecretUri=https://SECRETURI)
52
53Restart the Azure Function and check the logs entries don't contain any errors.
54
55## Testing
56Access the Azure Storage account configured earlier. Debug logs will be generated and should be collected and processed by the Azure Function after an hour. The log entries generated by the Function should show the access.
57After an hour the entries will appear in the Sentinel workspace.