Merge pull request #9899 from hashicorp/wildcard-ixn-oss

Add methods to check intention has wildcard src or dst
This commit is contained in:
Freddy 2021-03-18 08:33:07 -06:00 committed by GitHub
commit 0bab999fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 3 deletions

View File

@ -965,9 +965,7 @@ func (s *Store) IntentionTopology(ws memdb.WatchSet,
// Intentions with wildcard source and destination have the lowest precedence, so they are last in the list
ixn := intentions[len(intentions)-1]
// TODO (freddy) This needs an enterprise split to account for (*/* -> */*)
// Maybe ixn.HasWildcardSource() && ixn.HasWildcardDestination()
if ixn.SourceName == structs.WildcardSpecifier && ixn.DestinationName == structs.WildcardSpecifier {
if ixn.HasWildcardSource() && ixn.HasWildcardDestination() {
defaultDecision = acl.Allow
if ixn.Action == structs.IntentionActionDeny {
defaultDecision = acl.Deny

View File

@ -150,3 +150,11 @@ func (s *Session) CheckIDs() []types.CheckID {
}
return checks
}
func (t *Intention) HasWildcardSource() bool {
return t.SourceName == WildcardSpecifier
}
func (t *Intention) HasWildcardDestination() bool {
return t.DestinationName == WildcardSpecifier
}

View File

@ -41,3 +41,35 @@ func TestServiceName_String(t *testing.T) {
require.Equal(t, "the-id", fmt.Sprintf("%v", &sn))
})
}
func TestIntention_HasWildcardSource(t *testing.T) {
t.Run("true", func(t *testing.T) {
ixn := Intention{
SourceName: WildcardSpecifier,
}
require.True(t, ixn.HasWildcardSource())
})
t.Run("false", func(t *testing.T) {
ixn := Intention{
SourceName: "web",
}
require.False(t, ixn.HasWildcardSource())
})
}
func TestIntention_HasWildcardDestination(t *testing.T) {
t.Run("true", func(t *testing.T) {
ixn := Intention{
DestinationName: WildcardSpecifier,
}
require.True(t, ixn.HasWildcardDestination())
})
t.Run("false", func(t *testing.T) {
ixn := Intention{
DestinationName: "web",
}
require.False(t, ixn.HasWildcardDestination())
})
}