envoy-auth-server-java is a sample project that provides authentication capability plug-ins. You can freely use this project to quickly understand envoy auth capabilities, and freely build your security authentication services based on this.
envoy-auth-server-java is mainly divided into two submodules:
- [(no need to modify)] The
APImodule is the definition of envoy's protobuf file. - The
authz-grpc-servermodule is the authentication logic processing address of the authentication server, and you can freely expand your authentication logic in this module.
In the sample project, we define the simplest authentication capability, you don't need to make any changes, just start the project:
@GrpcService()
public class AuthzService extends AuthorizationGrpc. AuthorizationImplBase {
@Override
public void check(CheckRequest request, StreamObserver<CheckResponse> responseObserver) {
CheckResponse checkResponse;
if ("/".equals(request.getAttributes().getRequest().getHttp().getPath())){
checkResponse = CheckResponse.newBuilder().setOkResponse(OkHttpResponse.getDefaultInstance()).setStatus(Status.newBuilder().setCode(Code.OK_VALUE)).build();
} else {
checkResponse = CheckResponse.newBuilder().setDeniedResponse(DeniedHttpResponse.newBuilder().setBody("No permission\n")).setStatus(Status.newBuilder().setCode(Code.PERMISSION_DENIED_VALUE).build()).build() ;
}
responseObserver.onNext(checkResponse);
responseObserver.onCompleted();
}
}If the request path is the root directory ("/"), return a CheckResponse with OK status; otherwise, return a CheckResponse with PERMISSION_DENIED status, and set the response body (body) to "No permission\n".
You can freely expand your authentication logic in the authz-grpc-server module. After you have completed the configuration of the authentication logic, you can build an image through Dockerfile, and then deploy it to your Kubernetes cluster.
In the sample project, we use Maven to build this project, you can complete the build with the command below, after the build is complete, you can find the built jar package in the target directory.
~ mvn clean packageSimilarly, we have provided some deployment examples in the project, and we will continue to expand them in the future
envoy-auth-server.yamlis a complete example that you can use directly to deploy your authentication service.remote-jwks.yamlis an example of using remote jwks, you can use this example to learn how to use remote jwks to complete authentication.
You can use this sample parameter to conduct tests. By modifying the Path parameter, you can see different results.
{
"attributes": {
"contextExtensions": {},
"request": {
"http": {
"path": "/"
}
}
}
}You can visit Postman to test quickly without installing any software.
Option 2. grpcui
Install grpcui
You can visit the GitHub repository grpcui of this project to get the latest installation information.
if use
grpcuion Mac, you can usebrewto install it.
#On Mac
brew install grpcui # https://formulae.brew.sh/formula/grpcuiRun grpcui & Test
If your deployment is complete, you can start grpcui with the command below, and then use grpcui to test your authentication service.
grpcui -plaintext localhost:18081

