Skip to content

Commit 33a902c

Browse files
committed
feat: enhance authentication plugin configurations with username and password fields
1 parent ec5ade3 commit 33a902c

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

api/adc/plugin_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,14 @@ type ForwardAuthConfig struct {
127127
// BasicAuthConfig is the rule config for basic-auth plugin.
128128
// +k8s:deepcopy-gen=true
129129
type BasicAuthConfig struct {
130+
Username string `json:"username,omitempty"`
131+
Password string `json:"password,omitempty"`
130132
}
131133

132134
// KeyAuthConfig is the rule config for key-auth plugin.
133135
// +k8s:deepcopy-gen=true
134136
type KeyAuthConfig struct {
137+
Header string `json:"header,omitempty"`
138+
Query string `json:"query,omitempty"`
139+
Key string `json:"key,omitempty"`
135140
}

internal/adc/translator/annotations/plugins/authorization.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ func (b *basicAuth) Handle(e annotations.Extractor) (any, error) {
3636
if e.GetStringAnnotation(annotations.AnnotationsAuthType) != "basicAuth" {
3737
return nil, nil
3838
}
39-
plugin := adctypes.BasicAuthConfig{}
39+
plugin := adctypes.BasicAuthConfig{
40+
Username: e.GetStringAnnotation(annotations.AnnotationsBasicAuthUsername),
41+
Password: e.GetStringAnnotation(annotations.AnnotationsBasicAuthPassword),
42+
}
4043
return &plugin, nil
4144
}
4245

@@ -56,6 +59,10 @@ func (k *keyAuth) Handle(e annotations.Extractor) (any, error) {
5659
if e.GetStringAnnotation(annotations.AnnotationsAuthType) != "keyAuth" {
5760
return nil, nil
5861
}
59-
plugin := adctypes.KeyAuthConfig{}
62+
plugin := adctypes.KeyAuthConfig{
63+
Header: e.GetStringAnnotation(annotations.AnnotationsKeyAuthHeader),
64+
Query: e.GetStringAnnotation(annotations.AnnotationsKeyAuthQuery),
65+
Key: e.GetStringAnnotation(annotations.AnnotationsKeyAuthKey),
66+
}
6067
return &plugin, nil
6168
}

internal/adc/translator/annotations/types.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646
AnnotationsCorsAllowMethods = AnnotationsPrefix + "cors-allow-methods"
4747

4848
// csrf plugin
49-
AnnotationsEnableCsrf = AnnotationsPrefix + "enable-csrf" // pingsix not support
49+
AnnotationsEnableCsrf = AnnotationsPrefix + "enable-csrf"
5050
AnnotationsCsrfKey = AnnotationsPrefix + "csrf-key"
5151

5252
// redirect plugin
@@ -60,10 +60,10 @@ const (
6060
AnnotationsRewriteTargetRegexTemplate = AnnotationsPrefix + "rewrite-target-regex-template"
6161

6262
// response-rewrite plugin
63-
AnnotationsEnableResponseRewrite = AnnotationsPrefix + "enable-response-rewrite" // pingsix not support
63+
AnnotationsEnableResponseRewrite = AnnotationsPrefix + "enable-response-rewrite"
6464
AnnotationsResponseRewriteStatusCode = AnnotationsPrefix + "response-rewrite-status-code"
65-
AnnotationsResponseRewriteBody = AnnotationsPrefix + "response-rewrite-body"
66-
AnnotationsResponseRewriteBodyBase64 = AnnotationsPrefix + "response-rewrite-body-base64"
65+
AnnotationsResponseRewriteBody = AnnotationsPrefix + "response-rewrite-body" // pingsix not support
66+
AnnotationsResponseRewriteBodyBase64 = AnnotationsPrefix + "response-rewrite-body-base64" // pingsix not support
6767
AnnotationsResponseRewriteHeaderAdd = AnnotationsPrefix + "response-rewrite-add-header"
6868
AnnotationsResponseRewriteHeaderSet = AnnotationsPrefix + "response-rewrite-set-header"
6969
AnnotationsResponseRewriteHeaderRemove = AnnotationsPrefix + "response-rewrite-remove-header"
@@ -85,13 +85,15 @@ const (
8585

8686
// key-auth plugin and basic-auth plugin
8787
// auth-type: keyAuth | basicAuth
88-
AnnotationsAuthType = AnnotationsPrefix + "auth-type" // need modify config with pingsix
88+
AnnotationsAuthType = AnnotationsPrefix + "auth-type"
89+
AnnotationsKeyAuthHeader = AnnotationsPrefix + "key-auth-header"
90+
AnnotationsKeyAuthQuery = AnnotationsPrefix + "key-auth-query"
91+
AnnotationsKeyAuthKey = AnnotationsPrefix + "key-auth-key"
92+
AnnotationsBasicAuthUsername = AnnotationsPrefix + "basic-auth-username"
93+
AnnotationsBasicAuthPassword = AnnotationsPrefix + "basic-auth-password"
8994

9095
// support backend service cross namespace
9196
AnnotationsSvcNamespace = AnnotationsPrefix + "svc-namespace"
92-
93-
// NOTE: PingSIX may support CSRF and Basic Authentication in the future.
94-
// NOTE: key-auth and basic-auth need to read configuration directly from annotations.
9597
)
9698

9799
const (

0 commit comments

Comments
 (0)