OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.16k stars 592 forks source link

authentication with openshift does not work with bound service account token #21124

Open chunlongliang-ibm opened 2 years ago

chunlongliang-ibm commented 2 years ago

Liberty supports login with openshift service account token, one of following methods work: https://www.ibm.com/docs/en/cloud-paks/cp-applications/4.3?topic=authentication-authenticating-openshift. https://www.ibm.com/docs/en/cloud-paks/cp-applications/4.3?topic=authentication-authenticating-service-account However, if service account token is bound service account token, neither works. Bound service account token is time-boxed and audience-scoped token, and is more secured than traditional service account token, see https://access.redhat.com/documentation/en-us/openshift_container_platform/4.9/html/authentication_and_authorization/bound-service-account-tokens.

chunlongliang-ibm commented 2 years ago

The fix is fairly easy. When calling k8's tokenreviews API, today Liberty sends request message like this: curl -X "POST" "https://{kubernetes API IP}:{kubernetes API Port}/apis/authentication.k8s.io/v1/tokenreviews" \ -H 'Authorization: Bearer {your bearer token}' \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "kind": "TokenReview", "apiVersion": "authentication.k8s.io/v1", "spec": { "token": "{token received in token request response}" }when ask tokenreviews api to validate the token }' Because bound service account token is audience scoped, so we need modify the request to include token audience in tokenreview api call. Here is a working request message if token is bound service account token

curl -X "POST" "https://{kubernetes API IP}:{kubernetes API Port}/apis/authentication.k8s.io/v1/tokenreviews" \ -H 'Authorization: Bearer {your bearer token}' \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "kind": "TokenReview", "apiVersion": "authentication.k8s.io/v1", "spec": { "token": "{token received in token request response}", "audiences": ["token audience here"] } }'

chunlongliang-ibm commented 2 years ago

Note that bound service account token does not work with this api, , and only work with https://{kubernetes API IP}:{kubernetes API Port}/apis/authentication.k8s.io/v1/tokenreviews API. If we are going to fix https://www.ibm.com/docs/en/cloud-paks/cp-applications/4.3?topic=authentication-authenticating-service-account, you will need update it to support https://{kubernetes API IP}:{kubernetes API Port}/apis/authentication.k8s.io/v1/tokenreviews API in addition to https://cluster.domain.example.com/apis/user.openshift.io/v1/users/~