Skip to content

Token retrieved by KubeResolverOptions expires #20

@MichalKoziorowski-TomTom

Description

Version

5.0.1

Context

I created following code:

ServiceResolverClient serviceResolverClient = ServiceResolverClient.create(vertx, new KubeResolverOptions());
ServiceAddress serviceAddress = ServiceAddress.of("some-service");
    vertx.setPeriodic(65000, event -> {
      System.out.println("Resolving endpoint for service: " + NKW_SERVICE_NAME);
      Future<Endpoint> endpointFuture = serviceResolverClient.resolveEndpoint(serviceAddress);
      endpointFuture
        .onSuccess(endpoint -> System.out.println("Resolved endpoint: " + endpoint + ". Servers: " + endpoint.servers()))
        .onFailure(cause -> System.err.println("Failed to resolve endpoint: " + cause.getMessage()));
    });

After some time, my kubernetes pod starts to throw errors like:

Failed to resolve endpoint: Invalid status code 401 : {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}

After some digging, I see that io.vertx.serviceresolver.kube.KubeResolverOptions is loading account token in static block https://github.com/eclipse-vertx/vertx-service-resolver/blob/main/src/main/java/io/vertx/serviceresolver/kube/KubeResolverOptions.java#L46. The problem is that token from /var/run/secrets/kubernetes.io/serviceaccount/token gets expired and needs to be reloaded periodically. My tokens (in Azure AKS) seems to be valid for about 45 minutes.

Steps to reproduce

No response

Do you have a reproducer?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions