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

Updating firewall: use config file to set up rules #138

Merged
merged 16 commits into from
Mar 30, 2018
Merged

Updating firewall: use config file to set up rules #138

merged 16 commits into from
Mar 30, 2018

Conversation

storojs72
Copy link
Contributor

Add ability to configure firewall from configuration file

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.

use yaml format and parser to read rules

@@ -29,65 +32,44 @@ func (firewall *Firewall) SetFirewallConfiguration(configuration string) error {
return nil
}

func updateFirewall(firewall *Firewall, configuration string) error {
func updateFirewall(firewall *Firewall, configuration []byte) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is it a function instead method? func (firewall *Firewall) update(configuration []byte)error.

Copy link
Contributor Author

@storojs72 storojs72 Mar 29, 2018

Choose a reason for hiding this comment

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

Agree. Changed

@@ -27,3 +29,9 @@ func (firewall *Firewall) HandleQuery(query string) error{
}
return nil
}

func (firewall *Firewall) PrintStatus() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how this method used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for debug purposes. Removed

configLineType = structureConfigHeader
break;
case "\n":
whitelistHandler.AddQueries(handlerConfiguration.Queries)
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 check queries on add operation and return error here? then we doesn't need extra function like testConfigurationSyntex that will grow with each new rule and handler types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we have separate function to test syntax, we are able to modify it if necessary. And we can't do it if logic of syntax checking will be scattered over multiply functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally, I agree. It also helps to reduce handler public interface

}
}

func (firewall *Firewall) SetFirewallConfiguration(configuration []byte) error {
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 firewall.SetFirewallConfiguration -> firewall.LoadConfiguration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Changed

return nil
}

func updateFirewall(firewall *Firewall, configuration []byte) error {
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 updateFirewall(firewall *Firewall, ...) -> func (firewall *Firewall) update(...)?

//Check tables
if len(handler.tables) != 0 {
parsedQuery, err := sqlparser.Parse(query)
if err != nil {
return err
return errors.New(err.Error() + " | blacklist (tables)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

bad pattern to concatenate strings via "+" operator. And bad way to create error in such way. Better to add new type of error. Then we can easily check is it correct error type in unit-tests without string comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Refactored

AddRules(rules []string)
RemoveRules(rules []string)

GetActiveQueries() []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Our handler interface grow and grow and in a future will be very big monolitic interface. But at start it was designed like simple abstract interface for different handlers with simple function CheckQuery and encapsulated logic in custom handler itself.
Anyway what mean Active in name? Now it's just added queries/tables/rules to handler. So will be enough to name GetQueries. Because active tell us that handler has some different queries too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Renamed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with your thought about handler interface. Actually we can remove some functions from it to make it simpler

}
}

case *sqlparser.Update:

return errors.New("not implemented yet")
Copy link
Collaborator

Choose a reason for hiding this comment

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

add new error like ErrNotImplemented and then in a future we can use it in another handlers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

var ErrAccessToForbiddenTable = errors.New("query tries to access forbidden table")
var ErrForbiddenSqlStructure = errors.New("query's structure is forbidden")

var ErrAccessToForbiddenTableBlacklist = errors.New("query tries to access forbidden table | blacklist")
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to add | blacklist at end of message for ErrAccessToForbiddenTableBlacklist error

@@ -0,0 +1,19 @@
[handler]
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this file?

Copy link
Contributor Author

@storojs72 storojs72 Mar 29, 2018

Choose a reason for hiding this comment

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

No. We don't. Removed

}

func (handler *WhitelistHandler) RemoveRules(rules []string){
func (handler * WhitelistHandler) RemoveRules(rules []string){
Copy link
Collaborator

Choose a reason for hiding this comment

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

gofmt will not agree with your space between * and type :)
please, run go fmt ./... in repo folder before pushing or we will not so excellent golang repo as now (https://goreportcard.com/report/github.com/cossacklabs/acra) :((

@@ -56,7 +56,7 @@ func (firewall *Firewall) update(configuration []byte) error {
}

firewallCheckers = append(firewallCheckers, whitelistHandler)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not add handler here? instead of second loop after this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Agree

@vixentael vixentael merged commit 18c8482 into cossacklabs:master Mar 30, 2018
@vixentael vixentael mentioned this pull request Mar 30, 2018
@vixentael vixentael changed the title Updating firewall Updating firewall: use config file to set up rules Apr 3, 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.

3 participants