mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:27:32 +00:00
fix: correct method and path for session api activity (#6880)
* fix: correct method and path for session api activity * fix: correct method and path for session api activity * fix: correct function name for activity trigger
This commit is contained in:
@@ -44,7 +44,7 @@ func (t TriggerMethod) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Trigger(ctx context.Context, orgID, userID string, trigger TriggerMethod) {
|
func TriggerHTTP(ctx context.Context, orgID, userID string, trigger TriggerMethod) {
|
||||||
ai := info.ActivityInfoFromContext(ctx)
|
ai := info.ActivityInfoFromContext(ctx)
|
||||||
triggerLog(
|
triggerLog(
|
||||||
authz.GetInstance(ctx).InstanceID(),
|
authz.GetInstance(ctx).InstanceID(),
|
||||||
@@ -55,11 +55,30 @@ func Trigger(ctx context.Context, orgID, userID string, trigger TriggerMethod) {
|
|||||||
ai.Method,
|
ai.Method,
|
||||||
ai.Path,
|
ai.Path,
|
||||||
ai.RequestMethod,
|
ai.RequestMethod,
|
||||||
|
"",
|
||||||
authz.GetCtxData(ctx).SystemMemberships != nil,
|
authz.GetCtxData(ctx).SystemMemberships != nil,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TriggerWithContext(ctx context.Context, trigger TriggerMethod) {
|
func TriggerGRPC(ctx context.Context, orgID, userID string, trigger TriggerMethod) {
|
||||||
|
ai := info.ActivityInfoFromContext(ctx)
|
||||||
|
// GRPC call the method is contained in the HTTP request path
|
||||||
|
method := ai.Path
|
||||||
|
triggerLog(
|
||||||
|
authz.GetInstance(ctx).InstanceID(),
|
||||||
|
orgID,
|
||||||
|
userID,
|
||||||
|
http_utils.ComposedOrigin(ctx),
|
||||||
|
trigger,
|
||||||
|
method,
|
||||||
|
"",
|
||||||
|
ai.RequestMethod,
|
||||||
|
ai.GRPCStatus.String(),
|
||||||
|
authz.GetCtxData(ctx).SystemMemberships != nil,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TriggerGRPCWithContext(ctx context.Context, trigger TriggerMethod) {
|
||||||
ai := info.ActivityInfoFromContext(ctx)
|
ai := info.ActivityInfoFromContext(ctx)
|
||||||
// GRPC call the method is contained in the HTTP request path
|
// GRPC call the method is contained in the HTTP request path
|
||||||
method := ai.Path
|
method := ai.Path
|
||||||
@@ -72,11 +91,12 @@ func TriggerWithContext(ctx context.Context, trigger TriggerMethod) {
|
|||||||
method,
|
method,
|
||||||
"",
|
"",
|
||||||
ai.RequestMethod,
|
ai.RequestMethod,
|
||||||
|
ai.GRPCStatus.String(),
|
||||||
authz.GetCtxData(ctx).SystemMemberships != nil,
|
authz.GetCtxData(ctx).SystemMemberships != nil,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func triggerLog(instanceID, orgID, userID, domain string, trigger TriggerMethod, method, path, requestMethod string, isSystemUser bool) {
|
func triggerLog(instanceID, orgID, userID, domain string, trigger TriggerMethod, method, path, requestMethod, status string, isSystemUser bool) {
|
||||||
logging.WithFields(
|
logging.WithFields(
|
||||||
"instance", instanceID,
|
"instance", instanceID,
|
||||||
"org", orgID,
|
"org", orgID,
|
||||||
@@ -85,6 +105,7 @@ func triggerLog(instanceID, orgID, userID, domain string, trigger TriggerMethod,
|
|||||||
"trigger", trigger.String(),
|
"trigger", trigger.String(),
|
||||||
"method", method,
|
"method", method,
|
||||||
"path", path,
|
"path", path,
|
||||||
|
"grpcStatus", status,
|
||||||
"requestMethod", requestMethod,
|
"requestMethod", requestMethod,
|
||||||
"isSystemUser", isSystemUser,
|
"isSystemUser", isSystemUser,
|
||||||
).Info(Activity)
|
).Info(Activity)
|
||||||
|
@@ -8,13 +8,22 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/activity"
|
"github.com/zitadel/zitadel/internal/activity"
|
||||||
|
"github.com/zitadel/zitadel/internal/api/grpc/errors"
|
||||||
|
ainfo "github.com/zitadel/zitadel/internal/api/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ActivityInterceptor() grpc.UnaryServerInterceptor {
|
func ActivityInterceptor() grpc.UnaryServerInterceptor {
|
||||||
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
||||||
resp, err := handler(ctx, req)
|
resp, err := handler(ctx, req)
|
||||||
if isResourceAPI(info.FullMethod) {
|
if isResourceAPI(info.FullMethod) {
|
||||||
activity.TriggerWithContext(ctx, activity.ResourceAPI)
|
code, _, _, _ := errors.ExtractCaosError(err)
|
||||||
|
ctx = ainfo.ActivityInfoFromContext(ctx).SetGRPCStatus(code).IntoContext(ctx)
|
||||||
|
activity.TriggerGRPCWithContext(ctx, activity.ResourceAPI)
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(info.FullMethod, "/zitadel.session.v1.SessionService/") {
|
||||||
|
code, _, _, _ := errors.ExtractCaosError(err)
|
||||||
|
ctx = ainfo.ActivityInfoFromContext(ctx).SetGRPCStatus(code).IntoContext(ctx)
|
||||||
|
activity.TriggerGRPCWithContext(ctx, activity.SessionAPI)
|
||||||
}
|
}
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
@@ -354,7 +354,7 @@ func (s *Server) checksToCommand(ctx context.Context, checks *session.Checks) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trigger activity log for session for user
|
// trigger activity log for session for user
|
||||||
activity.Trigger(ctx, user.ResourceOwner, user.ID, activity.SessionAPI)
|
activity.TriggerHTTP(ctx, user.ResourceOwner, user.ID, activity.SessionAPI)
|
||||||
sessionChecks = append(sessionChecks, command.CheckUser(user.ID, user.ResourceOwner))
|
sessionChecks = append(sessionChecks, command.CheckUser(user.ID, user.ResourceOwner))
|
||||||
}
|
}
|
||||||
if password := checks.GetPassword(); password != nil {
|
if password := checks.GetPassword(); password != nil {
|
||||||
|
@@ -2,6 +2,8 @@ package info
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
)
|
)
|
||||||
|
|
||||||
type activityInfoKey struct{}
|
type activityInfoKey struct{}
|
||||||
@@ -10,6 +12,8 @@ type ActivityInfo struct {
|
|||||||
Method string
|
Method string
|
||||||
Path string
|
Path string
|
||||||
RequestMethod string
|
RequestMethod string
|
||||||
|
GRPCStatus codes.Code
|
||||||
|
HTTPStatus int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ActivityInfo) IntoContext(ctx context.Context) context.Context {
|
func (a *ActivityInfo) IntoContext(ctx context.Context) context.Context {
|
||||||
@@ -32,6 +36,7 @@ func (a *ActivityInfo) SetMethod(method string) *ActivityInfo {
|
|||||||
a.Method = method
|
a.Method = method
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ActivityInfo) SetPath(path string) *ActivityInfo {
|
func (a *ActivityInfo) SetPath(path string) *ActivityInfo {
|
||||||
a.Path = path
|
a.Path = path
|
||||||
return a
|
return a
|
||||||
@@ -41,3 +46,13 @@ func (a *ActivityInfo) SetRequestMethod(method string) *ActivityInfo {
|
|||||||
a.RequestMethod = method
|
a.RequestMethod = method
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ActivityInfo) SetGRPCStatus(status codes.Code) *ActivityInfo {
|
||||||
|
a.GRPCStatus = status
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ActivityInfo) SetHTTPStatus(status int) *ActivityInfo {
|
||||||
|
a.HTTPStatus = status
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
@@ -198,7 +198,7 @@ func (o *OPStorage) CreateAccessToken(ctx context.Context, req op.TokenRequest)
|
|||||||
userOrgID = authReq.UserOrgID
|
userOrgID = authReq.UserOrgID
|
||||||
case *AuthRequestV2:
|
case *AuthRequestV2:
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, "", authReq.CurrentAuthRequest.UserID, activity.OIDCAccessToken)
|
activity.TriggerHTTP(ctx, "", authReq.CurrentAuthRequest.UserID, activity.OIDCAccessToken)
|
||||||
return o.command.AddOIDCSessionAccessToken(setContextUserSystem(ctx), authReq.GetID())
|
return o.command.AddOIDCSessionAccessToken(setContextUserSystem(ctx), authReq.GetID())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ func (o *OPStorage) CreateAccessToken(ctx context.Context, req op.TokenRequest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, userOrgID, req.GetSubject(), activity.OIDCAccessToken)
|
activity.TriggerHTTP(ctx, userOrgID, req.GetSubject(), activity.OIDCAccessToken)
|
||||||
return resp.TokenID, resp.Expiration, nil
|
return resp.TokenID, resp.Expiration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,11 +225,11 @@ func (o *OPStorage) CreateAccessAndRefreshTokens(ctx context.Context, req op.Tok
|
|||||||
switch tokenReq := req.(type) {
|
switch tokenReq := req.(type) {
|
||||||
case *AuthRequestV2:
|
case *AuthRequestV2:
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, "", tokenReq.GetSubject(), activity.OIDCRefreshToken)
|
activity.TriggerHTTP(ctx, "", tokenReq.GetSubject(), activity.OIDCRefreshToken)
|
||||||
return o.command.AddOIDCSessionRefreshAndAccessToken(setContextUserSystem(ctx), tokenReq.GetID())
|
return o.command.AddOIDCSessionRefreshAndAccessToken(setContextUserSystem(ctx), tokenReq.GetID())
|
||||||
case *RefreshTokenRequestV2:
|
case *RefreshTokenRequestV2:
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, "", tokenReq.GetSubject(), activity.OIDCRefreshToken)
|
activity.TriggerHTTP(ctx, "", tokenReq.GetSubject(), activity.OIDCRefreshToken)
|
||||||
return o.command.ExchangeOIDCSessionRefreshAndAccessToken(setContextUserSystem(ctx), tokenReq.OIDCSessionWriteModel.AggregateID, refreshToken, tokenReq.RequestedScopes)
|
return o.command.ExchangeOIDCSessionRefreshAndAccessToken(setContextUserSystem(ctx), tokenReq.OIDCSessionWriteModel.AggregateID, refreshToken, tokenReq.RequestedScopes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ func (o *OPStorage) CreateAccessAndRefreshTokens(ctx context.Context, req op.Tok
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, userOrgID, req.GetSubject(), activity.OIDCRefreshToken)
|
activity.TriggerHTTP(ctx, userOrgID, req.GetSubject(), activity.OIDCRefreshToken)
|
||||||
return resp.TokenID, token, resp.Expiration, nil
|
return resp.TokenID, token, resp.Expiration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ func (o *OPStorage) TokenRequestByRefreshToken(ctx context.Context, refreshToken
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, "", oidcSession.UserID, activity.OIDCRefreshToken)
|
activity.TriggerHTTP(ctx, "", oidcSession.UserID, activity.OIDCRefreshToken)
|
||||||
return &RefreshTokenRequestV2{OIDCSessionWriteModel: oidcSession}, nil
|
return &RefreshTokenRequestV2{OIDCSessionWriteModel: oidcSession}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ func (o *OPStorage) TokenRequestByRefreshToken(ctx context.Context, refreshToken
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trigger activity log for use of refresh token for user
|
// trigger activity log for use of refresh token for user
|
||||||
activity.Trigger(ctx, tokenView.ResourceOwner, tokenView.UserID, activity.OIDCRefreshToken)
|
activity.TriggerHTTP(ctx, tokenView.ResourceOwner, tokenView.UserID, activity.OIDCRefreshToken)
|
||||||
return RefreshTokenRequestFromBusiness(tokenView), nil
|
return RefreshTokenRequestFromBusiness(tokenView), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -151,7 +151,7 @@ func (p *Storage) SetUserinfoWithUserID(ctx context.Context, applicationID strin
|
|||||||
setUserinfo(user, userinfo, attributes, customAttributes)
|
setUserinfo(user, userinfo, attributes, customAttributes)
|
||||||
|
|
||||||
// trigger activity log for authentication for user
|
// trigger activity log for authentication for user
|
||||||
activity.Trigger(ctx, user.ResourceOwner, user.ID, activity.SAMLResponse)
|
activity.TriggerHTTP(ctx, user.ResourceOwner, user.ID, activity.SAMLResponse)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user