Skip to content

Commit c0413ac

Browse files
authored
Never render secrets into values.yaml (#8497)
- Added tests
1 parent 0a182d5 commit c0413ac

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/Aspire.Hosting.Kubernetes/KubernetesResourceContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private HelmExpressionWithValue AllocateParameter(ParameterResource parameter)
360360
formattedName.ToHelmSecretExpression(resource.Name) :
361361
formattedName.ToHelmConfigExpression(resource.Name);
362362

363-
var value = parameter.Default is null ? null : parameter.Value;
363+
var value = parameter.Default is null || parameter.Secret ? null : parameter.Value;
364364
return new(expression, value);
365365
}
366366

tests/Aspire.Hosting.Kubernetes.Tests/ExpectedValues.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static class ExpectedValues
2929
secrets:
3030
myapp:
3131
param1: ""
32+
param3: ""
3233
config:
3334
myapp:
3435
ASPNETCORE_ENVIRONMENT: "Development"
@@ -39,7 +40,7 @@ public static class ExpectedValues
3940
OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES: "true"
4041
OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY: "in_memory"
4142
services__myapp__http__0: "http://myapp:8080"
42-
43+
4344
""";
4445

4546
public const string ProjectOneDeployment =
@@ -194,6 +195,7 @@ public static class ExpectedValues
194195
component: "myapp"
195196
stringData:
196197
param1: "{{ .Values.secrets.myapp.param1 }}"
198+
param3: "{{ .Values.secrets.myapp.param3 }}"
197199
ConnectionStrings__cs: "Url={{ .Values.config.myapp.param0 }}, Secret={{ .Values.secrets.myapp.param1 }}"
198200
type: "Opaque"
199201

tests/Aspire.Hosting.Kubernetes.Tests/KubernetesPublisherTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public async Task PublishAsync_GeneratesValidHelmChart(string expectedFile)
4848
var param0 = builder.AddParameter("param0");
4949
var param1 = builder.AddParameter("param1", secret: true);
5050
var param2 = builder.AddParameter("param2", "default", publishValueAsDefault: true);
51+
var param3 = builder.AddResource(ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, "param3"));
5152
var cs = builder.AddConnectionString("cs", ReferenceExpression.Create($"Url={param0}, Secret={param1}"));
5253

5354
// Add a container to the application
@@ -57,6 +58,7 @@ public async Task PublishAsync_GeneratesValidHelmChart(string expectedFile)
5758
.WithEnvironment("param0", param0)
5859
.WithEnvironment("param1", param1)
5960
.WithEnvironment("param2", param2)
61+
.WithEnvironment("param3", param3)
6062
.WithReference(cs)
6163
.WithVolume("logs", "/logs")
6264
.WithArgs("--cs", cs.Resource);

0 commit comments

Comments
 (0)