tintoy / dotnet-kube-client

A Kubernetes API client for .NET Standard / .NET Core
MIT License
192 stars 32 forks source link

ExecAndConnect example yields 403 Forbidden #150

Open cveld opened 2 years ago

cveld commented 2 years ago

When running the example

K8sMultiplexer connection = await client.PodsV1().ExecAndConnect(
            kubeNamespace: "default",
            podName: "nginx",
            command: "/bin/bash",
            stdin: true,
            stdout: true,
            tty: true
        );

This yields

Error: System.Net.WebSockets.WebSocketException (0x80004005): WebSocket connection failure.
 ---> System.Net.WebSockets.WebSocketException (0x80004005): Connection failure (status line = 'HTTP/1.1 403 Forbidden').
   at KubeClient.Extensions.WebSockets.K8sWebSocket.ParseAndValidateConnectResponseAsync(Stream stream, K8sWebSocketOptions options, String expectedSecWebSocketAccept, CancellationToken cancellationToken)
   at KubeClient.Extensions.WebSockets.K8sWebSocket.ConnectAsync(Uri uri, K8sWebSocketOptions options, CancellationToken cancellationToken)
   at KubeClient.Extensions.WebSockets.K8sWebSocket.ConnectAsync(Uri uri, K8sWebSocketOptions options, CancellationToken cancellationToken)
   at KubeClient.ResourceClientWebSocketExtensions.ExecAndConnectRaw(IPodClientV1 podClient, String podName, String command, Boolean stdin, Boolean stdout, Boolean stderr, Boolean tty, String container, String kubeNamespace, CancellationToken cancellation)
   at KubeClient.KubeClientExtensions.Multiplexed(Task`1 webSocketTask, Byte[] inputStreamIndexes, Byte[] outputStreamIndexes, ILoggerFactory loggerFactory)
   at BlazorTerraformRunner.Pages.Index.ExecPodClicked() in C:\work\git\github\cveld\Experiments\2022-11 Blazor terraform runner\BlazorTerraformRunner\BlazorTerraformRunner\Pages\Index.razor:line 39
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

dotnet 6

    <PackageReference Include="KubeClient" Version="2.4.9" />
    <PackageReference Include="KubeClient.Extensions.WebSockets" Version="2.4.9" />

kubernetes 1.24

tintoy commented 2 years ago

Hi - what type of authentication are you using, and are you able to successfully perform any other API calls against that cluster (e.g. client.PodsV1().List()?