Kubernetes REST API - Unauthorized

3/22/2019

I have following Kubernetes REST API request

GET https://theserver/api/v1/pods?includeUninitialized=true

and include following HTTP Headers in the request:

Authorization: Basic ***************
Accept: application/json, */*
User-Agent: kubectl.exe/v1.13.0 (windows/amd64) kubernetes/ddf47ac

Result is the following error

{
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Failure",
    "message": "Unauthorized",
    "reason": "Unauthorized",
    "code": 401
}

I already tried the following:

  • Analog kubectl request "kubectl describe pods --all-namespaces" works fine (but I need REST)
  • Used "--v=12" parameter as in newkind101's comment to Kubernetes REST API to see the underlying REST API calls - looks same as mine
  • Read Kubernetes Documentation - but I failed to find detail information which HTTP headers or/and HTTP body values to send to authenticate properly (few thing I could retrieve from curl sample calls in that docs)
  • I read Access Kubernetes API using REST APIs but what to understand my issue before I use a framework like GoDaddy

kubectl seems to do a bit more than I can see in with the "--v=12" parameter. This bit is likely conneted to things in ".kube/config" file. Still I don't know what exactly and where to put in my HTTP request.

-- Markus
api
authorization
kubernetes
rest

1 Answer

3/26/2019

As far as I remember Basic authentication method is disabled by default and needs to be enabled by adding --basic-auth-file flag to the API server configuration, therefore all requests to REST API are identified as anonymous user and might be resulted in 401 Unauthorized error.

-- mk_sta
Source: StackOverflow