Pengine_rpc and HTTP Basic Auth

Hello,

I have a server which makes some interface available through engines. The entire server sits behind an nginx which secures it with basic Authentication. Now I trye to make a pengine_rpc call over the public internet – of course this fails with

permission_error(url,‘https://mainframe.capcorn.net:443/services/pengine/create’) (status(401,Unauthorized))

But I have no idea how to pass the user and password with pengine_rpc. Is there a way?

Thanks!

pengine_rpc/3 passes its options to pengine_create/1, which passes its options to http_open/3. That has an authorization option that supports basic, digest and bearer authentication.

Thanks Jan for the quick answer! It would be a clever solution, but it doesn’t seem to work, because the authorization isn’t passed to pengines:probe. Trace with a spy point on pengines:remote_post_rec/5:

[debug]  ?- rdf(A,B,C).
 * Call: (17) pengines:remote_post_rec('https://<my_server_url>:443/services', create, _3338{ask:":(rdf_db,rdf(A,B,C))", template:"v(A,B,C)"}, _3372, [id(_3022), timeout(300), authorization(basic(admin, '****'))]) ? 
   Call: (18) pengines:server_url('https://<my_server_url>:443/services', create, [], _4214) ? s
   Exit: (18) pengines:server_url('https://<my_server_url>:443/services', create, [], 'https://<my_server_url>:443/services/pengine/create') ? 
   Call: (18) pengines:probe(create, 'https://<my_server_url>:443/services/pengine/create') ? 
^  Call: (19) http_open:http_open('https://<my_server_url>:443/services/pengine/create', _6752, [method(options)]) ? 
^  Call: (20) swi_option:meta_options(is_meta, pengines:[method(options)], _7602) ? a
% Execution Aborted

If I continue at this point, it still throws the error (no surprise).

What version are you using? Here, pengines:probe has 3 arguments and passes the options. git blame tells me this is fixed in 437a17c98dc47ed0a4e51c777c0536bd742010b7 by Pieter Van den Abeele on Aug 21 00:25:05 2024. Seems you need 9.2.7 or 9.3.10 or later for that.

Oh you are right. I was on 9.0.4, you are way ahead of me, thanks again!

Side note: The 64bit Windows installer did not add swipl to the PATH (for all users) on either of two machines I used it, even though I checked the checkbox. I am confident that this worked with earlier versions.

Can I make my pengines app handle requests on <server>/services/pengine/create instead of <server>/pengine/create? The client can handle this, but I don’t know how to configure it in the server – I only do :- use_module(library(pengines)) in a normal HTTP server.

I’m not aware of any changes to the CMake/CPack generated installers. If anyone likes to sort that out …

You can use this to change all paths registered as root(Path).

:- multifile http:location/3.
http:location(root, '/services/', []).

I guess we should have an additional alias for pengines, so one can separately rebase the pengine services.

Ok, that doesn’t work in my case because I have multiple prefixes in this server. I could restructure it, but it doesn’t matter, I’ll just accept /pengine in nginx. All working fine now, thanks!

I pushed a patch that allows changing the HTTP path alias pengine. Should be in tomorrows daily build of the development version. 9.0.4 to 9.3.18+ is a jump :slight_smile:

1 Like