Skip to content

Commit

Permalink
policy: Fix derived-from labels
Browse files Browse the repository at this point in the history
Use the "allow-any-ingress" label instead of "allow-localhost-ingress"
when allowing all on ingress.

Define a new "allow-remotehost-ingress" label and use that when
allowing remote hosts instead of "allow-localhost-ingress".

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme authored and brb committed Jul 27, 2021
1 parent 951eded commit dd4f60f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/policy/distillery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ var (
FromEndpoints: []api.EndpointSelector{api.WildcardEndpointSelector},
},
}})
lblsAllowLocalHostIngress = labels.LabelArray{
labels.NewLabel(LabelKeyPolicyDerivedFrom, LabelAllowLocalHostIngress, labels.LabelSourceReserved),
lblsAllowAllIngress = labels.LabelArray{
labels.NewLabel(LabelKeyPolicyDerivedFrom, LabelAllowAnyIngress, labels.LabelSourceReserved),
}

lbls_____NoDeny = labels.ParseLabelArray("deny")
Expand Down Expand Up @@ -1104,7 +1104,7 @@ func Test_AllowAll(t *testing.T) {
rules api.Rules
result MapState
}{
{0, api.EndpointSelectorNone, api.Rules{rule____AllowAll}, MapState{mapKeyAllowAll__: mapEntryL7None_(lblsAllowLocalHostIngress)}},
{0, api.EndpointSelectorNone, api.Rules{rule____AllowAll}, MapState{mapKeyAllowAll__: mapEntryL7None_(lblsAllowAllIngress)}},
{1, api.WildcardEndpointSelector, api.Rules{rule____AllowAll}, MapState{mapKeyAllowAll__: mapEntryL7None_(lbls____AllowAll)}},
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/policy/mapstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ var (
)

const (
LabelKeyPolicyDerivedFrom = "io.cilium.policy.derived-from"
LabelAllowLocalHostIngress = "allow-localhost-ingress"
LabelAllowAnyIngress = "allow-any-ingress"
LabelAllowAnyEgress = "allow-any-egress"
LabelVisibilityAnnotation = "visibility-annotation"
LabelKeyPolicyDerivedFrom = "io.cilium.policy.derived-from"
LabelAllowLocalHostIngress = "allow-localhost-ingress"
LabelAllowRemoteHostIngress = "allow-remotehost-ingress"
LabelAllowAnyIngress = "allow-any-ingress"
LabelAllowAnyEgress = "allow-any-egress"
LabelVisibilityAnnotation = "visibility-annotation"
)

// MapState is a state of a policy map.
Expand Down Expand Up @@ -349,6 +350,11 @@ func (keys MapState) DetermineAllowLocalhostIngress() {
var isHostDenied bool
v, ok := keys[localHostKey]
isHostDenied = ok && v.IsDeny
derivedFrom := labels.LabelArrayList{
labels.LabelArray{
labels.NewLabel(LabelKeyPolicyDerivedFrom, LabelAllowRemoteHostIngress, labels.LabelSourceReserved),
},
}
es := NewMapStateEntry(nil, derivedFrom, false, isHostDenied)
keys.DenyPreferredInsert(localRemoteNodeKey, es)
}
Expand All @@ -368,7 +374,7 @@ func (keys MapState) AllowAllIdentities(ingress, egress bool) {
}
derivedFrom := labels.LabelArrayList{
labels.LabelArray{
labels.NewLabel(LabelKeyPolicyDerivedFrom, LabelAllowLocalHostIngress, labels.LabelSourceReserved),
labels.NewLabel(LabelKeyPolicyDerivedFrom, LabelAllowAnyIngress, labels.LabelSourceReserved),
},
}
keys[keyToAdd] = NewMapStateEntry(nil, derivedFrom, false, false)
Expand Down

0 comments on commit dd4f60f

Please sign in to comment.