News for hackers. Stuff that matters.
Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Wednesday January 11, 2017 @07:45PM (#13378919)
> I wanted something agent-less [...]

Sorry to break it to you, but you have an agent anyway, except it's the same fragile channel for debugging, administrative access, and running scripts, so once you start to need to configure it, you can break all the things at the same time.

Oh, and you just dropped proper configuration management. Now you need to add a task queue (another thing that can break and overflow and what not) to re-send configuration commands when some server is down, which would not be a problem in the first place with appropriate architecture of the system.

Re:Show HN: Posixcube, a shell script automation framework a... by deathanatos on Thursday January 12, 2017 @04:50AM (#13381078)
> just dropped proper configuration management.

Unless I'm not understanding what you mean by configuration management, I don't see what prevents the "agent-less" setup from having this. Store the config in VCS, or if it has secrets, some ACL'd storage system that's accessible by your laptop/whatever is actually running the deploy.

Agent-less here, at least to me, means not having a server that the hosts phone back to, and instead having the deploying machine call out to the servers with SSH. It's just connecting in the opposite direction, but allows you to connect from wherever is most convenient. SSH is built for running commands, and a lot of the existing stuff seems to just reinvent that.

> Now you need to add a task queue (another thing that can break and overflow and what not) to re-send configuration commands when some server is down,

If a server is oddly down that I expect up, I'd much rather the task failed outright, as I've clearly expected the machine to be up (by attempting to have it execute something) when it is not. Time to for a human to re-evaluate the situation, not retry.

It also isn't clear to me that all deployment tasks are idempotent, and safe to retry. Most that I've dealt with are, but only most, not all.

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @05:06AM (#13381144)
> Agent-less here, at least to me, means not having a server that the hosts phone back to, and instead having the deploying machine call out to the servers with SSH.

So instead of a single place where your machine gets configs from you have potentially multiple machines that appear and disappear in an ad-hoc manner. Such setup is harder to maintain (and harder to defend security-wise) than a setup that has designated master.

> SSH is built for running commands, and a lot of the existing stuff seems to just reinvent that.

You're mistaken. SSH was not built for running commands, it was built for providing interactive shell access -- and for this works good.

Running administrative commands through SSH is just silly. With the tooling we have there's not even proper error reporting (how to tell that a command reached its target server but failed there? you can use heuristics of exit code at best).

>> Now you need to add a task queue (another thing that can break and overflow and what not) to re-send configuration commands when some server is down,

> If a server is oddly down that I expect up,

And if it was planned downtime? "Tough luck"?

> I'd much rather the task failed outright, as I've clearly expected the machine to be up (by attempting to have it execute something) when it is not.

You'd much rather the server be monitored, with other systems being resilient than failing every now and then for random reasons and needing special additional actions to be taken to recover them.

Re:Show HN: Posixcube, a shell script automation framework a... by deathanatos on Thursday January 12, 2017 @11:43AM (#13383718)
> Running administrative commands through SSH is just silly. With the tooling we have there's not even proper error reporting (how to tell that a command reached its target server but failed there? you can use heuristics of exit code at best).

The exit code of the remote process is exactly what you should use; I'm not seeing what you think is heuristical about it. Either you get back that the remote process failed, in which case you know it failed on the remote, or you get back success, in which case you know it succeeded, or you don't get anything back at all, in which case you just don't know. This isn't particular to exit codes per-se, any network message to a remote machine is going to be subject to the network or remote host possibly dying between sending it and receiving confirmation of whether or not it was received and had any effect.

If you're using SSH-the-process, it's going to mux things like network failures into that error code. You can either use a library (in a language a bit more robust than Bash) so that you know you're looking at the exit code of the remote process. If you must use SSH-the-process, you can always output the exit code of the remote process that you're interested in into stderr, in a manner that you can parse it back out on the receiving end.

> And if it was planned downtime? "Tough luck"?

Again, yes, though I don't see the "Tough Luck" about it; if I'm attempting to run some unknown and arbitrary command on a machine that was planned to be down, then yes, I need to step back and realize that as a human, and make sure that I'm doing the right thing. (Again, it depends on the command; what would be the effects of re-running it, and can you programmatically guarantee that re-running is a safe operation?)

> You'd much rather the server be monitored, with other systems being resilient than failing every now and then for random reasons and needing special additional actions to be taken to recover them.

Well, yes, I would rather the server be monitored. But monitoring is significantly orthogonal to the system I use to run administrative commands on the machine.

Again, it's not so much about being resilient as it is about not taking a bad situation and making it worst. I've run a lot of administrative commands across tons of machines that were not idempotent, and if any failed anywhere, I would need to intervene. (I also usually tested heavily prior to these, to make sure there was a decent chance of not needing to intervene later.) But that still, to me, implies that whether a given command should be retried until it definitely runs is at a layer higher than the tooling used to distribute commands out to host machines, and in the general case, could quite very well require a human.

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @12:04PM (#13383942)
> The exit code of the remote process is exactly what you should use; I'm not seeing what you think is heuristical about it.

Lucky you if your SSH client never failed to connect. How do you think it reports a network failure?

> This isn't particular to exit codes per-se, any network message to a remote machine is going to be subject to the network or remote host possibly dying between sending it and receiving confirmation of whether or not it was received and had any effect.

You see, there are tools that allow you to easily tell between network failure and remote command failure. RPC protocols are an example.

> If you're using SSH-the-process, it's going to mux things like network failures into that error code. You can either use a library (in a language a bit more robust than Bash) so that you know you're looking at the exit code of the remote process.

Now let's get practical: find me such a library.

>> And if it was planned downtime? "Tough luck"?

> [...] if I'm attempting to run some unknown and arbitrary command on a machine that was planned to be down, then yes, I need to step back and realize that as a human, and make sure that I'm doing the right thing.

We were talking about configuring servers. You basically tell me that I would have to pay for "agentlessness" with tracking state of each and every machine I would possibly want to reconfigure, and remembering to check if the machine was booted to re-issue a reconfiguration command.

> (Again, it depends on the command; what would be the effects of re-running it, and can you programmatically guarantee that re-running is a safe operation?)

Sorry, I'm lost here: what re-running? The command didn't get the chance to run in the first place. I don't know where did you get the idea that I propose running the command again if it got through to the remote server and failed there.

Re:Show HN: Posixcube, a shell script automation framework a... by deathanatos on Thursday January 12, 2017 @05:03PM (#13386559)
> Now let's get practical: find me such a library.

Certainly. I'm most familiar with Python, and for that, both Paramiko and asyncssh support returning the exit status of a command, distinct from any network failure.

As I mentioned in the above reply, even with command-line ssh (and any other library, really), if you're creative about how you structure the output on stderr, you can encode the exit status there to be able to differentiate it from ssh returning other errors. E.g., if you pipe the entirety of stderr through, say, base64 and then append at the end a newline and the exit status, you can parse out the exit status on the receiving end. (This is admittedly quite a hack: using a library in Python with direct access to the data is much nicer. The ssh binary is mostly a porcelain interface to the SSH protocol; libraries are a better tool for building on top of.)

> with tracking state of each and every machine I would possibly want to reconfigure, and remembering to check if the machine was booted to re-issue a reconfiguration command.

Perhaps this is just a difference in our production environments. We strive very hard to have all our machines online at all times. (Excepting short outages for rebooting for patches, etc., of course.) We use VMs, so there's not much point to having it be shut down.

> Sorry, I'm lost here: what re-running?

My larger point was about non idempotent commands. If your infrastructure retries commands, are you just very careful to not have non-idempotent stuff? Generally, these things are either "run at most once" or "run at least once"; running exactly once is (in general) impossible, as the command might finish successfully, but the host machine crash prior to recording that success. Again, if you can structure the command to be idempotent, you can work around this, but in my experience there always seems to be some patch or database upgrade that this can't be accomplished for.

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @06:24PM (#13387086)
>> Now let's get practical: find me such a library.

> Certainly. I'm most familiar with Python, and for that, both Paramiko and asyncssh support returning the exit status of a command, distinct from any network failure.

Oh, that's something new. From what I heard, Paramiko used `ssh' under the hood, but apparently I was wrong.

> ([...] The ssh binary is mostly a porcelain interface to the SSH protocol; libraries are a better tool for building on top of.)

There's still a big problem on the client side itself. SSHv2 is a complicated protocol, so client libraries' APIs are not pretty or force you to use OpenSSH-like home (or both, like Paramiko does).

>> with tracking state of each and every machine I would possibly want to reconfigure, and remembering to check if the machine was booted to re-issue a reconfiguration command.

> Perhaps this is just a difference in our production environments. We strive very hard to have all our machines online at all times.

You must then have very homogenous environment with a small team. Sounds like a startup of sorts. Anything more loose (e.g. more than one team working on the servers, or split between who installs the machines in racks and their OSes on disk and who manages the OSes) and you won't have the luxury of keeping everything up and running all the time.

>> Sorry, I'm lost here: what re-running?

> My larger point was about non idempotent commands. If your infrastructure retries commands, are you just very careful to not have non-idempotent stuff?

And what does it have anything to do with re-sending the commands when they didn't reach their target machine?

> Again, if you can structure the command to be idempotent, you can work around this, but in my experience there always seems to be some patch or database upgrade that this can't be accomplished for.

Uhm... What? Where did you get the idea that upgrading database is managing configuration? It's a deployment operation. A different category.

Re:Show HN: Posixcube, a shell script automation framework a... by deathanatos on Thursday January 12, 2017 @07:28PM (#13387445)
> And what does it have anything to do with re-sending the commands when they didn't reach their target machine?

It has to do with whether its at all safe to run the command twice. If you don't hear back from a machine that your command ran, you don't know if the command reached the machine or not, in general. If you decide to not re-run the command, it may be that it never made it, and you never run the command. If you decide to re-run the command, it may have reached the machine, and you've now run the command twice. Consider:

  1. You send command $X to a remote machine.
  2. The remote receives and executes $X successfully.
  3. Just prior to sending back that $X was successful, the remote dies.
From the point of view of the deployment machine, you never hear back from the remote. You don't even need two machines to get into this state: even on a single command, if you run $X and the machine crashes just as $X is about to return whether or not it succeeded or failed, you're out of luck.

For specific commands, such as ones that log their progress and can recover from crashes, you can determine after a crash the correct procedure automatically. But not every arbitrary Unix administration command falls into that bucket, especially in the weird and wacky things that need to be done to keep production machines alive.

> Uhm... What? Where did you get the idea that upgrading database is managing configuration? It's a deployment operation. A different category.

We used our deployment infra for all sorts of fun stuff.

Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Thursday January 12, 2017 @12:28PM (#13384206)
Again, thanks for the objections, they're making me think hard about the design choices.

> Lucky you if your SSH client never failed to connect. How do you think it reports a network failure?

Currently posixcube handles this by checking the return code and reporting the error.

> You see, there are tools that allow you to easily tell between network failure and remote command failure. RPC protocols are an example.

ssh does have some basic differentiation: "ssh exits with the exit status of the remote command or with 255 if an error occurred." Although, of course, 255 might be returned by a remote command (not sure how likely that is), so it's still ambiguous. I guess you're saying that if it's an SSH error, then that's pretty safe to retry and it would be a nice feature, and I agree so I've opened this issue: https://github.com/myplaceonline/posixcube/issues/6

> Now let's get practical: find me such a library.

I guess it would just be a matter of, first, checking for 255, and next, checking the output of the command to see if it's an SSH error for sure?

> We were talking about configuring servers. You basically tell me that I would have to pay for "agentlessness" with tracking state of each and every machine I would possibly want to reconfigure, and remembering to check if the machine was booted to re-issue a reconfiguration command.

So you bring up a good point. On DigitalOcean, for example, their Fedora images use extlinux for booting and I can easily update the Linux command line (e.g. crashkernel), reboot, and it picks it up. Their Ubuntu distribution uses grub, and update-grub works fine, but for some reason, it requires a hard shutdown instead of a reboot to pick up the change. The way I handle this now is here: https://github.com/myplaceonline/myplaceonline_posixcubes/bl...

We echo this instruction to the user. This prints a red-text error message and stops execution. This seems even better than an agent-based execution because with an agent-based architecture, the agent is now gone (hard powered off); whereas, this style of orchestration in the front-end can use a script on top of posixcube.sh that waits a minute, remotely calls DO to start the droplet, and then continues execution (using the same script since it's essentially idempotent). The only other option would be to have a centralized server that orchestrates all of this, which posixcube avoids.

> Sorry, I'm lost here: what re-running? The command didn't get the chance to run in the first place. I don't know where did you get the idea that I propose running the command again if it got through to the remote server and failed there.

See above, I'll need to try it, but I think the ssh error code for "command didn't get through" along with some simple heuristics on the command output /might/ work; I'll investigate in issue #6.

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @04:11PM (#13386146)
> ssh does have some basic differentiation: "ssh exits with the exit status of the remote command or with 255 if an error occurred." Although, of course, 255 might be returned by a remote command (not sure how likely that is), so it's still ambiguous.

If one uses SSH for running such scripts, then it is not unlikely that the script itself would have another call to `ssh' to an even-more-remote machine.

And then there is the case of not expecting that a command would ever exit with 255 code. My trust to a system would be quite damaged if I happened to run into such a bug that a proper remote error would be mistaken for a network error. How can I, as the script writer, be sure that I never run into this situation?

Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Thursday January 12, 2017 @04:44PM (#13386399)
I agree the ambiguous return code is a major limitation of SSH. I think I'll just avoid any retry logic and treat every failure the same: fail immediately and let the user to decide how to retry. Since posixcube does most of its execution over a single SSH connection (packaging all commands/cubes into a cube_exec.sh which is executed remotely), I think the immediate need for automatic retry on failing to connect over SSH isn't large.
Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Wednesday January 11, 2017 @07:51PM (#13378965)
> but you have an agent anyway

By agent, I meant something more narrow: a prerequisite that must be installed on a server before it works. In that sense, the agent here is sshd, but that can be presumed to always exist.

> so once you start to need to configure it, you can break all the things at the same time.

Do you mean if the script updates sshd configuration?

> Oh, and you just dropped proper configuration management. Now you need to add a task queue (another thing that can break and overflow and what not) to re-send configuration commands when some server is down

I'm not sure what you mean, can you please elaborate on a use case of a task queue?

Thanks for the comments!

Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Wednesday January 11, 2017 @08:13PM (#13379081)
> I'm not sure what you mean, can you please elaborate on a use case of a task queue?

Answering my own question by re-reading your comment: I'm not familiar with systems automatically re-trying commands. What if there is some fatal error on the server? It seems like this is something that requires a human, not a task queue. Relatedly, if the system has the `caller` built-in, when there's an error, a stack trace is dumped, including the line number of the failing cube for someone to quickly jump to the failing line in the script.

With that said, a retry mechanism could be built-in if it's a big use case.

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @05:16AM (#13381177)
>> so once you start to need to configure it, you can break all the things at the same time.

> Do you mean if the script updates sshd configuration?

If you ask this question, it means you've probably never configured SSH in bigger environments, because you don't imagine how easy is to accidentally cut off your access. User's public key disappears, user's shell changes or becomes un-executable, user doesn't get mentioned in AllowUsers and/or AllowGroups, user's home gets unreadable, and plenty other failure modes.

>> I'm not sure what you mean, can you please elaborate on a use case of a task queue?

> Answering my own question by re-reading your comment: I'm not familiar with systems automatically re-trying commands. What if there is some fatal error on the server? It seems like this is something that requires a human, not a task queue.

You actually have provided me another important point: how to tell that the command reached its destination server, but failed there? This is vastly different case than when a command didn't get through to the server, so it can be safely re-sent. (And I was talking about the latter case.)

> With that said, a retry mechanism could be built-in if it's a big use case.

But now you have a queue which needs to be managed and that also can break. This is not an improvement. Setup with a dedicated agent that works in "pull" mode (instead of one that was not designed for this task, but just happened to be already installed) doesn't have the problem that needs solving with queue in the first place.

Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Thursday January 12, 2017 @12:18PM (#13384085)
First, I just want to say that I appreciate this conversation and debate. It's making me think hard about certain concepts, so thank you.

> If you ask this question, it means you've probably never configured SSH in bigger environments, because you don't imagine how easy is to accidentally cut off your access.

Many moons ago, I was mucking with sshd configuration, and locked myself out. It was the first and only time I ever had to truly hack - my own system. The system had a Wordpress installation which, at least back then, allowed you to modify the PHP code through the web console. I knew I had gcc on the box, so I found a NULL-dereference root escalation exploit for my kernel version, jammed a bunch of C code into a php system call, and step by step, escalated, and then overwrote my ssh config (all through escaped C code in PHP!). It was fun. So I totally hear ya, updating sshd configuration can be disastrous, and it's certainly required in certain situations. Posixcube is certainly not ready for massive enterprise usage, but I don't see why it couldn't be. For this particular point, it seems that no matter what technology you're using, SSH can always get mucked up, and I see no inherent reason why shell scripts are worse.

> You actually have provided me another important point: how to tell that the command reached its destination server, but failed there? This is vastly different case than when a command didn't get through to the server, so it can be safely re-sent. (And I was talking about the latter case.)

The way this is handled now is that all cube_* APIs check all return codes and if non-zero, they print the full stack and `exit $code` which is passed back through SSH into the client and reported and the script stops. In the latter case of safely re-sending a command that didn't even get to the server, I don't think that's much of an issue here, because posixcube doesn't execute one command at a time (since the overhead of re-establishing the SSH connection would be massive), but actually generates a shell script on the fly (cube_exec.sh) which has all the commands you want to execute, uploads that as well as all of the cubes, and then executes cube_exec.sh on the other side.

> But now you have a queue which needs to be managed and that also can break. This is not an improvement. Setup with a dedicated agent that works in "pull" mode (instead of one that was not designed for this task, but just happened to be already installed) doesn't have the problem that needs solving with queue in the first place.

Are you talking about a use case where an administrator is not monitoring a deployment (i.e. fire and forget)?

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @12:37PM (#13384291)
> Posixcube is certainly not ready for massive enterprise usage, but I don't see why it couldn't be.

Because its architecture doesn't fit the job. The same situation is with Ansible or Salt being used for maintaining configuration of servers.

> For this particular point, it seems that no matter what technology you're using, SSH can always get mucked up, and I see no inherent reason why shell scripts are worse.

I don't say shell scripts are worse. I say the "push" architecture over SSH is worse for configuring machines than with an agent in "pull" mode. You could easily write an agent that works on a cron-like schedule, downloads commands to be run, (verify their origin with a digital signature,) runs them, and reports the results back, all in shell.

> Are you talking about a use case where an administrator is not monitoring a deployment (i.e. fire and forget)?

No, I'm not talking about deployment. Deployment is a one-off operation (even if similar is repeated in the future). I'm talking about managing configuration, which is what Chef, Puppet, and CFEngine are for. If you were trying to use Chef for deployment, then no wonder you got a terrible experience.

Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Thursday January 12, 2017 @12:53PM (#13384431)
> Because its architecture doesn't fit the job. The same situation is with Ansible or Salt being used for maintaining configuration of servers.

> I don't say shell scripts are worse. I say the "push" architecture is worse for configuring machines than with an agent in "pull" mode. You could easily write an agent that works on a cron-like schedule, downloads commands to be run, (verify their origin with a digital signature,) runs them, and reports the results back, all in shell.

I'm still not completely understanding, so let me see if I can rephrase your objection and please correct me if I'm getting it wrong:

A "pull" architecture for configuration management is better than a "push" architecture because updating configuration shouldn't require synchronous human interaction.

If so, then one example of a counterargument is needing to reload/restart a service after updating its configuration file. What if there's an error reloading/restarting the service? Does the agent then email the administrator? And what if the emails fail?

Re:Show HN: Posixcube, a shell script automation framework a... by dozzie on Thursday January 12, 2017 @03:58PM (#13386045)
> A "pull" architecture for configuration management is better than a "push" architecture because updating configuration shouldn't require synchronous human interaction.

One may put it this way as one of the reasons, yes.

> If so, then one example of a counterargument is needing to reload/restart a service after updating its configuration file. What if there's an error reloading/restarting the service? Does the agent then email the administrator? And what if the emails fail?

You're on a good track here. There are several things not quite there yet, though.

First, e-mail reports don't scale. For a dozen of servers the volume is still readable if every report fits on a single screen, but a move in any direction (report's length or number of servers) makes the situation unsustainable.

Second, all of the operations should be reported, not just the failures, as you want to be able to see what was done, when, and in what order. Usually it's not interesting, as most logs are, but there are cases when you need this information and you learn about the need after the fact. Also, there are abnormalities that are reported as successes (e.g. a config that gets changed on every scheduled execution that gets replaced by something else, thus creating the need for updating the config again).

Third, the operation logs should be structured. Plain text doesn't cut it, as you can't process them with a machine in a reliable and convenient way.

And fourth, you were right when you asked what if the report transport breaks down. This is covered by having reports from each execution; a simple automaton (that either queries execution reports from their store or tracks them as they come) can easily tell that a server went missing. Such an automaton would be a part of reports receiver or reports store.

By the way, reading execution reports from a push tool doesn't scale for the same reason as e-mail: too much manual reading. And if the tool stops on the first error to be encountered, tool's use will be annoying in the long run (how to recover and resume operations?)

Re:Show HN: Posixcube, a shell script automation framework a... by schizoidboy on Thursday January 12, 2017 @04:38PM (#13386357)
Thanks, I understand your perspective much better.

Regarding the last point, I've always just re-run my last command. If the commands are broken up into separate independent scripts (e.g. install ElasticSearch, install Kibana, etc.), then I might only re-run the script (-c) that was failing to ensure that works, before re-running the whole spec (-z).