I am trying to write a schema to validate that an AWS IAM security group MUST NOT specify incoming IP addresses "0.0.0.0/0" can connect to port 22.
I am using oneOf operator and defining two set of properties and my intuition is that if both of the properties are satisfied, JSON schema should fail but it doesn't.
Sample JSON -
{
"ipPermissions": [
{
"toPort": -1,
"fromPort": -1,
"ipRanges": [
"10.0.0.0/16"
]
},
{
"toPort": 22,
"fromPort": 53,
"ipRanges": [
"0.0.0.0/0"
],
"ipProtocol": "tcp"
}
]
}
The above JSON should fail as ipPermission[1] object is-
{
"toPort": 22,
"fromPort": 53,
"ipRanges": [
"0.0.0.0/0"
],
"ipProtocol": "tcp"
}
as ipRanges has value 0.0.0.0/0 when toPort is 22
Following JSON document should pass validation-
{
"ipPermissions": [
{
"toPort": 22,
"fromPort": -1,
"ipRanges": [
"10.0.0.0/16"
]
},
{
"toPort": 22,
"fromPort": 53,
"ipRanges": [
"somethingElse"
],
"ipProtocol": "tcp"
}
]
}
because ipPermissions index[0] object has toPort value of 22 but ipRanges[0] has value 10.0.0.0/16 which is NOT 0.0.0.0/0
the following JSON should NOT pass the validation -
{
"ipPermissions": [
{
"toPort": 22,
"fromPort": -1,
"ipRanges": [
"10.0.0.0/16"
]
},
{
"toPort": 22,
"fromPort": 53,
"ipRanges": [
"somethingElse",
"0.0.0.0/0"
],
"ipProtocol": "tcp"
}
]
}
as ipPermissions[1].ipRanges[1] value is 0.0.0.0/0
My JSON Schema-
{
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [
"ipPermissions"
],
"properties": {
"ipPermissions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"oneOf": {
"ipRanges": {
"type": "array",
"items": {
"type": "string",
"value": "0.0.0.0/0"
}
},
"toPort": {
"type": "integer",
"minimum": 23
}
}
}
}
}
}
}