其他分享
首页 > 其他分享> > screct

screct

作者:互联网

一  对于一些保密度比较高的文件,k8s又是如何存储的呢?

 

  针对那些保密度比较高的配置文件,例如证书以及一些认证配置不能直接存储在configmap中,而是需要存储在另外一种资源中,需要对存储在里面的数据进行加密,并且只会调度到需要的pod上面,在pod上面所在的节点上,secerts卷并不会存储在硬盘等设备上,而是需要存储在node上面的内存中,这样就不需要擦拭来提高保密性,同样的secrets和configmap类似,支持两种数据渲染到pod中的容器

  另外一点需要注意的是,对于主节点本身,secerts是按照明文的形式进行存储,这就需要保障主节点安全从而确保存储在secerts的数据安全性,同样需要保障的一点是禁止未被授权的用户访问主节点服务器,因为在没有确实授权之前,任何用户都可以通过pod拉去secerts数据并可能造成数据暴露因此是将数据存储到configmap或者secert是需要认真考虑的一件事情

 

二  secrets的相关应用和创建

  

    2.1  来看一个pod中默认的令牌

[root@node01 ~]# k get secrets
NAME                  TYPE                                  DATA   AGE
default-token-tzwwt   kubernetes.io/service-account-token   3      15d


[root@node01 ~]# k describe secrets
Name:         default-token-tzwwt
Namespace:    default
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: default
              kubernetes.io/service-account.uid: 61b7be2c-433e-11eb-90ae-5254002a5691

Type:  kubernetes.io/service-account-token

Data
====
namespace:  7 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tdHp3d3QiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjYxYjdiZTJjLTQzM2UtMTFlYi05MGFlLTUyNTQwMDJhNTY5MSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.zwEvc13whMJW7MaCcDpXkpLmQsi2qfih-OUiNAVt8gwqZ9KWmFOj7Qye_vtzeYhc1m3YyM6YkCTjCtKqTUX28P0Y50-_Pl_0fQKrm2BTb7fGIskRwB4egFiwMZmcgzqUr4CHuvINdb339mYp8eYqpf1Io51fFKmLRwE3U1zWLRFod_QP-eBxlSCq5O76BtPjkH0egWvEgScao5tYJLw-tFMdkhyeFpJCoVdjf4plxi5yFYdxP86kc0jjtW9x9Z6LBKVhTC18_cQawG24UgOAjwZW4TF4v5y25Me4G3itTTVx_IKx8M6ndK5MrerFGCZoppFeSJdFr_TFyuWgcznuTw
ca.crt:     1025 bytes

 

  2.2  查看该默认的secrets挂载pod中的位置

[root@node01 ~]# k exec test-for-all-env-from-configmap -- ls -Alrt /var/run/secrets/kubernetes.io/serviceaccount
total 0
lrwxrwxrwx. 1 root root  12 Jan  4 13:51 token -> ..data/token
lrwxrwxrwx. 1 root root  16 Jan  4 13:51 namespace -> ..data/namespace
lrwxrwxrwx. 1 root root  13 Jan  4 13:51 ca.crt -> ..data/ca.crt
lrwxrwxrwx. 1 root root  31 Jan  4 13:51 ..data -> ..2021_01_04_13_51_29.048076121
drwxr-xr-x. 2 root root 100 Jan  4 13:51 ..2021_01_04_13_51_29.048076121

 

  2.3  创建一个secrets

[root@node01 Chapter07]# openssl genrsa -out https.key 2048
Generating RSA private key, 2048 bit long modulus

[root@node01 Chapter07]# openssl req -new -x509 -key https.key -out https.cert -days 3650 -subj /CN=www.kubia-example.com

[root@node01 Chapter07]# echo wxm-test>wxm-test

[root@node01 Chapter07]# k create secret generic fortune-https --from-file=https.cert --from-file=https.key --from-file=wxm-test
secret/fortune-https created

[root@node01 Chapter07]# k get secret
NAME                  TYPE                                  DATA   AGE
default-token-tzwwt   kubernetes.io/service-account-token   3      15d
fortune-https         Opaque                                3      24s

 

  2.4 对比configmap以及secret

    

    2.4.1 通过yaml的形式查看刚才创建的secret    

[root@node01 Chapter07]# k get secret fortune-https -o yaml
apiVersion: v1
data:
  https.cert: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURFekNDQWZ1Z0F3SUJBZ0lKQU5jQk83ZW0wYk5pTUEwR0NTcUdTSWIzRFFFQkN3VUFNQ0F4SGpBY0JnTlYKQkFNTUZYZDNkeTVyZFdKcFlTMWxlR0Z0Y0d4bExtTnZiVEFlRncweU1UQXhNRFV3TkRBMk1EUmFGdzB6TVRBeApNRE13TkRBMk1EUmFNQ0F4SGpBY0JnTlZCQU1NRlhkM2R5NXJkV0pwWVMxbGVHRnRjR3hsTG1OdmJUQ0NBU0l3CkRRWUpLb1pJaHZjTkFRRUJCUUFEZ2dFUEFEQ0NBUW9DZ2dFQkFLdkNkUFFHRWlJaElwZ0ZDRkU2U21oZFJ5ODMKaldoRDZPZUtLcndNcms1cWMweWUrSmg5N3lqRHY4Q3NtbGFpZWJPZjZXTUN0L1Z2ajhPWVhsZUR2K2xFclNPVgo0Y0NnR3Qvd1B3SmJQSS9WcUhoR1ZPUGVHM0RTcFpGaUpPSWJOUTkyK1N5SWZyWUVUeDRYSGlNKzRQcWVVeGh2CmtqaGxUZXFqZ0wrOVJHQlFZa1ROZDBlUlJ1cnRGbkRUYnFZOFVSbmdieVVGVkVVcnM5ODB5OGtxK1pucmZIQ1cKS2Y2VjQwRUVxNlh0eXd0RElaQnlUMGJGZWlMbi9iTVF3Z1hFOEUwRzNvZmU3NFFUWjZicmFYNFNLVVovaUIxSgpiV1pQSkJVS3B3ZmdNN2Rlamo4ZGsvRW9WaXE3VnZqQTdxYTdGQkJqSURSZ2txKzNPSnQvNndCWmc0VUNBd0VBCkFhTlFNRTR3SFFZRFZSME9CQllFRkQ1Rld5VUtDZHA2SVpGaWlSQnpTclprbnpqVU1COEdBMVVkSXdR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Ws4MHpObmpoUmh3WnBkdEJWY0NnWUFiclhqdEl5VVpRZWx3anpzeStvaTEKS056S2lqalR1V0ZSc3FCZTlLQ1F1NjE0U010dU9VU0RSZGVVczhmelNEN3FtbWYyWHVudysyNjgycml3YlZzZwpNUEZkTFJmNG9meGExenVVZGhYZEtmY0p1TktYbFU3aVlzeTVMNm9SNFlFYjE2b2EzeTd4cVR0cENVeDh1LzRsCndRRkVtbkxzMHh3MUZqRjdKNXlwdXdLQmdRQ1NOVjRaUGJuUlRjZjVnWEQyVW1VUDNiVFBGbGNQc2JRYmdzbVQKcm1GU0RLN1pYRUs2Z2tES3dwQ1FzWC9jdVZINTczVTljQ1o3T0YwVzVzRmFLRXlhcmtPUjB4U1N1aTZKeEV0TApaTmppaHZOMDZBVG1kY28zUHhKbXlkZTdYem8vZ2xhRXZjUENDNFYrVmRqUjVuTy9JSE50Zmxsak1XTVNHc1JHCmxPTjg5d0tCZ1FDMk5YTG9KeGk4OWt4aUg1Q05ENjJ5dzEwMGNvallsVEVvNVZoU1dMeFRqc1VzcUg1T0RGUTYKZ0NORVBRcHFJNWtNa1NsMUtHdVloSnY5L1ZyckpvMi9QalJ0RGMyaXdMdzFlaU5sQmZ1dDdXOHZWeHhrY21EaApNb21GRjdBUklqQ1VHc1ZnVmJWRElNZkE5VmpMSTNhTitGWGhsdVI1U1dtUWZydzloQ2Q4dWc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
  wxm-test: d3htLXRlc3QK
kind: Secret
metadata:
  creationTimestamp: "2021-01-05T04:08:43Z"
  name: fortune-https
  namespace: default
  resourceVersion: "2145910"
  selfLink: /api/v1/namespaces/default/secrets/fortune-https
  uid: b3435209-4f0b-11eb-ae9a-5254002a5691
type: Opaque

 

标签:screct,secrets,存储,token,https,pod,root
来源: https://www.cnblogs.com/wxm-pythoncoder/p/14235048.html