Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

WIT Deployments API fails with 401 to /api/user/services #4631

Closed
sbose78 opened this issue Dec 10, 2018 · 14 comments · Fixed by fabric8-ui/fabric8-ui#3469
Closed

WIT Deployments API fails with 401 to /api/user/services #4631

sbose78 opened this issue Dec 10, 2018 · 14 comments · Fixed by fabric8-ui/fabric8-ui#3469

Comments

@sbose78
Copy link
Collaborator

sbose78 commented Dec 10, 2018

curl --header "Authorization: Bearer $token" https://prod-preview.openshift.io/api/deployments/spaces/f1432a96-179b-4d04-8abd-32e8972a950b

fails with

{"errors":[{"code":"unknown_error","detail":"failed to GET /api/user/services due to status code 401","status":"500","title":"Unknown error"}]}

https://github.com/fabric8-services/fabric8-wit/blob/master/controller/deployments_osioclient.go#L122

Note, call to wit/api/user/services

curl --header "Authorization: Bearer $token" https://api.prod-preview.openshift.io/api/user/services

works perfectly.

@joshuawilson
Copy link
Member

related to #4621

@sbose78
Copy link
Collaborator Author

sbose78 commented Dec 10, 2018

@tinakurian Could you please investigate and see if you can catch something ? As a starting point, setting up everything locally might be hard. However, verify if the token is being passed on to the /api/user/services call.

@joshuawilson
Copy link
Member

I can confirm that it is not in the UI as I get no error when I point the UI at the prod server.

@jarifibrahim
Copy link
Collaborator

The failure is reproducible only on prod-preview. The deployments API works fine on prod.
@sbryzak could fabric8-services/fabric8-auth#689 have caused this?

@sbose78
Copy link
Collaborator Author

sbose78 commented Dec 11, 2018

The request being passed on from the WIT Deployments API to WIT user/services API doesn't pass on the Authorization header.

{"err":"[Gwrp9CdH] 401 jwt_security_error: missing header \"Authorization\"","err_type":{},"error_message":"[Gwrp9CdH] 401 jwt_security_error: missing header \"Authorization\"","file":"/tmp/go/src/github.com/fabric8-services/fabric8-wit/jsonapi/jsonapi_utility.go","func":"github.com/fabric8-services/fabric8-wit/jsonapi.ErrorToJSONAPIError","level":"error","line":43,"msg":"an error occurred in our api","pid":1,"pkg":"jsonapi","req_headers":{"Accept-Encoding":["gzip"],"Forwarded":["for=174.129.114.152;host=prod-preview.openshift.io;proto=https;proto-version="],"Referer":["http://prod-preview.openshift.io/api/user/services"],"User-Agent":["Go-http-client/1.1"],"X-Forwarded-For":["174.129.114.152"],"X-Forwarded-Host":["prod-preview.openshift.io"],"X-Forwarded-Port":["443"],"X-Forwarded-Proto":["https"],"X-Request-Id":["Ojy7OwfpIg-47066"]},"req_id":"Ojy7OwfpIg-47066","time":"2018-12-11  11:04:47"}

@jarifibrahim
Copy link
Collaborator

jarifibrahim commented Dec 11, 2018

I tried to reproduce the error locally but the header was correctly passed to the /user/service endpoint.

@jarifibrahim
Copy link
Collaborator

jarifibrahim commented Dec 11, 2018

Interestingly I can no longer reproduce the issue.

➜  fabric8-wit git:(master) ✗ curl --header "Authorization: Bearer $token" https://prod-preview.openshift.io/api/deployments/spaces/f1432a96-179b-4d04-8abd-32e8972a950b | jq 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   127  100   127    0     0    127      0  0:00:01  0:00:01 --:--:--    95
{
  "data": {
    "attributes": {
      "applications": [],
      "name": "sbosedecspace1"
    },
    "id": "f1432a96-179b-4d04-8abd-32e8972a950b",
    "type": "space"
  }
}

UPDATE - I couldn't reproduce the issue because we moved back 2 versions of core on prod-preview. The latest core might still have this issue.

@joshuawilson
Copy link
Member

I think this issue has to do with a difference in GoLang versions

@sbose78
Copy link
Collaborator Author

sbose78 commented Dec 12, 2018

With zero code changes in the WIT deployments API , the above golang version changes is our prime suspect. The specific code here makes a call from WIT to another WIT API using the goa WIT client, and in the process doesn't pass headers properly causing a 401. This code needs to be refactored : WIT needs to call Tenant service instead of WIT --> WIT --> Tenant.

@sbose78
Copy link
Collaborator Author

sbose78 commented Dec 12, 2018

Here's what we are gonna do next:

@kwk
Copy link
Contributor

kwk commented Dec 12, 2018

  • On a sidenote, @jarifibrahim & @corinnekrych will work on moving WIT ( and other repos ) to 1.11 as being done for all other repos.

Since when is Go 1.11 available in CentOS or RHEL?

@corinnekrych
Copy link
Collaborator

  • On a sidenote, @jarifibrahim & @corinnekrych will work on moving WIT ( and other repos ) to 1.11 as being done for all other repos.

Since when is Go 1.11 available in CentOS or RHEL?

See Shoubhik link #4618

@jarifibrahim
Copy link
Collaborator

Here's what we'll be doing to investigate the failure.

What we know till now

  • The /deployments/spaces/spaceID API on WIT calls the/api/user/services endpoint on WIT (wit to wit api call)[0]. The /deployments/spaces/spaceID API receives the Authorization header but the /user/services endpoint doesn't receive the Authorization header and the JWT middleware fails with missing header error[1] even before the request reaches the user service controller. The JWT middleware returns the 401 error.

  • The issue is reproducible only on prod preview. We have tried locally with multiple versions of golang and the docker image that runs on prod preview but we couldn't reproduce the error locally.

What we are going to do

  1. We will be using go1.9.4 in the builder container and ensure the /deployment API works fine. This build will be our fall back incase things go south. The go version is our prime suspect right now. We think the version change has caused this failure. See also WIT Deployments API fails with 401 to /api/user/services #4631 (comment).
    PR Use golang 1.9.4 from website fabric8-services/fabric8-wit#2383
  2. Update prod-preview to use go1.11. The /deployments/spaces API should start failing. We will be pushing more log statements so that we can figure out why the header was removed. The e2e tests would fail while we are investigating the failure.

cc @corinnekrych @sbose78
[0] - https://github.com/fabric8-services/fabric8-wit/blob/master/controller/deployments_osioclient.go#L106
[1] - https://github.com/fabric8-services/fabric8-wit/blob/master/goamiddleware/jwt_middleware.go#L92

@sbose78
Copy link
Collaborator Author

sbose78 commented Dec 18, 2018

👍 CC @ppitonak

@jarifibrahim jarifibrahim removed their assignment Apr 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.