Skip to content

Commit

Permalink
fix(auth): Encode auth bearer token (#291)
Browse files Browse the repository at this point in the history
* Update readmes

* Encode token

* Update tests
  • Loading branch information
Janelle Law committed Nov 3, 2021
1 parent 0888a01 commit 1708d3c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ install/remove cert-manager from your cluster.

### User Authentication

Users can use `oc whoami --show-token` to retrieve their OpenShift OAuth token
for the currently logged in user account. This token can be used when directly
Users can use `oc whoami --show-token | base64` to retrieve their encoded OpenShift OAuth token
for the currently logged in user account. This encoded token can be used when directly
interacting with the deployed Cryostat instance(s), for example on the
web-client login page.

Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ status:

If running on OpenShift, you will need to pass your bearer token with the `curl` request. (You may also need -k if your test cluster uses a self-signed certificate)
```shell
$ curl -k -H "Authorization: Bearer $(oc whoami -t)" \
$ curl -k -H "Authorization: Bearer $(oc whoami -t | base64)" \
https://cryostat-sample-cryostat-operator-system.apps-crc.testing:443/api/v1/recordings/10-217-0-29_my-recording_20210429T220400Z.jfr \
my-recording.jfr
```
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/common/common_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ package common

import (
"context"
b64 "encoding/base64"
"errors"
"fmt"
"net/url"
Expand Down Expand Up @@ -130,7 +131,7 @@ func (r *commonReconciler) GetCryostatClient(ctx context.Context, namespace stri
if err != nil {
return nil, err
}
strTok := string(tok)
strTok := b64.StdEncoding.EncodeToString(tok)

// Get JMX authentication credentials, if present
var jmxCreds *cryostatClient.JMXAuthCredentials
Expand Down
2 changes: 1 addition & 1 deletion internal/test/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func NewTemplates() []operatorv1beta1.TemplateInfo {
}

func verifyToken() http.HandlerFunc {
return ghttp.VerifyHeaderKV("Authorization", "Bearer myToken")
return ghttp.VerifyHeaderKV("Authorization", "Bearer bXlUb2tlbg==")
}

func verifyJMXAuth() http.HandlerFunc {
Expand Down

0 comments on commit 1708d3c

Please sign in to comment.