Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: add support for secure serving #4297

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

zhangzujian
Copy link
Member

@zhangzujian zhangzujian commented Jul 16, 2024

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes

Without secure serving:

$ curl -i http://172.19.0.2:10661/metrics
HTTP/1.1 200 OK
Content-Type: text/plain; version=0.0.4; charset=utf-8; escaping=values
Date: Wed, 17 Jul 2024 09:56:16 GMT
Transfer-Encoding: chunked

# metrics...

With secure serving:

$ curl -ik https://172.19.0.2:10661/metrics
HTTP/2 403
cache-control: no-cache, private
content-type: application/json
x-content-type-options: nosniff
content-length: 224
date: Wed, 17 Jul 2024 09:57:42 GMT

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/metrics\"",
  "reason": "Forbidden",
  "details": {},
  "code": 403
}

$ token=`kubectl create token -n kube-system coredns`
$ curl -ik -H "Authorization: Bearer $token" https://172.19.0.2:10661/metrics
HTTP/2 403
cache-control: no-cache, private
content-type: application/json
x-content-type-options: nosniff
content-length: 249
date: Wed, 17 Jul 2024 09:59:06 GMT

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "forbidden: User \"system:serviceaccount:kube-system:coredns\" cannot get path \"/metrics\"",
  "reason": "Forbidden",
  "details": {},
  "code": 403
}

$ cat <<EOF | kubectl apply -f - 
apiVersion: v1
kind: ServiceAccount
metadata:
  name: metrics-client
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: metrics-client
roleRef:
  name: system:monitoring
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
subjects:
  - kind: ServiceAccount
    name: metrics-client
    namespace: default
EOF
# OR
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
  name: metrics-client
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: metrics-client
rules:
  - nonResourceURLs:
      - "/metrics"
    verbs:
      - get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: metrics-client
roleRef:
  name: metrics-client
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
subjects:
  - kind: ServiceAccount
    name: metrics-client
    namespace: default
EOF

$ token=`kubectl create token metrics-client`
$ curl -ik -H "Authorization: Bearer $token" https://172.19.0.2:10661/metrics
HTTP/2 200
cache-control: no-cache, private
content-type: text/plain; version=0.0.4; charset=utf-8; escaping=values
date: Wed, 17 Jul 2024 10:04:41 GMT

# metrics...

@zhangzujian zhangzujian changed the title listen on metrics port with self-signed cert add support for serving metrics with self-signed cert Jul 17, 2024
@zhangzujian zhangzujian force-pushed the metrics/auth branch 5 times, most recently from 8bf5036 to bb432de Compare July 17, 2024 09:41
@zhangzujian zhangzujian changed the title add support for serving metrics with self-signed cert metrics: add support for secure serving Jul 17, 2024
@zhangzujian zhangzujian force-pushed the metrics/auth branch 7 times, most recently from fe946e4 to babf5a9 Compare July 17, 2024 11:03
@zhangzujian zhangzujian marked this pull request as ready for review July 17, 2024 11:05
@zhangzujian zhangzujian force-pushed the metrics/auth branch 2 times, most recently from f39a3a7 to a3d41a8 Compare July 17, 2024 23:07
@zhangzujian zhangzujian merged commit 3a0a910 into kubeovn:master Jul 18, 2024
62 checks passed
@zhangzujian zhangzujian deleted the metrics/auth branch July 18, 2024 02:35
zhangzujian added a commit to zhangzujian/kube-ovn that referenced this pull request Jul 18, 2024
* add support for serving metrics with self-signed cert
* add support for serving metrics with authn/authz

---------

Signed-off-by: zhangzujian <[email protected]>
zhangzujian added a commit to zhangzujian/kube-ovn that referenced this pull request Jul 18, 2024
* add support for serving metrics with self-signed cert
* add support for serving metrics with authn/authz

---------

Signed-off-by: zhangzujian <[email protected]>
zhangzujian added a commit to zhangzujian/kube-ovn that referenced this pull request Jul 19, 2024
* add support for serving metrics with self-signed cert
* add support for serving metrics with authn/authz

---------

Signed-off-by: zhangzujian <[email protected]>
bobz965 pushed a commit that referenced this pull request Jul 22, 2024
* add support for serving metrics with self-signed cert
* add support for serving metrics with authn/authz

---------

Signed-off-by: zhangzujian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants