\chapter{Access control}
\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control}{}\label{md_workspace_2post-scarcity_2docs_2_access-control}\index{Access control@{Access control}}
\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md0}%
\Hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md0}%
 {\itshape Not yet implemented}

{\itshape Note that a number of details not yet finalised are used in examples in this note. There must be some mechanism for creating fully qualified and partially qualified hierarchical names, but I haven\textquotesingle{}t finalised it yet. In this note I\textquotesingle{}ve assumed that the portions of an hierarchical name are separated by periods (\textquotesingle{}.\textquotesingle{}); that fully qualified names start with a quote mark; and that where a name doesn\textquotesingle{}t start with a quote mark, the first portion of it is evaluated in the current environment and its value assumed to be a fully qualified equivalent. All of these details may change.}

In a multi-\/user environment, access control is necessary in order for a user to be able to protect an item of data from being seen by someone who isn\textquotesingle{}t authorised to see it. But actually, in a world of immutable data, it\textquotesingle{}s less necessary than you might think. As explained in my note on \href{https://www.journeyman.cc/blog/posts-output/2017-01-08-post-scarcity-memory-threads-and-communication/}{\texttt{ Memory, threads and communication}}, if there\textquotesingle{}s strict immutability, and all user processes spawn from a common root process, then no user can see into any other user\textquotesingle{}s data space anyway.

But that makes collaboration and communication impossible, so I\textquotesingle{}ve proposed namespaces be mutable. So the value of a name in a \href{Namespace.html}{\texttt{ namespace}} will be a data item and inevitably that data item will be in some user\textquotesingle{}s data space. So we do need an access control list on each data item.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md1}{}\doxysection{\texorpdfstring{Initial thoughts}{Initial thoughts}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md1}
My initial plan was that the access control list would have the following structure\+:


\begin{DoxyEnumerate}
\item {\bfseries{NIL}} would mean only the owner could read it;
\item {\bfseries{T}} would mean that anyone could read it;
\item A list of user objects and group objects, any of whom could read it.
\end{DoxyEnumerate}

This does not work. We don\textquotesingle{}t know who the owner of a cell is; in the current design we don\textquotesingle{}t store that information, and I cannot see merit in storing that information. So {\bfseries{NIL}} cannot mean \textquotesingle{}only the owner could read it\textquotesingle{}. It essentially means \textquotesingle{}no-\/one can read it\textquotesingle{} (or possibly \textquotesingle{}only system processes can read it, which is potentially useful).

Worse though, if the list points to immutable user and group objects, then if a new user is added to the system after the object was created, they can never be added to the access control list.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md2}{}\doxysection{\texorpdfstring{Write access}{Write access}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md2}
As most data is immutable, there\textquotesingle{}s no need for write access lists. If it exists, you can\textquotesingle{}t write it, period. You can make a modified copy, but you can\textquotesingle{}t modify the original. So most data objects don\textquotesingle{}t need a write access list.

A sort-\/of minor exception to this is write streams. If you have normal access to a write stream, gatekept by the normal access lists, you can write to the stream; what you can\textquotesingle{}t do is change where the stream points to. As you can\textquotesingle{}t read from a write stream, there\textquotesingle{}s still only one access list needed.

However, if (some) \href{Namespace.html}{\texttt{ namespaces}} are mutable -\/ and I believe some must be -\/ then a namespace does need a write access list, in addition to its (normal) read access list. The structure of a write access list will be the same as of a read access list.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md3}{}\doxysubsection{\texorpdfstring{Modifying write access lists on mutable namespaces}{Modifying write access lists on mutable namespaces}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md3}
If mutable namespaces have write access lists, then someone has to be able to manage the content of those write access lists -\/ including modify them. Of course, data being immutable, \textquotesingle{}modify\textquotesingle{} here really means replace. Who has authority to modify the access control list of a mutable namespace? The simplest thing would be for mutable namespaces to have an extra key, \textquotesingle{}{\bfseries{write-\/access}}\textquotesingle{}, which pointed to the write access list. Then any user with write access to the namespace could modify the write access list. That may be undesirable and needs further thought, but any other solution is going to be complex.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md4}{}\doxysection{\texorpdfstring{Execute access}{Execute access}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md4}
I don\textquotesingle{}t see the need for separate read and execute access lists. This is possibly slightly affected by whether the system can run interpreted code, compiled code, or both. If it can run interpreted code, then having read access to the source is equivalent to having execute access, unless there is a separate execute access list (which I don\textquotesingle{}t want). Thus, a user able to edit a system function would also be able to execute it -\/ but as themselves, not as system, so it would not be able to call any further system functions it depended on, unless the user also had read access to them. Note that, of course, in order to put the new version of the function into the system namespace, to make it the version which will be called by other processes, the user would need write access to the system namespace.

However, it\textquotesingle{}s really hard to make the semantics of interpreted code identical to compiled code, and compilation is no longer such a big deal on modern fast processors. So I don\textquotesingle{}t see the necessity of being able to run interpretted code; it\textquotesingle{}s easier if source and executable are different objects, and, if they\textquotesingle{}re different objects, they can have different access lists. So having access to the source doesn\textquotesingle{}t necessarily means having access to the executable, and vice versa.

If only compiled code can be executed, then it seems to me that having access to the compiled code means one can execute it, and still there\textquotesingle{}s only one access list needed.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md5}{}\doxysection{\texorpdfstring{Read access}{Read access}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md5}
Thus the default access list is the read access list; every cell has an access list. What do its possible values mean?


\begin{DoxyEnumerate}
\item {\bfseries{T}} everyone can read this;
\item An executable function of two arguments\+: the current user can read the cell if the function, when passed as arguments the current user and the cell to which access is requested, returns {\bfseries{T}} or a list of names as below, and the user is present on that list;
\item A list of names\+: true if the value of one of those names is the user object of the current user, or is a group which contains the user object of the current user.
\end{DoxyEnumerate}

If there\textquotesingle{}s anything on the list which isn\textquotesingle{}t a name it\textquotesingle{}s ignored. Any value of the access list which isn\textquotesingle{}t {\bfseries{T}}, an executable function, of a list of names is problematic; we either have to treat it as {\bfseries{T}} (everyone) or as {\bfseries{NIL}} (either no-\/one or system-\/only). We should probably flag an error if an attempt is made to create a cell with an invalid access list. Access control list cells also clearly have their own access control lists; there is a potential for very deep recursion and consequently poor performance here, so it will be desirable to keep such access control lists short or just {\bfseries{T}}. Obviously, if you can\textquotesingle{}t read an access control list you can\textquotesingle{}t read the cell that it guards.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md6}{}\doxysection{\texorpdfstring{If data is immutable, how is an access control list set?}{If data is immutable, how is an access control list set?}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md6}
My idea of this is that there will be a priviliged name which is bound in the environment of each user; each user will have their own binding for this name, and, furthermore, they can change the binding of the name in their environment. For now I propose that this name shall be {\bfseries{friends}}. The value of {\bfseries{friends}} should be an access list as defined above. The access control list of any cell is the value that {\bfseries{friends}} had in the environment in the environment in which it was created, at the time it was created.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md7}{}\doxysection{\texorpdfstring{Managing access control}{Managing access control}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md7}
The {\ttfamily with} function can be used to make this easier\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{(with\ ((*friends*\ .\ list-\/or-\/t-\/or-\/executable))\ s-\/exprs...)}

\end{DoxyCode}


Creates a new environment in which {\bfseries{friends}} is bound to the value of {\bfseries{list-\/or-\/t-\/or-\/executable}}, and within that environment evaluates the specified {\bfseries{s-\/exprs}}. Any cells created during that evaluation will obviously have {\bfseries{list-\/or-\/t-\/or-\/executable}} as their access control. Returns the value of executing the last {\bfseries{s-\/expr}}.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md8}{}\doxysubsection{\texorpdfstring{(get-\/access-\/control s-\/expr)}{(get-access-control s-expr)}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md8}
Returns the access control list of the object which is the value of the {\bfseries{s-\/expr}}.\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md9}{}\doxysubsection{\texorpdfstring{Typical use cases}{Typical use cases}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md9}
Suppose I want to compile a function {\bfseries{foo}} which will be executable by all my current friends and additionally the group {\bfseries{foo-\/users}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{(with-\/open-\/access-\/control}
\DoxyCodeLine{\ \ (cons\ ::system:groups:foo-\/users\ *friends*)}
\DoxyCodeLine{\ \ (rebind!\ ::system:users:simon:functions:foo\ (compile\ foo))}

\end{DoxyCode}


{\itshape Here {\bfseries{rebind!}} creates a new binding for the name {\bfseries{foo}} in the namespace \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}\+::system\+:users\+:simon\+:functions\texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}, whether or not that name was previously bound there. Analogous to the Clojure function {\bfseries{swap!}}}

Suppose I want to compile a function {\bfseries{bar}} which will be executable by exactly the same people as {\bfseries{foo}}\+: \begin{DoxyVerb}(with-access-control
  (get-access-control 'system.users.simon.exec.foo)
  (rebind! 'system.users.simon.exec.bar (compile bar))
\end{DoxyVerb}
 Suppose I want to do some work which is secret, visible only to me and not to my normal friends\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{(with\ ((*friends*\ .\ (list\ current-\/user)))}
\DoxyCodeLine{\ \ (repl))}

\end{DoxyCode}


(or, obviously, 
\begin{DoxyCode}{0}
\DoxyCodeLine{(with\ ((*friends*\ current-\/user))}
\DoxyCodeLine{\ \ (repl))}

\end{DoxyCode}
 which is in practice exactly the same)

{\itshape Here {\bfseries{repl}} starts a new read-\/eval-\/print loop in the modified environment -\/ I suspect this is a common use case.}

Suppose I want to permanently add Anne and Bill to my normal friends\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{(rebind!\ *environment*:*friends*\ (cons\ ::system:users:anne\ (cons\ ::system:users:bill\ *friends*)))}

\end{DoxyCode}


{\itshape Here I\textquotesingle{}m presuming that {\ttfamily \texorpdfstring{$\ast$}{*}environment\texorpdfstring{$\ast$}{*}} is bound to the value of {\ttfamily \+::system\+:users\+:simon\+:environment}, and that unqualified names are searched for first in my own environment.}

Suppose I want everyone to be able to play a game, but only outside working hours; and for my friends to be able to play it additionally at lunchtime\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{(with\ ((*friends*\ }
\DoxyCodeLine{\ \ (compile}
\DoxyCodeLine{\ \ \ \ (lambda\ (user\ cell)}
\DoxyCodeLine{\ \ \ \ \ \ (let\ ((time\ .\ (now)))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ (cond\ }
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ ((<\ time\ 09:00)\ T)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ ((>\ time\ 17:00)\ T)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ ((and\ (>\ time\ 12:30)(<\ time\ 13:30))\ *friends*)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ (T\ NIL)))))))}
\DoxyCodeLine{\ \ (rebind!\ ::system:users:simon:functions:excellent-\/game\ (compile\ excellent-\/game)))}

\end{DoxyCode}
\hypertarget{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md10}{}\doxysection{\texorpdfstring{Summary}{Summary}}\label{md_workspace_2post-scarcity_2docs_2_access-control_autotoc_md10}
Security is hard to do well, and all this requires careful further thought, in part because the proposed post-\/scarcity environment is so unlike any existing software environment. 