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

fixed #2240 secondary ext-jwt processing would fail... #2242

Merged
merged 2 commits into from
Jul 18, 2024
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 controller/db/external_jwt_signer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (entity *ExternalJwtSigner) GetEntityType() string {
var _ ExternalJwtSignerStore = (*externalJwtSignerStoreImpl)(nil)

type ExternalJwtSignerStore interface {
NameIndexed
Store[*ExternalJwtSigner]
}

Expand All @@ -96,6 +97,10 @@ type externalJwtSignerStoreImpl struct {
issuerIndex boltz.ReadIndex
}

func (store *externalJwtSignerStoreImpl) GetNameIndex() boltz.ReadIndex {
return store.indexName
}

func (store *externalJwtSignerStoreImpl) initializeLocal() {
store.AddExtEntitySymbols()
store.indexName = store.addUniqueNameField()
Expand Down
5 changes: 5 additions & 0 deletions controller/env/appenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ func (ae *AppEnv) ProcessJwt(rc *response.RequestContext, token *jwt.Token) erro
}

func (ae *AppEnv) FillRequestContext(rc *response.RequestContext) error {
// do no process auth headers on authenticate request
if strings.HasSuffix(rc.Request.URL.Path, "/v1/authenticate") && !strings.HasSuffix(rc.Request.URL.Path, "/authenticate/mfa") {
return nil
}

ztSession := ae.getZtSessionFromRequest(rc.Request)

if ztSession != "" {
Expand Down
32 changes: 1 addition & 31 deletions controller/model/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ import (
)

type AuthResult interface {
IdentityId() string
ExternalId() string
AuthenticatorId() string
SessionCerts() []*x509.Certificate
Identity() *Identity
Authenticator() *Authenticator
AuthPolicy() *AuthPolicy
AuthPolicyId() string
IsSuccessful() bool
}

Expand Down Expand Up @@ -121,25 +118,14 @@ func (context *AuthContextHttp) GetChangeContext() *change.Context {
var _ AuthResult = &AuthResultBase{}

type AuthResultBase struct {
identityId string
externalId string
identity *Identity
authenticatorId string
authenticator *Authenticator
sessionCerts []*x509.Certificate
authPolicyId string
authPolicy *AuthPolicy
env Env
}

func (a *AuthResultBase) IdentityId() string {
return a.identityId
}

func (a *AuthResultBase) ExternalId() string {
return a.externalId
}

func (a *AuthResultBase) AuthenticatorId() string {
return a.authenticatorId
}
Expand All @@ -149,14 +135,6 @@ func (a *AuthResultBase) SessionCerts() []*x509.Certificate {
}

func (a *AuthResultBase) Identity() *Identity {
if a.identity == nil {
if a.identityId != "" {
a.identity, _ = a.env.GetManagers().Identity.Read(a.identityId)
} else if a.externalId != "" {
a.identity, _ = a.env.GetManagers().Identity.ReadByExternalId(a.externalId)
}

}
return a.identity
}

Expand All @@ -168,17 +146,9 @@ func (a *AuthResultBase) Authenticator() *Authenticator {
}

func (a *AuthResultBase) AuthPolicy() *AuthPolicy {
if a.authPolicy == nil {
a.authPolicy, _ = a.env.GetManagers().AuthPolicy.Read(a.authPolicyId)
}

return a.authPolicy
}

func (a *AuthResultBase) AuthPolicyId() string {
return a.authPolicyId
}

func (a *AuthResultBase) IsSuccessful() bool {
return a.identityId != ""
return a.identity != nil
}
4 changes: 0 additions & 4 deletions controller/model/authenticator_mod_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/michaelquigley/pfxlog"
"github.com/openziti/foundation/v2/errorz"
nfpem "github.com/openziti/foundation/v2/pem"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/ziti/common/cert"
"github.com/openziti/ziti/controller/apierror"
"github.com/openziti/ziti/controller/change"
Expand Down Expand Up @@ -225,13 +224,10 @@ func (module *AuthModuleCert) Process(context AuthContext) (AuthResult, error) {
}

return &AuthResultBase{
identityId: identity.Id,
externalId: stringz.OrEmpty(identity.ExternalId),
identity: identity,
authenticatorId: authenticator.Id,
authenticator: authenticator,
sessionCerts: []*x509.Certificate{clientCert},
authPolicyId: authPolicy.Id,
authPolicy: authPolicy,
env: module.env,
}, nil
Expand Down
Loading
Loading