Skip to content

Commit 2d719c2

Browse files
committed
Add Azure Application Gateway configuration for secure HTTPS access
1 parent 755040e commit 2d719c2

2 files changed

Lines changed: 154 additions & 9 deletions

File tree

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ docker run -p 8501:8501 -e AZURE_OPENAI_ENDPOINT="<your-endpoint>" -e AZURE_OPEN
5353

5454
3. **Access the application**:
5555

56-
Open your browser and navigate to:
57-
58-
```
59-
http://localhost:8501
60-
```
56+
For local development, use `http://localhost:8501` (HTTPS is not configured for localhost).
6157

6258
## Container Registry Setup and Deployment
6359

@@ -132,10 +128,38 @@ You can get ACR credentials using:
132128
az acr credential show --name <your-acr-name>
133129
```
134130

135-
Once deployed, access your application at:
136-
```
137-
http://<your-container-group-name>.<region>.azurecontainer.io:8501
138-
```
131+
### Using Azure Application Gateway for SSL Termination
132+
133+
To enable secure communication over HTTPS, this solution integrates with Azure Application Gateway. The Application Gateway handles SSL termination and proxies traffic to the Azure Container Instance (ACI) running on port 8501.
134+
135+
#### Steps to Configure Azure Application Gateway
136+
137+
1. **Update Parameters**:
138+
- Add the following parameters to your deployment command:
139+
- `applicationGatewayName`: The name of the Azure Application Gateway resource.
140+
- `publicIpName`: The name of the public IP resource for the Application Gateway.
141+
142+
2. **Deploy with Application Gateway**:
143+
```bash
144+
az deployment group create \
145+
--resource-group <your-resource-group> \
146+
--template-file infra/aci.bicep \
147+
--parameters image="<your-image-path>" \
148+
azureOpenAIEndpoint="<your-endpoint>" \
149+
azureOpenAIAPIKey="<your-api-key>" \
150+
registryType="<DockerHub|ACR>" \
151+
registryName="<your-acr-name>" \
152+
applicationGatewayName="<your-app-gateway-name>" \
153+
publicIpName="<your-public-ip-name>"
154+
```
155+
156+
3. **Access the Application**:
157+
- Once deployed, access your application securely at the public IP or DNS name of the Application Gateway.
158+
159+
#### Notes
160+
- The Application Gateway listens on port 443 and forwards traffic to the ACI on port 8501.
161+
- SSL termination is handled by the Application Gateway using the provided SSL certificate.
162+
- Ensure that the SSL certificate is in PFX format and base64-encoded, and provide the password as a parameter.
139163

140164
## GitHub Actions CI/CD
141165

infra/aci.bicep

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ param registryPassword string = ''
2525
@description('ACR registry name (required for ACR, without .azurecr.io)')
2626
param registryName string = ''
2727

28+
@description('Azure Application Gateway name')
29+
param applicationGatewayName string
30+
31+
@description('Azure Application Gateway public IP name')
32+
param publicIpName string
33+
2834
resource containerGroup 'Microsoft.ContainerInstance/containerGroups@2023-05-01' = {
2935
name: containerGroupName
3036
location: resourceGroup().location
@@ -80,4 +86,119 @@ resource containerGroup 'Microsoft.ContainerInstance/containerGroups@2023-05-01'
8086
}
8187
}
8288

89+
resource publicIp 'Microsoft.Network/publicIPAddresses@2021-02-01' = {
90+
name: publicIpName
91+
location: resourceGroup().location
92+
sku: {
93+
name: 'Standard'
94+
}
95+
properties: {
96+
publicIPAllocationMethod: 'Static'
97+
}
98+
}
99+
100+
resource applicationGateway 'Microsoft.Network/applicationGateways@2021-02-01' = {
101+
name: applicationGatewayName
102+
location: resourceGroup().location
103+
properties: {
104+
sku: {
105+
name: 'Standard_v2'
106+
tier: 'Standard_v2'
107+
capacity: 1
108+
}
109+
gatewayIPConfigurations: [
110+
{
111+
name: 'appGatewayIpConfig'
112+
properties: {
113+
subnet: {
114+
id: resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnetName', 'subnetName')
115+
}
116+
}
117+
}
118+
]
119+
frontendIPConfigurations: [
120+
{
121+
name: 'appGatewayFrontendIp'
122+
properties: {
123+
publicIPAddress: {
124+
id: publicIp.id
125+
}
126+
}
127+
}
128+
]
129+
frontendPorts: [
130+
{
131+
name: 'appGatewayFrontendPort'
132+
properties: {
133+
port: 443
134+
}
135+
}
136+
]
137+
backendAddressPools: [
138+
{
139+
name: 'appGatewayBackendPool'
140+
properties: {
141+
backendAddresses: [
142+
{
143+
fqdn: containerGroup.properties.ipAddress.fqdn
144+
}
145+
]
146+
}
147+
}
148+
]
149+
httpListeners: [
150+
{
151+
name: 'appGatewayListener'
152+
properties: {
153+
frontendIPConfiguration: {
154+
id: resourceId('Microsoft.Network/applicationGateways/frontendIPConfigurations', applicationGatewayName, 'appGatewayFrontendIp')
155+
}
156+
frontendPort: {
157+
id: resourceId('Microsoft.Network/applicationGateways/frontendPorts', applicationGatewayName, 'appGatewayFrontendPort')
158+
}
159+
protocol: 'Https'
160+
sslCertificate: {
161+
id: resourceId('Microsoft.Network/applicationGateways/sslCertificates', applicationGatewayName, 'appGatewaySslCert')
162+
}
163+
}
164+
}
165+
]
166+
requestRoutingRules: [
167+
{
168+
name: 'appGatewayRoutingRule'
169+
properties: {
170+
httpListener: {
171+
id: resourceId('Microsoft.Network/applicationGateways/httpListeners', applicationGatewayName, 'appGatewayListener')
172+
}
173+
backendAddressPool: {
174+
id: resourceId('Microsoft.Network/applicationGateways/backendAddressPools', applicationGatewayName, 'appGatewayBackendPool')
175+
}
176+
backendHttpSettings: {
177+
id: resourceId('Microsoft.Network/applicationGateways/backendHttpSettingsCollection', applicationGatewayName, 'appGatewayBackendHttpSettings')
178+
}
179+
}
180+
}
181+
]
182+
backendHttpSettingsCollection: [
183+
{
184+
name: 'appGatewayBackendHttpSettings'
185+
properties: {
186+
port: 8501
187+
protocol: 'Http'
188+
cookieBasedAffinity: 'Disabled'
189+
}
190+
}
191+
]
192+
sslCertificates: [
193+
{
194+
name: 'appGatewaySslCert'
195+
properties: {
196+
data: '<base64-encoded-pfx>'
197+
password: '<certificate-password>'
198+
}
199+
}
200+
]
201+
}
202+
}
203+
83204
output fqdn string = containerGroup.properties.ipAddress.fqdn

0 commit comments

Comments
 (0)