16. 公开 Dashboard
您可以通过 ingress
公开 dashboard
,而不是每次想要
查看发生了什么时都使用 linkerd viz dashboard
。
这也会公开 Grafana
。
Nginx
具有 basic auth 的 Nginx
示例 ingress 定义是:
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: web-ingress-auth
namespace: linkerd-viz
data:
auth: YWRtaW46JGFwcjEkbjdDdTZnSGwkRTQ3b2dmN0NPOE5SWWpFakJPa1dNLgoK
---
# apiVersion: networking.k8s.io/v1beta1 # for k8s < v1.19
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
namespace: linkerd-viz
annotations:
nginx.ingress.kubernetes.io/upstream-vhost: $service_name.$namespace.svc.cluster.local:8084
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Origin "";
proxy_hide_header l5d-remote-ip;
proxy_hide_header l5d-server-id;
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: web-ingress-auth
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
spec:
ingressClassName: nginx
rules:
- host: dashboard.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8084
这会在 dashboard.example.com
上公开 dashboard
,
并使用 admin/admin
通过 basic auth
对其进行保护。
有关如何更改用户名
和密码
的详细信息,请查看 ingress-nginx 文档。
Nginx with oauth2-proxy
basic auth
的一种更安全的替代方法是使用身份验证代理,例如
oauth2-proxy。
有关如何在 kubernetes
中部署和配置 oauth2-proxy
的参考,请参阅 blog post by Don
Bowman。
如果您通过 helm
chart 部署 oauth2-proxy
,则需要以下值:
config:
existingSecret: oauth2-proxy
configFile: |-
email_domains = [ "example.com" ]
upstreams = [ "file:///dev/null" ]
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
path: /oauth2
ingress:
hosts:
- linkerd.example.com
其中 oauth2-proxy
secret 将包含所需的 oauth2
config,
例如 client-id
client-secret
和 cookie-secret
。
设置后,示例 ingress
将是:
# apiVersion: networking.k8s.io/v1beta1 # for k8s < v1.19
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
namespace: linkerd-viz
annotations:
nginx.ingress.kubernetes.io/upstream-vhost: $service_name.$namespace.svc.cluster.local:8084
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Origin "";
proxy_hide_header l5d-remote-ip;
proxy_hide_header l5d-server-id;
nginx.ingress.kubernetes.io/auth-signin: https://$host/oauth2/start?rd=$escaped_request_uri
nginx.ingress.kubernetes.io/auth-url: https://$host/oauth2/auth
spec:
ingressClassName: nginx
rules:
- host: linkerd.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8084
Traefik
示例 ingress
定义是:
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: web-ingress-auth
namespace: linkerd-viz
data:
auth: YWRtaW46JGFwcjEkbjdDdTZnSGwkRTQ3b2dmN0NPOE5SWWpFakJPa1dNLgoK
---
# apiVersion: networking.k8s.io/v1beta1 # for k8s < v1.19
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
namespace: linkerd-viz
annotations:
ingress.kubernetes.io/custom-request-headers: l5d-dst-override:web.linkerd-viz.svc.cluster.local:8084
traefik.ingress.kubernetes.io/auth-type: basic
traefik.ingress.kubernetes.io/auth-secret: web-ingress-auth
spec:
ingressClassName: traefik
rules:
- host: dashboard.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8084
这会在 dashboard.example.com
上公开 dashboard
,
并使用 admin/admin
通过 basic auth
对其进行保护。
有关如何更改用户名和密码的详细信息,请查看 Traefik 文档。
Ambassador
Ambassador
的工作原理是将mapping
定义
为服务的 annotation
。
下面的 annotation
在 dashboard.example.com
上公开了 dashboard
。
annotations:
getambassador.io/config: |-
---
apiVersion: getambassador.io/v2
kind: Mapping
name: web-mapping
host: dashboard.example.com
prefix: /
host_rewrite: web.linkerd-viz.svc.cluster.local:8084
service: web.linkerd-viz.svc.cluster.local:8084
DNS 重绑定保护
为防止 DNS-rebinding 攻击,
Dashboard
拒绝任何 Host
header 不是 localhost
、127.0.0.1
或
服务名称不是 web.linkerd-viz.svc
的请求。
请注意,此保护还涵盖 Grafana dashboard。
上面的 ingress-nginx
配置使用
nginx.ingress.kubernetes.io/upstream-vhost
annotation 来正确设置上游 Host
header。
另一方面,Traefik
不提供该选项,因此您必须手动设置所需的 Host
,如下所述。
调整 Host 要求
如果您的 HTTP
客户端(Ingress
或其他方式)不允许重写 Host
header,
您可以更改 dashboard
服务器使用的验证正则表达式,
该正则表达式通过 enforced-host
容器参数输入到 web
deployment 中。
如果您使用 Helm
管理 Linkerd
,那么您可以使用 enforcedHostRegexp
值设置主机。
另一种方法是通过 Kustomize
,
如自定义安装中所述,使用这样的覆盖:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
template:
spec:
containers:
- name: web
args:
- -linkerd-controller-api-addr=linkerd-controller-api.linkerd.svc.cluster.local:8085
- -linkerd-metrics-api-addr=metrics-api.linkerd-viz.svc.cluster.local:8085
- -cluster-domain=cluster.local
- -grafana-addr=grafana.linkerd-viz.svc.cluster.local:3000
- -controller-namespace=linkerd
- -viz-namespace=linkerd-viz
- -log-level=info
- -enforced-host=^dashboard\.example\.com$
如果您想完全禁用 Host
header 检查,只需为 -enforced-host
使用一个 catch-all(捕获所有)
的正则表达式 .*
。