-
Notifications
You must be signed in to change notification settings - Fork 219
CORS-4230: Add a firewall spec and the ability to manage or unmanaged firewall rule creation #1532
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,33 @@ type Network struct { | |
APIInternalForwardingRule *string `json:"apiInternalForwardingRule,omitempty"` | ||
} | ||
|
||
// FirewallSpec contains configuration for the firewall. | ||
type FirewallSpec struct { | ||
// RulesManagement determines the management policy for firewall rules. | ||
// "Managed": The controller will create and manage firewall rules. | ||
// "Unmanaged": The controller will not touch any firewall rules. If this is | ||
// changed to "Off" after rules have been created, they will not be | ||
// deleted. | ||
// Defaults to "Managed". | ||
// +optional | ||
// +kubebuilder:default:="Managed" | ||
RulesManagement RulesManagementPolicy `json:"rulesManagement,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So one nit: do we want people to have to write I think @JoelSpeed suggested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @justinsb would you prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about ways this could go
So for those four choice to be valid, we are going to want a discriminated union (IMO). That could look something like:
Would we expect the custom rules to be on the same level as the rules/policy selector? If so, we wouldn't want the custom rules to be allowed when the rules are unmanaged We would also need a way to say exclude the default rules still, in which case, you have an oddity of Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could keep a value specifically for the default rules that are included in CAPG
We should also have a field (this is currently in another PR) for the custom firewall rules. This includes the firewall rules that a caller would like to have created by CAPG. I don't believe that this list needs a value of Managed or Unmanaged. When the caller provides any firewall rules in this field they should be considered managed. I don't believe that there is a need to fill in this field with firewall rules and then state that they want these to be managed or created. I think that this is a fair assumption since we have no other need for the firewall rules. If there was another reason for specifying the firewall rules that could make sense but we have no other use.
|
||
} | ||
|
||
// RulesManagementPolicy is a string enum type for managing firewall rules. | ||
// +kubebuilder:validation:Enum=Managed;Unmanaged | ||
type RulesManagementPolicy string | ||
|
||
const ( | ||
// RulesManagementManaged indicates that the controller should create and manage | ||
// firewall rules. This is the default behavior. | ||
RulesManagementManaged RulesManagementPolicy = "Managed" | ||
|
||
// RulesManagementUnmanaged indicates that the controller should not create or manage | ||
// any firewall rules. If rules already exist, they will be left as-is. | ||
RulesManagementUnmanaged RulesManagementPolicy = "Unmanaged" | ||
) | ||
|
||
// NetworkSpec encapsulates all things related to a GCP network. | ||
type NetworkSpec struct { | ||
// Name is the name of the network to be used. | ||
|
@@ -137,6 +164,10 @@ type NetworkSpec struct { | |
// +optional | ||
HostProject *string `json:"hostProject,omitempty"` | ||
|
||
// Firewall configuration. | ||
// +optional | ||
Firewall FirewallSpec `json:"firewall,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a struct so needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is using go 1.24 I believe. |
||
|
||
// Mtu: Maximum Transmission Unit in bytes. The minimum value for this field is | ||
// 1300 and the maximum value is 8896. The suggested value is 1500, which is | ||
// the default MTU used on the Internet, or 8896 if you want to use Jumbo | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,12 @@ func (s *ManagedClusterScope) NetworkProject() string { | |
return ptr.Deref(s.GCPManagedCluster.Spec.Network.HostProject, s.Project()) | ||
} | ||
|
||
// SkipFirewallRuleCreation returns whether the spec indicates that firewall rules | ||
// should be created or not. | ||
func (s *ManagedClusterScope) SkipFirewallRuleCreation() bool { | ||
return (s.GCPManagedCluster.Spec.Network.Firewall.RulesManagement == infrav1.RulesManagementUnmanaged) || s.IsSharedVpc() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you explain this relationship in the API documentation/validations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no custom rules in this PR so this should be taken only with the information in this PR. If the installation includes a shared VPC or if the user has explicitly said firewall rules are unmanaged then the firewall rules should not be created. It is important to note that this will ONLY apply to the default rules. |
||
} | ||
|
||
// IsSharedVpc returns true If sharedVPC used else , returns false. | ||
func (s *ManagedClusterScope) IsSharedVpc() bool { | ||
return s.NetworkProject() != s.Project() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,8 @@ import ( | |
// Reconcile reconcile cluster firewall compoenents. | ||
func (s *Service) Reconcile(ctx context.Context) error { | ||
log := log.FromContext(ctx) | ||
if s.scope.IsSharedVpc() { | ||
log.V(2).Info("Shared VPC enabled. Ignore Reconciling firewall resources") | ||
if s.scope.SkipFirewallRuleCreation() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW I like this a lot, even if SkipFirewallRuleCreation just called IsSharedVpc, it is much more self-documenting to have self-descriptive functions like this and put the logic in those functions, rather than put the logic in the caller. |
||
log.V(2).Info("Ignore Reconciling firewall resources") | ||
return nil | ||
} | ||
log.Info("Reconciling firewall resources") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you kubectl describe, does this formatting print out correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I haven't tried. This is the same formatting someone used on a suggested entry of mine in the past.