'How to block multiple countries with one expression in google cloud armor?
I can block multiple countries in google cloud armor with below rule.
origin.region_code == "RU" || origin.region_code == "UA"
But it considers this rule to be having 2 expressions so I can block only 5 couontries per rule and will have to add additional rules to block additional countries.
Is there a way (like in_origin_regioncode) where I can provide a comma separated list of all countries I want to block in a single expression?
Solution 1:[1]
I have one option that we discover, you can use x.contains(y) function in your cloud armor rule, that function return true if substring y is in string x, so you can use it like this '[CN,KP,LT,UA,RU,AF,DZ,MM,CU,EG,GN,IR,IQ,LR,LY,NE,SL,SO,SS,SD,SY,UA,YE]'.contains(origin.region_code) instead of origin.region_code=='CN'||origin.region_code=='SL' for example, and it works!!!
I hope I've helped :)
Solution 2:[2]
In my case I just want to allow ** CL REGION ** traffic, I created a permission rule in advanced mode. Traffic from other regions is blocked.
origin.region_code == 'CL'
Solution 3:[3]
The best way that I found is using a regex, something like this:
"origin.region_code.matches('^ES|PT|AD|GI$')"
So you can include all countries as you want.
Solution 4:[4]
As you correctly pointed out, and as documented here, the currently custom rule limit is 5. The only workaround available to circumvent this is creating additional custom rules in order to implement additional country blocks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | José de Jesus Barajas Figueroa |
| Solution 2 | Camilo Elgueta Basso |
| Solution 3 | Christian |
| Solution 4 | Frank |
