diff --git a/engine/internal/platform/platform.go b/engine/internal/platform/platform.go index 600ba12880de6784f76854499005ee1d70f9e0cf..6370a5a6c3b0d473657868f1f18aeb85b69ebbb3 100644 --- a/engine/internal/platform/platform.go +++ b/engine/internal/platform/platform.go @@ -112,3 +112,8 @@ func (s *Service) OriginURL() string { return platformURL.String() } + +// AccessToken returns Platform AccessToken. +func (s *Service) AccessToken() string { + return s.cfg.AccessToken +} diff --git a/engine/internal/srv/server.go b/engine/internal/srv/server.go index 3e3375a3499f9480f929b1a587487b66c5e79304..5311cb627bded8e32e259445da1f400524fbc940 100644 --- a/engine/internal/srv/server.go +++ b/engine/internal/srv/server.go @@ -276,6 +276,10 @@ func (s *Server) initLogRegExp() { secretPatterns = append(secretPatterns, s.Config.VerificationToken) } + if accessToken := s.Platform.AccessToken(); len(accessToken) >= minTokenLength && !containsSpace(accessToken) { + secretPatterns = append(secretPatterns, accessToken) + } + s.re = regexp.MustCompile("(?i)" + strings.Join(secretPatterns, "|")) } diff --git a/engine/internal/srv/ws_test.go b/engine/internal/srv/ws_test.go index b08bd8b7d78cbb1dcb49c2cd9df861251b1d4ef6..67cb393bb6eda9ebf6a99219389f18765c2b0df6 100644 --- a/engine/internal/srv/ws_test.go +++ b/engine/internal/srv/ws_test.go @@ -1,15 +1,21 @@ package srv import ( + "context" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gitlab.com/postgres-ai/database-lab/v3/internal/platform" "gitlab.com/postgres-ai/database-lab/v3/internal/srv/config" ) func TestLogLineFiltering(t *testing.T) { - s := Server{Config: &config.Config{VerificationToken: "secretToken"}} + pl, err := platform.New(context.Background(), platform.Config{AccessToken: "platformAccessToken"}) + require.NoError(t, err) + + s := Server{Config: &config.Config{VerificationToken: "secretToken"}, Platform: pl} s.initLogRegExp() testCases := []struct { @@ -56,6 +62,10 @@ func TestLogLineFiltering(t *testing.T) { input: []byte(`AWS_ACCESS_KEY_ID:password`), output: []byte(`AWS_********`), }, + { + input: []byte(`platform: "platformAccessToken"`), + output: []byte(`platform: "********"`), + }, } for _, tc := range testCases {