Hi Everyone,
I have been working on routing using envoyproxy.
I am using docker to deploy envoy and my springboot application.
The above scenario for routing without ext_auth is working perfectly
The problem i am facing is when i am using ext_authz filter and using another authorization service written in springboot.
Please find below the config and my api code.
______________________________________________________________________________________
envoy.yamlstats_sinks:
- name: envoy.stat_sinks.statsd
typed_config:
"@type": type.googleapis.com/envoy.config.metrics.v3.StatsdSink
address:
socket_address:
address: 10.131.50.226
port_value: 8092
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: backend
domains:
- "*"
routes:
- match:
prefix: "/serviceA"
route:
cluster: my_cluster
- match:
prefix: "/serviceB"
route:
cluster: my_cluster
access_log:
- name: envoy.access_loggers.stdout
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
http_filters:
- name: envoy.filters.http.ext_authz
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz
http_service:
server_uri:
uri: http://host.docker.internal:8084/auth
cluster: ext_authz_service
timeout: 0.250s
authorization_request:
allowed_headers:
patterns:
- exact: token
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: my_cluster
type: STRICT_DNS
# Comment out the following line to test on v6 networks
dns_lookup_family: V4_ONLY
load_assignment:
cluster_name: my_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: host.docker.internal
port_value: 8085
- name: ext_authz_service
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: ext_authz_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: host.docker.internal
port_value: 8084
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9910
layered_runtime:
layers:
- name: static_layer_0
static_layer:
envoy:
resource_limits:
listener:
example_listener_name:
connection_limit: 10000______________________________________________________________________________________
service codepackage com.ukg.App.DemoApp.Controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/serviceA")
public class Controller {
@GetMapping("hello")
ResponseEntity<String> getHelloResponse() {
System.out.println("Test Logs printing");
return ResponseEntity.ok()
.body("If You are watching this message. You have successfully logged in!!!");
}
@GetMapping("bye")
ResponseEntity<String> getByeResponse() {
return ResponseEntity.ok().body("Login again!!!");
}
}
package com.ukg.App.DemoApp.Controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/serviceB")
public class AnotherController {
@PostMapping("write")
ResponseEntity<String> getValue(@RequestBody String value) {
return ResponseEntity.ok().body("You wrote: " + value);
}
}
______________________________________________________________________________________
Authorization Service api
@RestController
@RequestMapping("/")
public class AuthorizationController {
@GetMapping(value = "auth", produces = "application/json")
ResponseEntity<String> validateAuthorization(
@RequestHeader("token") String authorizationHeader) {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
try {
String token = authorizationHeader;
if (token.equals("validToken"))
{
System.out.println("Token:" + token);
return new ResponseEntity<String>("{\"Token\": \"Valid Token\"}", httpHeaders,
HttpStatus.OK);
} else {
return new ResponseEntity<String>("{\"Token\": \"InvalidToken\"}", httpHeaders,
HttpStatus.FORBIDDEN);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
______________________________________________________________________________________
After ext_authz configuration,
This is what i am getting as a response when i am hitting localhost:10000/serviceA/hello
also i am providing a header as {token : validToken} to authorize and route
{
"timestamp": "2023-07-06T13:00:01.797+00:00",
"status": 404,
"error": "Not Found",
"path": "/serviceA/hello"
}
I am stuck due to this issue and could not find any solution
on the internet. Can someone point out the issue here and let me know
what i am doing wrong here?