The client API lets a program on this computer, or another one, use SD as a
back-end data store. Application code uses SDConnect() and the rest of the
client library as with any SD Core — see Client distribution.
Is it on?#
| Any computer | only if you chose local or open when installing (--api, or api= in the control file). Off by default |
Off means there is no listener at all: the installer writes no socket unit,
and SD opens no port. A computer that an SD Core for Linux server manages (one
with a global password) needs the API open, because the server connects through
it; the installer warns you if you give it a global password and choose less.
Signing in#
| User name | always sduser |
| Password | the account password — or, on a managed computer, the global password, which the server uses |
| Account | sduser |
The login is SCRAM-SHA-256, inside TLS 1.3. The password is never sent in any form; the server sets a challenge only someone who knows the password can answer, and then proves itself back, so a program that grabbed the port before SD started cannot collect passwords by pretending to be SD.
The client library pins the server's certificate. The first
connection from a client to an address and port is trusted, and its certificate is
remembered — the SHA-256 of the whole certificate — in ~/.sdcore/known_servers
(or the file named by the environment variable SD_KNOWN_SERVERS), one line,
<host>:<port> <64 hex digits>, per server. Any later connection to the same
address and port that presents another certificate is refused before a single
byte of the login is sent, with a message that names both fingerprints and the
line to remove. A reinstalled computer has a new certificate: remove its line
and connect again, and the new certificate is remembered. Removing the line is
the remedy, and only if you know why the certificate changed. A store the client cannot
read or write refuses the connection rather than connecting unchecked. This is
done in the client library, so it applies to every program that uses SDConnect.
The very first connection is trusted, as with ssh: someone in the middle at
that moment would be remembered instead of the computer.
A managed computer's server can ask this computer to install its ssh key over the API, once it has signed in with the global password: see Managed mode.
A client that sends a password in clear is refused with "Cleartext login is no longer supported; this server requires SCRAM authentication".
A wrong password is refused, and the refusal is written to the audit trail —
for example api refused user=sduser reason=wrong password. It is written
before the three-second wait SD adds to slow down guessing, so a program that
hangs up during the wait is recorded as well.
Known issue: TLS read failed. A refused login made through the C client
library can report TLS read failed instead of Invalid username or password.
The login is refused either way and nothing else is affected.
The only account an API session may enter is sduser. Asking for SDSYS, or
any other name, is answered User not allowed in requested account — the same
wording for an account that does not exist, so the API cannot be used to find
out what accounts there are. The administrator password is not an API login:
it is refused.
On a computer installed from a control file, until the account password has been chosen at the keyboard, only the global password is accepted.
SDConnectLocal is disabled. It sends no password, which SD Core Solo for Linux does not
allow. A client that calls it gets, at once, SDConnectLocal is not available in
SD Core Solo for Linux - connect with SDConnect and the account password. Use
SDConnect to this computer's own address instead (127.0.0.1).
The port#
The API is a systemd socket unit, sd-solo-api.socket, listening on TCP
port 4249, which is fixed: there is no option to move it. (SD Core for Linux
uses 4247, so the two can share a computer.) Each connection starts one SD session
(sd-solo-api@.service), so the API works whether or not anything else is
connected.
local |
listens on 127.0.0.1 — this computer only |
open |
listens on 0.0.0.0 — every address the computer has. A firewall on the computer must allow the port; the installer opens it with ufw if ufw is running, or with firewall-cmd if firewalld is, and says so if it cannot |
off |
no socket unit |
To change it afterwards, use remote.api inside SD (below), or run the
service script again with the new choice — it stops the old listener first:
bash ~/SDCoreSolo/tools/solo-service.sh install ~/SDCoreSolo --api open
bash ~/SDCoreSolo/tools/solo-service.sh install ~/SDCoreSolo --api local
bash ~/SDCoreSolo/tools/solo-service.sh install ~/SDCoreSolo --api off
Each of those holds: open listens on 0.0.0.0, off leaves nothing
listening and the unit not active, local is 127.0.0.1 again. An open API
on a computer with a firewall still needs the firewall told; that part is
yours.
Linger matters here too. Without it the socket, like SD, stops when your last session ends; see Running SD.
From inside SD: remote.api#
remote.api
remote.api {off | local | open}
The three words are the three rows above (on is taken as open). It is the administrator's: type
admin first, or it stops with Command requires administrator privileges, and that holds for the report
too. With no keyword it reports the setting and changes nothing: The API is off: SD has no listener
for it, The API is local: only this computer can connect (port 4249) or The API is open: other computers
can connect (port 4249), and, when the socket is not running whatever the setting, ...but its listener is
not running (systemd says ...).
It moves Solo's own socket unit and nothing else. It runs the same service script with no sudo, and
the report it prints afterwards is read back from the installed socket unit and systemd, not what was
asked. A change the script did not confirm says The API was not changed: and the script's last line,
and changes nothing. No firewall is touched: when open is asked and a firewall is running, the one
command an administrator of the computer would run to let port 4249 through is printed. Every change writes
one audit line, remote.api mode=local status=ok (or status=refused). No SD session is ended: the
listener belongs to the socket unit, and a connection already accepted is its own service instance, so
nothing already talking to the API is disturbed. On a managed computer leave it open: the server
connects through it. remote.ssh does the same for ssh (see ssh access).
Everything that reaches SD from outside, on one screen: tool.remote#
tool.remote
A full-screen page for the administrator (admin first; a window of 140 columns by 43 lines or more) of
four views, chosen with the keys 1 to 4:
| View | What it shows and does |
|---|---|
1 doors |
what remote.api and remote.ssh say with no keyword: the machine's own answer, read back from the socket units, not what the page meant. A changes the API and S changes ssh (off, local or open, chosen from a list that starts on off); open lets other computers reach this one, so its box wants the word open typed (in either case) |
2 servers |
the SDNet servers you have defined: name, address, remote account and mode, the pin shortened, the accounts that may use it. X deletes the one under the cursor (delete.server, which does not ask itself, so the box is the question). N asks every field, checks them the way set.server does and gives the terminal to the verb, whose connect step shows the key the server presents and its hash and asks whether to trust it |
3 connected |
every session now by the door it came through: the user number, the kind (user, api, sdnet, phantom), the login user, the account and where it came from |
4 TLS |
this installation's TLS identity as settings.report gives it: the certificate fields and the public-key hash another SD server pins. Never the private key |
The page runs remote.api, remote.ssh and delete.server only after a box that shows the command and
what it does was answered Run (Cancel is what Enter chooses); set.server is run by the verb itself on
the terminal. The verbs write their own audit lines; the page writes nothing else. F5 reads everything
again, F1 explains the page and Ctrl-Q leaves. Opening the page writes the audit line
tool start app=tool.remote.
What a connection costs, and how big a request may be#
Each API connection is one sd-solo -n -q process, running as your Linux user
(never root), and it is there before anybody has logged in. It ends when the connection ends, and it refuses a request whose declared
length it cannot accept: a client that sends four bytes that read as a huge
length, or that declares a request and closes before
sending it, or that closes while its own command waits in a shell and then
clears its input, does not leave the process polling at 100% of a processor.
Every request starts with a 4-byte length that counts the whole packet, itself included, and a 2-byte request code, so the smallest packet is 6 bytes. The client library never sends one that breaks the rules, so a program using it does not meet them; they matter to a program that speaks the protocol itself, and to anyone probing the port.
| When | The length of a packet may be |
|---|---|
| before the client has logged in (the password proof not yet accepted) | 6 to 65,536 bytes. The login messages are all under 4 KB |
| after the login | 6 to 1,073,741,832 bytes: the largest SD string (1,073,741,822) plus the 10 bytes of header the client library allows for |
A packet that declares anything else (below 6, negative, or over the limit that
applies) is not read: the server ends the session at once and writes one line to
the system log (API packet length ... refused (before login) or (after
login)). The same test applies to the reply a client sends to an INPUT prompt.
How the server knows the login has happened, and how that differs from SD Core. SD Core knows "not yet logged in" because its server is still root until the client has logged in. Solo's server is never root, so it keeps a flag that is set when the password proof has been accepted (when the server gives the session its user name); the limit before the login applies until then. This is a difference from SD Core. A packet of exactly 65,536 bytes is accepted before the login and one byte more ends the session; after the login a record of any size SD can hold can be written and read back.
A session is held to its own account#
| Allowed | everything inside its own account, and the shipped system files every account needs — messages, syscom, the dictionaries — which the account's VOC names. Ordinary programs are unaffected |
| Not allowed | opening, renaming, deleting or listing a file by a pathname outside the account |
This is the account's os switch, the same one a session at the keyboard is held by.
While it is off, as delivered, a refused OPEN takes the ELSE branch and
STATUS() is 3035, which means not permitted rather than not found: 3035 is a
containment refusal, not a missing file. A client that opens a sequential file by a
pathname outside the account is told the name is not a file this account may open. Once the
administrator has turned the os switch on (set.os.access os on) the session has no
such limit, which is why the switch is the thing to weigh — see
Operating system access.
If your data lives outside the account, name the directory in the NETDIRS
setting in sd.conf, separating several with a semicolon. It is empty as delivered.
An entry that is not an absolute path, not an existing directory, the root of the
file system, or that holds or lies inside the Solo folder (where the account, the
passwords and the account register are) is ignored and named in the error log when
SD starts. SD reads the line when it starts, so a change takes effect at the next
start. See The parameters. config('NETDIRS') does not
read it: read the file. A server session may reach global.bp.out.
SDCLIENT in sd.conf is the further control: any non-zero value stops files being
opened by an API session, and 2 also refuses a subroutine that is not compiled as
callable from a client (0, the default, allows everything).
An API session is you#
It runs as your Linux user, in the account sduser, with the same rights as
a session at the keyboard — and the same two switches: the API server reads
sh and os from the account's register record when it enters the account, so
sh and OS.EXECUTE, and a path outside the account, are refused to a remote
client while the switches are off, as delivered, and usable by it once the
administrator has turned them on (set.os.access; a client that is already
signed in sees the change at its next login). See
Operating system access. Records an API
session creates are yours, and if your Linux user may not read something, the
API session may not read it either.
A session signed in with the global password is a server session, with the administrator commands unlocked. See Managed mode.
Request 29, the NET gate and NETFILES#
Request 29 opens an account;file file for a client — the one door of SDNet
that is still in the server. It is shut as delivered, and two things have to be
turned on, by the administrator, before it opens anything: bit 2 of NETFILES
in sd.conf (NETFILES=2; the default is 0) and the account's NET gate,
which set.net.access turns on (set.net.access on after admin; with no
argument it shows where the gate stands). The gate is off as delivered, is kept in field
15 of the register record, is read when the request is asked (so a change reaches
a client that is already signed in), and only the word yes means on.
With both on, the request still refuses, with no file number and a line in the
audit trail that says why: when SDCLIENT is not 0 (as an ordinary open is);
when the account is named by a path (a path names no register record, so
nothing says who may enter it); when it names another account or SDSYS (the
one account a session may enter is its own); and when the account is
suspended. A refusal of the account rule is User not allowed in requested
account, whatever the reason, as for request 3.
Where the file is. The request asks the account's os switch
(set.os.access os on) as dir, openseq, openpath and the OSCOPY verbs do. A file the account's VOC names with an
F-pointer must lead inside the account's own directory, with .. and symbolic
links resolved, unless the account has the os switch on: a pointer at an absolute
path outside the account, a relative path that climbs out, a link to the outside, the
directory next door whose name merely begins with the account's own, a system
directory, or a dictionary half that leads out (though its data half is inside), is
refused. The refusal is error ELSE with status 3035 (permission), no file number comes
back, and the audit trail gets api refused request=29 reason=os gate off user=... account=... path=....
The switch is read from the register record when the request is asked, so taking it off
reaches a client that is already signed in. The pointers SD itself puts in the VOC
(syscom, newvoc and the like) lead out of the account and are refused here
too: a client of request 29 has no use for them. A pointer that opened before and leads out
of an account whose os switch is off stops opening: turn the switch on if that was
intended. Solo has no SDSYS exemption, because SDSYS is never a target of the request.
The NETFILES bit alone is not the
gate: without the os switch a file named in the VOC of a directory outside the account is not opened.
Client libraries#
| The shared library | sdclilib.so, in ~/SDCoreSolo/bin |
| Source | built as part of SD Core Solo, or standalone at https://github.com/dmontaine/linuxsdclilib |
It must speak SCRAM. A client library that sends the password in clear is refused by the server. See Client distribution.
Programs using the !sdclient class — SD BASIC reaching another SD over the
API — speak the same login, from this release at both ends.