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

feat: Introduce --no-default-rules flag, deprecate --create-rules #462

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1290,11 +1290,18 @@ $ civo firewall create civocli_demo
Created a firewall called civocli_demo with ID ab2a25d7-edd4-4ecd-95c4-58cb6bc402de
```

You can also create a firewall without any default rules by using the flag `-r` or `--create-rules` set to `false`. In both cases, the usage is like:
By default, this newly created firewall will come with the default rules applied.

To create a firewall without any default rules, use the `--no-default-rules` flag:

```bash
civo firewall create new_firewall_name --create-rules=false
civo firewall create new_firewall_name --no-default-rules
```

You can also use the `-r` or `--create-rules` flag set to `false` to create a firewall without default rules, but it is deprecated and will be removed in future versions. In both cases, the usage is like:

```bash
civo firewall create new_firewall_name --create-rules=false
```

You will then be able to **configure rules** that allow connections to and from your instance by adding a new rule using `civo firewall rule create firewall_id` with the required and your choice of optional parameters, listed here and used in an example below:
Expand Down
6 changes: 5 additions & 1 deletion cmd/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func init() {
FirewallCmd.AddCommand(firewallRemoveCmd)

firewallCreateCmd.Flags().StringVarP(&firewallnetwork, "network", "n", "default", "the network to create the firewall")
firewallCreateCmd.Flags().BoolVarP(&createRules, "create-rules", "r", true, "the create rules flag is used to create the default firewall rules, if is not defined will be set to true")
firewallCreateCmd.Flags().BoolVarP(&createRules, "create-rules", "r", true, "the create rules flag is used to create the default firewall rules, if is not defined will be set to true (deprecated)")
firewallCreateCmd.Flags().BoolVarP(&noDefaultRules, "no-default-rules", "", false, "the no-default-rules flag will ensure no default rules are created for the firewall, if not defined it will be set to false")

// Firewalls rule cmd
FirewallCmd.AddCommand(firewallRuleCmd)
Expand All @@ -57,4 +58,7 @@ func init() {
firewallRuleCreateCmd.Flags().StringVarP(&action, "action", "a", "allow", "the action of the rule can be allow or deny (default is allow)")
firewallRuleCreateCmd.Flags().StringVarP(&label, "label", "l", "", "a string that will be the displayed as the name/reference for this rule")
firewallRuleCreateCmd.MarkFlagRequired("startport")

// Mark the create-rules flag as deprecated
firewallCreateCmd.Flags().MarkDeprecated("create-rules", "it will be removed in future versions. Default firewall rules are created by default. Use --no-default-rules flag to create firewalls without them.\n")
}
13 changes: 13 additions & 0 deletions cmd/firewall/firewall_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var firewallnetwork string
var createRules bool
var noDefaultRules bool
var defaultNetwork *civogo.Network

var firewallCreateCmd = &cobra.Command{
Expand All @@ -21,6 +22,18 @@ var firewallCreateCmd = &cobra.Command{
Short: "Create a new firewall",
Example: "civo firewall create NAME",
Args: cobra.MinimumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
createRulesFlag := cmd.Flags().Lookup("create-rules")
noDefaultRulesFlag := cmd.Flags().Lookup("no-default-rules")

if createRulesFlag.Changed && noDefaultRulesFlag.Changed {
utility.Error("conflicting flags: --create-rules and --no-default-rules cannot be used together")
os.Exit(1)
}
if noDefaultRules {
createRules = false
}
},
Run: func(cmd *cobra.Command, args []string) {
utility.EnsureCurrentRegion()

Expand Down