mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-26 22:38:45 +00:00
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. <[email protected]> Co-authored-by: conblem <[email protected]> Co-authored-by: Silvan <[email protected]>
This commit is contained in:
co-authored by
Marco A.
conblem
Silvan
parent
72c8f0192c
commit
791d0587aa
@@ -2,6 +2,8 @@ package action
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"connectrpc.com/connect"
|
||||
"github.com/muhlemmer/gu"
|
||||
@@ -64,6 +66,60 @@ func (s *Server) DeleteTarget(ctx context.Context, req *connect.Request[action.D
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (s *Server) AddPublicKey(ctx context.Context, req *connect.Request[action.AddPublicKeyRequest]) (*connect.Response[action.AddPublicKeyResponse], error) {
|
||||
instanceID := authz.GetInstance(ctx).InstanceID()
|
||||
var expirationDate time.Time
|
||||
if req.Msg.GetExpirationDate() != nil {
|
||||
expirationDate = req.Msg.GetExpirationDate().AsTime()
|
||||
}
|
||||
key := &command.TargetPublicKey{
|
||||
TargetID: strings.TrimSpace(req.Msg.GetTargetId()),
|
||||
PublicKey: req.Msg.GetPublicKey(),
|
||||
Expiration: expirationDate,
|
||||
}
|
||||
creationDate, err := s.command.AddTargetPublicKey(ctx, key, instanceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&action.AddPublicKeyResponse{
|
||||
KeyId: key.KeyID,
|
||||
CreationDate: timestamppb.New(creationDate),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (s *Server) ActivatePublicKey(ctx context.Context, req *connect.Request[action.ActivatePublicKeyRequest]) (*connect.Response[action.ActivatePublicKeyResponse], error) {
|
||||
instanceID := authz.GetInstance(ctx).InstanceID()
|
||||
changeDate, err := s.command.ActivateTargetPublicKey(ctx, strings.TrimSpace(req.Msg.GetTargetId()), strings.TrimSpace(req.Msg.GetKeyId()), instanceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&action.ActivatePublicKeyResponse{
|
||||
ChangeDate: timestamppb.New(changeDate),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (s *Server) DeactivatePublicKey(ctx context.Context, req *connect.Request[action.DeactivatePublicKeyRequest]) (*connect.Response[action.DeactivatePublicKeyResponse], error) {
|
||||
instanceID := authz.GetInstance(ctx).InstanceID()
|
||||
changeDate, err := s.command.DeactivateTargetPublicKey(ctx, strings.TrimSpace(req.Msg.GetTargetId()), strings.TrimSpace(req.Msg.GetKeyId()), instanceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&action.DeactivatePublicKeyResponse{
|
||||
ChangeDate: timestamppb.New(changeDate),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (s *Server) RemovePublicKey(ctx context.Context, req *connect.Request[action.RemovePublicKeyRequest]) (*connect.Response[action.RemovePublicKeyResponse], error) {
|
||||
instanceID := authz.GetInstance(ctx).InstanceID()
|
||||
deletionDate, err := s.command.RemoveTargetPublicKey(ctx, strings.TrimSpace(req.Msg.GetTargetId()), strings.TrimSpace(req.Msg.GetKeyId()), instanceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&action.RemovePublicKeyResponse{
|
||||
DeletionDate: timestamppb.New(deletionDate),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func createTargetToCommand(req *action.CreateTargetRequest) *command.AddTarget {
|
||||
var (
|
||||
targetType target_domain.TargetType
|
||||
@@ -85,6 +141,22 @@ func createTargetToCommand(req *action.CreateTargetRequest) *command.AddTarget {
|
||||
Endpoint: req.GetEndpoint(),
|
||||
Timeout: req.GetTimeout().AsDuration(),
|
||||
InterruptOnError: interruptOnError,
|
||||
PayloadType: payloadTypeToDomain(req.GetPayloadType()),
|
||||
}
|
||||
}
|
||||
|
||||
func payloadTypeToDomain(payloadType action.PayloadType) target_domain.PayloadType {
|
||||
switch payloadType {
|
||||
case action.PayloadType_PAYLOAD_TYPE_UNSPECIFIED:
|
||||
return target_domain.PayloadTypeUnspecified
|
||||
case action.PayloadType_PAYLOAD_TYPE_JSON:
|
||||
return target_domain.PayloadTypeJSON
|
||||
case action.PayloadType_PAYLOAD_TYPE_JWT:
|
||||
return target_domain.PayloadTypeJWT
|
||||
case action.PayloadType_PAYLOAD_TYPE_JWE:
|
||||
return target_domain.PayloadTypeJWE
|
||||
default:
|
||||
return target_domain.PayloadTypeUnspecified
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +174,7 @@ func updateTargetToCommand(req *action.UpdateTargetRequest) *command.ChangeTarge
|
||||
Name: req.Name,
|
||||
Endpoint: req.Endpoint,
|
||||
ExpirationSigningKey: expirationSigningKey,
|
||||
PayloadType: payloadTypeToDomain(req.GetPayloadType()),
|
||||
}
|
||||
if req.TargetType != nil {
|
||||
switch t := req.GetTargetType().(type) {
|
||||
|
||||
Reference in New Issue
Block a user