Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt-out for signing JWT with Backstage source #63

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading