Merge branch 'update_auth_check' into 'master'

add skip for check exist method && handler for user methods

See merge request integration-system/isp-gate-service!2
This commit is contained in:
yan komissarov committed 2020-01-17 13:29:28 +03:00
commit 2d936e543c
14 files changed
+136 -87

No files matched your search

+1 -1
View File
@@ -1 +1 @@
2.4.0
2.5.0
+3
View File
@@ -1,3 +1,6 @@
## 2.5.0
* add skip for check exist method
* add handler for user methods
## 2.4.0
* add access checkout by user id
## 2.3.0
Generated
+61 -51
View File
@@ -2,12 +2,12 @@
[[projects]]
digest = "1:320e7ead93de9fd2b0e59b50fd92a4d50c1f8ab455d96bc2eb083267453a9709"
digest = "1:c68aba66f5db6052fd838d9a7d60d8859f8c11b8c1d9ac9758f69c7a51efc07a"
name = "github.com/asaskevich/govalidator"
packages = ["."]
pruneopts = "UT"
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
version = "v9"
revision = "475eaeb164960a651e97470412a7d3b0c5036105"
version = "v10"
[[projects]]
digest = "1:652880afc6b57ce0a67173f552cb35ccda816493a1da6ca20e5074a66bcd083f"
@@ -18,12 +18,12 @@
version = "v0.1.1"
[[projects]]
digest = "1:44f56f927970ceccb0a28eccbea0cde48e56f04619ddbb70198036407f14cd0e"
digest = "1:bc7e9c56408594a678dd165db7c579c2498a3c9eab9b308099820ddbfe85b720"
name = "github.com/cenkalti/backoff"
packages = ["."]
pruneopts = "UT"
revision = "1ff1c09ea627d2be64cea605afa999c582c7cd01"
version = "v3.1.1"
revision = "a9a4cec6c9a26336ca42700ccc319ca842be56c0"
version = "v4.0.0"
[[projects]]
digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
@@ -43,11 +43,11 @@
[[projects]]
branch = "master"
digest = "1:dfc03bd895603c3186f77cd6069f3953a1f14713a9c9901b52d837afd19205c0"
digest = "1:14f76940ab7adca0fe74b977f88312990f3577fd51517afb9d6cd7850aca48c6"
name = "github.com/fasthttp/websocket"
packages = ["."]
pruneopts = "UT"
revision = "41f3051261751fe62d58a04b14bd522a96f0f7e9"
revision = "4824a47506583ed9c4c44b6e266137898af82503"
[[projects]]
digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd"
@@ -147,12 +147,12 @@
revision = "ac5582987a2f25e8743e0ebb7259312adda05c23"
[[projects]]
branch = "master"
digest = "1:abd0cd78d6d27a98080f2b2a7fd39bb2f3d3eef6aa20c720093129f04fb41d78"
name = "github.com/integration-system/gowsdl"
packages = ["soap"]
pruneopts = "UT"
revision = "368713356c71961354e09ab9b734740ebdd94784"
revision = "f40910e51f21c991494ec27da83b8aa9ff3242f3"
version = "v1.0.0"
[[projects]]
digest = "1:0e89aed3581cac97a24fcbde2cc3dcc7bf7168401c56284c81213fa2cc273ed5"
@@ -191,7 +191,7 @@
version = "v1.3.0"
[[projects]]
digest = "1:fd6dd9f3a50fce97343298aec27f3748df9ed9fc30abe082bfc01ef6c00f2f8a"
digest = "1:03cb16497b7b2b0328e62a3755d5662a74f70bea23c09b56a64d7dc8619e8c0c"
name = "github.com/integration-system/isp-lib"
packages = [
"backend",
@@ -209,8 +209,8 @@
"utils",
]
pruneopts = "UT"
revision = "abfa9a9776d64e6d04d495bfe00db8ca4dcbe7fc"
version = "v2.0.1"
revision = "4ea9449f1b3f2565b9038b0d4cdda3b02089aa8c"
version = "v2.1.0"
[[projects]]
branch = "master"
@@ -224,12 +224,12 @@
revision = "a22bf2e0b56a9ef47db4a98756e39f700a99b688"
[[projects]]
branch = "master"
digest = "1:48f3a739fabefebf152d0196277ee89136c1fa6d88fc67fa486fc765a05b1caa"
digest = "1:e9229e8f68f2f13e638de9159274f536a7a609a61beba0416af603282bfa3464"
name = "github.com/integration-system/jsonschema"
packages = ["."]
pruneopts = "UT"
revision = "5475a8b08e62e41fa886641861ac225e7f91e4e5"
revision = "e1ccd0b9edbdf65911efd04d92220df84a9ce388"
version = "v1.0.0"
[[projects]]
digest = "1:01ed62f8f4f574d8aff1d88caee113700a2b44c42351943fa73cc1808f736a50"
@@ -240,18 +240,18 @@
version = "v1.0.0"
[[projects]]
digest = "1:d78015a9da26d37166a2119592019e8bfe9b24bec60aff4a46db6110070fb1b2"
digest = "1:1e5d8fd04f72d46575b44341578192f5a473c23301262c8ea9867bd2f4130687"
name = "github.com/json-iterator/go"
packages = [
".",
"extra",
]
pruneopts = "UT"
revision = "03217c3e97663914aec3faafde50d081f197a0a2"
version = "1.1.8"
revision = "acfec88f7a0d5140ace3dcdbee10184e3684a9e1"
version = "v1.1.9"
[[projects]]
digest = "1:fa4b4bfa0edfb83c4690d8746ea25bc2447ad0c20063ba72adcb5725f54acde0"
digest = "1:60a4c716301192a7be42f363c41b2b1fab64ae80d9db4453c702b13b05ccddeb"
name = "github.com/klauspost/compress"
packages = [
"flate",
@@ -259,8 +259,8 @@
"zlib",
]
pruneopts = "UT"
revision = "4e96aec082898e4dad17d8aca1a7e2d01362ff6c"
version = "v1.9.2"
revision = "f61bac3a179b270c811148ce2a1f819dfc82825f"
version = "v1.9.7"
[[projects]]
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
@@ -271,7 +271,7 @@
version = "v1.0.2"
[[projects]]
digest = "1:12cb143f2148bf54bcd9fe622abac17325e85eeb1d84b8ec6caf1c80232108fd"
digest = "1:9ff22c26414baf7deaf74f2a788fe7b97666048bcbe346c52cfe823442abbdfb"
name = "github.com/lib/pq"
packages = [
".",
@@ -279,8 +279,8 @@
"scram",
]
pruneopts = "UT"
revision = "3427c32cb71afc948325f299f040e53c1dd78979"
version = "v1.2.0"
revision = "99274577be97ac9b1d95a2d61d566dc9b7cc6a54"
version = "v1.3.0"
[[projects]]
digest = "1:5a0ef768465592efca0412f7e838cdc0826712f8447e70e6ccc52eb441e9ab13"
@@ -299,12 +299,12 @@
version = "v0.1.4"
[[projects]]
digest = "1:d62282425ffb75047679d7e2c3b980eea7f82c05ef5fb9142ee617ebac6e7432"
digest = "1:29895093e370d9da5fd1c9ab12a5855ccb568f28766e0c3ff159c4b0f09aa127"
name = "github.com/mattn/go-isatty"
packages = ["."]
pruneopts = "UT"
revision = "88ba11cfdc67c7588b30042edf244b2875f892b6"
version = "v0.0.10"
revision = "31745d66dd679ac0ac4f8d3ecff168fce6170c6a"
version = "v0.0.11"
[[projects]]
branch = "master"
@@ -355,12 +355,12 @@
version = "v1.6.0"
[[projects]]
digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b"
digest = "1:9e1d37b58d17113ec3cb5608ac0382313c5b59470b94ed97d0976e69c7022314"
name = "github.com/pkg/errors"
packages = ["."]
pruneopts = "UT"
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
version = "v0.8.1"
revision = "614d223910a179a466c1767a985424175c39b465"
version = "v0.9.1"
[[projects]]
digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
@@ -388,11 +388,11 @@
[[projects]]
branch = "master"
digest = "1:8232b87605be15cba8bb9b5089d91a79bb678406aa8b48aaf7b582a104aa5b14"
digest = "1:46aede8169d6df9d740c0fd6f3f8bf4f15e1c465a45cd1d7a1943c5d3c580934"
name = "github.com/savsgio/gotils"
packages = ["."]
pruneopts = "UT"
revision = "524bc4f475005d9dbedc1bc77248a07aef318ef0"
revision = "8f138daf3830703e420eba613f733190da9393ff"
[[projects]]
digest = "1:04457f9f6f3ffc5fea48e71d62f2ca256637dee0a04d710288e27e05c8b41976"
@@ -414,12 +414,12 @@
version = "v1.2.2"
[[projects]]
digest = "1:08d65904057412fc0270fc4812a1c90c594186819243160dc779a402d4b6d0bc"
digest = "1:ff4cd55a3666b6ea3a876c9e133bfb54d6c812e725409a773f2c94a0b3a92f4f"
name = "github.com/spf13/cast"
packages = ["."]
pruneopts = "UT"
revision = "8c9545af88b134710ab1cd196795e7f2388358d7"
version = "v1.3.0"
revision = "1ffadf551085444af981432dd0f6d1160c11ec64"
version = "v1.3.1"
[[projects]]
digest = "1:1b753ec16506f5864d26a28b43703c58831255059644351bbcb019b843950900"
@@ -438,12 +438,12 @@
version = "v1.0.5"
[[projects]]
digest = "1:0b60fc944fb6a7b6c985832bd341bdb7ed8fe894fea330414e7774bb24652962"
digest = "1:83d0e0f3f46dc86daf27e4d7c834c8c492db787c53c09d94183de7478db92142"
name = "github.com/spf13/viper"
packages = ["."]
pruneopts = "UT"
revision = "72b022eb357a56469725dcd03918449e2278d02e"
version = "v1.5.0"
revision = "4525543ce4fe90f7970f5e2cdc300b8ffc8c0582"
version = "v1.6.2"
[[projects]]
digest = "1:8548c309c65a85933a625be5e7d52b6ac927ca30c56869fae58123b8a77a75e1"
@@ -479,7 +479,7 @@
[[projects]]
branch = "master"
digest = "1:dfb4a218519e3b4c8b5d92885496521d7f54d53350ea9ff5eacb5df2fea3d8b9"
digest = "1:7c0bdc8b37e445219e90c5909cfaef9dfb8caf5fb75cfe598a6221427ff85744"
name = "github.com/valyala/fasthttp"
packages = [
".",
@@ -487,7 +487,7 @@
"stackless",
]
pruneopts = "UT"
revision = "32de06dba4ebe30a9f88b43c3bc0f767994467be"
revision = "03813ae4bce8b5984118f62d5f017da3e87c9189"
[[projects]]
digest = "1:39a425f98fb19427061a693fe6bf0683c9bddec4b25b17067e34fdb465e39cb9"
@@ -499,18 +499,18 @@
[[projects]]
branch = "master"
digest = "1:35ce874cf16f78a2da908ab28b0277497e36603d289db00d39da5200bc8ace08"
digest = "1:c0aaca73817c074594c68efae05e33b71abbcc7d10af8ac7bf964bccbe308a8f"
name = "golang.org/x/crypto"
packages = [
"pbkdf2",
"ssh/terminal",
]
pruneopts = "UT"
revision = "ac88ee75c92c889b97e05591e9a39b6480c538b3"
revision = "6d4e4cb37c7d6416dfea8472e751c7b6615267a6"
[[projects]]
branch = "master"
digest = "1:957579c244f371e4490a28c38685bfdb573639943d9add65aceb2dbd0ae76d50"
digest = "1:4311090d37cc317b15a3a3d2ce9a3d187d0b667ded11339a9564b3ec38cb21e4"
name = "golang.org/x/net"
packages = [
"context",
@@ -522,18 +522,18 @@
"trace",
]
pruneopts = "UT"
revision = "ffdde105785063a81acd95bdf89ea53f6e0aac2d"
revision = "6afb5195e5aab057fda82e27171243402346b0ad"
[[projects]]
branch = "master"
digest = "1:adc8dbdd1348594585d83239cf52498fd87e103577dda9b50ccac2122d9ead72"
digest = "1:f7b9c8ac6e14581494d8f20a044878b1d23aac99e49bc4f1ac831a973fb9ccfd"
name = "golang.org/x/sys"
packages = [
"unix",
"windows",
]
pruneopts = "UT"
revision = "bd437916bb0eb726b873ee8e9b2dcf212d32e2fd"
revision = "b77594299b429d05028403d72b68172959c7dad5"
[[projects]]
digest = "1:8d8faad6b12a3a4c819a3f9618cb6ee1fa1cfc33253abeeea8b55336721e3405"
@@ -569,13 +569,14 @@
"googleapis/rpc/status",
]
pruneopts = "UT"
revision = "83cc0476cb11ea0da33dacd4c6354ab192de6fe6"
revision = "ca5a22157cba8746e7aa978de1b1ac4085150840"
[[projects]]
digest = "1:b59ce3ddb11daeeccccc9cb3183b58ebf8e9a779f1c853308cd91612e817a301"
digest = "1:3fe55026bb11519b45c0fc9d848fd779028b868dc62f5563c518cf850c7421d5"
name = "google.golang.org/grpc"
packages = [
".",
"attributes",
"backoff",
"balancer",
"balancer/base",
@@ -612,8 +613,16 @@
"tap",
]
pruneopts = "UT"
revision = "1a3960e4bd028ac0cec0a2afd27d7d8e67c11514"
version = "v1.25.1"
revision = "f5b0812e6fe574d90da76b205e9eb51f6ddb1919"
version = "v1.26.0"
[[projects]]
digest = "1:c4b5592c342f273e18de68e16957f536f6648f2e90c9d7ece653ac90c22079a9"
name = "gopkg.in/ini.v1"
packages = ["."]
pruneopts = "UT"
revision = "94291fffe2b14f4632ec0e67c1bfecfc1287a168"
version = "v1.51.1"
[[projects]]
digest = "1:b75b3deb2bce8bc079e16bb2aecfe01eb80098f5650f9e93e5643ca8b7b73737"
@@ -673,6 +682,7 @@
"github.com/json-iterator/go",
"github.com/pkg/errors",
"github.com/rcrowley/go-metrics",
"github.com/spf13/cast",
"github.com/stretchr/testify/assert",
"github.com/valyala/fasthttp",
"golang.org/x/net/context",
+6 -2
View File
@@ -88,9 +88,8 @@ func Do(ctx *fasthttp.RequestCtx, path string) (int32, error) {
userId, err := verifyToken.User(verifiableKeys[utils.UserTokenHeader])
if err != nil {
return 0, createError("forbidden", codes.PermissionDenied)
} else {
verifiableKeys[utils.UserIdHeader] = userId
}
verifiableKeys[utils.UserIdHeader] = userId
}
permittedToCall := false
@@ -115,6 +114,11 @@ func Do(ctx *fasthttp.RequestCtx, path string) (int32, error) {
return 0, createError("forbidden", codes.PermissionDenied)
}
}
if verifiableKeys[utils.UserIdHeader] == "" {
if _, ok := routing.AuthUserMethods[path]; ok {
return 0, createError("forbidden", codes.PermissionDenied)
}
}
//TODO backward capability for isp-config-service 1.x.x
uuid := config.Get().(*conf.Configuration).InstanceUuid
+2 -2
View File
@@ -7,8 +7,8 @@ httpOuterAddress:
httpInnerAddress:
ip: 0.0.0.0
port: 9003
moduleName: isp-gate
instanceUuid: ec183598-746a-425f-b5e5-27b7fa8bc6af
moduleName: gate
instanceUuid: 9d89354b-c728-4b48-b002-a7d3b229f151
locations:
- pathPrefix: /api
protocol: grpc
+5 -4
View File
@@ -15,10 +15,11 @@ type (
}
Location struct {
SkipAuth bool
PathPrefix string `valid:"required~Required"`
Protocol string `valid:"required~Required"`
TargetModule string `valid:"required~Required"`
SkipAuth bool
SkipExistCheck bool
PathPrefix string `valid:"required~Required"`
Protocol string `valid:"required~Required"`
TargetModule string `valid:"required~Required"`
}
)
+6 -4
View File
@@ -66,10 +66,12 @@ func (handlerHelper) AuthenticateAccountingProxy(ctx *fasthttp.RequestCtx) domai
return domain.Create().SetError(errors.New(msg))
}
if _, ok := routing.AllMethods[path]; !ok {
msg := "not implemented"
utils.WriteError(ctx, msg, codes.Unimplemented, nil)
return domain.Create().SetError(errors.New(msg))
if !p.SkipExistCheck() {
if _, ok := routing.AllMethods[path]; !ok {
msg := "not implemented"
utils.WriteError(ctx, msg, codes.Unimplemented, nil)
return domain.Create().SetError(errors.New(msg))
}
}
if !p.SkipAuth() {
+2 -1
View File
@@ -115,7 +115,8 @@ func getRequiredModulesByLocations(locations []conf.Location) map[string]func([]
for targetModule, locations := range locationsByTargetModule {
consumerStorage := make([]func([]structure.AddressConfiguration) bool, len(locations))
for i, location := range locations {
if p, err := proxy.Init(location.Protocol, location.PathPrefix, location.SkipAuth); err != nil {
p, err := proxy.Init(location.Protocol, location.PathPrefix, location.SkipAuth, location.SkipExistCheck)
if err != nil {
log.Fatal(stdcodes.ModuleInvalidLocalConfig, err)
} else {
consumerStorage[i] = p.Consumer
+6 -5
View File
@@ -26,29 +26,30 @@ type (
ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse
Consumer([]structure.AddressConfiguration) bool
SkipAuth() bool
SkipExistCheck() bool
Close()
}
)
func Init(protocol, pathPrefix string, skipAuth bool) (Proxy, error) {
func Init(protocol, pathPrefix string, skipAuth, skipExistCheck bool) (Proxy, error) {
if pathPrefix[0] != '/' {
return nil, errors.Errorf("path must begin with '/' in path '%s'", pathPrefix)
}
switch protocol {
case httpProtocol:
proxy := http.NewProxy(skipAuth)
proxy := http.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
case grpcProtocol:
proxy := grpc.NewProxy(skipAuth)
proxy := grpc.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
case healthCheckProtocol:
proxy := health_check.NewProxy(skipAuth)
proxy := health_check.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
case websocketProtocol:
proxy := websocket.NewProxy(skipAuth)
proxy := websocket.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
default:
+10 -4
View File
@@ -16,11 +16,12 @@ import (
)
type grpcProxy struct {
client *backend.RxGrpcClient
skipAuth bool
client *backend.RxGrpcClient
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *grpcProxy {
func NewProxy(skipAuth, skipExistCheck bool) *grpcProxy {
return &grpcProxy{
client: backend.NewRxGrpcClient(
backend.WithDialOptions(
@@ -31,7 +32,8 @@ func NewProxy(skipAuth bool) *grpcProxy {
backend.WithDialingErrorHandler(func(err error) {
log.Errorf(log_code.ErrorClientGrpc, "dialing err: %v", err)
})),
skipAuth: skipAuth,
skipAuth: skipAuth,
skipExistCheck: skipExistCheck,
}
}
@@ -57,6 +59,10 @@ func (p *grpcProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *grpcProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
func (p *grpcProxy) Close() {
p.client.Close()
}
+8 -3
View File
@@ -7,11 +7,12 @@ import (
)
type healthCheckProxy struct {
skipAuth bool
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *healthCheckProxy {
return &healthCheckProxy{skipAuth: skipAuth}
func NewProxy(skipAuth, skipExistCheck bool) *healthCheckProxy {
return &healthCheckProxy{skipAuth: skipAuth, skipExistCheck: skipExistCheck}
}
func (p *healthCheckProxy) Consumer(addressList []structure.AddressConfiguration) bool {
@@ -28,6 +29,10 @@ func (p *healthCheckProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *healthCheckProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
func (p *healthCheckProxy) Close() {
}
+9 -4
View File
@@ -14,12 +14,13 @@ import (
)
type httpProxy struct {
client *fasthttp.HostClient
skipAuth bool
client *fasthttp.HostClient
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *httpProxy {
return &httpProxy{client: nil, skipAuth: skipAuth}
func NewProxy(skipAuth, skipExistCheck bool) *httpProxy {
return &httpProxy{client: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
}
func (p *httpProxy) Consumer(addressList []structure.AddressConfiguration) bool {
@@ -72,6 +73,10 @@ func (p *httpProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *httpProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
func (p *httpProxy) Close() {
p.client = nil
}
+9 -4
View File
@@ -41,12 +41,13 @@ var upgrader = websocket.FastHTTPUpgrader{
}
type websocketProxy struct {
addrs *RoundRobinAddrs
skipAuth bool
addrs *RoundRobinAddrs
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *websocketProxy {
return &websocketProxy{addrs: nil, skipAuth: skipAuth}
func NewProxy(skipAuth, skipExistCheck bool) *websocketProxy {
return &websocketProxy{addrs: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
}
func (p *websocketProxy) Consumer(addressList []structure.AddressConfiguration) bool {
@@ -129,6 +130,10 @@ func (p *websocketProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *websocketProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
// no-op
func (p *websocketProxy) Close() {
}
+8 -2
View File
@@ -5,13 +5,15 @@ import (
)
var (
InnerMethods = make(map[string]bool)
AllMethods = make(map[string]bool)
InnerMethods = make(map[string]bool)
AllMethods = make(map[string]bool)
AuthUserMethods = make(map[string]bool)
)
func InitRoutes(configs structure.RoutingConfig) {
newAddressMap := make(map[string]bool)
newInnerAddressMap := make(map[string]bool)
newAuthUserAddressMap := make(map[string]bool)
for _, backend := range configs {
if backend.Address.IP == "" || backend.Address.Port == "" || len(backend.Endpoints) == 0 {
continue
@@ -21,8 +23,12 @@ func InitRoutes(configs structure.RoutingConfig) {
if v.Inner {
newInnerAddressMap[v.Path] = true
}
if v.UserAuthRequired {
newAuthUserAddressMap[v.Path] = true
}
}
}
AllMethods = newAddressMap
InnerMethods = newInnerAddressMap
AuthUserMethods = newAuthUserAddressMap
}