【问题标题】:SprintBoot - Unable to disable sensitive metricsSpring Boot - 无法禁用敏感指标
【发布时间】:2017-05-24 20:30:30
【问题描述】:

我目前在一个 K8S 集群中工作,我暴露了以下端点。

http://172.16.46.16:8080/websocket/metrics

现在我拥有的应用程序与 Sprint Boot 相关。为了点击这个 URL,它目前是敏感的,这意味着它需要一个用户名/密码。

根据documentation,我可以关闭metrics上的敏感功能,这样我就不需要用户名/密码来授权自己了。由于我不想在配置中对此进行硬编码,因此我在运行时传递了所需的参数。

我的 K8S 控制器文件是 ::

# cat websocket-replication-controller.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: websocket-backend-controller
spec:
  replicas: 2
  selector:
    name: websocket-backend
  template:
    metadata:
      labels:
        name: websocket-backend
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/path: /websocket/metrics
        prometheus.io/port: '8080'
    spec:
      containers:
      - name: websocket-backend
        image: armdocker.rnd.ericsson.se/proj_csdp/websocket_backend:3.0.6
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8080
        livenessProbe:
          httpGet:
            port: 8080
            path: /websocket/health
          initialDelaySeconds: 300
          timeoutSeconds: 30
        volumeMounts:
          - name: nfs
            mountPath: "/vault"
        command:
          - java
          - -Duser.timezone=UTC
          - -jar
          - -Dspring.profiles.active=clustered
          - websocket.jar
          - --endpoints.metrics.sensitive=false
      volumes:
        - name: nfs
          nfs:
            server: kube-nfs
            path: "/kubenfs/vault"
            readOnly: true

最终的命令如下:

java -Duser.timezone=UTC -jar -Dspring.profiles.active=clustered websocket.jar --endpoints.metrics.sensitive=false

以这种方式启动应用程序似乎并没有超越指标敏感行为。我仍然得到server returned HTTP status 401 Unauthorized

我能够访问我的 pod 并查找任何错误,但我没有看到任何错误。

我在这里缺少什么吗?

【问题讨论】:

    标签: spring spring-boot kubernetes spring-boot-actuator prometheus


    【解决方案1】:

    也尝试禁用Spring Security进行管理--management.security.enabled=false,命令:

    java -Duser.timezone=UTC -jar -Dspring.profiles.active=clustered websocket.jar 
         --endpoints.metrics.sensitive=false
         --management.security.enabled=false
    

    在这种情况下,在自定义端口上公开管理端点是个好主意,例如:management.port=9081

    您还可以启用安全性并提供默认用户和密码:

    management.security.enabled=true
    security.user.name=user
    security.user.password=pa55word
    

    请阅读 Spring 文档:Monitoring and management over HTTP

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 2012-09-02
      • 2018-03-26
      • 2016-07-24
      • 2016-03-27
      • 2016-07-21
      相关资源
      最近更新 更多