Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions istio/_istio152/filter/stream/jwtauthn/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ func newAuthenticator(provider string, jwksCache JwksCache, fetcher JwksFetcher,
}

func (a *authenticator) Verify(headers api.HeaderMap, tokens []JwtLocation) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Infof("JWT authentication starts, tokens size=%d", len(tokens))
}
log.DefaultLogger.Debugf("JWT authentication starts, tokens size=%d", len(tokens))
if len(tokens) == 0 {
return a.done(ErrJwtNotFound)
}
Expand Down Expand Up @@ -71,9 +69,7 @@ func (a *authenticator) name() string {
}

func (a *authenticator) done(err error) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("%s: JWT token verification completed with: %v", a.name(), err)
}
log.DefaultLogger.Debugf("%s: JWT token verification completed with: %v", a.name(), err)

// if on allow missing or failed this should verify all tokens, otherwise stop on ok.
if len(a.tokens) == 0 {
Expand Down Expand Up @@ -105,9 +101,7 @@ func (a *authenticator) startVerify() error {
a.jwtPayload = parts[1]
claims := jwtToken.Claims.(*jwt.StandardClaims)

if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("Verifying JWT token of issuer: %s", claims.Issuer)
}
log.DefaultLogger.Debugf("Verifying JWT token of issuer: %s", claims.Issuer)
// Check if token extracted from the location contains the issuer specified by config.
if !a.currToken.IsIssuerSpecified(claims.Issuer) {
return a.done(ErrJwtUnknownIssuer)
Expand Down
4 changes: 1 addition & 3 deletions istio/_istio152/filter/stream/jwtauthn/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ type FilterConfigFactory struct {

// CreateJwtAuthnFilterFactory creates a new JwtAuthnFilterFactory.
func CreateJwtAuthnFilterFactory(cfg map[string]interface{}) (api.StreamFilterChainFactory, error) {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("create jwt authn stream filter factory")
}
log.DefaultLogger.Debugf("create jwt authn stream filter factory")
c, err := ParseJWTAuthnFilter(cfg)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions istio/_istio152/filter/stream/jwtauthn/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func newJwtAuthnFilter(config FilterConfig) *filter {
}

func (f *filter) OnReceive(ctx context.Context, headers api.HeaderMap, buf buffer.IoBuffer, trailers api.HeaderMap) api.StreamFilterStatus {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("call jwt_authn filter")
}
log.DefaultLogger.Debugf("call jwt_authn filter")

// TODO(huangrh): bypass

Expand Down
8 changes: 2 additions & 6 deletions istio/_istio152/filter/stream/jwtauthn/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func (p *prefixMatcher) Matches(headers api.HeaderMap, requestPath string) bool
prefixMatch := strings.HasPrefix(path, prefix)

if p.baseMatcher.matchRoutes(headers, requestPath) && prefixMatch {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("Prefix requirement '%s' matched.", p.prefix)
}
log.DefaultLogger.Debugf("Prefix requirement '%s' matched.", p.prefix)
return true
}
return false
Expand Down Expand Up @@ -109,9 +107,7 @@ func (p *pathMatcher) Matches(headers api.HeaderMap, requestPath string) bool {
pathMatch = strings.EqualFold(strings.ToLower(p.path), strings.ToLower(requestPath))
}
if p.baseMatcher.matchRoutes(headers, requestPath) && pathMatch {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("Path requirement '%s' matched.", p.path)
}
log.DefaultLogger.Debugf("Path requirement '%s' matched.", p.path)
return true
}
return false
Expand Down
4 changes: 1 addition & 3 deletions istio/_istio152/sds/sds.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ func (sc *SdsStreamClientImpl) ackResponse(resp *xdsapi.DiscoveryResponse) error
},
}

if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("send a ack request to server: %v", req)
}
log.DefaultLogger.Infof("send a ack request to server: %v", req)

return sc.streamSecretsClient.Send(req)
}
Expand Down
4 changes: 1 addition & 3 deletions istio/_istio152/xds/cds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (

func (ads *AdsStreamClient) handleCds(resp *envoy_api_v2.DiscoveryResponse) error {
clusters := HandleClusterResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d clusters from CDS", len(clusters))
}
log.DefaultLogger.Infof("get %d clusters from CDS", len(clusters))
ads.config.converter.ConvertUpdateClusters(clusters)
ads.AckResponse(resp)

Expand Down
4 changes: 1 addition & 3 deletions istio/_istio152/xds/eds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (

func (ads *AdsStreamClient) handleEds(resp *envoy_api_v2.DiscoveryResponse) error {
endpoints := HandleEndpointResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d endpoints from EDS", len(endpoints))
}
log.DefaultLogger.Infof("get %d endpoints from EDS", len(endpoints))
ads.config.converter.ConvertUpdateEndpoints(endpoints)

ads.AckResponse(resp)
Expand Down
4 changes: 1 addition & 3 deletions istio/_istio152/xds/lds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (

func (ads *AdsStreamClient) handleLds(resp *envoy_api_v2.DiscoveryResponse) error {
listeners := HandleListenerResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d listeners from LDS", len(listeners))
}
log.DefaultLogger.Infof("get %d listeners from LDS", len(listeners))
ads.config.converter.ConvertAddOrUpdateListeners(listeners)

ads.AckResponse(resp)
Expand Down
8 changes: 2 additions & 6 deletions istio/_istio152/xds/rds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (

func (ads *AdsStreamClient) handleRds(resp *envoy_api_v2.DiscoveryResponse) error {
routes := HandleRouteResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d routes from RDS", len(routes))
}
log.DefaultLogger.Infof("get %d routes from RDS", len(routes))
ads.config.converter.ConvertAddOrUpdateRouters(routes)

ads.AckResponse(resp)
Expand All @@ -38,9 +36,7 @@ func (ads *AdsStreamClient) handleRds(resp *envoy_api_v2.DiscoveryResponse) erro
func CreateRdsRequest(config *AdsConfig) *envoy_api_v2.DiscoveryRequest {
routerNames := config.converter.GetRouterNames()
if len(routerNames) < 1 {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("no routers, skip rds request")
}
log.DefaultLogger.Debugf("no routers, skip rds request")
return nil
}
return &envoy_api_v2.DiscoveryRequest{
Expand Down
12 changes: 3 additions & 9 deletions istio/istio1106/filter/stream/jwtauthn/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ func newAuthenticator(provider string, jwksCache JwksCache, fetcher JwksFetcher,
}

func (a *authenticator) Verify(headers api.HeaderMap, tokens []JwtLocation) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Infof("JWT authentication starts, tokens size=%d", len(tokens))
}
log.DefaultLogger.Debugf("JWT authentication starts, tokens size=%d", len(tokens))
if len(tokens) == 0 {
return a.done(ErrJwtNotFound)
}
Expand Down Expand Up @@ -71,9 +69,7 @@ func (a *authenticator) name() string {
}

func (a *authenticator) done(err error) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("%s: JWT token verification completed with: %v", a.name(), err)
}
log.DefaultLogger.Debugf("%s: JWT token verification completed with: %v", a.name(), err)

// if on allow missing or failed this should verify all tokens, otherwise stop on ok.
if len(a.tokens) == 0 {
Expand Down Expand Up @@ -105,9 +101,7 @@ func (a *authenticator) startVerify() error {
a.jwtPayload = parts[1]
claims := jwtToken.Claims.(*jwt.StandardClaims)

if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("Verifying JWT token of issuer: %s", claims.Issuer)
}
log.DefaultLogger.Debugf("Verifying JWT token of issuer: %s", claims.Issuer)
// Check if token extracted from the location contains the issuer specified by config.
if !a.currToken.IsIssuerSpecified(claims.Issuer) {
return a.done(ErrJwtUnknownIssuer)
Expand Down
4 changes: 1 addition & 3 deletions istio/istio1106/filter/stream/jwtauthn/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ type FilterConfigFactory struct {

// CreateJwtAuthnFilterFactory creates a new JwtAuthnFilterFactory.
func CreateJwtAuthnFilterFactory(cfg map[string]interface{}) (api.StreamFilterChainFactory, error) {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("create jwt authn stream filter factory")
}
log.DefaultLogger.Debugf("create jwt authn stream filter factory")
c, err := ParseJWTAuthnFilter(cfg)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions istio/istio1106/filter/stream/jwtauthn/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func newJwtAuthnFilter(config FilterConfig) *filter {
}

func (f *filter) OnReceive(ctx context.Context, headers api.HeaderMap, buf buffer.IoBuffer, trailers api.HeaderMap) api.StreamFilterStatus {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("call jwt_authn filter")
}
log.DefaultLogger.Debugf("call jwt_authn filter")

// TODO(huangrh): bypass

Expand Down
8 changes: 2 additions & 6 deletions istio/istio1106/filter/stream/jwtauthn/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func (p *prefixMatcher) Matches(headers api.HeaderMap, requestPath string) bool
prefixMatch := strings.HasPrefix(path, prefix)

if p.baseMatcher.matchRoutes(headers, requestPath) && prefixMatch {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("Prefix requirement '%s' matched.", p.prefix)
}
log.DefaultLogger.Debugf("Prefix requirement '%s' matched.", p.prefix)
return true
}
return false
Expand Down Expand Up @@ -109,9 +107,7 @@ func (p *pathMatcher) Matches(headers api.HeaderMap, requestPath string) bool {
pathMatch = strings.EqualFold(strings.ToLower(p.path), strings.ToLower(requestPath))
}
if p.baseMatcher.matchRoutes(headers, requestPath) && pathMatch {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("Path requirement '%s' matched.", p.path)
}
log.DefaultLogger.Debugf("Path requirement '%s' matched.", p.path)
return true
}
return false
Expand Down
4 changes: 1 addition & 3 deletions istio/istio1106/xds/cds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (

func (ads *AdsStreamClient) handleCds(resp *envoy_service_discovery_v3.DiscoveryResponse) error {
clusters := HandleClusterResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d clusters from CDS", len(clusters))
}
log.DefaultLogger.Infof("get %d clusters from CDS", len(clusters))
// TODO: handle error, support error detail for ack
ads.config.converter.ConvertUpdateClusters(clusters)
// save response info
Expand Down
4 changes: 1 addition & 3 deletions istio/istio1106/xds/eds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (

func (ads *AdsStreamClient) handleEds(resp *envoy_service_discovery_v3.DiscoveryResponse) error {
endpoints := HandleEndpointResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d endpoints from EDS", len(endpoints))
}
log.DefaultLogger.Infof("get %d endpoints from EDS", len(endpoints))
ads.config.converter.ConvertUpdateEndpoints(endpoints)
info := &responseInfo{
VersionInfo: resp.VersionInfo,
Expand Down
4 changes: 1 addition & 3 deletions istio/istio1106/xds/lds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (

func (ads *AdsStreamClient) handleLds(resp *envoy_service_discovery_v3.DiscoveryResponse) error {
listeners := HandleListenerResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d listeners from LDS", len(listeners))
}
log.DefaultLogger.Infof("get %d listeners from LDS", len(listeners))
ads.config.converter.ConvertAddOrUpdateListeners(listeners)
info := &responseInfo{
ResponseNonce: resp.Nonce,
Expand Down
8 changes: 2 additions & 6 deletions istio/istio1106/xds/rds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (

func (ads *AdsStreamClient) handleRds(resp *envoy_service_discovery_v3.DiscoveryResponse) error {
routes := HandleRouteResponse(resp)
if log.DefaultLogger.GetLogLevel() >= log.INFO {
log.DefaultLogger.Infof("get %d routes from RDS", len(routes))
}
log.DefaultLogger.Infof("get %d routes from RDS", len(routes))
ads.config.converter.ConvertAddOrUpdateRouters(routes)
resourceNames := make([]string, 0, len(routes))
for _, rt := range routes {
Expand All @@ -48,9 +46,7 @@ func (ads *AdsStreamClient) handleRds(resp *envoy_service_discovery_v3.Discovery
func CreateRdsRequest(config *AdsConfig) *envoy_service_discovery_v3.DiscoveryRequest {
routerNames := config.converter.GetRouterNames()
if len(routerNames) < 1 {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("no routers, skip rds request")
}
log.DefaultLogger.Debugf("no routers, skip rds request")
return nil
}
info := config.previousInfo.Find(EnvoyRoute)
Expand Down
9 changes: 2 additions & 7 deletions pkg/configmanager/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ func AddOrUpdateListenerFilterFactories(listenerName string, configs []v2.Filter
}

listenerFilterFactoryMap.Store(listenerName, factories)
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("[config] AddOrUpdateListenerFilterFactories store listener factory, name: %v, config: %v",
listenerName, configs)
}
log.DefaultLogger.Debugf("[config] AddOrUpdateListenerFilterFactories store listener factory, name: %v, config: %v", listenerName, configs)

return factories
}
Expand Down Expand Up @@ -436,9 +433,7 @@ func AddOrUpdateNetworkFilterFactories(listenerName string, ln *v2.Listener) []a
}

networkFilterFactoryMap.Store(listenerName, factories)
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("[config] AddOrUpdateNetworkFilterFactories store network filter factories, name: %v", listenerName)
}
log.DefaultLogger.Debugf("[config] AddOrUpdateNetworkFilterFactories store network filter factories, name: %v", listenerName)

return factories
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/filter/listener/originaldst/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ func (filter *originalDst) OnAccept(cb api.ListenerFilterChainFactoryCallbacks)
return api.Continue
}

if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("%s remote addr: %s:%d", logTag, ip, port)
}
log.DefaultLogger.Debugf("%s remote addr: %s:%d", logTag, ip, port)

if filter.FallbackToLocal {
ctx := cb.GetOriContext()
Expand Down
28 changes: 7 additions & 21 deletions pkg/filter/network/grpc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ var _ net.Conn = (*Connection)(nil)
func (c *Connection) Read(b []byte) (n int, err error) {
data, ok := <-c.r
if !ok { // connection closed
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection read error: %s", c.event)
}
log.DefaultLogger.Debugf("grpc connection read error: %s", c.event)
if c.event == api.RemoteClose {
return 0, io.EOF
}
Expand All @@ -76,9 +74,7 @@ func (c *Connection) Read(b []byte) (n int, err error) {
n = copy(b, data.Bytes())
data.Drain(n)
c.endRead <- struct{}{}
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection read data: %d, %v", n, err)
}
log.DefaultLogger.Debugf("grpc connection read data: %d, %v", n, err)
return
}

Expand All @@ -89,9 +85,7 @@ func (c *Connection) Write(b []byte) (n int, err error) {
n = len(b)
buf := buffer.NewIoBufferBytes(b)
err = c.raw.Write(buf) // write directly to raw connection
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection write data: %d, %v", n, err)
}
log.DefaultLogger.Debugf("grpc connection write data: %d, %v", n, err)
return
}

Expand All @@ -103,9 +97,7 @@ func (c *Connection) Close() error {
if !c.closed.CAS(false, true) {
return syscall.EINVAL
}
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection: closed")
}
log.DefaultLogger.Debugf("grpc connection: closed")
close(c.r)
close(c.endRead)
c.raw.Close(api.NoFlush, api.LocalClose)
Expand All @@ -124,23 +116,17 @@ func (c *Connection) RemoteAddr() net.Addr {
// This connection's timeout takes no effect on real connection.
// If the real connection reads timeout, no data send to this connection
func (c *Connection) SetDeadline(t time.Time) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection: set a deadline: %v", t)
}
log.DefaultLogger.Debugf("grpc connection: set a deadline: %v", t)
return nil
}

func (c *Connection) SetReadDeadline(t time.Time) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection: set a read deadline: %v", t)
}
log.DefaultLogger.Debugf("grpc connection: set a read deadline: %v", t)
return nil
}

func (c *Connection) SetWriteDeadline(t time.Time) error {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("grpc connection: set a write deadline: %v", t)
}
log.DefaultLogger.Debugf("grpc connection: set a write deadline: %v", t)
return nil
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/filter/network/grpc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ var _ api.NetworkFilterChainFactory = (*grpcServerFilterFactory)(nil)
var _ api.FactoryInitializer = (*grpcServerFilterFactory)(nil)

func (f *grpcServerFilterFactory) CreateFilterChain(ctx context.Context, callbacks api.NetWorkFilterChainFactoryCallbacks) {
if log.DefaultLogger.GetLogLevel() >= log.DEBUG {
log.DefaultLogger.Debugf("create a new grpc filter")
}
log.DefaultLogger.Debugf("create a new grpc filter")
rf := NewGrpcFilter(ctx, f.server.ln)
callbacks.AddReadFilter(rf)
}
Expand Down
Loading