|
6 | 6 | "net/http" |
7 | 7 | "net/url" |
8 | 8 | "os" |
| 9 | + "strconv" |
9 | 10 | "strings" |
10 | 11 | "sync" |
11 | 12 | "time" |
@@ -168,6 +169,11 @@ func (a *Authenticator) Check(ctx context.Context, request *Request) (finalRespo |
168 | 169 | ctx, span := startSpan(ctx, request.Request, wsvc, ns) |
169 | 170 | defer endSpan(span, start_time, finalResponse, reason) |
170 | 171 |
|
| 172 | + if wsvc == "none" { |
| 173 | + reason, headers := a.CheckWebserviceless(ctx, request) |
| 174 | + return generateResponse(reason, headers), nil |
| 175 | + } |
| 176 | + |
171 | 177 | if reason != "" { |
172 | 178 | return generateResponse(reason, nil), nil |
173 | 179 | } |
@@ -202,6 +208,50 @@ func (a *Authenticator) Check(ctx context.Context, request *Request) (finalRespo |
202 | 208 | return |
203 | 209 | } |
204 | 210 |
|
| 211 | +func (a *Authenticator) CheckWebserviceless(ctx context.Context, request *Request) (CerberusReason, ExtraHeaders) { |
| 212 | + wsvc, reason := wsvcForWebservicelessRequest(request) |
| 213 | + if reason != "" { |
| 214 | + return reason, nil |
| 215 | + } |
| 216 | + |
| 217 | + var extraHeaders ExtraHeaders |
| 218 | + reason = a.checkServiceUpstreamAuth(wsvc, request, &extraHeaders, ctx) |
| 219 | + return reason, extraHeaders |
| 220 | +} |
| 221 | + |
| 222 | +func wsvcForWebservicelessRequest(request *Request) (WebservicesCacheEntry, CerberusReason) { |
| 223 | + if request.Context["authURL"] == "" { |
| 224 | + return WebservicesCacheEntry{}, CerberusReasonWebservicelessAuthURLEmpty |
| 225 | + } |
| 226 | + |
| 227 | + readTokenFrom := request.Context["readTokenFrom"] |
| 228 | + if readTokenFrom == "" { |
| 229 | + readTokenFrom = "Authorization" |
| 230 | + } |
| 231 | + writeTokenTo := request.Context["writeTokenTo"] |
| 232 | + if writeTokenTo == "" { |
| 233 | + writeTokenTo = "Authorization" |
| 234 | + } |
| 235 | + timeout, err := strconv.Atoi(request.Context["timeout"]) |
| 236 | + if err != nil { |
| 237 | + timeout = 200 |
| 238 | + } |
| 239 | + |
| 240 | + return WebservicesCacheEntry{ |
| 241 | + WebService: v1alpha1.WebService{ |
| 242 | + Spec: v1alpha1.WebServiceSpec{ |
| 243 | + UpstreamHttpAuth: v1alpha1.UpstreamHttpAuthService{ |
| 244 | + Address: request.Context["authURL"], |
| 245 | + ReadTokenFrom: readTokenFrom, |
| 246 | + WriteTokenTo: writeTokenTo, |
| 247 | + Timeout: timeout, |
| 248 | + CareHeaders: strings.Split(request.Context["careHeaders"], ","), |
| 249 | + }, |
| 250 | + }, |
| 251 | + }, |
| 252 | + }, "" |
| 253 | +} |
| 254 | + |
205 | 255 | // startSpan starts span for Check Function |
206 | 256 | func startSpan(ctx context.Context, request http.Request, wsvc string, ns string) (context.Context, trace.Span) { |
207 | 257 | parentCtx := tracing.ReadParentSpanFromRequest(ctx, request) |
@@ -255,6 +305,10 @@ func readRequestContext(request *Request) (wsvc string, ns string, reason Cerber |
255 | 305 | return "", "", CerberusReasonWebserviceEmpty |
256 | 306 | } |
257 | 307 |
|
| 308 | + if wsvc == "none" { |
| 309 | + return wsvc, "", "" |
| 310 | + } |
| 311 | + |
258 | 312 | ns = request.Context["namespace"] |
259 | 313 | if ns == "" { |
260 | 314 | return "", "", CerberusReasonWebserviceNamespaceEmpty |
|
0 commit comments