Skip to content

Commit 7f23980

Browse files
authored
remove basic-auth useless annotation (#1779)
1 parent 6fb0684 commit 7f23980

File tree

2 files changed

+1
-295
lines changed

2 files changed

+1
-295
lines changed

pkg/ingress/kube/annotations/auth.go

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
package annotations
1616

1717
import (
18-
"errors"
19-
"sort"
20-
"strings"
21-
22-
corev1 "k8s.io/api/core/v1"
23-
2418
"github.com/alibaba/higress/pkg/ingress/kube/util"
2519
. "github.com/alibaba/higress/pkg/ingress/log"
2620
)
@@ -57,101 +51,10 @@ func (a auth) Parse(annotations Annotations, config *Ingress, globalContext *Glo
5751
if !needAuthConfig(annotations) {
5852
return nil
5953
}
60-
61-
authConfig := &AuthConfig{
62-
AuthType: defaultAuthType,
63-
}
64-
65-
// Check auth type
66-
authType, err := annotations.ParseStringASAP(authType)
67-
if err != nil {
68-
IngressLog.Errorf("Parse auth type error %v within ingress %/%s", err, config.Namespace, config.Name)
69-
return nil
70-
}
71-
if authType != defaultAuthType {
72-
IngressLog.Errorf("Auth type %s within ingress %/%s is not supported yet.", authType, config.Namespace, config.Name)
73-
return nil
74-
}
75-
76-
secretName, _ := annotations.ParseStringASAP(authSecretAnn)
77-
namespaced := util.SplitNamespacedName(secretName)
78-
if namespaced.Name == "" {
79-
IngressLog.Errorf("Auth secret name within ingress %s/%s is invalid", config.Namespace, config.Name)
80-
return nil
81-
}
82-
if namespaced.Namespace == "" {
83-
namespaced.Namespace = config.Namespace
84-
}
85-
86-
configKey := util.ClusterNamespacedName{
87-
NamespacedName: namespaced,
88-
ClusterId: config.ClusterId,
89-
}
90-
authConfig.AuthSecret = configKey
91-
92-
// Subscribe secret
93-
globalContext.WatchedSecrets.Insert(configKey.String())
94-
95-
secretType := authFileAuthSecretType
96-
if rawSecretType, err := annotations.ParseStringASAP(authSecretTypeAnn); err == nil {
97-
resultAuthSecretType := authSecretType(rawSecretType)
98-
if resultAuthSecretType == authFileAuthSecretType || resultAuthSecretType == authMapAuthSecretType {
99-
secretType = resultAuthSecretType
100-
}
101-
}
102-
103-
authConfig.AuthRealm, _ = annotations.ParseStringASAP(authRealm)
104-
105-
// Process credentials.
106-
secretLister, exist := globalContext.ClusterSecretLister[config.ClusterId]
107-
if !exist {
108-
IngressLog.Errorf("secret lister of cluster %s doesn't exist", config.ClusterId)
109-
return nil
110-
}
111-
authSecret, err := secretLister.Secrets(namespaced.Namespace).Get(namespaced.Name)
112-
if err != nil {
113-
IngressLog.Errorf("Secret %s within ingress %s/%s is not found",
114-
namespaced.String(), config.Namespace, config.Name)
115-
return nil
116-
}
117-
credentials, err := convertCredentials(secretType, authSecret)
118-
if err != nil {
119-
IngressLog.Errorf("Parse auth secret fail, err %v", err)
120-
return nil
121-
}
122-
authConfig.Credentials = credentials
123-
124-
config.Auth = authConfig
54+
IngressLog.Error("The annotation nginx.ingress.kubernetes.io/auth-type is no longer supported after version 2.0.0, please use the higress wasm plugin (e.g., basic-auth) as an alternative.")
12555
return nil
12656
}
12757

128-
func convertCredentials(secretType authSecretType, secret *corev1.Secret) ([]string, error) {
129-
var result []string
130-
switch secretType {
131-
case authFileAuthSecretType:
132-
users, exist := secret.Data[authFileKey]
133-
if !exist {
134-
return nil, errors.New("the auth file type must has auth key in secret data")
135-
}
136-
userList := strings.Split(string(users), "\n")
137-
for _, item := range userList {
138-
if !strings.Contains(item, ":") {
139-
continue
140-
}
141-
result = append(result, item)
142-
}
143-
case authMapAuthSecretType:
144-
for name, password := range secret.Data {
145-
result = append(result, name+":"+string(password))
146-
}
147-
}
148-
sort.SliceStable(result, func(i, j int) bool {
149-
return result[i] < result[j]
150-
})
151-
152-
return result, nil
153-
}
154-
15558
func needAuthConfig(annotations Annotations) bool {
15659
return annotations.HasASAP(authType) &&
15760
annotations.HasASAP(authSecretAnn)

pkg/ingress/kube/annotations/auth_test.go

Lines changed: 0 additions & 197 deletions
This file was deleted.

0 commit comments

Comments
 (0)