-
Notifications
You must be signed in to change notification settings - Fork 127
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
[ON HOLD] - adds firewall whitelisting feature #211
base: main
Are you sure you want to change the base?
Conversation
This looks like a duplicate of the PR I created: #158 |
#158 is a blacklist implementation while this one is a whitelist. I copied port range detection logic from #158, but I had to reimplement the rest. I tried to make the matching as explicit as possible and avoided flags like any, all, *. |
For what it's worth, the bulk of the cases would be of the format "Do not allow a connection unless the following things match: (ip:box1, port 443,from:dmz..)" Blacklisting 'specific' bad actors from entering your everybody-is-welcome setup is helpful too, but much less common since it requires a lot of manual work. Of course the ideal case is "blacklist a,b,c, but everybody else can only connect to vm x, nowhere else" |
I disagree with the exclude option due to the ambiguity that it brings. At the beginning I was also in favor of the exclude option since it sounds intuitive and I spent almost a day to enable it. But in the end, I find it ambiguous and vulnerable to misconfigurations. Check following examples: A firewall rule: Constraints:
So what should be the outcome of both rules? Both of them agrees and disagrees with the firewall rule at the same time. Due to these ambiguities, I believe we should be strict about whitelist and blacklist. If you think in set theory, In blacklist any intersection should be a violation, while in whitelist case, only firewall rules that are subsets of a given constraint should be allowed. Combinations of both is open to mistakes. |
Hey team, do you have more questions/suggestions? |
@yunus I do think exclude support is required. How else could you do something like never allow SSH except to the bastion? To be clear, "exclude" would be applied for an entire rule. You couldn't specify |
What I do is to create a superset of allowed firewall rules. If an actual firewall rule is a subset of the whitelist that policy library defines, then it is allowed. I see that it is not easy to understand, so I am open to suggestions. If you wish, we can have a call to discuss in depth. Never Allow SSH except Bastion == Allow SSH only for Bastion. And the real firewall for that is: "data": {
"allowed": [
{
"IPProtocol": "tcp",
"ports": [
"22"
]
}
],
"sourceRanges": [
"0.0.0.0/0"
],
"targetTags": [
"bastion"
]
}
} Below are the rules that allow only the bastion VM, # Allow SSH (22) to the bastion VMs only
# the bastion VM is defined by a service account
- direction: ingress
allowed:
- IPProtocol: "tcp"
ports:
- "22"
targetServiceAccounts:
- "[email protected]"
sourceRanges:
- "0.0.0.0/0"
# Allow SSH (22) to the bastion VMs only
# the bastion VM is defined by a target tag
- direction: ingress
allowed:
- IPProtocol: "tcp"
ports:
- "22"
targetTags:
- "^bastion$"
- "^entry$"
sourceRanges:
- "0.0.0.0/0" If a firewall rule allows both targetTag and targetServiceAccount at the same time: # Allow SSH to VMs defined by a target tag or service account
- direction: ingress
allowed:
- IPProtocol: "tcp"
ports:
- "22"
targetTags:
- "^bastion$"
targetServiceAccounts:
- "bastion-sa@.*.iam.gserviceaccount.com"
sourceRanges:
- "0.0.0.0/0" |
adds more comments and examples
5036f36
to
20bfd1c
Compare
@yunus Would that be a whitelist? The issue I see is then how do we know that another rule, say http is allowed, in that mode? If the user intent is "blacklist 22 except to my bastion" they should be able to convey that. In our discussions with customers (and current Forseti usage), I think simple "exclusion" semantics are required. |
Thanks for the comments. You are right that in whitelist case all the rules have to be specified. But I don't claim that every customer should choose this whitelist one. Both methods has its own benefits like all other rules with blacklist & whitelist. Let's wait for exclusion rules to make a decision. |
I think the key is that we need to support common customer scenarios like "blacklist access to port 22 unless it is targeting my bastion host" — IMO the easiest way to do that is with exclusion rules.
Will you add those to the PR? |
This constraint enables users to provide a list of allowed/whitelisted firewall rules so that they are able to detect deviations. Detailed usage information can be found inside the samples/gcp_network_firewall_whitelisting.yaml file. This rule complements the other restricted_firewalls rule. I have copied the port range functionality from there as well.
The decision sequence
Raise an alert if a firewall rule is not listed by any of the whitelist rules defined in this constraint file:
All the values in a firewall rule should be whitelisted. PARTIAL matches are NOT enough.
Matching features
It is possible to use regex, port ranges and IP CIDR ranges to define whitelists.
For instance: