Other questions of note:
Question the first:
Is the sensu-agent running from inside the cluster? If so, the that node check command (which is based on the rubygem package kubeclient) has logic to detect cluster service account creds injected into the pod environment. So if this is running inside the k8s cluster you might try using k8s service account concept instead of passing a token and url as options,. The --in-cluster
option to the check command enables the automatic service account detection logic.
Question the second:
Have you tried a diagnostic sensu check using curl with the label substitution to see if it also 403s?
here’s the thing when you get a 403 the full message includes the user the token is associated with. If a 403 forbidden response is obtained is means k8s mapped the token to a user, but the user was not authorized due to RBAC.
If you git a 401 access denied response… that means the token was not recognized at all.
For example If I deliberately try to use a token that does not exist I get this:
$ check-kube-nodes-ready.rb -t "aaaaaaaa" -s ${APISERVER}
AllNodesAreReady CRITICAL: API error: Unauthorized
$ curl -X GET $APISERVER/api/v1/nodes --insecure --header "Authorization: Bearer aaaaaaa"
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "Unauthorized",
"reason": "Unauthorized",
"code": 401
But if I use my valid token with the bad RBAC policy that does not grant me access to the nodes endpoint I get this:
$ check-kube-nodes-ready.rb -t ${TOKEN} -s ${APISERVER}
AllNodesAreReady CRITICAL: API error: nodes is forbidden: User "system:serviceaccount:default:default" cannot list resource "nodes" in API group "" at the cluster scope
$ curl -X GET $APISERVER/api/v1/nodes --insecure --header "Authorization: Bearer $TOKEN"
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "nodes is forbidden: User \"system:serviceaccount:default:default\" cannot list resource \"nodes\" in API group \"\" at the cluster scope",
"reason": "Forbidden",
"details": {
"kind": "nodes"
},
"code": 403
If your get a 403, it sure smells like RBAC or perhaps the wrong token for a different user? The 403 response message gives you the k8s user name, so you can at least verify that the token you used matches the user you expected (just in case what you are seeing is a stale token).
As of right now I don’t know what else I can do to help you. I’m unable to reproduce the problem, and I’m probably not knowledgable enough about troubleshooting k8s RBAC in fine detail to take it further.
But one thing I am pretty sure that you can setup K8s RBAC is such a way that users that have access from inside of a cluster don’t necessarily have access from outside… so if you are testing partly from outside a cluster and partly from inside a cluster… you can get different RBAC permissions for the same user token just because you are inside or outside the cluster…that can complicate things and drive you nuts until you realize k8s permissions lets you do this. This is why in my local minikube I have to add a new RBAC policy to allow API access to the nodes endpoint… it works without a hitch from inside the cluster by default because mini-kubes default RBAC policy assumes you are going to be playing with the API from inside the cluster.