This code used to work for a long time, but now it stopped working as expected:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo TEST >> ' + setup_file ];
cockpit.spawn (cmd, { superuser: true, err: "message" })
Now the output file (setup_file) is empty.
When I run that command on F33 it also does not write to the file. Ok, so I changed it to just "echo STRING >> /tmp/my_file" which works on the command line, but in Cockpit spawn it still does not write/echo to the file:
let cmd = [ '/usr/bin/echo TEST >> ' + setup_file ];
cockpit.spawn (cmd, { superuser: true, err: "message" })
I've tried different variations of this command, but none of them actually write (or echo) to the file whne using spawn(). I also tried "script(), but it didn't help. This used to work until just recently, so I'm not sure what is wrong or what changed in Cockpit/Fedora...
Any suggestions would be great.
Thanks,
Mark
Well I tried a lot of different things, but for some reason switching the first two items to use single quotes instead of double quotes got it working:
let cmd = [ - "/bin/sh", - "-c", + '/bin/sh', '-c', '/usr/bin/echo -e "' + setup_inf + '" >> ' + setup_file ];
Mark
On 8/25/21 12:38 PM, Mark Reynolds wrote:
This code used to work for a long time, but now it stopped working as expected:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo TEST >> ' + setup_file ];
cockpit.spawn (cmd, { superuser: true, err: "message" })
Now the output file (setup_file) is empty.
When I run that command on F33 it also does not write to the file. Ok, so I changed it to just "echo STRING >> /tmp/my_file" which works on the command line, but in Cockpit spawn it still does not write/echo to the file:
let cmd = [ '/usr/bin/echo TEST >> ' + setup_file ];
cockpit.spawn (cmd, { superuser: true, err: "message" })
I've tried different variations of this command, but none of them actually write (or echo) to the file whne using spawn(). I also tried "script(), but it didn't help. This used to work until just recently, so I'm not sure what is wrong or what changed in Cockpit/Fedora...
Any suggestions would be great.
Thanks,
Mark
On Wed, Aug 25, 2021 at 8:51 PM Mark Reynolds mreynolds@redhat.com wrote:
Well I tried a lot of different things, but for some reason switching the first two items to use single quotes instead of double quotes got it working:
let cmd = [
"/bin/sh",
"-c",
'/bin/sh', '-c', '/usr/bin/echo -e "' +
setup_inf + '" >> ' + setup_file ];
That's strange. Not sure what would cause such a regression. Perhaps a different javascript compiler/transpiler?
In any case, you may be looking for cockpit.script():
https://cockpit-project.org/guide/latest/cockpit-spawn#cockpit-spawn-script
Cheers,
Stef
On 8/25/21 12:38 PM, Mark Reynolds wrote:
This code used to work for a long time, but now it stopped working as expected:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo TEST >> ' + setup_file ]; cockpit.spawn (cmd, { superuser: true, err: "message" })
Now the output file (setup_file) is empty.
When I run that command on F33 it also does not write to the file. Ok, so I changed it to just "echo STRING >> /tmp/my_file" which works on the command line, but in Cockpit spawn it still does not write/echo to the file:
let cmd = [ '/usr/bin/echo TEST >> ' + setup_file ]; cockpit.spawn (cmd, { superuser: true, err: "message" })
I've tried different variations of this command, but none of them actually write (or echo) to the file whne using spawn(). I also tried "script(), but it didn't help. This used to work until just recently, so I'm not sure what is wrong or what changed in Cockpit/Fedora...
Any suggestions would be great.
Thanks,
Mark
On 8/26/21 5:15 AM, Stef Walter wrote:
On Wed, Aug 25, 2021 at 8:51 PM Mark Reynolds <mreynolds@redhat.com mailto:mreynolds@redhat.com> wrote:
Well I tried a lot of different things, but for some reason switching the first two items to use single quotes instead of double quotes got it working: let cmd = [ - "/bin/sh", - "-c", + '/bin/sh', '-c', '/usr/bin/echo -e "' + setup_inf + '" >> ' + setup_file ];
That's strange. Not sure what would cause such a regression. Perhaps a different javascript compiler/transpiler?
In any case, you may be looking for cockpit.script():
Actually below I stated I had tried script() as well, but it was also behaving the same way. Very odd...
https://cockpit-project.org/guide/latest/cockpit-spawn#cockpit-spawn-script https://cockpit-project.org/guide/latest/cockpit-spawn#cockpit-spawn-script
Cheers,
Stef
On 8/25/21 12:38 PM, Mark Reynolds wrote:
This code used to work for a long time, but now it stopped working as expected:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo TEST >> ' + setup_file ];
cockpit.spawn (cmd, { superuser: true, err: "message" })
Now the output file (setup_file) is empty.
When I run that command on F33 it also does not write to the file. Ok, so I changed it to just "echo STRING >> /tmp/my_file" which works on the command line, but in Cockpit spawn it still does not write/echo to the file:
let cmd = [ '/usr/bin/echo TEST >> ' + setup_file ];
cockpit.spawn (cmd, { superuser: true, err: "message" })
I've tried different variations of this command, but none of them actually write (or echo) to the file whne using spawn(). I also tried "script(), but it didn't help. This used to work until just recently, so I'm not sure what is wrong or what changed in Cockpit/Fedora...
Any suggestions would be great.
Thanks,
Mark
-- Directory Server Development Team _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org mailto:cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org mailto:cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste... https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahosted.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure https://pagure.io/fedora-infrastructure
-- Stef Walter (he / his) Linux Engineering Red Hat
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste... Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Hello Mark,
Mark Reynolds [2021-08-25 12:38 -0400]:
This code used to work for a long time, but now it stopped working as expected:
let cmd = [ "/bin/sh", "-c",
I can't possibly believe that ' vs. " has any actual influence about it -- this makes absolutely no difference in JavaScript, as per spec [1]. This must be a red herring.
'/usr/bin/echo TEST >> ' + setup_file
Is it possible that setup_file contains quotes?
cockpit.spawn (cmd, { superuser: true, err: "message" })
Are you actually waiting for this promise to settle? I.e. did you remove the .then/.catch only to shorten your email, or are they actually missing in your code?
In a running Cockpit session, I opened the developer console and ran
cockpit.spawn(['/bin/sh', '-c', '/usr/bin/echo TEST >> /tmp/my_file'], { superuser: true, err: "message"}).then(() => console.log("success")).catch(e => console.error(e))
This works, logs "succcess", and I have a root-owned /tmp/my_file with "TEST" in it. You can try the same -- that's much more convenient than having to re-build a script and reloading the page.
If your promise handlers are missing, can you try to add them and see what they complain about?
Now the output file (setup_file) is empty.
Does it get created, or is a leftover from a previous run? I.e. try to remove it first, to see if the shell at least gets that far, or if it already aborts ealier on. It may be a permission error (although unlikely as it runs as root, but there's always SELinux and such -- the rejection message will tell you).
Another possible gotcha might be that you did not elevate to sudo privileges in your cockpit session, so the spawn call would fail (it has `superuser: true`). Again, the rejection message will tell you.
Martin
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj...
On 8/26/21 6:43 AM, Martin Pitt wrote:
Hello Mark,
Mark Reynolds [2021-08-25 12:38 -0400]:
This code used to work for a long time, but now it stopped working as expected:
let cmd = [ "/bin/sh", "-c",
I can't possibly believe that ' vs. " has any actual influence about it -- this makes absolutely no difference in JavaScript, as per spec [1]. This must be a red herring.
I agree, yet that's what I saw (and others on my team). It was driving me nuts, and it was just a coincidence that I made the quotes uniform. And sorry I kind of added sudo code to this email, but it was an example that I had tried in the code.
Anyway I'm not sure how much time i want to invest in this since it's working now, but here is the entire code block before I made the quotes the same:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo -e "' + setup_inf + '" >> ' + setup_file ]; // Do not log inf file as it contains the DM password log_cmd("createInstance", "Apply changes to INF file...", ""); cockpit .spawn(cmd, { superuser: true, err: "message" }) .fail(err => { this.setState({ loadingCreate: false }); addNotification( "error", `Failed to populate installation file! ${err.message}` ); }) .done(_ => { /* * Next, create the instance... */ let cmd = ["dscreate", "-j", "from-file", setup_file]; log_cmd("createInstance", "Creating instance...", cmd); cockpit .spawn(cmd, { superuser: true, err: "message" }) .fail(err => { let errMsg = JSON.parse(err); cockpit.spawn(rm_cmd, { superuser: true }); // Remove Inf file with clear text password this.setState({ loadingCreate: false }); addNotification( "error", `${errMsg.desc}` ); }) .done(_ => { // Success!!! Now cleanup everything up... log_cmd("createInstance", "Instance creation compelete, clean everything up...", rm_cmd); cockpit.spawn(rm_cmd, { superuser: true }); // Remove Inf file with clear text password this.setState({ loadingCreate: false });
loadInstanceList(createServerId); addNotification( "success", `Successfully created instance: slapd-${createServerId}` ); closeHandler(); this.resetModal(); }); }); });
I got no errors, and it moved on to the next spawn() command and it attempted the instance installation even thought the setup file was empty. We've been using this code for almost two years now, and then it just started failing for us. Then all I did was change the quotes and it started working again. Very odd and it doesn't make any sense to me either...
For completeness, the "setup_inf" variable contained:
[general] config_version = 2 full_machine_name = localhost.localdomain start = True
[slapd] port = 389 root_dn = cn=dm root_password = Secret123
[backend-userroot] sample_entries = yes suffix = dc=example,dc=com
No special characters or quotes, or anything out of place.
One thing I am on F34 not F33, not sure if that makes a difference or not. And I am on Cockpit 250...
Thanks,
Mark
'/usr/bin/echo TEST >> ' + setup_file
Is it possible that setup_file contains quotes?
cockpit.spawn (cmd, { superuser: true, err: "message" })
Are you actually waiting for this promise to settle? I.e. did you remove the .then/.catch only to shorten your email, or are they actually missing in your code?
In a running Cockpit session, I opened the developer console and ran
cockpit.spawn(['/bin/sh', '-c', '/usr/bin/echo TEST >> /tmp/my_file'], { superuser: true, err: "message"}).then(() => console.log("success")).catch(e => console.error(e))
This works, logs "succcess", and I have a root-owned /tmp/my_file with "TEST" in it. You can try the same -- that's much more convenient than having to re-build a script and reloading the page.
If your promise handlers are missing, can you try to add them and see what they complain about?
Now the output file (setup_file) is empty.
Does it get created, or is a leftover from a previous run? I.e. try to remove it first, to see if the shell at least gets that far, or if it already aborts ealier on. It may be a permission error (although unlikely as it runs as root, but there's always SELinux and such -- the rejection message will tell you).
Another possible gotcha might be that you did not elevate to sudo privileges in your cockpit session, so the spawn call would fail (it has `superuser: true`). Again, the rejection message will tell you.
Martin
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj... _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste... Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Hello Mark,
I'm afraid I have no further idea about the original bug -- at this point I'd need to try this code and reproduce. But..
Mark Reynolds [2021-08-26 8:54 -0400]:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo -e "' + setup_inf + '" >> ' + setup_file ]; // Do not log inf file as it contains the DM password
This is a security issue, BTW -- The default umask is 022, thus this file will still be world-readable on most systems.
/* * Next, create the instance... */ let cmd = ["dscreate", "-j", "from-file", setup_file];
Can dscreate read from stdin by any chance? In the worst case, by specifying /dev/stdin as a file? Then you could use .input() to feed it the data, something like
let dscreate = cockpit.spawn(...); dscreate.input(setup_inf); dscreate .then(() => console.log("success")) .catch(err => console.error(JSON.stringify(err));
This is much simpler (one spawn instead of three, safer (no writing of the password to the file system on disk), and most probably also avoids this weird error.
[1] https://cockpit-project.org/guide/latest/cockpit-spawn.html#cockpit-spawn-in...
One thing I am on F34 not F33, not sure if that makes a difference or not. And I am on Cockpit 250...
Same here.
Pitti
On 8/27/21 11:32 AM, Martin Pitt wrote:
Hello Mark,
I'm afraid I have no further idea about the original bug -- at this point I'd need to try this code and reproduce. But..
Mark Reynolds [2021-08-26 8:54 -0400]:
let cmd = [ "/bin/sh", "-c", '/usr/bin/echo -e "' + setup_inf + '" >> ' + setup_file ]; // Do not log inf file as it contains the DM password
This is a security issue, BTW -- The default umask is 022, thus this file will still be world-readable on most systems.
Actually the file was already created higher up in the code, and the permissions were changed prior to appending (>>) to the setup file. Then the file is removed immediately after install (pass or fail).
/* * Next, create the instance... */ let cmd = ["dscreate", "-j", "from-file", setup_file];
Can dscreate read from stdin by any chance?
Actually I think it can...
In the worst case, by specifying /dev/stdin as a file? Then you could use .input() to feed it the data, something like
let dscreate = cockpit.spawn(...); dscreate.input(setup_inf); dscreate .then(() => console.log("success")) .catch(err => console.error(JSON.stringify(err));
This is much simpler (one spawn instead of three, safer (no writing of the password to the file system on disk), and most probably also avoids this weird error.
We will definitely consider this for the next phase of the UI.
Thanks,
Mark
[1] https://cockpit-project.org/guide/latest/cockpit-spawn.html#cockpit-spawn-in...
One thing I am on F34 not F33, not sure if that makes a difference or not. And I am on Cockpit 250...
Same here.
Pitti
cockpit-devel@lists.fedorahosted.org