-
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-11896] Add OAS IPAccessControl #6824
base: master
Are you sure you want to change the base?
Conversation
💔 The detected issue is not in one of the allowed statuses 💔
Please ensure your jira story is in one of the allowed statuses |
API Changes --- prev.txt 2025-01-10 12:18:43.159942886 +0000
+++ current.txt 2025-01-10 12:18:38.325952713 +0000
@@ -256,6 +256,7 @@
AllowedIPs []string `mapstructure:"allowed_ips" bson:"allowed_ips" json:"allowed_ips"`
EnableIpBlacklisting bool `mapstructure:"enable_ip_blacklisting" bson:"enable_ip_blacklisting" json:"enable_ip_blacklisting"`
BlacklistedIPs []string `mapstructure:"blacklisted_ips" bson:"blacklisted_ips" json:"blacklisted_ips"`
+ IPAccessControlDisabled bool `mapstructure:"ip_access_control_disabled" bson:"ip_access_control_disabled" json:"ip_access_control_disabled"`
DontSetQuotasOnCreate bool `mapstructure:"dont_set_quota_on_create" bson:"dont_set_quota_on_create" json:"dont_set_quota_on_create"`
ExpireAnalyticsAfter int64 `mapstructure:"expire_analytics_after" bson:"expire_analytics_after" json:"expire_analytics_after"` // must have an expireAt TTL index set (http://docs.mongodb.org/manual/tutorial/expire-data/)
ResponseProcessors []ResponseProcessor `bson:"response_processors" json:"response_processors"`
@@ -2835,6 +2836,26 @@
func (id *IDExtractorConfig) Fill(api apidef.APIDefinition)
Fill fills IDExtractorConfig from supplied classic APIDefinition.
+type IPAccessControl struct {
+ // Enabled indicates whether IP access control is enabled.
+ Enabled bool `bson:"enabled" json:"enabled"`
+
+ // Allow is a list of allowed IP addresses or CIDR blocks (e.g. "192.168.1.0/24").
+ // Note that if an IP address is present in both Allow and Block, the Block rule will take precedence.
+ Allow []string `bson:"allow,omitempty" json:"allow,omitempty"`
+
+ // Block is a list of blocked IP addresses or CIDR blocks (e.g. "192.168.1.100/32").
+ // If an IP address is present in both Allow and Block, the Block rule will take precedence.
+ Block []string `bson:"block,omitempty" json:"block,omitempty"`
+}
+ IPAccessControl represents IP access control configuration.
+
+func (i *IPAccessControl) ExtractTo(api *apidef.APIDefinition)
+ ExtractTo extracts *IPAccessControl into *apidef.APIDefinition.
+
+func (i *IPAccessControl) Fill(api apidef.APIDefinition)
+ Fill fills *IPAccessControl from apidef.APIDefinition.
+
type Info struct {
// ID is the unique identifier of the API within Tyk.
// Tyk classic API definition: `api_id`
@@ -3681,6 +3702,11 @@
//
// Tyk classic API definition: `event_handlers`
EventHandlers EventHandlers `bson:"eventHandlers,omitempty" json:"eventHandlers,omitempty"`
+
+ // IPAccessControl configures IP access control for this API.
+ //
+ // Tyk classic API definition: `allowed_ips` and `blacklisted_ips`.
+ IPAccessControl *IPAccessControl `bson:"ipAccessControl,omitempty" json:"ipAccessControl,omitempty"`
}
Server contains the configuration that sets Tyk up to receive requests from
the client applications. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
7dfb355
to
6801e5a
Compare
6801e5a
to
5dea91b
Compare
apidef/oas/server.go
Outdated
// IPAccessControl represents IP access control configuration. | ||
type IPAccessControl struct { | ||
// Enabled indicates whether IP access control is enabled. | ||
Enabled bool `json:"enabled"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need bson tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to follow the pattern, yes.
but when we think about how we're handling the db interaction, it's probably a no since we're storing the json blob in db.
that can be a separate discussion. I'll add the bson tag
Co-authored-by: Tit Petric <[email protected]>
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
User description
Description
This PR adds IP Access control configurations to OAS API definition.
Related Issue
https://tyktech.atlassian.net/browse/TT-11896
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Introduced
IPAccessControl
feature for API definitions.Added migration logic for IP access control settings.
Enhanced middleware logic for IP whitelisting and blacklisting.
Comprehensive test coverage for new IP access control functionality.
Changes walkthrough 📝
6 files
Added `IPAccessControlDisabled` field to API definitions.
Added migration logic for IP access control settings.
Added `IPAccessControl` struct and integration with API definitions.
Updated blacklist middleware to support `IPAccessControl`.
Updated whitelist middleware to support `IPAccessControl`.
Updated OAS schema to include `IPAccessControl` definition.
5 files
Added tests for IP access control migration logic.
Updated OAS tests to include `IPAccessControlDisabled`.
Added tests for `IPAccessControl` functionality in server logic.
Added tests for blacklist middleware with `IPAccessControl`.
Added tests for whitelist middleware with `IPAccessControl`.