Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-12710], deleting All Partitioned Policies a Key is linked to does not delete the Key #6473

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

andrei-tyk
Copy link
Contributor

@andrei-tyk andrei-tyk commented Aug 28, 2024

User description

Fixed case in which trying to apply a non-existing policy error would be swallowed when having partitioned keys.

Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

Bug fix


Description

  • Fixed a bug where errors for non-existing policies were ignored if multiple policies were processed, ensuring that an error is returned immediately.
  • Improved error handling in the Apply method of the Service to prevent silent failures when policies are missing.

Changes walkthrough 📝

Relevant files
Bug fix
apply.go
Fix error handling for non-existing policies in Apply method

internal/policy/apply.go

  • Removed logic that continued processing policies when a non-existing
    policy was encountered.
  • Ensured that an error is returned immediately if a policy is not
    found.
  • +0/-4     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    …rror would be swallowed when having partitioned keys
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Error Handling
    The removal of the conditional block that allows continuation in the loop when multiple policies are being processed might lead to unintended behavior where a single missing policy could halt the entire operation, even if other policies could be applied successfully.

    Copy link
    Contributor

    github-actions bot commented Aug 28, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Improve error handling when a policy is not found in a list of multiple policies

    Consider handling the error more gracefully when multiple policies are involved.
    Instead of skipping the current iteration when a policy is not found, log the error
    and continue checking other policies. This ensures that all policies are evaluated,
    and the error handling is consistent.

    internal/policy/apply.go [117]

     if !ok {
       err := fmt.Errorf("policy not found: %q", polID)
       t.Logger().Error(err)
    +  if len(policyIDs) > 1 {
    +    continue
    +  }
       return err
     }
     
    Suggestion importance[1-10]: 9

    Why: The suggestion correctly identifies a potential issue with error handling when multiple policies are involved. By reintroducing the condition to continue the loop when a policy is not found, it ensures that all policies are evaluated, which is a more robust and consistent approach.

    9

    Copy link
    Contributor

    github-actions bot commented Aug 28, 2024

    API Changes

    --- prev.txt	2024-08-30 14:25:20.822441511 +0000
    +++ current.txt	2024-08-30 14:25:17.770426502 +0000
    @@ -5252,10 +5252,7 @@
     
     type CertificatesConfig struct {
     	API []string `json:"apis"`
    -	// Upstream is used to specify the certificates to be used in mutual TLS connections to upstream services. These are set at gateway level as a map of domain -> certificate id or path.
    -	// For example if you want Tyk to use the certificate `ab23ef123` for requests to the `example.com` upstream and `/certs/default.pem` for all other upstreams then:
    -	// In `tyk.conf` you would configure `"security": {"certificates": {"upstream": {"*": "/certs/default.pem", "example.com": "ab23ef123"}}}`
    -	// And if using environment variables you would set this to `*:/certs/default.pem,example.com:ab23ef123`.
    +	// Specify upstream mutual TLS certificates at a global level in the following format: `{ "<host>": "<cert>" }``
     	Upstream map[string]string `json:"upstream"`
     	// Certificates used for Control API Mutual TLS
     	ControlAPI []string `json:"control_api"`

    Copy link

    sonarcloud bot commented Aug 30, 2024

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants