【发布时间】:2021-10-22 01:19:35
【问题描述】:
我有一个 .net core 应用程序,它是 dockerized 并在 Kubernetes 集群 (AKS) 中运行。
我想应用 securityContext readOnlyRootFilesystem = true 来满足Immutable (read-only) root filesystem should be enforced for containers 的要求。
安全上下文: 特权:假 readOnlyRootFilesystem: true
对于.net core app,我想读取 TLS 证书并想添加到 POD/Container 的证书存储中并在启动时执行此操作,我有以下代码,
var cert = new X509Certificate2(Convert.FromBase64String(File.ReadAllText(Environment.GetEnvironmentVariable("cert_path"))));
AddCertificate(cert, StoreName.Root);
问题是当我设置readOnlyRootFilesystem = true 时,应用程序出现以下错误,
异常:System.Security.Cryptography.CryptographicException:无法将 X509 证书添加到存储区。 ---> System.IO.IOException: 只读文件系统 在 System.IO.FileSystem.CreateDirectory(String fullPath)
这是说只读文件系统我不能添加证书。有没有办法克服这个问题?
更新
如果我设置emptyDir: {},我会遇到错误吗?我可以在哪里添加它?
spec.template.spec.volumes[0].csi: Forbidden: may not specify more than 1 volume type
volumeMounts:
- name: secrets-store
mountPath: /app/certs
securityContext:
privileged: false
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
volumes:
- name: secrets-store
emptyDir: {}
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: azure-kvname
【问题讨论】:
-
programmerq的解决方案对你有帮助吗?
-
没有。我将秘密卷与 CSI 驱动程序结合使用。如果我尝试添加 mptyDir: {}。它给出错误:spec.template.spec.volumes[0].csi: Forbidden: may not specify more than 1 volume type
-
检查我的问题的
update部分。
标签: c# kubernetes asp.net-core-3.1 azure-aks