Files
zitadel/internal/command/action_v2_target_key_model.go
791d0587aa feat(action v2): add JWT and JWE payload type options (#11196)
# Which Problems Are Solved

The payload in actions V2 is currently sent as JSON to the target
endpoint. It might get exposed to intermediary infrastructure or logging
systems.
For these scenarios there needs to be an application-layer encryption,
where the provider of the endpoint can define an key to be used for the
encryption.

# How the Problems Are Solved

- Added an additional option to the target to specify the payload type:
`JSON` (current and default), `JWT`, `JWE` (api and console)
- added endpoints to upload and manage public keys (to be used for
encryption) for a target
- updated all action v2 executions (interceptors, oidc, saml, ...) to
provide the `GetActiveSigningWebKey` from queries
- implemented jwt and jwe in the exections incl. refactoring of code and
tests
- changes to the authn_keys table:
  - added a `fingerprint` column
  - dropped not null constraint on expiration
- moved the `GetSignerOnce` into its own package to prevent circular
dependencies

# Additional Changes

None

# Additional Context

closes #11061

---------

Co-authored-by: Marco A. <marco@zitadel.com>
Co-authored-by: conblem <mail@conblem.me>
Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com>
2025-12-29 13:35:53 +00:00

95 lines
2.3 KiB
Go

package command
import (
"time"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/target"
)
type TargetKeyWriteModel struct {
eventstore.WriteModel
KeyID string
KeyExists bool
TargetExists bool
Active bool
ExpirationDate time.Time
}
func NewTargetKeyWriteModel(targetID, keyID string, resourceOwner string) *TargetKeyWriteModel {
return &TargetKeyWriteModel{
WriteModel: eventstore.WriteModel{
AggregateID: targetID,
ResourceOwner: resourceOwner,
},
KeyID: keyID,
}
}
func (wm *TargetKeyWriteModel) AppendEvents(events ...eventstore.Event) {
for _, event := range events {
switch e := event.(type) {
case *target.KeyAddedEvent:
if wm.KeyID != e.KeyID {
continue
}
wm.WriteModel.AppendEvents(e)
case *target.KeyActivatedEvent:
// don't check for KeyID, as only one key can be active at a time any activation event affects all keys
wm.WriteModel.AppendEvents(e)
case *target.KeyDeactivatedEvent:
if wm.KeyID != e.KeyID {
continue
}
wm.WriteModel.AppendEvents(e)
case *target.KeyRemovedEvent:
if wm.KeyID != e.KeyID {
continue
}
wm.WriteModel.AppendEvents(e)
case *target.AddedEvent:
wm.WriteModel.AppendEvents(e)
case *target.RemovedEvent:
wm.WriteModel.AppendEvents(e)
}
}
}
func (wm *TargetKeyWriteModel) Reduce() error {
for _, event := range wm.Events {
switch e := event.(type) {
case *target.KeyAddedEvent:
wm.KeyID = e.KeyID
wm.KeyExists = true
wm.ExpirationDate = e.ExpirationDate
case *target.KeyActivatedEvent:
wm.Active = wm.KeyID == e.KeyID
case *target.KeyDeactivatedEvent:
wm.Active = false
case *target.KeyRemovedEvent:
wm.KeyExists = false
case *target.AddedEvent:
wm.TargetExists = true
case *target.RemovedEvent:
wm.TargetExists = false
}
}
return wm.WriteModel.Reduce()
}
func (wm *TargetKeyWriteModel) Query() *eventstore.SearchQueryBuilder {
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
ResourceOwner(wm.ResourceOwner).
AddQuery().
AggregateTypes(target.AggregateType).
AggregateIDs(wm.AggregateID).
EventTypes(target.KeyAddedEventType,
target.KeyActivatedEventType,
target.KeyDeactivatedEventType,
target.KeyRemovedEventType,
target.AddedEventType,
target.RemovedEventType).
Builder()
}