Skip to content

Commit

Permalink
Add persistent tokens for iprose authentication (#154)
Browse files Browse the repository at this point in the history
* Add trusted token

* Fix config

* Fix option naming

* Rename tokens option

* Revert deps

* Fix naming
  • Loading branch information
RandoMan70 committed Apr 27, 2024
1 parent 20e682c commit 5c265fd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/iprose/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import (
)

type Config struct {
QueueSize int `yaml:"queue_size"`
QueueSize int `yaml:"queue_size"`
PersistentTokens []string `yaml:"persistent_tokens"`
}

type Instance struct {
iprose *server.IPRoseServer
authorizer authorizer.JWTAuthorizer
config *Config
}

func New(config *Config, jwtAuthorizer authorizer.JWTAuthorizer) (*Instance, error) {
Expand All @@ -32,6 +34,7 @@ func New(config *Config, jwtAuthorizer authorizer.JWTAuthorizer) (*Instance, err

instance := &Instance{
authorizer: authorizer.WithEntitlement(jwtAuthorizer, authorizer.IPRose),
config: config,
}
var err error
instance.iprose, err = server.New(
Expand All @@ -54,6 +57,13 @@ func (instance *Instance) authenticate(r *http.Request) error {
return xerror.EAuthenticationFailed("no auth token", nil)
}

for _, t := range instance.config.PersistentTokens {
if userToken == t {
zap.L().Debug("Authenticated with fixed trusted token")
return nil
}
}

_, err := instance.authorizer.Authenticate(userToken, auth.AudienceTunnel)
if err != nil {
return err
Expand Down

0 comments on commit 5c265fd

Please sign in to comment.