-
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-13375/TT-13422] Add validation rules for Upstream auth #6680
[TT-13375/TT-13422] Add validation rules for Upstream auth #6680
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
API Changes --- prev.txt 2024-10-29 11:45:49.471446051 +0000
+++ current.txt 2024-10-29 11:45:43.147435634 +0000
@@ -74,6 +74,11 @@
OAuthType = "oauth"
ExternalOAuthType = "externalOAuth"
OIDCType = "oidc"
+
+ // OAuthAuthorizationTypeClientCredentials is the authorization type for client credentials flow.
+ OAuthAuthorizationTypeClientCredentials = "clientCredentials"
+ // OAuthAuthorizationTypePassword is the authorization type for password flow.
+ OAuthAuthorizationTypePassword = "password"
)
const (
GraphQLEngineDataSourceKindREST = "REST"
@@ -1231,11 +1236,22 @@
ErrAPINotFound = errors.New("API not found")
ErrMissingAPIID = errors.New("missing API ID")
)
+var (
+ // ErrMultipleUpstreamAuthEnabled is the error to be returned when multiple upstream authentication modes are configured.
+ ErrMultipleUpstreamAuthEnabled = errors.New("multiple upstream authentication modes not allowed")
+ // ErrMultipleUpstreamOAuthAuthorizationType is the error to return when multiple OAuth authorization types are configured.
+ ErrMultipleUpstreamOAuthAuthorizationType = errors.New("multiple upstream OAuth authorization type not allowed")
+ // ErrUpstreamOAuthAuthorizationTypeRequired is the error to return when OAuth authorization type is not specified.
+ ErrUpstreamOAuthAuthorizationTypeRequired = errors.New("upstream OAuth authorization type is required")
+ // ErrInvalidUpstreamOAuthAuthorizationType is the error to return when configured OAuth authorization type is invalid.
+ ErrInvalidUpstreamOAuthAuthorizationType = errors.New("invalid OAuth authorization type")
+)
var DefaultValidationRuleSet = ValidationRuleSet{
&RuleUniqueDataSourceNames{},
&RuleAtLeastEnableOneAuthSource{},
&RuleValidateIPList{},
&RuleValidateEnforceTimeout{},
+ &RuleUpstreamAuth{},
}
var ErrAllAuthSourcesDisabled = "all auth sources are disabled for %s, at least one of header/cookie/query must be enabled"
var ErrDuplicateDataSourceName = errors.New("duplicate data source names are not allowed")
@@ -2270,6 +2286,13 @@
func (r *RuleUniqueDataSourceNames) Validate(apiDef *APIDefinition, validationResult *ValidationResult)
+type RuleUpstreamAuth struct{}
+ RuleUpstreamAuth implements validations for upstream authentication
+ configurations.
+
+func (r *RuleUpstreamAuth) Validate(apiDef *APIDefinition, validationResult *ValidationResult)
+ Validate validates api definition upstream authentication configurations.
+
type RuleValidateEnforceTimeout struct{}
func (r *RuleValidateEnforceTimeout) Validate(apiDef *APIDefinition, validationResult *ValidationResult)
@@ -8401,10 +8424,8 @@
ECDSASign = "ecdsa"
)
const (
- UpstreamOAuthErrorEventName = "UpstreamOAuthError"
- UpstreamOAuthMiddlewareName = "UpstreamOAuth"
- ClientCredentialsAuthorizeType = "clientCredentials"
- PasswordAuthorizeType = "password"
+ UpstreamOAuthErrorEventName = "UpstreamOAuthError"
+ UpstreamOAuthMiddlewareName = "UpstreamOAuth"
)
const (
ErrOAuthAuthorizationFieldMissing = "oauth.auth_field_missing" |
PR Code Suggestions ✨Explore these optional code suggestions:
|
ff682aa
to
1bb669a
Compare
1bb669a
to
fbab56a
Compare
Quality Gate failedFailed conditions |
User description
TT-13422
Description
Add validation rules for upstream auth
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
enhancement, tests
Description
RuleUpstreamAuth
to enforce constraints on upstream authentication modes.PRDescriptionHeader.CHANGES_WALKTHROUGH
api_definitions.go
Add constants for OAuth authorization types
apidef/api_definitions.go
validator.go
Implement validation rules for upstream authentication
apidef/validator.go
RuleUpstreamAuth
.mw_oauth2_auth.go
Refactor OAuth authorization type handling
gateway/mw_oauth2_auth.go
apidef
.validator_test.go
Add test cases for upstream authentication validation
apidef/validator_test.go
RuleUpstreamAuth
validation.mw_oauth2_auth_test.go
Update test cases with new OAuth constants
gateway/mw_oauth2_auth_test.go