Skip to content

Unable to exec in a container, 403 Forbidden error #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jconallen opened this issue Feb 22, 2018 · 5 comments
Closed

Unable to exec in a container, 403 Forbidden error #196

jconallen opened this issue Feb 22, 2018 · 5 comments

Comments

@jconallen
Copy link

Trying out one of the examples I am unable to exec a simple shell command in a container. I am using 1.0.0-beta2.

		      ApiClient client = Config.fromToken(
				"https://xxx.xxx.xxx.xxx:8001", 
				"<some incredibly long token string>",
				false);
                    Exec exec = new Exec(client);
		    boolean tty = System.console() != null;
		    final Process proc = exec.exec(
		    		"default", 
		    		"kubetoy-7447675dbf-72lcj", 
		    		new String[] {"sh", "-c", "echo foo"}, 
		    		true, 
		    		tty );


		    new Thread(
		            new Runnable() {
		              public void run() {
		                try {
		                  ByteStreams.copy(System.in, proc.getOutputStream());
		                } catch (IOException ex) {
		                  ex.printStackTrace();
		                }
		              }
		            })
		        .start();

		    new Thread(
		            new Runnable() {
		              public void run() {
		                try {
		                  ByteStreams.copy(proc.getInputStream(), System.out);
		                } catch (IOException ex) {
		                  ex.printStackTrace();
		                }
		              }
		            })
		        .start();

		    proc.waitFor();
		    try {
		      // Wait for buffers to flush.
		      Thread.sleep(2000);
		    } catch (InterruptedException ex) {
		      ex.printStackTrace();
		    }

		    proc.destroy();

with the exception being:

java.net.ProtocolException: Expected HTTP 101 response but was '403 Forbidden'
	at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:123)
	at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:40)
	at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:98)
	at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
	at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
`
@karthikkondapally
Copy link
Contributor

karthikkondapally commented Feb 22, 2018

this may be similar to #180
BearerToken is missing in header (in /util/src/main/java/io/kubernetes/client/util/WebSockets.java)

@jconallen
Copy link
Author

Yes, when I turn on debugging I don't see the BearerToken being passed as well.

@brendandburns
Copy link
Contributor

Yeah, that's my guess too, waiting on a fix from @ceeaspb but if it doesn't show up in a few days, I may just kick one in myself... In the meantime #180 describes the needed change if you want to recompile...

@brendandburns
Copy link
Contributor

I just merged #202 can you check at HEAD? I will build new maven libs once there is confirmation of the fix.

@jconallen
Copy link
Author

This fixed it for me thanx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants