Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
|
4 |
+
def render_mermaid(graph):
|
5 |
+
components.html(
|
6 |
+
f"""
|
7 |
+
<pre class="mermaid">
|
8 |
+
{graph}
|
9 |
+
</pre>
|
10 |
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
11 |
+
<script>mermaid.initialize({{startOnLoad:true}});</script>
|
12 |
+
""",
|
13 |
+
height=500,
|
14 |
+
)
|
15 |
+
|
16 |
+
st.set_page_config(page_title="Azure Setup Guide", layout="wide")
|
17 |
+
|
18 |
+
st.title("Azure Two-Subscription Solution Setup Guide")
|
19 |
+
|
20 |
+
st.header("Architecture Overview")
|
21 |
+
|
22 |
+
mermaid_diagram = """
|
23 |
+
graph TB
|
24 |
+
subgraph "Subscription 1"
|
25 |
+
AI[AI Service]
|
26 |
+
NSG1[Network Security Group]
|
27 |
+
end
|
28 |
+
|
29 |
+
subgraph "Subscription 2"
|
30 |
+
FW[Azure Firewall]
|
31 |
+
VNET[Virtual Network]
|
32 |
+
NSG2[Network Security Group]
|
33 |
+
ACR[Azure Container Registry]
|
34 |
+
ACAE[Azure Container Apps Environment]
|
35 |
+
subgraph "Container Apps"
|
36 |
+
ACA1[AI App 1 with UI]
|
37 |
+
ACA2[AI App 2 with UI]
|
38 |
+
ACA3[AI App 3 with UI]
|
39 |
+
ACA4[AI App 4 with UI]
|
40 |
+
end
|
41 |
+
AD[Azure Active Directory]
|
42 |
+
APIM[API Management]
|
43 |
+
end
|
44 |
+
|
45 |
+
User((User)) -->|1. Access| FW
|
46 |
+
FW -->|2. Route| APIM
|
47 |
+
APIM -->|3. Redirect| AD
|
48 |
+
AD -->|4. Authenticate| User
|
49 |
+
User -->|5. Token| APIM
|
50 |
+
APIM -->|6. Authorized Request| NSG2
|
51 |
+
NSG2 --> ACAE
|
52 |
+
ACAE -->|Egress| FW
|
53 |
+
FW -->|Filtered Egress| AI
|
54 |
+
NSG1 -->|Allows| FW
|
55 |
+
ACR --> ACAE
|
56 |
+
"""
|
57 |
+
|
58 |
+
render_mermaid(mermaid_diagram)
|
59 |
+
|
60 |
+
st.header("Configuration Steps")
|
61 |
+
|
62 |
+
resources = {
|
63 |
+
"Azure Firewall": {
|
64 |
+
"description": "Configure inbound NAT rules and set up application and network rules.",
|
65 |
+
"code": """
|
66 |
+
az network firewall application-rule create --collection-name 'Azure_AD' --firewall-name 'myFirewall' --name 'Allow_AzureAD' --protocols 'http=80' 'https=443' --resource-group 'myResourceGroup' --target-fqdns 'login.microsoftonline.com' 'graph.microsoft.com' --source-addresses '*' --action 'Allow' --priority 100
|
67 |
+
"""
|
68 |
+
},
|
69 |
+
"API Management": {
|
70 |
+
"description": "Set up to handle incoming requests and manage authentication.",
|
71 |
+
"code": """
|
72 |
+
<policies>
|
73 |
+
<inbound>
|
74 |
+
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized">
|
75 |
+
<openid-config url="https://login.microsoftonline.com/<tenant-id>/.well-known/openid-configuration" />
|
76 |
+
<audiences>
|
77 |
+
<audience>your-app-id-uri</audience>
|
78 |
+
</audiences>
|
79 |
+
</validate-jwt>
|
80 |
+
</inbound>
|
81 |
+
</policies>
|
82 |
+
"""
|
83 |
+
},
|
84 |
+
"Azure Active Directory": {
|
85 |
+
"description": "Register your application and configure app roles if needed.",
|
86 |
+
"code": """
|
87 |
+
az ad app create --display-name "MyACAApp" --web-redirect-uris "https://myapim.azure-api.net/oauth2/callback"
|
88 |
+
"""
|
89 |
+
},
|
90 |
+
"Azure Container Apps Environment": {
|
91 |
+
"description": "Enable authentication and set it to use Azure AD.",
|
92 |
+
"code": """
|
93 |
+
az containerapp auth update --name myapp --resource-group myResourceGroup --enable-authentication true --provider microsoft --client-id <client-id> --client-secret <client-secret>
|
94 |
+
"""
|
95 |
+
},
|
96 |
+
"Network Security Group (NSG2)": {
|
97 |
+
"description": "Configure to allow inbound traffic from APIM to ACAE.",
|
98 |
+
"code": """
|
99 |
+
az network nsg rule create --name AllowAPIM --nsg-name myNSG --priority 100 --source-address-prefixes 'ApiManagement' --source-port-ranges '*' --destination-address-prefixes '*' --destination-port-ranges 443 --access Allow --protocol Tcp --description "Allow APIM inbound traffic"
|
100 |
+
"""
|
101 |
+
},
|
102 |
+
"Virtual Network (VNET)": {
|
103 |
+
"description": "Ensure APIM, ACAE, and Azure Firewall are in the same VNET.",
|
104 |
+
"code": """
|
105 |
+
az network vnet subnet create --name apim --resource-group myResourceGroup --vnet-name myVNet --address-prefixes 10.0.1.0/24
|
106 |
+
az network vnet subnet create --name acae --resource-group myResourceGroup --vnet-name myVNet --address-prefixes 10.0.2.0/24
|
107 |
+
"""
|
108 |
+
},
|
109 |
+
"Azure Container Registry (ACR)": {
|
110 |
+
"description": "Configure with private endpoints for secure access from ACAE.",
|
111 |
+
"code": """
|
112 |
+
az acr private-endpoint-connection create --name myACR --resource-group myResourceGroup
|
113 |
+
"""
|
114 |
+
},
|
115 |
+
"Network Security Group (NSG1)": {
|
116 |
+
"description": "Update to allow traffic from Subscription 2's Azure Firewall IP.",
|
117 |
+
"code": """
|
118 |
+
az network nsg rule create --name AllowSubnet2Firewall --nsg-name myNSG1 --priority 100 --source-address-prefixes '<Firewall-IP>' --destination-port-ranges '*' --access Allow --protocol '*'
|
119 |
+
"""
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
for resource, details in resources.items():
|
124 |
+
st.subheader(resource)
|
125 |
+
st.write(details["description"])
|
126 |
+
st.code(details["code"], language="bash")
|
127 |
+
|
128 |
+
st.header("Authentication Flow")
|
129 |
+
auth_flow = """
|
130 |
+
1. User attempts to access an ACA app URL
|
131 |
+
2. Azure Firewall routes the request to API Management
|
132 |
+
3. APIM redirects the user to Azure AD login page
|
133 |
+
4. User authenticates with Azure AD
|
134 |
+
5. Azure AD sends a token back to the user's browser
|
135 |
+
6. Browser sends the token to APIM
|
136 |
+
7. APIM validates the token and, if valid, forwards the request to the appropriate ACA app
|
137 |
+
8. ACA app processes the request and sends the response back through APIM and Azure Firewall to the user
|
138 |
+
"""
|
139 |
+
st.write(auth_flow)
|
140 |
+
|
141 |
+
st.header("Deploying New Apps using Azure Resources Extension in VS Code")
|
142 |
+
vscode_instructions = """
|
143 |
+
1. Install the Azure Resources extension in VS Code
|
144 |
+
2. Sign in to your Azure account in VS Code
|
145 |
+
3. Open the Azure Resources view in the sidebar
|
146 |
+
4. Right-click on your Container Apps Environment and select "Create Container App"
|
147 |
+
5. Follow the prompts to configure your new app:
|
148 |
+
- Choose a name for your app
|
149 |
+
- Select the appropriate container image
|
150 |
+
- Configure environment variables if needed
|
151 |
+
- Set up ingress rules
|
152 |
+
6. Review and create the new Container App
|
153 |
+
7. Once deployed, update the app's authentication settings using the Azure CLI command provided earlier
|
154 |
+
8. Update API Management to route traffic to the new app if necessary
|
155 |
+
"""
|
156 |
+
st.write(vscode_instructions)
|
157 |
+
|
158 |
+
st.header("Final Notes")
|
159 |
+
st.write("""
|
160 |
+
- Ensure all resources are properly secured and follow Azure best practices
|
161 |
+
- Regularly update and patch all components
|
162 |
+
- Monitor your applications and infrastructure using Azure Monitor
|
163 |
+
- Implement proper logging and alerting mechanisms
|
164 |
+
- Conduct regular security audits and penetration testing
|
165 |
+
""")
|