前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linkerd 2.10(Step by Step)—暴露 Dashboard

Linkerd 2.10(Step by Step)—暴露 Dashboard

作者头像
为少
发布2021-07-07 11:11:04
9150
发布2021-07-07 11:11:04
举报
文章被收录于专栏:黑客下午茶

Linkerd 2.10 系列

Linkerd 2.10 中文手册持续修正更新中:

  • https://linkerd.hacker-linner.com

您可以通过 ingress 暴露仪表板,而不是每次想要 查看发生了什么时都使用 linkerd viz dashboard。这也会暴露 Grafana。

Nginx

具有 basic auth 的 Nginx

示例 ingress 定义是:

代码语言:javascript
复制
apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: web-ingress-auth
  namespace: linkerd-viz
data:
  auth: YWRtaW46JGFwcjEkbjdDdTZnSGwkRTQ3b2dmN0NPOE5SWWpFakJPa1dNLgoK
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  namespace: linkerd-viz
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    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:
  rules:
    - host: dashboard.example.com
      http:
        paths:
          - backend:
              serviceName: web
              servicePort: 8084

这会在 dashboard.example.com 上暴露仪表板, 并使用 admin/admin 通过 basic auth 对其进行保护。有关如何更改用户名和密码的详细信息,请查看 ingress-nginx 文档。

带有 oauth2-proxy 的 Nginx

basic auth 的一种更安全的替代方法是使用身份验证代理,例如 oauth2-proxy。

有关如何在 kubernetes 中部署和配置 oauth2-proxy 的参考,请参阅 blog post by Don Bowman。

如果您通过 helm chart 部署 oauth2-proxy,则需要以下值:

代码语言:javascript
复制
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-secretcookie-secret

设置后,示例 ingress 将是:

代码语言:javascript
复制
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web
  namespace: linkerd-viz
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    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:
  rules:
    - host: linkerd.example.com
      http:
        paths:
          - backend:
              serviceName: web
              servicePort: 8084

Traefik

示例 ingress 定义是:

代码语言:javascript
复制
apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: web-ingress-auth
  namespace: linkerd-viz
data:
  auth: YWRtaW46JGFwcjEkbjdDdTZnSGwkRTQ3b2dmN0NPOE5SWWpFakJPa1dNLgoK
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  namespace: linkerd-viz
  annotations:
    kubernetes.io/ingress.class: 'traefik'
    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:
  rules:
    - host: dashboard.example.com
      http:
        paths:
          - backend:
              serviceName: web
              servicePort: 8084

这会在 dashboard.example.com 上公开仪表板, 并使用 admin/admin 通过 basic auth 对其进行保护。有关如何更改用户名和密码的详细信息,请查看 Traefik 文档。

Ambassador

Ambassador 的工作原理是将mapping 定义 为服务的 annotation。

下面的 annotation 在 dashboard.example.com 上公开了仪表板。

代码语言:javascript
复制
  annotations:
    getambassador.io/config: |-
      ---
      apiVersion: ambassador/v1
      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 攻击, 仪表板拒绝任何 Host header 不是 localhost127.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 server)使用的验证正则表达式, 该正则表达式通过 enforced-host 容器参数输入到 web deployment 中。

如果您使用 Helm 管理 Linkerd,那么您可以使用 enforcedHostRegexp 值设置主机。

另一种方法是通过 Kustomize,如:自定义安装中所述,使用这样的覆盖:

代码语言:javascript
复制
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 使用空字符串。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-06-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 黑客下午茶 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Linkerd 2.10 系列
  • Nginx
    • 具有 basic auth 的 Nginx
      • 带有 oauth2-proxy 的 Nginx
      • Traefik
      • Ambassador
      • DNS 重绑定保护
        • 调整 Host 要求
        相关产品与服务
        访问管理
        访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档