Implement Network Security
About
Network security plays a
crucial role in preventing unauthorized individuals from accessing the services
you aim to protect. Restricting user visibility is always a smart strategy, as
they cannot jeopardize what they cannot observe.
Apply network access
restrictions
By default, all networks
can access Azure AI services. Certain individual resources within AI services
(like Azure AI Face service, Azure AI Vision, and others) can be set up to
limit access to designated network addresses, whether those are public Internet
addresses or addresses within virtual networks.
When network restrictions
are in place, a client attempting to connect from an unauthorized IP address
will encounter an Access Denied error.
Secure key Access With
Azure Key Vault
Using a key for
authentication, you can create apps that use Azure AI services. But this
implies that the key must be obtainable by the application code. One choice is
to keep the key in a configuration file or environment variable where the
application is deployed, but this method exposes the key to unwanted access.
When creating apps on Azure, it is preferable to keep the key safely in Azure
Key Vault and grant access to it via a managed identity, or user account that
the application uses.
Create a key vault and
add a secret
- First, you need to create a key vault and add a secret for the Azure AI services key.
- Make a note of the key1 value for your Azure AI services resource (or copy it to the clipboard).
- In the Azure portal, on
the Home page, select the +Create
a resource button, search for Key Vault.
- Create a Key Vault resource.
- Access configuration tab.
- Scroll down to Access policies section and select your user using the checkbox on the left.
- Wait for deployment to complete and then go to your key vault resource.
- In the left navigation pane, select Secrets (in the Objects section).
- Select + Generate/Import and add a new secret.
- Select Create.
Create a service
principal
Your application needs to
use a service principal with access to the secret in order to access it in the
key vault. You will use the Azure command line interface (CLI) to create the
service principal, find its object ID, and grant access to the secret in Azure
Vault.
- Run Azure CLI command, replacing <spName> with a unique suitable name for an application identity. Also replace <subscriptionId> and <resourceGroup> with the correct values for your subscription ID and the resource group containing your Azure AI services and key vault resources. The output of this command will include information about your new service principal.
- To get the object ID of your service principal, run the Azure CLI command, replacing <appId> with the value of your service principal's app ID.
- Copy the id value in the JSON returned in response.
- To assign permission for your new service principal to access secrets in your Key Vault, run the <objectId> Azure CLI command, replacing with the name of your Azure Key Vault resource and with the value of your service principal's ID value you've just copied.
Use the service principal
in an application
Now you're ready to use
the service principal identity in an application, so it can access the secret
Azure AI services key in your key vault and use it to connect to your Azure AI
services resource.
- In your terminal, switch to the C-Sharp or Python folder depending on your language preference by running cd C-Sharp or cd Python . Then run cd keyvault_client to navigate to the app folder.
- Install the packages you will need to use for Azure Key Vault and the Text Analytics API in your Azure AI services resource by running the appropriate command for your language preference.
- View the contents of the keyvault-client folder, and note that it contains a file for configuration settings.
- Note that the keyvault-client folder contains a code file for the client application.
- Enter the command to run the program.
- When prompted, enter some text and review the language that is detected by the service.
- When you have finished testing the application, enter "quit" to stop the program.
Clean Up Resources
If you're not using the
Azure resource, you can delete them to avoid incurring further charges:
- Open the Azure portal at https://portal.azure.com , and in the top search bar, search for the resources you created.
- On the resource page, select Delete and follow the instructions to delete the resource. Alternatively, you can delete the entire resource group to clean up all resources at the same time.
Conclusion
We have successfully
learnt about the network access restrictions and secured key access.
Comments
Post a Comment