大网数据广告活动
服务器运维问答

How to disable kubectl insecure approval towards the kube apiserver

· 52CE 我爱测

I am trying to make my Master Server-API more secure in order to avoid allowing non https requests to go through. Sample of config: $ kubectl config view apiVersion: v1 clusters: - cluster: server: https://ip:6443 name: kubernete…

问题原文

原帖链接 · Thanos · CC BY-SA 4.0

I am trying to make my Master Server-API more secure in order to avoid allowing non https requests to go through.

Sample of config:

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    server: https://ip:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
    token: REDACTED

Which works as long as I am using the correct CAs.

My problem is it also works if I remove the CAs or I have wrongly CAs and simply I apply the flag --insecure-skip-tls-verify.

How can I force the server to allow https connections instead of http on the Server-API?

I have also disabled anonymous requests Anonymous requests but I can still see the requests can pass through.

已采纳解答

原帖链接 · PjoterS · CC BY-SA 4.0

My problem is it also works if I remove the CAs or I have wrongly CAs and simply I apply the flag --insecure-skip-tls-verify.

Using --insecure-skip-tls-verify is highly NOT RECOMMENDED in production environment. It can be used when you want to do some local tests or for learning purpose.

In Kubectl documentation you have information:

--insecure-skip-tls-verify

If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure

So, if this flag will be set as true, it will always skip certs and identity of server is not checked at all. It's similar to curl -k

-k, --insecure
              (TLS) By default, every SSL connection curl makes is verified to
              The  server  connection  is verified by making sure the server's
              interface name, IP address or host name.

You can secure your cluster in many ways but it depends on scenario. However, there are some main API server ports and IPs concepts:

Use SecurePort

By default the Kubernetes API server serves HTTP on 2 ports:

  1. localhost port:
  • is intended for testing and bootstrap, and for other components of the master >node (scheduler, controller-manager) to talk to the API
  • no TLS
  • Disable insecure http connections: default is port 8080, change with --insecure-port flag. (It can be disabled by --insecure-port=0)
  • default IP is localhost, change with --insecure-bind-address flag. (Remove --insecure-bind-address)
  • request bypasses authentication and authorization modules.
  • request handled by admission control module(s).
  • protected by need to have host access
  1. Secure port:
  • use whenever possible Enable secure port:
  • uses TLS. Set cert with --tls-cert-file and key with --tls-private-key-file flag.
  • default is port 6443, change with --secure-port flag.
  • default IP is first non-localhost network interface, change with --bind-address flag.
  • request handled by authentication and authorization modules.
  • request handled by admission control module(s).
  • authentication and authorization modules run.

Restrict API access, meaning you should allow access to your api only from specific IP or specific IP range (authorized networks). It shouldn't be accessible from the outside of the world. To do it, you may use firewall rules or Network Policy.

Turn off Anonymouse Requests, which you already did.

You can look into --insecure-port=0, however it should be deprecated in newer versions.

As an additional information, I would advise you to check Kubernetes The Hard Way, especially 3 chapters: Provisioning Compute Resources, Provisioning the CA and Generating TLS Certificates, Generating Kubernetes Configuration Files for Authentication. You can find there some best practices.

Very good explanation of the Kube API-server flags you can find in this article

Useful links about Cluster Security:

The Basics of Keeping Kubernetes Clusters Secure - How to secure the kube-apiserver

Controlling Access to the Kubernetes API

Kubernetes security best practices

Kubernetes Security 101: Risks and 29 Best Practices

Controlling Access to the Kubernetes API

Accessing Clusters

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。