Convert template from MongoDB API to SQL API with managed identity authentication #12
+402
−153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR converts the Azure template from using connection strings to managed identity authentication to resolve Azure policy violations that were causing deployment failures.
Problem
The template was failing deployment with the following policy violations:
Local authentication methods are not allowed
for Cosmos DBAnonymous blob access is not allowed
for Storage AccountSolution
Infrastructure Changes
disableLocalAuth: true
00000000-0000-0000-0000-000000000002
)allowBlobPublicAccess: false
)Application Changes
DefaultAzureCredential
requirements.txt
to useazure-cosmos
instead ofbeanie
API Compatibility
The public REST API endpoints remain unchanged, ensuring backward compatibility:
Key Files Modified
infra/app/db-avm.bicep
- Converted to SQL API with disabled local authinfra/app/cosmos-role-assignment.bicep
- New RBAC moduleinfra/main.bicep
- Updated app settings and role assignmentssrc/api/todo/models.py
- Complete rewrite using SQL APIsrc/api/todo/app.py
- Managed identity integrationsrc/api/todo/routes.py
- Updated to use SQL API operationsSecurity Improvements
✅ Eliminated connection string storage and usage
✅ Implemented managed identity authentication
✅ Proper RBAC with minimal required permissions
✅ Disabled public storage account access
✅ Complies with Azure security policies
The template now follows Azure security best practices and should deploy successfully without policy violations.
Fixes #11.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
aka.ms
bicep build infra/main.bicep
(dns block)bicep build infra/app/cosmos-role-assignment.bicep --stdout
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.