配置kubernetes服务basic auth

  

  因为一些内部服务访问并不须要鉴权,如kubernetes-dashboard、traefik-ui,因此当咱们想经过外网域名访问的时候会有安全问题。这里咱们能够为服务配置basic auth,访问时须要验证,如下是配置过程:web

 

1. 建立用户密码文件

  这里咱们使用htpasswd建立加密过的密码文件。api

# htpasswd -bc basic-auth-secret username password

 

2. 建立Kubernetes Secret

# kubectl create secret generic basic-auth --from-file=basic-auth-secret --namespace=kube-system

 

3. 部署服务Ingress使其使用basic auth

 经过在Ingress中添加鉴权annotation实现服务basic auth。这里须要注意:安全

  • Secret文件必须与Ingress规则在同一命名空间。
  • 目前只支持basic authentication。
  • Realm不可配置,默认使用traefik。
  • Secret必须只包含一个文件。
apiVersion: v1
kind: Service
metadata:
  name: traefik-web-ui
  namespace: kube-system
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
  - port: 80
    targetPort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: traefik-web-ui
  namespace: kube-system
  annotations:
kubernetes.io/ingress.class: traefik ingress.kubernetes.io/auth-type: basic ingress.kubernetes.io/auth-secret: basic-auth spec: rules: - host: traefik-ui.domain.com http: paths: - backend: serviceName: traefik-web-ui servicePort: 80

  

相关文章
相关标签/搜索