-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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-12897] Merge path based permissions when combining policies #6597
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
API Changes --- prev.txt 2024-10-10 13:49:20.936564915 +0000
+++ current.txt 2024-10-10 13:49:15.005508863 +0000
@@ -7651,6 +7651,13 @@
MsgCertificateExpired = "Certificate has expired"
)
const (
+ Pass = model.Pass
+ Fail = model.Fail
+ Warn = model.Warn
+ Datastore = model.Datastore
+ System = model.System
+)
+const (
// Zero value - the service is open and ready to use
OPEN = 0
@@ -8790,6 +8797,13 @@
func (gw *Gateway) SetNodeID(nodeID string)
SetNodeID writes NodeID safely.
+func (gw *Gateway) SetPolicies(pols map[string]user.Policy)
+ SetPolicies updates the internal policy map with a new policy map.
+
+func (gw *Gateway) SetPoliciesByID(pols ...user.Policy)
+ SetPoliciesByID will update the internal policiesByID map with new policies.
+ The key used will be the policy ID.
+
func (gw *Gateway) SetupNewRelic() (app newrelic.Application)
SetupNewRelic creates new newrelic.Application instance
@@ -9031,6 +9045,12 @@
RevProxyTransform RevProxyTransform `mapstructure:"rev_proxy_header_cleanup" bson:"rev_proxy_header_cleanup" json:"rev_proxy_header_cleanup"`
}
+type HealthCheckItem = model.HealthCheckItem
+
+type HealthCheckResponse = model.HealthCheckResponse
+
+type HealthCheckStatus = model.HealthCheckStatus
+
type HealthCheckValues struct {
ThrottledRequestsPS float64 `bson:"throttle_reqests_per_second,omitempty" json:"throttle_reqests_per_second"`
QuotaViolationsPS float64 `bson:"quota_violations_per_second,omitempty" json:"quota_violations_per_second"`
@@ -12389,6 +12409,23 @@
package coprocess // import "github.com/TykTechnologies/tyk/tests/coprocess"
+# Package: ./tests/policy
+
+package policy // import "github.com/TykTechnologies/tyk/tests/policy"
+
+
+CONSTANTS
+
+const DefaultOrg = "default-org-id"
+
+VARIABLES
+
+var StartTest = gateway.StartTest
+
+TYPES
+
+type APISpec = gateway.APISpec
+
# Package: ./tests/proxy
package proxy // import "github.com/TykTechnologies/tyk/tests/proxy"
@@ -12898,6 +12935,12 @@
Clone returns a fresh copy of s
func (s *SessionState) CustomPolicies() (map[string]Policy, error)
+ CustomPolicies returns a map of custom policies on the session. To preserve
+ policy order, use GetCustomPolicies instead.
+
+func (s *SessionState) GetCustomPolicies() ([]Policy, error)
+ GetCustomPolicies is like CustomPolicies but returns the list, preserving
+ order.
func (s *SessionState) GetQuotaLimitByAPIID(apiID string) (int64, int64, int64, int64)
GetQuotaLimitByAPIID return quota max, quota remaining, quota renewal rate
@@ -12937,6 +12980,7 @@
Reset marks the session as not modified, skipping related updates.
func (s *SessionState) SetCustomPolicies(list []Policy)
+ SetCustomPolicies sets custom policies into session metadata.
func (s *SessionState) SetKeyHash(hash string)
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
9cfab8f
to
a241116
Compare
1050f28
to
a29d972
Compare
Quality Gate passedIssues Measures |
/release to release-5.3 |
Working on it! Note that it can take a few minutes. |
<details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-12897" title="TT-12897" target="_blank">TT-12897</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[Security]Path-Based Permissions permissions in policies are not preserved when policies are combined</td> </tr> <tr> <th>Type</th> <td> <img alt="Bug" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium" /> Bug </td> </tr> <tr> <th>Status</th> <td>In Dev</td> </tr> <tr> <th>Points</th> <td>N/A</td> </tr> <tr> <th>Labels</th> <td><a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20customer_bug%20ORDER%20BY%20created%20DESC" title="customer_bug">customer_bug</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20jira_escalated%20ORDER%20BY%20created%20DESC" title="jira_escalated">jira_escalated</a></td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- PR uses custom policies to combine several policies with access rights set. Since a `map` was in the path, user API for custom policies needed an extension to preserve policy ID order. The existing function returning a map didn't handle json decode errors properly and go semantics when looping over maps don't preserve this order, but it's random so tests would fail. Verified with `task stress`. Issue: https://tyktech.atlassian.net/browse/TT-12897 ___ Bug fix, Enhancement, Tests ___ - Enhanced policy application logic by introducing `MergeAllowedURLs` to merge allowed URLs efficiently. - Refactored `Store` to use a slice for policies, and introduced `StoreMap` for unordered policy storage. - Improved custom policy handling by adding `GetCustomPolicies` to preserve policy order. - Updated tests to ensure proper application of policies and added new tests for `MergeAllowedURLs`. - Updated Taskfile to include a new `stress` task for running stress tests. ___ <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>apply.go</strong><dd><code>Enhance policy application logic and logging</code> </dd></summary> <hr> internal/policy/apply.go <li>Introduced <code>MergeAllowedURLs</code> function to merge allowed URLs.<br> <li> Updated <code>Logger</code> function to return a <code>logrus.Entry</code>.<br> <li> Changed <code>session.CustomPolicies()</code> to <code>session.GetCustomPolicies()</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-59b92e9d31f142f1d99b746eb3ff7db4e26bf6c3044c9b87b58034a947ee04d1">+9/-17</a> </td> </tr> <tr> <td> <details> <summary><strong>store.go</strong><dd><code>Refactor Store to use slice for policies</code> </dd></summary> <hr> internal/policy/store.go <li>Changed <code>Store</code> to use a slice for policies.<br> <li> Updated methods to accommodate slice-based storage. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-13dec7bc453c9ff99550c83d2f86a017bbf7fb863584dc30603af15d29ef9d3d">+20/-7</a> </td> </tr> <tr> <td> <details> <summary><strong>store_map.go</strong><dd><code>Add StoreMap for unordered policy storage</code> </dd></summary> <hr> internal/policy/store_map.go <li>Introduced <code>StoreMap</code> for unordered policy storage.<br> <li> Implemented methods for <code>StoreMap</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-24a7a95a1cf4f14b59a3475127dc45541357638d6949323255faeeb2ed657d27">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>util.go</strong><dd><code>Introduce MergeAllowedURLs and remove unused functions</code> </dd></summary> <hr> internal/policy/util.go <li>Added <code>MergeAllowedURLs</code> function for merging URL access specs.<br> <li> Removed <code>copyAllowedURLs</code> and <code>contains</code> functions. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-0323c3da13f08a9ccd340ac04208d680856354fd566dffcad925fa6645639955">+46/-70</a> </td> </tr> <tr> <td> <details> <summary><strong>custom_policies.go</strong><dd><code>Enhance custom policies handling with order preservation</code> </dd></summary> <hr> user/custom_policies.go <li>Added <code>GetCustomPolicies</code> to preserve policy order.<br> <li> Updated <code>CustomPolicies</code> to use <code>GetCustomPolicies</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-911674993eef6c43a04edc0e90ea1f2e6d595792eef840d23b2e3deb1c8265c5">+21/-7</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>apply_test.go</strong><dd><code>Update tests for policy application</code> </dd></summary> <hr> internal/policy/apply_test.go <li>Added initialization of <code>policy.Service</code> in tests.<br> <li> Ensured <code>Apply</code> method is tested with <code>assert.NoError</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-5af7e299a6b0ce11e22f8aa4a01854b1151f4b54dccc68f0cd1cbedee5aed7c8">+29/-28</a> </td> </tr> <tr> <td> <details> <summary><strong>util_test.go</strong><dd><code>Add tests for MergeAllowedURLs function</code> </dd></summary> <hr> internal/policy/util_test.go - Added tests for `MergeAllowedURLs` function. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-c750a1b8a01d19dacf02ba7512b8e2b987bf8147cf3345a4374504d9d5b3840e">+64/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Configuration changes</strong></td><td><table> <tr> <td> <details> <summary><strong>Taskfile.yml</strong><dd><code>Update Taskfile with stress test task</code> </dd></summary> <hr> internal/policy/Taskfile.yml <li>Added <code>stress</code> task for running stress tests.<br> <li> Updated <code>default</code> task to include <code>test</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-e0f19d4dd27acb397e19ccb080f3142a09f5978699da5843bfc71e7ffa4bb775">+16/-0</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information --------- Co-authored-by: Tit Petric <tit@tyk.io> (cherry picked from commit e31a08f)
@titpetric Succesfully merged PR |
<details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-12897" title="TT-12897" target="_blank">TT-12897</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[Security]Path-Based Permissions permissions in policies are not preserved when policies are combined</td> </tr> <tr> <th>Type</th> <td> <img alt="Bug" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium" /> Bug </td> </tr> <tr> <th>Status</th> <td>In Dev</td> </tr> <tr> <th>Points</th> <td>N/A</td> </tr> <tr> <th>Labels</th> <td><a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20customer_bug%20ORDER%20BY%20created%20DESC" title="customer_bug">customer_bug</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20jira_escalated%20ORDER%20BY%20created%20DESC" title="jira_escalated">jira_escalated</a></td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- PR uses custom policies to combine several policies with access rights set. Since a `map` was in the path, user API for custom policies needed an extension to preserve policy ID order. The existing function returning a map didn't handle json decode errors properly and go semantics when looping over maps don't preserve this order, but it's random so tests would fail. Verified with `task stress`. Issue: https://tyktech.atlassian.net/browse/TT-12897 ___ Bug fix, Enhancement, Tests ___ - Enhanced policy application logic by introducing `MergeAllowedURLs` to merge allowed URLs efficiently. - Refactored `Store` to use a slice for policies, and introduced `StoreMap` for unordered policy storage. - Improved custom policy handling by adding `GetCustomPolicies` to preserve policy order. - Updated tests to ensure proper application of policies and added new tests for `MergeAllowedURLs`. - Updated Taskfile to include a new `stress` task for running stress tests. ___ <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>apply.go</strong><dd><code>Enhance policy application logic and logging</code> </dd></summary> <hr> internal/policy/apply.go <li>Introduced <code>MergeAllowedURLs</code> function to merge allowed URLs.<br> <li> Updated <code>Logger</code> function to return a <code>logrus.Entry</code>.<br> <li> Changed <code>session.CustomPolicies()</code> to <code>session.GetCustomPolicies()</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-59b92e9d31f142f1d99b746eb3ff7db4e26bf6c3044c9b87b58034a947ee04d1">+9/-17</a> </td> </tr> <tr> <td> <details> <summary><strong>store.go</strong><dd><code>Refactor Store to use slice for policies</code> </dd></summary> <hr> internal/policy/store.go <li>Changed <code>Store</code> to use a slice for policies.<br> <li> Updated methods to accommodate slice-based storage. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-13dec7bc453c9ff99550c83d2f86a017bbf7fb863584dc30603af15d29ef9d3d">+20/-7</a> </td> </tr> <tr> <td> <details> <summary><strong>store_map.go</strong><dd><code>Add StoreMap for unordered policy storage</code> </dd></summary> <hr> internal/policy/store_map.go <li>Introduced <code>StoreMap</code> for unordered policy storage.<br> <li> Implemented methods for <code>StoreMap</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-24a7a95a1cf4f14b59a3475127dc45541357638d6949323255faeeb2ed657d27">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>util.go</strong><dd><code>Introduce MergeAllowedURLs and remove unused functions</code> </dd></summary> <hr> internal/policy/util.go <li>Added <code>MergeAllowedURLs</code> function for merging URL access specs.<br> <li> Removed <code>copyAllowedURLs</code> and <code>contains</code> functions. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-0323c3da13f08a9ccd340ac04208d680856354fd566dffcad925fa6645639955">+46/-70</a> </td> </tr> <tr> <td> <details> <summary><strong>custom_policies.go</strong><dd><code>Enhance custom policies handling with order preservation</code> </dd></summary> <hr> user/custom_policies.go <li>Added <code>GetCustomPolicies</code> to preserve policy order.<br> <li> Updated <code>CustomPolicies</code> to use <code>GetCustomPolicies</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-911674993eef6c43a04edc0e90ea1f2e6d595792eef840d23b2e3deb1c8265c5">+21/-7</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>apply_test.go</strong><dd><code>Update tests for policy application</code> </dd></summary> <hr> internal/policy/apply_test.go <li>Added initialization of <code>policy.Service</code> in tests.<br> <li> Ensured <code>Apply</code> method is tested with <code>assert.NoError</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-5af7e299a6b0ce11e22f8aa4a01854b1151f4b54dccc68f0cd1cbedee5aed7c8">+29/-28</a> </td> </tr> <tr> <td> <details> <summary><strong>util_test.go</strong><dd><code>Add tests for MergeAllowedURLs function</code> </dd></summary> <hr> internal/policy/util_test.go - Added tests for `MergeAllowedURLs` function. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-c750a1b8a01d19dacf02ba7512b8e2b987bf8147cf3345a4374504d9d5b3840e">+64/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Configuration changes</strong></td><td><table> <tr> <td> <details> <summary><strong>Taskfile.yml</strong><dd><code>Update Taskfile with stress test task</code> </dd></summary> <hr> internal/policy/Taskfile.yml <li>Added <code>stress</code> task for running stress tests.<br> <li> Updated <code>default</code> task to include <code>test</code>. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6597/files#diff-e0f19d4dd27acb397e19ccb080f3142a09f5978699da5843bfc71e7ffa4bb775">+16/-0</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information --------- Co-authored-by: Tit Petric <tit@tyk.io>
User description
TT-12897
PR uses custom policies to combine several policies with access rights set.
Since a
map
was in the path, user API for custom policies needed an extension to preserve policy ID order. The existing function returning a map didn't handle json decode errors properly and go semantics when looping over maps don't preserve this order, but it's random so tests would fail. Verified withtask stress
.Issue: https://tyktech.atlassian.net/browse/TT-12897
PR Type
Bug fix, Enhancement, Tests
Description
MergeAllowedURLs
to merge allowed URLs efficiently.Store
to use a slice for policies, and introducedStoreMap
for unordered policy storage.GetCustomPolicies
to preserve policy order.MergeAllowedURLs
.stress
task for running stress tests.Changes walkthrough 📝
apply.go
Enhance policy application logic and logging
internal/policy/apply.go
MergeAllowedURLs
function to merge allowed URLs.Logger
function to return alogrus.Entry
.session.CustomPolicies()
tosession.GetCustomPolicies()
.store.go
Refactor Store to use slice for policies
internal/policy/store.go
Store
to use a slice for policies.store_map.go
Add StoreMap for unordered policy storage
internal/policy/store_map.go
StoreMap
for unordered policy storage.StoreMap
.util.go
Introduce MergeAllowedURLs and remove unused functions
internal/policy/util.go
MergeAllowedURLs
function for merging URL access specs.copyAllowedURLs
andcontains
functions.custom_policies.go
Enhance custom policies handling with order preservation
user/custom_policies.go
GetCustomPolicies
to preserve policy order.CustomPolicies
to useGetCustomPolicies
.apply_test.go
Update tests for policy application
internal/policy/apply_test.go
policy.Service
in tests.Apply
method is tested withassert.NoError
.util_test.go
Add tests for MergeAllowedURLs function
internal/policy/util_test.go
MergeAllowedURLs
function.Taskfile.yml
Update Taskfile with stress test task
internal/policy/Taskfile.yml
stress
task for running stress tests.default
task to includetest
.