Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logger-handler to firewall #151

Merged
merged 17 commits into from Apr 12, 2018
Merged

Add logger-handler to firewall #151

merged 17 commits into from Apr 12, 2018

Conversation

storojs72
Copy link
Contributor

No description provided.

Copy link
Collaborator

@Lagovas Lagovas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add please saving state on changes
reloading forbidden queries now can wait

loggingHandler.MarkQueryAsForbidden(testQueries[1])
loggingHandler.MarkQueryAsForbidden(testQueries[2])

blacklist.AddQueries(loggingHandler.GetForbiddenQueries())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

"encoding/json"
)

type LoggingHandler struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about to add filepath field and NewLoggingHandler function that will return new handler with loaded queries from file?

queryInfo := &QueryInfo{}
queryInfo.rawQuery = query
queryInfo.isForbidden = false
handler.Queries = append(handler.Queries, *queryInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be better to save new queries to file to commit current state of handler

func (handler *LoggingHandler) MarkQueryAsForbidden(query string) {
for index, queryInfo := range handler.Queries {
if strings.EqualFold(query, queryInfo.rawQuery) {
handler.Queries[index].isForbidden = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here will be good too to save new state to file

func (handler *LoggingHandler) GetAllInputQueries() []string{
var queries []string
for _, queryInfo := range handler.Queries {
queries = append(queries, queryInfo.rawQuery)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a future would be great to check file update on new queries and if file was updated reload and return new values
it will be useful when separate instance of webui will add changes and acraserver's handler should update too without restarting

func (config *Config) SetFirewall(fw firewall.FirewallInterface) {
config.firewall = fw
func (config *Config) SetFirewall(censorConfigPath string) error {
firewall := &firewall.Firewall{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to assign one time config.firewall = &firewall.Firewall{} instead 5 extra lines

handler.Queries[index].IsForbidden = true
}
}
handler.Serialize()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if error?


func (handler *LoggingHandler) Serialize() error {
jsonFile, err := json.Marshal(handler.Queries)
err = ioutil.WriteFile(handler.filePath, jsonFile, 0600)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can return result because it err itself

if err != nil {
return err
}
json.Unmarshal(bufferBytes, &handler.Queries)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err := json.Unmarshal(...)

return err
}
json.Unmarshal(bufferBytes, &handler.Queries)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you check ReadFile call

@vixentael
Copy link
Collaborator

Please add info log to see if query was allowed/filtered here:
https://github.com/cossacklabs/acra/blob/master/firewall/firewall_implementation.go#L23

And show example of json output

}

func (acraCensor *AcraCensor) HandleQuery(query string) error {
log.Infof("Censor works")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will receive this log message on every query. which is not very useful, i'd remove it

for _, handler := range acraCensor.handlers {
log.Infof("Handler: %s", handler.GetName())
if err := handler.CheckQuery(query); err != nil {
return err
Copy link
Collaborator

@vixentael vixentael Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.WithFields(log.Fields{"acracensor" : handler.GetName()}).Infof("Forbidden query: %s", query)

func (acraCensor *AcraCensor) HandleQuery(query string) error {
log.Infof("Censor works")
for _, handler := range acraCensor.handlers {
log.Infof("Handler: %s", handler.GetName())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should remove this

log.Infof("Handler: %s", handler.GetName())
if err := handler.CheckQuery(query); err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.WithFields(log.Fields{"acracensor" : handler.GetName()}).Infof("Allowed query: %s", query)

@@ -50,7 +51,7 @@ type Config struct {
postgresql bool
configPath string
debug bool
firewall firewall.FirewallInterface
firewall acracensor.AcracensorInterface
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

censor instead of firewall?

Copy link
Contributor Author

@storojs72 storojs72 Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Renamed

@@ -52,8 +52,9 @@ const (
EventCodeErrorCantParseAuthData = 557
EventCodeErrorCantDumpConfig = 558

// firewall
// acracensor
EventCodeErrorFirewallQueryIsNotAllowed = 560
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

censor instead of firewall?

Copy link
Contributor Author

@storojs72 storojs72 Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Renamed

@storojs72 storojs72 requested a review from mozhmike April 12, 2018 13:42
if err != nil {
return err
}
config.censor = acraCensor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary

func (acraCensor *AcraCensor) HandleQuery(query string) error {
for _, handler := range acraCensor.handlers {
if err := handler.CheckQuery(query); err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log error. will be good to log handler name too

@vixentael vixentael merged commit de97f23 into cossacklabs:master Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants