Skip to content

Commit 1189b16

Browse files
Alirexaaeerhardt
andauthored
Reapply Redis password (#7599)
This PR addresses the previous issue by changing the container entrypoint and providing the password from an environment variable. * Revert "Revert redis password change (#7518)" This reverts commit 6a9540c. * checkout eventhubns.module.bicep and eventhubs aspire-manifest.json * Set password from envs * Add redis-command in single arg instead of multiple args * Update playground manifest * Address PR feedback * Respond to PR feedback * Change Redis password generation to exclude special characters. SE.Redis doesn't support commas in the password when parsing the connection string. * Fix ACA bug with HostAndPort * Always display the port for HostAndPort Fix #3838 --------- Co-authored-by: Eric Erhardt <[email protected]>
1 parent 6b18df7 commit 1189b16

File tree

17 files changed

+560
-59
lines changed

17 files changed

+560
-59
lines changed

playground/AzureContainerApps/AzureContainerApps.AppHost/api.module.bicep

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ param api_containerport string
55

66
param storage_outputs_blobendpoint string
77

8+
@secure()
9+
param cache_password_value string
10+
811
param account_outputs_connectionstring string
912

1013
@secure()
@@ -30,6 +33,10 @@ resource api 'Microsoft.App/containerApps@2024-03-01' = {
3033
properties: {
3134
configuration: {
3235
secrets: [
36+
{
37+
name: 'connectionstrings--cache'
38+
value: 'cache:6379,password=${cache_password_value}'
39+
}
3340
{
3441
name: 'value'
3542
value: secretparam_value
@@ -88,7 +95,7 @@ resource api 'Microsoft.App/containerApps@2024-03-01' = {
8895
}
8996
{
9097
name: 'ConnectionStrings__cache'
91-
value: 'cache:6379'
98+
secretRef: 'connectionstrings--cache'
9299
}
93100
{
94101
name: 'ConnectionStrings__account'

playground/AzureContainerApps/AzureContainerApps.AppHost/aspire-manifest.json

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@
3131
},
3232
"cache": {
3333
"type": "container.v1",
34-
"connectionString": "{cache.bindings.tcp.host}:{cache.bindings.tcp.port}",
34+
"connectionString": "{cache.bindings.tcp.host}:{cache.bindings.tcp.port},password={cache-password.value}",
3535
"image": "docker.io/library/redis:7.4",
3636
"deployment": {
3737
"type": "azure.bicep.v0",
3838
"path": "cache.module.bicep",
3939
"params": {
4040
"cache_volumes_0_storage": "{cache.volumes.0.storage}",
41+
"cache_password_value": "{cache-password.value}",
4142
"outputs_azure_container_registry_managed_identity_id": "{.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID}",
4243
"outputs_managed_identity_client_id": "{.outputs.MANAGED_IDENTITY_CLIENT_ID}",
4344
"outputs_azure_container_apps_environment_id": "{.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_ID}"
4445
}
4546
},
47+
"entrypoint": "/bin/sh",
4648
"args": [
47-
"--save",
48-
"60",
49-
"1"
49+
"-c",
50+
"redis-server --requirepass $REDIS_PASSWORD --save 60 1"
5051
],
5152
"volumes": [
5253
{
@@ -55,6 +56,9 @@
5556
"readOnly": false
5657
}
5758
],
59+
"env": {
60+
"REDIS_PASSWORD": "{cache-password.value}"
61+
},
5862
"bindings": {
5963
"tcp": {
6064
"scheme": "tcp",
@@ -116,6 +120,7 @@
116120
"params": {
117121
"api_containerport": "{api.containerPort}",
118122
"storage_outputs_blobendpoint": "{storage.outputs.blobEndpoint}",
123+
"cache_password_value": "{cache-password.value}",
119124
"account_outputs_connectionstring": "{account.outputs.connectionString}",
120125
"secretparam_value": "{secretparam.value}",
121126
"outputs_azure_container_registry_managed_identity_id": "{.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID}",
@@ -152,6 +157,22 @@
152157
"external": true
153158
}
154159
}
160+
},
161+
"cache-password": {
162+
"type": "parameter.v0",
163+
"value": "{cache-password.inputs.value}",
164+
"inputs": {
165+
"value": {
166+
"type": "string",
167+
"secret": true,
168+
"default": {
169+
"generate": {
170+
"minLength": 22,
171+
"special": false
172+
}
173+
}
174+
}
175+
}
155176
}
156177
}
157178
}

playground/AzureContainerApps/AzureContainerApps.AppHost/cache.module.bicep

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ param location string = resourceGroup().location
33

44
param cache_volumes_0_storage string
55

6+
@secure()
7+
param cache_password_value string
8+
69
param outputs_azure_container_registry_managed_identity_id string
710

811
param outputs_managed_identity_client_id string
@@ -14,6 +17,12 @@ resource cache 'Microsoft.App/containerApps@2024-03-01' = {
1417
location: location
1518
properties: {
1619
configuration: {
20+
secrets: [
21+
{
22+
name: 'redis-password'
23+
value: cache_password_value
24+
}
25+
]
1726
activeRevisionsMode: 'Single'
1827
ingress: {
1928
external: false
@@ -27,12 +36,18 @@ resource cache 'Microsoft.App/containerApps@2024-03-01' = {
2736
{
2837
image: 'docker.io/library/redis:7.4'
2938
name: 'cache'
39+
command: [
40+
'/bin/sh'
41+
]
3042
args: [
31-
'--save'
32-
'60'
33-
'1'
43+
'-c'
44+
'redis-server --requirepass \$REDIS_PASSWORD --save 60 1'
3445
]
3546
env: [
47+
{
48+
name: 'REDIS_PASSWORD'
49+
secretRef: 'redis-password'
50+
}
3651
{
3752
name: 'AZURE_CLIENT_ID'
3853
value: outputs_managed_identity_client_id

playground/ProxylessEndToEnd/ProxylessEndToEnd.AppHost/aspire-manifest.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
"resources": {
44
"redis": {
55
"type": "container.v0",
6-
"connectionString": "{redis.bindings.tcp.host}:{redis.bindings.tcp.port}",
6+
"connectionString": "{redis.bindings.tcp.host}:{redis.bindings.tcp.port},password={redis-password.value}",
77
"image": "docker.io/library/redis:7.4",
8+
"entrypoint": "/bin/sh",
9+
"args": [
10+
"-c",
11+
"redis-server --requirepass $REDIS_PASSWORD"
12+
],
13+
"env": {
14+
"REDIS_PASSWORD": "{redis-password.value}"
15+
},
816
"bindings": {
917
"tcp": {
1018
"scheme": "tcp",
@@ -59,6 +67,22 @@
5967
"port": 13456
6068
}
6169
}
70+
},
71+
"redis-password": {
72+
"type": "parameter.v0",
73+
"value": "{redis-password.inputs.value}",
74+
"inputs": {
75+
"value": {
76+
"type": "string",
77+
"secret": true,
78+
"default": {
79+
"generate": {
80+
"minLength": 22,
81+
"special": false
82+
}
83+
}
84+
}
85+
}
6286
}
6387
}
6488
}

playground/Redis/Redis.AppHost/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.WithDataVolume("valkey-data");
1313

1414
builder.AddProject<Projects.Redis_ApiService>("apiservice")
15+
.WithExternalHttpEndpoints()
1516
.WithReference(redis).WaitFor(redis)
1617
.WithReference(garnet).WaitFor(garnet)
1718
.WithReference(valkey).WaitFor(valkey);

playground/Redis/Redis.AppHost/aspire-manifest.json

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"resources": {
44
"redis": {
55
"type": "container.v0",
6-
"connectionString": "{redis.bindings.tcp.host}:{redis.bindings.tcp.port}",
6+
"connectionString": "{redis.bindings.tcp.host}:{redis.bindings.tcp.port},password={redis-password.value}",
77
"image": "docker.io/library/redis:7.4",
8+
"entrypoint": "/bin/sh",
89
"args": [
9-
"--save",
10-
"60",
11-
"1"
10+
"-c",
11+
"redis-server --requirepass $REDIS_PASSWORD --save 60 1"
1212
],
1313
"volumes": [
1414
{
@@ -17,6 +17,9 @@
1717
"readOnly": false
1818
}
1919
],
20+
"env": {
21+
"REDIS_PASSWORD": "{redis-password.value}"
22+
},
2023
"bindings": {
2124
"tcp": {
2225
"scheme": "tcp",
@@ -96,12 +99,30 @@
9699
"http": {
97100
"scheme": "http",
98101
"protocol": "tcp",
99-
"transport": "http"
102+
"transport": "http",
103+
"external": true
100104
},
101105
"https": {
102106
"scheme": "https",
103107
"protocol": "tcp",
104-
"transport": "http"
108+
"transport": "http",
109+
"external": true
110+
}
111+
}
112+
},
113+
"redis-password": {
114+
"type": "parameter.v0",
115+
"value": "{redis-password.inputs.value}",
116+
"inputs": {
117+
"value": {
118+
"type": "string",
119+
"secret": true,
120+
"default": {
121+
"generate": {
122+
"minLength": 22,
123+
"special": false
124+
}
125+
}
105126
}
106127
}
107128
}

playground/TestShop/TestShop.AppHost/aspire-manifest.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
},
3434
"basketcache": {
3535
"type": "container.v0",
36-
"connectionString": "{basketcache.bindings.tcp.host}:{basketcache.bindings.tcp.port}",
36+
"connectionString": "{basketcache.bindings.tcp.host}:{basketcache.bindings.tcp.port},password={basketcache-password.value}",
3737
"image": "docker.io/library/redis:7.4",
38+
"entrypoint": "/bin/sh",
3839
"args": [
39-
"--save",
40-
"60",
41-
"1"
40+
"-c",
41+
"redis-server --requirepass $REDIS_PASSWORD --save 60 1"
4242
],
4343
"volumes": [
4444
{
@@ -47,6 +47,9 @@
4747
"readOnly": false
4848
}
4949
],
50+
"env": {
51+
"REDIS_PASSWORD": "{basketcache-password.value}"
52+
},
5053
"bindings": {
5154
"tcp": {
5255
"scheme": "tcp",
@@ -240,6 +243,22 @@
240243
}
241244
}
242245
},
246+
"basketcache-password": {
247+
"type": "parameter.v0",
248+
"value": "{basketcache-password.inputs.value}",
249+
"inputs": {
250+
"value": {
251+
"type": "string",
252+
"secret": true,
253+
"default": {
254+
"generate": {
255+
"minLength": 22,
256+
"special": false
257+
}
258+
}
259+
}
260+
}
261+
},
243262
"messaging-password": {
244263
"type": "parameter.v0",
245264
"value": "{messaging-password.inputs.value}",

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppsInfrastructure.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ BicepValue<string> GetHostValue(string? prefix = null, string? suffix = null)
608608
EndpointProperty.Url => GetHostValue($"{scheme}://", suffix: isHttpIngress ? null : $":{port}"),
609609
EndpointProperty.Host or EndpointProperty.IPV4Host => GetHostValue(),
610610
EndpointProperty.Port => port.ToString(CultureInfo.InvariantCulture),
611+
EndpointProperty.HostAndPort => GetHostValue(suffix: $":{port}"),
611612
EndpointProperty.TargetPort => targetPort is null ? AllocateContainerPortParameter() : targetPort,
612613
EndpointProperty.Scheme => scheme,
613614
_ => throw new NotSupportedException(),

0 commit comments

Comments
 (0)