kura icon indicating copy to clipboard operation
kura copied to clipboard

Unable to install package with basic authentication

Open pintify opened this issue 5 years ago • 19 comments

Describe the bug The download/install via URL is not capable to process URLs with user/pass authentication included.

To Reproduce

  1. Go to Packages tab -> Install/Upgrade package -> URL
  2. Insert a url with format https://username:[email protected]/packages/package1.dp
  3. Install fails with
2019-10-23T14:22:30,038 [DeploymentAgent] ERROR o.e.k.d.a.i.DeploymentAgent - Exception installing package at URL https://username:[email protected]/packages/package1.dp
java.io.IOException: Server returned HTTP response code: 401 for URL: https://username:[email protected]/packages/package1.dp
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1900) ~[?:1.8.0_232]
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) ~[?:1.8.0_232]
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268) ~[?:1.8.0_232]
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.getFileFromRemote(DeploymentAgent.java:492) ~[?:?]
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installDeploymentPackageInternal(DeploymentAgent.java:441) ~[?:?]
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installer(DeploymentAgent.java:309) ~[?:?]
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.lambda$0(DeploymentAgent.java:173) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_232]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_232]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_232]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_232]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]

The URL works perfectly when used from curl.

Expected behavior Authentication is processed and package installed.

Target Environment:

  • OS version: Linux -- 4.4.0-cip #1 Thu Jan 31 17:58:56 CST 2019 armv7l GNU/Linux
  • Additional info: Debian 9

pintify avatar Oct 23 '19 15:10 pintify

Turned out it was the SSL the issue. We're working on it but it doesn't look like a Kura problem so I'm closing this issue.

pintify avatar Nov 27 '19 12:11 pintify

SSL issue solved, but the authentication problem remains. Is this an expected behaviour? How could basic authentication be achieved?

pintify avatar Jan 10 '20 07:01 pintify

From a brief look that should be the format for basic authentication. Did you try with another tool to see if that resolves correctly?

MMaiero avatar Jan 10 '20 08:01 MMaiero

Exactly the same URL works with curl or wget in the same device.

pintify avatar Jan 10 '20 09:01 pintify

To remove any doubt, I've created a reproducible example.

  1. Launch two Kura containers, one with host network configuration:

    docker run --name kura1 --net host -d eclipse/kura
    docker run --name kura2 -p 8081:8080 -d eclipse/kura
    
  2. Enter in http://localhost:8080/kura with default credentials.

  3. Try to install a package via URL from http://admin:admin@localhost:8081

  4. Receive the error:

    2020-01-10T10:30:52,712 [qtp83912762-73] INFO  o.e.k.w.s.s.FileServlet - Installing package...
    2020-01-10T10:30:52,712 [DeploymentAgent] INFO  o.e.k.d.a.i.DeploymentAgent - About to install package at URL http://admin:admin@localhost:8081/kura
    2020-01-10T10:30:53,242 [DeploymentAgent] ERROR o.e.k.d.a.i.DeploymentAgent - Exception installing package at URL http://admin:admin@localhost:8081/kura
    java.io.IOException: Server returned HTTP response code: 401 for URL: http://admin:admin@localhost:8081/kura
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.getFileFromRemote(DeploymentAgent.java:498)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installDeploymentPackageInternal(DeploymentAgent.java:450)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.execInstall(DeploymentAgent.java:323)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installer(DeploymentAgent.java:307)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.lambda$0(DeploymentAgent.java:172)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    2020-01-10T10:30:53,243 [DeploymentAgent] INFO  o.e.k.d.a.i.DeploymentAgent - Posting INSTALLED event for package at URL http://admin:admin@localhost:8081/kura: unsuccessful
    

Not that such URL could ever install anything, but the authentication should be properly achieved and it should give an error similar to:

2020-01-10T10:38:10,381 [qtp83912762-77] INFO  o.e.k.w.s.s.FileServlet - Installing package...
2020-01-10T10:38:10,381 [DeploymentAgent] INFO  o.e.k.d.a.i.DeploymentAgent - About to install package at URL http://www.google.com
2020-01-10T10:38:10,528 [DeploymentAgent] ERROR o.e.k.d.a.i.DeploymentAgent - Exception installing package at URL http://www.google.com
org.osgi.service.deploymentadmin.DeploymentException: No manifest present in deployment package!
	at org.apache.felix.deploymentadmin.DeploymentAdminImpl.installDeploymentPackage(DeploymentAdminImpl.java:178)
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installDeploymentPackageInternal(DeploymentAgent.java:464)
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.execInstall(DeploymentAgent.java:323)
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installer(DeploymentAgent.java:307)
	at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.lambda$0(DeploymentAgent.java:172)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
2020-01-10T10:38:10,530 [DeploymentAgent] INFO  o.e.k.d.a.i.DeploymentAgent - Posting INSTALLED event for package at URL http://www.google.com: unsuccessful

pintify avatar Jan 10 '20 10:01 pintify

Having a look it seems that Java APIs do not support out of the box basic authentication as encoded directly in the URL.

MMaiero avatar Jan 10 '20 16:01 MMaiero

Then, how would you suggest to make this? We are interested in use this service to install from Kapua.

pintify avatar Jan 14 '20 09:01 pintify

I believe you can use the deployment feature in Kapua that should also support basic authentication. Maybe refer to that project for more info.

MMaiero avatar Jan 14 '20 11:01 MMaiero

And in order to do it directly through the Kura web?

pintify avatar Jan 14 '20 13:01 pintify

That requires a new feature in develop.

MMaiero avatar Jan 14 '20 14:01 MMaiero

Sorry for the wrong closing. The feature will be part of the Deployment Package Service and integrated from Kapua? Just to be sure before making a decision regarding the deployment procedure.

pintify avatar Jan 14 '20 15:01 pintify

The support for basic authentication is already there via deploy-v2 in Kapus. It is not there in the url upload from the Kura web ui. Maybe with a contribution, it can be there in the next release.

MMaiero avatar Jan 14 '20 15:01 MMaiero

Ok, I've already achieved it through Kapua with a different configuration thanks to @lorthirk.

pintify avatar Jan 16 '20 09:01 pintify

@alebianchin Can you take care of this enhancement in local web UI?

MMaiero avatar Feb 05 '20 11:02 MMaiero