Caution
THIS REPOSITORY CODE IS NOT READY FOR PRODUCTION USE AND SHOULD NOT BE USED FOR ANYTHING OTHER THAN LEARNING.
- The functionality is not built to scale. Parts of the design work for a demo with a handful of users and documents, and would not hold up under real load or real data volumes.
- The application code has a number of known security gaps that would be very dangerous to deploy. These are not about the landing zone or network infrastructure. They are in the application code and how it is implemented.
Use this repository to learn from, not to run anything real.
This repo is the home base for two talks: Building an Enterprise Chat GPT and Securing Your Azure AI Workload.
It holds a complete, private-by-default Azure AI workload in Bicep, a reusable Azure OpenAI library, an ingestion function and a chat web app built on it.
| Folder | Contents |
|---|---|
iac/ |
Bicep for the whole workload: VNet and private DNS, AI Services with model deployments, SQL, Key Vault, Event Grid, a Flex Consumption function app with its storage, blob storage, App Service, Log Analytics and Application Insights. Also the RBAC, OIDC and validation scripts. |
src-lib/ |
The AzureAI.Interop library as source: AzureAI.Interop.Abstractions, AzureAI.Interop and AzureAI.Interop.Rag, plus their tests. |
src-data/aidata |
The document and chunk tables (EF Core), shared by both apps. Embeddings live in an Azure SQL vector(1536) column. The web app applies the migrations. |
src-web/aiweb |
ASP.NET Core MVC app with Identity sign-in and two roles, User and Admin. Documents uploads files to blob storage and shows their ingestion status. Chat answers from the uploaded documents with numbered citations, creates images on request (gpt-image-2), takes spoken questions (gpt-4o-transcribe) and reads answers aloud (gpt-4o-mini-tts). Admin grants roles and shows each user's spend for the day. |
src-fn/aifunctions |
Azure Functions (isolated worker) app. IngestUploadedDocument receives BlobCreated events from Event Grid, extracts the text (PDF, DOCX, Markdown, text), chunks and embeds it, and stores the chunks in SQL. |
src-web/tests, src-fn/tests |
Tests for both apps. SQLite in memory stands in for Azure SQL; the vector query is checked by the SQL it generates. |
.github/workflows |
Build and test, infrastructure deploy, and web and function deploys. |
- A signed-in user uploads a file on Documents. The web app writes a
Pendingrow todocs.Documents, then the blob to theuploadscontainer. - Storage raises
BlobCreated. Event Grid delivers it toIngestUploadedDocument, which is the only inbound traffic the function app accepts. - The function extracts, chunks and embeds the file, replaces its rows in
docs.DocumentChunks, and marks the documentReady(orFailed, with the reason). - On each chat message the web app embeds the question and asks Azure SQL for the nearest chunks with
VECTOR_DISTANCE. The matches go to the chat model as delimited, numbered sources. - When the model calls
generate_image, the image is saved togenerated-imagesand served back through the web app. The Listen button sends an answer to text-to-speech. - The mic button records a spoken question, transcribes it, and sends the text as an ordinary chat message, then reads the answer aloud. It's turn-based: one recording per question, not a live conversation.
- No public data plane. AI Services, SQL, Key Vault and both storage accounts have public network access disabled and are reachable only through private endpoints in
snet-pe. - No keys. AI Services has local (key) auth disabled, storage has shared-key access disabled, and
BannedSymbols.txtturns any API-key credential in the code into a build error. Apps authenticate with their managed identities. - One secret, in Key Vault. The SQL connection string lives in a private Key Vault. The apps get a
@Microsoft.KeyVault(...)reference, and the password is seeded once from a GitHub secret, never from a param file. - Locked-down function app. Inbound traffic is denied by default, except for the Event Grid service tag. The deployment (SCM) endpoint is closed, and
Set-FunctionDeployAccess.ps1opens it only for the length of a publish. - Role-gated app. Anyone can register, but a new account sees nothing until an admin grants the User role.
- Spend control. Per-user, per-minute rate limits on chat, speech and uploads, plus per-user daily caps on chat tokens, images, speech and spoken questions, counted in SQL (
UsageLimitsinappsettings.json). - Least-privilege deployment. The deployment principal can't assign roles. Role assignments are a separate, reviewed step (
iac/RBAC-SETUP.md).
- Change the globally unique names in
iac/main.bicepparam. - Set up GitHub-to-Azure sign-in with
iac/OIDC-SETUP.md. - Run Deploy infrastructure from the Actions tab.
- Apply the role assignments with
iac/scripts/Set-WorkloadRbac.ps1, then verify withiac/scripts/Test-WorkloadDeployment.ps1. - Run Deploy web app first (it creates the database tables on startup), then Deploy function app. The first function deploy in an environment also runs Deploy infrastructure again, to create the Event Grid subscription that connects uploads to ingestion; Event Grid refuses to create it until the function exists.
- Open the web app and sign in as the seeded admin,
checkov@starfleet.com/NuclearWessels#1!. Create a second admin, then change this password or disable the account; it is in the source. - People who register (the confirmation link is shown on screen, because no email sender is configured) get access once you give them the User role on the Admin tab.
The vector column needs Azure SQL or SQL Server 2025, so the app's migrations don't run against LocalDB.
To build locally:
dotnet build CreatingAnEnterpriseAISolution.slnx
dotnet test CreatingAnEnterpriseAISolution.slnxMIT. See LICENSE.
