关于哈希科普·沃尔特,我有一个基本的基本问题。我想把一些秘密(密码到数据库)从Vault向容器注入Spring应用程序。
我为使用Vault和Kubernetes编写了一个特定的注释,所有操作都很好,在环境允许我在application.properties文件中使用的情况下保存密码变量。
template:
metadata:
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "myapp-role"
vault.hashicorp.com/agent-inject-secret-foo: "secret/creds"
vault.hashicorp.com/agent-inject-template-foo: |
{{`{{- with secret "secret/creds" -}}
PASSWORD={{ .Data.passcode }}
{{- end }}`}}
labels:
app.kubernetes.io/name: {{ $appName }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ $appName }}
image: "{{ .Values.vvvv.image.repository }}:{{ .Values.vvvv.image.tag }}"
command: ["/bin/bash", "-c","while read line; do export $line; done < /vault/secrets/foo; /usr/local/tomcat/bin/catalina.sh run"]
volumeMounts:
- name: application-properties
mountPath: /usr/local/tomcat/lib/application.properties
subPath: application.properties
ports:
- name: http
containerPort: 8080
protocol: TCP 这个问题很简单,有道理吗?注入代理在/vault路径中保存带有纯文本密码的文件,这样每个人都可以看到这个秘密.另一个问题是,如何轮换应用程序的凭据?我应该在spring应用程序中使用特定的控制器,对吗?
发布于 2021-04-13 17:43:23
我认为这无疑是有意义的,因为其目的是避免规范中的硬编码凭据。
注入代理在/vault路径中保存带有纯文本密码的文件,这样每个人都可以看到这个秘密。
即使在裸金属服务器或云实例中,凭据也以纯文本形式保存。如果是k8s,它就在一个容器中。在这两种情况下,您将控制谁可以访问您的实例或k8s荚。只有获得授权的人员才能进入生产集群中的吊舱。
如何旋转应用程序的凭据
保险库代理注射器运行一个侧面容器与您的应用程序容器在同一个吊舱。其目的是定期寻找金库秘密中的任何变化。如果您执行了一个kubectl describe po <pod-name>,您将发现一个运行着的sidecar容器vault-agent。
kubectl get po app-example-deployment-7c4b45cf8-4fkr7
NAME READY STATUS RESTARTS AGE
app-example-deployment-7c4b45cf8-4fkr7 2/2 Running 0 166mkubectl describe pod app-example-deployment-7c4b45cf8-4fkr7:
...
vault-agent:
Container ID: docker://b6f9df32ed903d684c972401f41e15a8f6b1bec62aa111bfd9c693159af1ff09
Image: vault:1.7.0
Image ID: docker-pullable://vault@sha256:635cf1c3f9b10fe03aad375f94cc61f63d74a189662165285a8bf1c189ea04b8
Port: <none>
Host Port: <none>
Command:
/bin/sh
-ec
Args:
echo ${VAULT_CONFIG?} | base64 -d > /home/vault/config.json && vault agent -config=/home/vault/config.json
State: Running
Started: Tue, 13 Apr 2021 15:40:10 +0100
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 128Mi
Requests:
cpu: 250m
memory: 64Mi
Environment:
VAULT_LOG_LEVEL: info
VAULT_LOG_FORMAT: standard
...在部署期间成功地从保险库获取秘密之后:
kubectl exec -it app-example-deployment-7c4b45cf8-4fkr7 -c app -- cat /vault/secrets/db-creds
mongodb+srv://testUser:testPass@test-5xxxx.mongodb.net/testDb如果我将Vault中的kv秘密设置为"testPass2",我不需要做任何事情,因为vault-agent侧加容器会自动为我更新它。
kubectl exec -it app-example-deployment-7c4b45cf8-4fkr7 -c app -- cat /vault/secrets/db-creds
mongodb+srv://testUser:testPass2@test-5xxxx.mongodb.net/testDb在vault-agent sidecar容器日志中,您将看到类似的内容。
kubectl logs app-example-deployment-7c4b45cf8-4fkr7 -c vault-agent --follow
2021-04-13T14:40:10.426Z [INFO] sink.file: creating file sink
2021-04-13T14:40:10.426Z [INFO] sink.file: file sink configured: path=/home/vault/.vault-token mode=-rw-r-----
==> Vault agent started! Log data will stream in below:
==> Vault agent configuration:
Cgo: disabled
Log Level: info
Version: Vault v1.7.0
Version Sha: 4e222b85c40a810b74400ee3c54449479e32bb9f
2021-04-13T14:40:10.426Z [INFO] template.server: starting template server
[INFO] (runner) creating new runner (dry: false, once: false)
2021-04-13T14:40:10.427Z [INFO] auth.handler: starting auth handler
2021-04-13T14:40:10.427Z [INFO] auth.handler: authenticating
2021-04-13T14:40:10.427Z [INFO] sink.server: starting sink server
[INFO] (runner) creating watcher
2021-04-13T14:40:10.437Z [INFO] auth.handler: authentication successful, sending token to sinks
2021-04-13T14:40:10.437Z [INFO] auth.handler: starting renewal process
2021-04-13T14:40:10.437Z [INFO] template.server: template server received new token
[INFO] (runner) stopping
[INFO] (runner) creating new runner (dry: false, once: false)
[INFO] (runner) creating watcher
[INFO] (runner) starting
2021-04-13T14:40:10.437Z [INFO] sink.file: token written: path=/home/vault/.vault-token
2021-04-13T14:40:10.439Z [INFO] auth.handler: renewed auth token
[INFO] (runner) rendered "(dynamic)" => "/vault/secrets/db-creds"
2021-04-13T15:23:43.315Z [INFO] auth.handler: renewed auth token
[INFO] (runner) rendered "(dynamic)" => "/vault/secrets/db-creds"
2021-04-13T16:07:16.191Z [INFO] auth.handler: renewed auth tokenhttps://stackoverflow.com/questions/67029078
复制相似问题