|
15 | 15 | package annotations
|
16 | 16 |
|
17 | 17 | import (
|
18 |
| - "errors" |
19 |
| - "sort" |
20 |
| - "strings" |
21 |
| - |
22 |
| - corev1 "k8s.io/api/core/v1" |
23 |
| - |
24 | 18 | "github.com/alibaba/higress/pkg/ingress/kube/util"
|
25 | 19 | . "github.com/alibaba/higress/pkg/ingress/log"
|
26 | 20 | )
|
@@ -57,101 +51,10 @@ func (a auth) Parse(annotations Annotations, config *Ingress, globalContext *Glo
|
57 | 51 | if !needAuthConfig(annotations) {
|
58 | 52 | return nil
|
59 | 53 | }
|
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.") |
125 | 55 | return nil
|
126 | 56 | }
|
127 | 57 |
|
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 |
| - |
155 | 58 | func needAuthConfig(annotations Annotations) bool {
|
156 | 59 | return annotations.HasASAP(authType) &&
|
157 | 60 | annotations.HasASAP(authSecretAnn)
|
|
0 commit comments