我有一个不安全的K8S集群安装程序:CoreOS alpha镜像+ Vagrant(自定义解决方案遵循K8S临时设置的入门指南)。现在,我想为可以通过kubectl cluster-info
命令等访问API的K8s集群管理员设置身份验证。我想设置类似design doc-简单配置文件的内容。
然后,我跟随authentication文档,选择了客户端证书身份验证作为身份验证插件。
我准备了certs,保存了/srv/kubernetes/ca.crt
,
主节点上的/srv/kubernetes/server.crt
和/srv/kubernetes/server.key
。
我还按照指南设置了kubeconfig
文件。
kubectl config set-cluster $CLUSTER_NAME --certificate-authority=$CA_CERT --embed-certs=true --server=https://$MASTER_IP
kubectl config set-credentials $CLUSTER_NAME --client-certificate=$CLI_CERT --client-key=$CLI_KEY --embed-certs=true --token=$TOKEN
kubectl config set-context $CLUSTER_NAME --cluster=$CLUSTER_NAME --user=admin
kubectl config use-context $CONTEXT --cluster=$CONTEXT
当api-server启动时,它也使用相同的值。参见
$CA_CERT
,$CLI_CERT
,$CLI_KEY
。 Q1:那些副词在正确的位置?/kube-apiserver \
--allow_privileged=true \
--bind_address=0.0.0.0 \
--secure_port=6443 \
--kubelet_https=true \
--service-cluster-ip-range=${SERVICE_CLUSTER_IP_RANGE} \
--etcd_servers=$ETCD_SERVER \
--service-node-port-range=${SERVICE_NODE_PORT_RANGE} \
--cluster-name=$CLUSTER_NAME \
--client-ca-file=$CA_CERT \
--tls-cert-file=$CLI_CERT \
--tls-private-key-file=$CLI_KEY \
--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota \
--logtostderr=true
日志如下
Aug 30 06:31:30 kube-master docker[3706]: E0830 06:31:30.373083 1 reflector.go:136] Failed to list *api.ResourceQuota: Get http://127.0.0.1:8080/api/v1/resourcequotas: dial tcp 127.0.0.1:8080: connection refused
Aug 30 06:31:30 kube-master docker[3706]: E0830 06:31:30.373523 1 reflector.go:136] Failed to list *api.Secret: Get http://127.0.0.1:8080/api/v1/secrets?fieldSelector=type%3Dkubernetes.io%2Fservice-account-token: dial tcp 127.0.0.1:8080: connection refused
Aug 30 06:31:30 kube-master docker[3706]: E0830 06:31:30.373631 1 reflector.go:136] Failed to list *api.ServiceAccount: Get http://127.0.0.1:8080/api/v1/serviceaccounts: dial tcp 127.0.0.1:8080: connection refused
Aug 30 06:31:30 kube-master docker[3706]: E0830 06:31:30.373695 1 reflector.go:136] Failed to list *api.LimitRange: Get http://127.0.0.1:8080/api/v1/limitranges: dial tcp 127.0.0.1:8080: connection refused
Aug 30 06:31:30 kube-master docker[3706]: E0830 06:31:30.373748 1 reflector.go:136] Failed to list *api.Namespace: Get http://127.0.0.1:8080/api/v1/namespaces: dial tcp 127.0.0.1:8080: connection refused
Aug 30 06:31:30 kube-master docker[3706]: E0830 06:31:30.373788 1 reflector.go:136] Failed to list *api.Namespace: Get http://127.0.0.1:8080/api/v1/namespaces: dial tcp 127.0.0.1:8080: connection refused
Aug 30 06:31:30 kube-master docker[3706]: [restful] 2015/08/30 06:31:30 log.go:30: [restful/swagger] listing is available at https://10.0.2.15:6443/swaggerapi/
Aug 30 06:31:30 kube-master docker[3706]: [restful] 2015/08/30 06:31:30 log.go:30: [restful/swagger] https://10.0.2.15:6443/swaggerui/ is mapped to folder /swagger-ui/
Aug 30 06:31:30 kube-master docker[3706]: I0830 06:31:30.398612 1 server.go:441] Serving securely on 0.0.0.0:6443
Aug 30 06:31:30 kube-master docker[3706]: I0830 06:31:30.399042 1 server.go:483] Serving insecurely on 127.0.0.1:8080
在我的 MacOS 机器上,我想将
kubectl
连接到我的 $ CLUSTER_NAME 群集。export KUBERNETES_MASTER=http://172.17.8.100:6443
kubectl cluster-info
终端输出:
➜ kubectl cluster-info
error: couldn't read version from server: Get http://172.17.8.100:6443/api: malformed HTTP response "\x15\x03\x01\x00\x02\x02"
这是我在MacOS机器上的
kubeconfig
文件~/.kube/config
➜ kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: REDACTED
server: http://172.17.8.100:6443
name: kube-01
contexts:
- context:
cluster: kube-01
user: admin
name: kube
current-context: kube
kind: Config
preferences: {}
users:
- name: admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
token: cxKranwtWI2nyASebbF1HV3p1EWJbNcE
问:在MacOS上,我的
kubectl
如何安全地访问我的K8S集群?由于我从未在api服务器上添加用户admin
,因此我假设所有身份验证均由ca-file
完成? 问:修复安全登录问题后,如何更新上面的
admission-control
连接拒绝之类的ServiceAccount
插件api错误问题? 问:我使用
http
还是https
?我更喜欢使用http://IP:6443
,不确定是否是问题所在? 问:是否需要应用
--token-auth-file=
或--basic-auth-file
?通过阅读文档,我认为我可以选择一种身份验证方法。我更喜欢用ca
来做,这更安全,对吗? 我使用
see function create-certs in cluster/gce/util.sh
生成了certs
文件。我对certs
和keys
不太熟悉,因此我将其发布在这里。好吧,它实际上是一个用于测试的虚拟certs
和keys
。它没有在任何地方使用。只需在此处发布以确认我在这里做错了什么。ca.crt
----- BEGIN证书-----
MIIDWTCCAkGgAwIBAgIJAMbTBaUcQSbGMA0GCSqGSIb3DQEBCwUAMCIxIDAeBgNV
BAMMFzE3Mi4xNy44LjEwMEAxNDQwNzgwMjgxMB4XDTE1MDgyODE2NDQ0MVoXDTI1
MDgyNTE2NDQ0MVowIjEgMB4GA1UEAwwXMTcyLjE3LjguMTAwQDE0NDA3ODAyODEw
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDNmT0O8sBXTd2Htbb + hnsq
P / YvUNYTXzLy6 + T / d9 / KRrxq1JWO70E7L2hFOvOdGF0gZuoAefki5ymkFYfwoZsK
NEXvA1AxBMtQnMCdUOp7m5XW + c9uFepW + jzvb4PRBoUHZjW5HhxT6UZ21FiEvwHP
NBnCL9gp1NIcNOaUIZvFI7hpko0tfAPFYY0NkHRo6mLpvzaGTippzySMSLyQ7cs4
IcUrFGJbsTNISCSsCG // + A6I62sQAURr0hjeW9FmGHxwYW + 0wdyyTtlFPTKrVrC4
ETc5WeQoJeZhjoH7Dkj8l6QBvv2cDtZwnY2oCUGXf63c3hoRaEkeFis1RWQcQKoT
AgMBAAGjgZEwgY4wHQYDVR0OBBYEFONIYbWt3l9D5j9VvJADUQfmIBpQMFIGA1Ud
IwRLMEmAFONIYbWt3l9D5j9VvJADUQfmIBpQoSakJDAiMSAwHgYDVQQDDBcxNzIu
MTcuOC4xMDBAMTQ0MDc4MDI4MYIJAMbTBaUcQSbGMAwGA1UdEwQFMAMBAf8wCwYD
VR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQCJtrf1Mf + pHwCsMG8HPcuR4oij
ugYkzawEF2FSCe2VbFMDxwmHbHw2N9ZOwRLyeSuR0JAY5aN31pqIzYCmmKf2otKU
+ mtTaK5YIsZU2IdxoR6VHaHT83zSGq9RhteqDdM8tuMvNsV5I9pJCu + Bkv3MsJpN
0PIc + GFs52A + bQC3cjWqLkgJeYEqolNnJpeex9G3ovqbTzavgM8q5gjdTyz8tDIo
Dc4RKcuwyrAnkiJ93HdWLwkKcEXzrX / lU9NYsvmycBVbkRaIh7md82HCUiwkmmJC
Xz3 + xVrghzMo0DgoInzxcPFRWPc00CZcb5P5VRepa2rPwEyNgEp3BsQLXFIt
-----结束证书-----
server.crt
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=172.17.8.100@1440780281
Validity
Not Before: Aug 28 16:44:41 2015 GMT
Not After : Aug 25 16:44:41 2025 GMT
Subject: CN=kube-master
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (2048 bit)
Modulus (2048 bit):
00:ab:3f:cf:95:50:3d:7f:b4:82:ba:72:7a:88:2e:
41:79:67:7d:9a:4a:22:27:5f:fd:5c:78:6f:3d:ad:
57:4c:fd:37:9e:b5:35:f1:88:59:c1:e9:10:38:3e:
de:7f:57:cf:e9:fc:fd:d7:b5:a8:7a:0e:5f:e4:16:
6f:2a:66:98:28:6c:42:a8:5f:95:3d:0b:02:f2:ec:
ab:aa:19:40:60:b3:e5:7a:64:7d:5b:f2:9c:84:d5:
bb:06:79:e7:00:2f:2c:a0:0a:88:f4:b0:c5:31:de:
7d:30:d6:b3:4d:ea:64:85:bb:f9:89:5a:f5:22:41:
92:35:d4:a4:7d:80:64:65:d9:1d:c9:30:39:af:34:
57:cd:d5:56:5d:9f:35:5d:ee:a3:07:ed:f1:c5:68:
db:db:12:65:31:e6:6c:1e:77:44:3e:7c:03:bc:89:
f0:4c:14:a6:41:39:22:a3:a3:a0:8d:20:eb:69:7a:
c5:de:b0:2f:94:67:68:ab:8c:8a:24:59:38:a4:57:
19:2d:c2:0e:37:c8:73:98:ae:d8:0a:a4:e2:72:22:
49:9a:55:58:ad:8e:c3:eb:42:b5:41:02:c9:40:27:
d1:77:41:ab:4f:0b:2a:6b:b2:b6:38:7f:a0:ce:cf:
9f:cd:7c:54:72:c6:43:cd:1d:5b:60:b9:45:eb:10:
ab:ad
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Subject Key Identifier:
B2:46:5F:5A:68:3E:08:78:25:8C:AE:5E:EB:F1:3B:7B:CF:9D:A6:F3
X509v3 Authority Key Identifier:
keyid:E3:48:61:B5:AD:DE:5F:43:E6:3F:55:BC:90:03:51:07:E6:20:1A:50
DirName:/CN=172.17.8.100@1440780281
serial:C6:D3:05:A5:1C:41:26:C6
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
IP Address:172.17.8.100, IP Address:10.100.0.1, DNS:kubernetes, DNS:kubernetes.default, DNS:kubernetes.default.svc, DNS:kubernetes.default.svc.cluster.local, DNS:kube-master
Signature Algorithm: sha256WithRSAEncryption
58:b1:63:41:3e:94:ed:3d:bd:3c:e8:0c:78:30:54:c1:6d:33:
00:42:74:c8:7a:64:cc:fd:9a:70:ab:38:5b:1c:92:7c:9b:56:
1a:d7:fd:38:51:07:cf:5a:b5:0a:11:85:01:3d:52:86:96:ad:
16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8A2WGo3EgtV1C4nAv1MaECgYAp0GP6IEB754wtLyB + gxFFpL8OPlwcgfhiJK2J
wIlOsOrMTutKAcOyewXvmt0qA7yd + 9izK8BKxj74SmHYqdRYWoKzDxj8Zn + U4Fkz
DTeHxRxkxN7KgKiUh274gqkWmrzKzXHg8qpVZ6fFciTfrmPgYwwjS1Vr5SzDBTFr
y7e1owKBgQDMKHPuEE9LT3ljiZFIoU6yxbWU / + rMaJwqmV5bEXbfrL06PjTw7kp /
UnLHJ3TVdCXnY2J4Si39cYAhL5Wr5JiubviaW5zCjjOXbrE3ck16kkJsS8DOXjHT
nHNGV48GE51THWl / NbuRQz / rD9McsCwixNm66C2EiakKuKLuv3tI3Q ==
-----结束RSA私钥-----
最佳答案
我认为您可能遇到了我刚解决的完全相同的问题。我相信是您在#google-containers上问了类似的问题,而用户“vishh”说的话为我解决了这个问题。确保您的主IP /主机名位于证书的Subject Alternative Name:
部分下用于api服务器的证书中。
$ openssl x509 -in kube-apiserver-server.pem -text -noout
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
1d:60:b0:98:70:95:23:f8
Signature Algorithm: sha256WithRSAEncryption
...
...
...
X509v3 Subject Alternative Name:
DNS:*.kubestack.io, DNS:*.c.kubestack.internal, IP Address:127.0.0.1, IP Address:192.168.10.50
我对证书和密钥的经验很少,因此我使用了here指南来生成我的证书。
您不需要使用任何其他身份验证标志( token /基本),这是通过您假设的证书完成的。
指定服务器时,需要使用http 和。
我不确定您的入学控制问题。
希望这可以帮助。
关于kubernetes - K8S是否可以通过MacOS终端上的kubectl安全访问API服务器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32294007/