Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/egress/pkg/credentialvault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ func (v *Store) Ready() error {
}

func (v *Store) validateCandidate(credentials map[string]record, bindings map[string]Binding, pol *policy.NetworkPolicy) error {
if len(bindings) > 0 && (pol == nil || len(pol.Egress) == 0) {
return fmt.Errorf("credential bindings require explicit networkPolicy.egress allow rules")
if len(bindings) > 0 && (pol == nil || (len(pol.Egress) == 0 && pol.DefaultAction != policy.ActionAllow)) {
return fmt.Errorf("credential bindings require explicit networkPolicy.egress allow rules or defaultAction allow")
}
for _, b := range bindings {
if err := validateBindingCredentialRefs(b, credentials); err != nil {
Expand Down Expand Up @@ -821,6 +821,12 @@ func explicitAllowCoversHost(pol *policy.NetworkPolicy, host string) bool {
if host == "" {
return false
}
if pol.DefaultAction == policy.ActionAllow {
if strings.HasPrefix(host, "*.") {
return pol.Evaluate("probe."+strings.TrimPrefix(host, "*.")) == policy.ActionAllow
Comment thread
hittyt marked this conversation as resolved.
Outdated
}
return pol.Evaluate(host) == policy.ActionAllow
}
if strings.HasPrefix(host, "*.") {
return explicitAllowRuleMatches(pol, host) && pol.Evaluate("probe."+strings.TrimPrefix(host, "*.")) == policy.ActionAllow
}
Expand Down
12 changes: 10 additions & 2 deletions components/egress/pkg/credentialvault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,20 @@ func TestCredentialVaultCreateSanitizesAndRendersActiveSnapshot(t *testing.T) {
require.Contains(t, payload.Redactions, "secret-token")
}

func TestCredentialVaultRejectsDefaultAllowWithoutExplicitCoverage(t *testing.T) {
func TestCredentialVaultAllowsDefaultAllowWithoutExplicitRules(t *testing.T) {
store := NewStore(nil, func() bool { return true })
pol := testCredentialPolicy(t, `{"defaultAction":"allow","egress":[]}`)

_, err := store.Create(testCredentialVaultRequest(), pol)
require.ErrorContains(t, err, "explicit networkPolicy.egress")
require.NoError(t, err, "defaultAction allow should not require explicit egress rules")
}

func TestCredentialVaultDefaultAllowRespectsExplicitDenyRule(t *testing.T) {
store := NewStore(nil, func() bool { return true })
pol := testCredentialPolicy(t, `{"defaultAction":"allow","egress":[{"action":"deny","target":"code.example.com"}]}`)

_, err := store.Create(testCredentialVaultRequest(), pol)
require.ErrorContains(t, err, "not covered")
}

func TestCredentialVaultRejectsReservedAndDuplicateHeaderNamesCaseInsensitively(t *testing.T) {
Expand Down
Loading