Skip to content

Commit 891eb6f

Browse files
backport of commit b19562d (#24025)
Co-authored-by: Kuba Wieczorek <[email protected]>
1 parent d828122 commit 891eb6f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

vault/policy_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func (ps *PolicyStore) GetNonEGPPolicyType(nsID string, name string) (*PolicyTyp
467467
pt, ok := ps.policyTypeMap.Load(index)
468468
if !ok {
469469
// Doesn't exist
470-
return nil, fmt.Errorf("policy does not exist in type map: %v", index)
470+
return nil, ErrPolicyNotExistInTypeMap
471471
}
472472

473473
policyType, ok := pt.(PolicyType)

vault/policy_store_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,15 @@ func TestPolicyStore_GetNonEGPPolicyType(t *testing.T) {
360360
paramNamespace: "1AbcD",
361361
paramPolicyName: "policy1",
362362
isErrorExpected: true,
363-
expectedErrorMessage: "policy does not exist in type map: 1AbcD/policy1",
363+
expectedErrorMessage: "policy does not exist in type map",
364364
},
365365
"not-in-map-rgp": {
366366
policyStoreKey: "2WxyZ/policy2",
367367
policyStoreValue: PolicyTypeRGP,
368368
paramNamespace: "1AbcD",
369369
paramPolicyName: "policy1",
370370
isErrorExpected: true,
371-
expectedErrorMessage: "policy does not exist in type map: 1AbcD/policy1",
371+
expectedErrorMessage: "policy does not exist in type map",
372372
},
373373
"unknown-policy-type": {
374374
policyStoreKey: "1AbcD/policy1",

vault/request_handling.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ var (
5252
// to complete, unless overridden on a per-handler basis
5353
DefaultMaxRequestDuration = 90 * time.Second
5454

55-
ErrNoApplicablePolicies = errors.New("no applicable policies")
55+
ErrNoApplicablePolicies = errors.New("no applicable policies")
56+
ErrPolicyNotExistInTypeMap = errors.New("policy does not exist in type map")
5657

5758
egpDebugLogging bool
5859

@@ -180,6 +181,13 @@ func (c *Core) getApplicableGroupPolicies(ctx context.Context, tokenNS *namespac
180181

181182
for _, policyName := range nsPolicies {
182183
t, err := c.policyStore.GetNonEGPPolicyType(policyNS.ID, policyName)
184+
if err != nil && errors.Is(err, ErrPolicyNotExistInTypeMap) {
185+
// When we attempt to get a non-EGP policy type, and receive an
186+
// explicit error that it doesn't exist (in the type map) we log the
187+
// ns/policy and continue without error.
188+
c.Logger().Debug(fmt.Errorf("%w: %v/%v", err, policyNS.ID, policyName).Error())
189+
continue
190+
}
183191
if err != nil || t == nil {
184192
return nil, fmt.Errorf("failed to look up type of policy: %w", err)
185193
}

0 commit comments

Comments
 (0)