Skip to content

Commit

Permalink
Opt-out for signing JWT with Backstage source
Browse files Browse the repository at this point in the history
It seems some Backstage instances may prefer to use a simple bearer
token over a signed JWT for authentication.

Provide an opt-out for those people.
  • Loading branch information
lawrencejones committed Nov 14, 2023
1 parent a9cb181 commit f16b39d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ This looks like:
//
// https://backstage.io/docs/auth/service-to-service-auth/#usage-in-external-callers
token: '$(BACKSTAGE_TOKEN)',
// Some Backstage instances (e.g. Roadie) may prefer tokens to be used
// as-is instead of signed into JWTs. If this is you, explicitly opt-out of
// signing like so:
sign_jwt: false,
},
}
```
Expand Down
16 changes: 12 additions & 4 deletions source/source_backstage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type SourceBackstage struct {
Endpoint string `json:"endpoint"` // https://backstage.company.io/api/catalog/entities
Token Credential `json:"token"`
SignJWT *bool `json:"sign_jwt"`
}

func (s SourceBackstage) Validate() error {
Expand All @@ -37,10 +38,17 @@ func (s SourceBackstage) String() string {
func (s SourceBackstage) Load(ctx context.Context, logger kitlog.Logger) ([]*SourceEntry, error) {
var token string
if s.Token != "" {
var err error
token, err = s.getJWT()
if err != nil {
return nil, err
// If not provided or explicitly enabled, sign the token into a JWT and use that as
// the Authorization header.
if s.SignJWT == nil || *s.SignJWT {
var err error
token, err = s.getJWT()
if err != nil {
return nil, err
}
// Otherwise if someone has told us not to, don't sign the token and use it as-is.
} else {
token = string(s.Token)
}
}

Expand Down

0 comments on commit f16b39d

Please sign in to comment.