From a39036a051252a123cdeb0e7dd25ab7860170f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 6 Nov 2025 14:00:26 +0300 Subject: [PATCH 1/5] MSP-6673 Up deps --- go.mod | 2 +- go.sum | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c374923..ea72fa5 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/redis/go-redis/v9 v9.11.0 github.com/stretchr/testify v1.11.1 github.com/tomakado/websocketproxy v0.1.0 - github.com/txix-open/isp-kit v1.57.1 + github.com/txix-open/isp-kit v1.62.0 github.com/txix-open/jsonschema v1.3.0 golang.org/x/net v0.44.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 diff --git a/go.sum b/go.sum index 9f94477..87bae38 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ github.com/getsentry/sentry-go v0.35.2 h1:jKuujpRwa8FFRYMIwwZpu83Xh0voll9bmvyc63 github.com/getsentry/sentry-go v0.35.2/go.mod h1:mdL49ixwT2yi57k5eh7mpnDyPybixPzlzEJFu0Z76QA= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-faker/faker/v4 v4.6.1 h1:xUyVpAjEtB04l6XFY0V/29oR332rOSPWV4lU8RwDt4k= +github.com/go-faker/faker/v4 v4.6.1/go.mod h1:arSdxNCSt7mOhdk8tEolvHeIJ7eX4OX80wXjKKvkKBY= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -123,8 +125,8 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8= github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM= github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po= -github.com/txix-open/isp-kit v1.57.1 h1:EltTEs9VZT8eqUrrRt5EqWAPdXFvw1XL2/EDN8xfdUU= -github.com/txix-open/isp-kit v1.57.1/go.mod h1:Mbprn7ExedjRg4yUPa9xShYx1oMJIU+a19x6ksVubaw= +github.com/txix-open/isp-kit v1.62.0 h1:SfY8x5/3yYEicr5phGTJBaUwFvgktSIsD/NubrKYbg4= +github.com/txix-open/isp-kit v1.62.0/go.mod h1:hyCFmWF0qoVY2loTLyHJx8QPZJuULntG0JfthqFCdsA= github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4= github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00= github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0= From fa803e9cac61d94909bb113984dc8f87eab6570e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 6 Nov 2025 13:53:19 +0300 Subject: [PATCH 2/5] MSP-6673 Add basic auth --- domain/auth.go | 1 + middleware/authenticate.go | 26 ++++++++++++++++++++++---- request/context.go | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/domain/auth.go b/domain/auth.go index 1813906..59766ec 100644 --- a/domain/auth.go +++ b/domain/auth.go @@ -1,6 +1,7 @@ package domain type AuthData struct { + AppName string SystemId int DomainId int ServiceId int diff --git a/middleware/authenticate.go b/middleware/authenticate.go index ced3821..02caadd 100644 --- a/middleware/authenticate.go +++ b/middleware/authenticate.go @@ -21,7 +21,7 @@ type Authenticator interface { func Authenticate(authenticator Authenticator) Middleware { return func(next Handler) Handler { return HandlerFunc(func(ctx *request.Context) error { - token := ctx.Param(applicationTokenHeader) + token, appName := extractToken(ctx) if token == "" { return httperrors.New( http.StatusUnauthorized, @@ -32,18 +32,36 @@ func Authenticate(authenticator Authenticator) Middleware { resp, err := authenticator.Authenticate(ctx.Context(), token) if err != nil { - return errors.WithMessagef(err, "authenticate: authenticate") + return errors.WithMessage(err, "authenticate: authenticator error") } + if !resp.Authenticated { return httperrors.New( http.StatusUnauthorized, "invalid application token", - errors.WithMessage(errors.New(resp.ErrorReason), "authenticate: authenticate"), + errors.Errorf("authenticate: %s", resp.ErrorReason), ) } - ctx.Authenticate(request.AuthData(*resp.AuthData)) + if appName != "" && resp.AuthData.AppName != appName { + return httperrors.New( + http.StatusUnauthorized, + "invalid application token", + errors.New("authenticate: basic auth failed"), + ) + } + + ctx.Authenticate(request.AuthData(*resp.AuthData)) return next.Handle(ctx) }) } } + +func extractToken(ctx *request.Context) (string, string) { + appName, token, ok := ctx.Request().BasicAuth() + if ok { + return token, appName + } + + return ctx.Param(applicationTokenHeader), "" +} diff --git a/request/context.go b/request/context.go index ede23ce..04323a8 100644 --- a/request/context.go +++ b/request/context.go @@ -13,6 +13,7 @@ var ( ) type AuthData struct { + AppName string SystemId int DomainId int ServiceId int From 069881f85fb896f14c132cd8ba1318597b1eaddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Tue, 11 Nov 2025 14:20:57 +0300 Subject: [PATCH 3/5] MSP-6673 Error on empty appName on basic auth --- middleware/authenticate.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/middleware/authenticate.go b/middleware/authenticate.go index 02caadd..f81a75f 100644 --- a/middleware/authenticate.go +++ b/middleware/authenticate.go @@ -21,7 +21,10 @@ type Authenticator interface { func Authenticate(authenticator Authenticator) Middleware { return func(next Handler) Handler { return HandlerFunc(func(ctx *request.Context) error { - token, appName := extractToken(ctx) + token, appName, err := extractToken(ctx) + if err != nil { + return err + } if token == "" { return httperrors.New( http.StatusUnauthorized, @@ -57,11 +60,18 @@ func Authenticate(authenticator Authenticator) Middleware { } } -func extractToken(ctx *request.Context) (string, string) { +func extractToken(ctx *request.Context) (string, string, error) { appName, token, ok := ctx.Request().BasicAuth() - if ok { - return token, appName + if !ok { + return ctx.Param(applicationTokenHeader), "", nil } - return ctx.Param(applicationTokenHeader), "" + if appName == "" { + return "", "", httperrors.New( + http.StatusUnauthorized, + "application name required", + errors.New("authenticate: application name required on basic auth"), + ) + } + return token, appName, nil } From 325ededd8659b43ac18edd89b063a4b00cfa6e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Tue, 11 Nov 2025 18:22:05 +0300 Subject: [PATCH 4/5] MSP-6673 Up internal error message --- middleware/authenticate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/authenticate.go b/middleware/authenticate.go index f81a75f..a5c5890 100644 --- a/middleware/authenticate.go +++ b/middleware/authenticate.go @@ -50,7 +50,7 @@ func Authenticate(authenticator Authenticator) Middleware { return httperrors.New( http.StatusUnauthorized, "invalid application token", - errors.New("authenticate: basic auth failed"), + errors.New("authenticate: application name mismatch"), ) } From abfd06b40715c2861d86b7c250da33a5356afcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 6 Nov 2025 14:01:39 +0300 Subject: [PATCH 5/5] MSP-6673 Bump version to 5.5.0 --- .version | 2 +- CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.version b/.version index 04edabd..c7ba1e8 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -5.4.1 \ No newline at end of file +5.5.0 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f23ccc4..85279d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v5.5.0 +* Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения ### v5.4.1 * Оптимизация очистки тела запроса от экранирования unicode символов для корректного логирования ### v5.4.0