SD Core for Linux LC2.0-0

Scheduled jobs

Running an SD command on a timer, and the permit list that decides which ones.

A cron job or a systemd timer can run an SD command, and only the commands an administrator has named for it.

Typing a command after sd — sd my.report — is gated: the group-membership test at entry proves who is running it, never what it might run unattended. A scheduled job has nobody at the keyboard to use judgement, so it runs only from a pre-vetted list, whoever's Linux identity is actually running it.

There are two ways past the gate now:

a session logged in as SDSYS runs anything, exactly as before
anything else runs what is listed for its account in the SD system file batch.jobs

Nothing changes for a session you type at. Commands entered at the : prompt are unaffected, and so is plain sd with no command after it.

There is no password anywhere in this. The job signs in as its own Linux account and SD puts it in the matching SD account, exactly as it would for a person at a keyboard. Nothing has to store a credential for the job to use, and the job grants nobody anything — no other account is in its group.

The permit list#

batch.jobs is a directory file in /usr/local/sdsys, so one record per account, named after the account, holding one command name per line.

Only an administrator can change it. It is read-only to sdusers (sdsys:sdusers 750) — a user who could add a line to their own record would be granting themselves the command line.

It is keyed by the account you end up in, not by the Linux account name, and the two are usually the same. sd -a<name> cannot be used to reach somebody else's list: that form is refused unless the account is your own.

Any account can be given a list. Every account has the same VOC now, so there is nothing about the account type to consider here; the account's record in batch.jobs is what decides what it may run. SDSYS itself has no list: its sessions run anything.

Both shapes of record are read — one name per line, and a multivalued field 1 — so a record written with ed and a record written by a program agree. A name still has to match exactly.

What may be listed#

Two rules, and both are tested when the command runs rather than when it is listed:

1. A single name with nothing after it. my.report may be listed; my.report yesterday may not, and neither will run:

A command run from the command line must be a single name with nothing
after it.  Put anything the job needs to vary inside the paragraph or
sentence being run.

That is the rule doing the security work. "It must be in the VOC" would be worth nothing on its own — every verb is a VOC entry — so it is the absence of arguments that stops a listed name being turned into something else.

2. A paragraph or a sentence in that account. A VOC entry of type PA or S. Anything else — a verb, a file pointer — is refused by name:

my.report has to be a paragraph or a sentence in this account to be run
from the command line, and it is neither.

Setting one up#

Four steps, and the first and third need an administrator for a new account.

1. Write the work as a paragraph in the account that will run it. A PA record in that account's VOC, with the commands on the lines after the type:

:ed voc my.report

Saving a record of the VOC needs the account to hold voc-on, which a new account does not have. SDSYS gives it with modify.account name voc-on (see Managing accounts); accounts that existed at an upgrade have it already.

2. Check it runs when you type it, in that account, before putting it on a timer.

3. Allow the name in that account, logged in to the machine as SDSYS:

:set.batch add fred my.report
my.report may now be run from the command line in account fred

set.batch checks that the name is a paragraph or a sentence in that account before it adds it, writes the account's record in batch.jobs, and records the change in the audit trail. set.batch remove fred my.report takes it off, and set.batch alone lists every account's commands. The administrator's own account has no list. Nothing is allowed as delivered.

Or use the Scheduled jobs page, tool.jobs. It lists every account with the number of commands it may run this way. F6 or Enter moves to the account's paragraphs and sentences, each marked as allowed or not. Enter on one shows the set.batch command and what it does, and runs it only when you answer Run. A name still on the list whose VOC record has gone, or is no longer a paragraph or a sentence, is shown as such, and Enter takes it off. A name holding a character other than a lower-case letter, a digit, a dot, a dash or an underscore cannot be sent from the page: it shows the set.batch command to type at the prompt.

The page does not write an account's schedule: step 4 is done in the crontab or the timer of the account's Linux user. (The page's Jobs view, below, schedules the administrator's own jobs.)

batch.jobs can still be edited directly (ed batch.jobs fred, one command name per line), but set.batch makes the same checks the login makes, so a mistake shows up when you make it, not at the job's first run.

4. Create the scheduled job. Either cron or a systemd timer runs it — what matters is which Linux account the job runs as:

# crontab -u fred -e
0 6 * * *  /usr/local/bin/sd my.report

The job runs as a Linux account, and that account needs a matching SD account — that is the whole of the sign-in. There is no password to configure anywhere in SD for it.

Do not run it as sdsys or via sudo. It is not needed, and the whole point of batch.jobs is a job that runs without administrator rights. It would not work either: the installer puts sdsys in /etc/cron.deny (and /etc/at.deny where at is installed), and per Security SD refuses an sdsys session that is not a genuine login of sdsys's own — it asks the kernel's audit loginuid, which a sudo'd shell cannot forge. Work that must run as the administrator is one of the administrator's own jobs, below.

Use a Linux account you already had — that is the case the design was built around.

When it refuses#

It fails closed. Every path that does not reach the end of the check leaves the command refused, and each one writes a reason to the audit trail:

What is wrong Recorded as
the command line carried an argument command line carried arguments
batch.jobs is missing or unreadable batch.jobs could not be opened
the name is not in this account's record command is not on the account list
the name has no VOC entry at all no VOC record for the command
it has one, but it is not PA or S VOC type is not PA or S

The message on the screen for the third of those names both the command and the account, and says where an administrator grants it:

my.report is not a command that account fred may run from the command line.

An administrator grants it by adding the name to the account's record in
the SD system file batch.jobs, which only an administrator can change.

A refusal is not a hang. sd <command> is never asked to set a password it cannot answer — see Running SD.

The administrator's own jobs#

Work that has to reach every account runs as the administrator, and only as one of two fixed jobs. An account's own job runs with that account's rights; the administrator's jobs are for what no single account may do:

Job Runs
backup-all backup.account all
update-accounts update.accounts all

Nothing is scheduled as delivered. Each job is a systemd timer that only root can set, kept by the root helper in /etc/sdcore/jobs.d; the sdsys user may not use cron or at. At each run systemd starts sd with the job's command as the sdsys user, and SD makes it the administrator only when the run is that unit's and the root-owned definition names exactly that command. Every line the run writes to the audit trail ends job=name. A run missed while the machine was off is not made up; times are the machine's.

A schedule is one of five shapes: every 5, 10, 15, 20 or 30 minutes; hourly; daily hh:mm; weekly mon..sun hh:mm; monthly 1..28 hh:mm.

SDSYS sets them up with set.job at the prompt, or in the Jobs view of tool.jobs (J):

:set.job add nightly backup-all daily 02:30
sd-elevate: job nightly created
sd-elevate: job nightly is scheduled: daily 02:30

set.job alone lists the jobs with their next and last runs; set.job change, delete and run do the rest. Everything else — the page's keys, what a damaged job is, how a run is recognized, where the definitions and units are kept, and the account lists from the administrator's side — is Scheduled jobs in the administrator's documentation.