# Compliance: the automatic checks of an ISO 27001 statement of applicability
What a library or a project can tell by itself about the measures of the annex A of ISO/IEC 27001:2022 it implements
(art. 9.1, A.5.36): the second factor of the privileged accounts, the chain of the journal, the age of the last restore
test... Each such check is a small class, registered by the library (or the project) that provides it; mmo.core runs
them, the hub writes them into the project's statement of applicability.
## A check
```php
namespace Acme\compliance;
use MMO\core\compliance\aCheck;
class BackupCheck extends aCheck {
const string NAME = 'acme.backup'; // unique: .
const array MEASURES = ['8.13']; // the measures it tells of, without « A. »
public function label(): string {return 'Backups of the database';}
public function unavailable(): ?string { // null: it can run here
return is_dir(\MMO\filename('{db}/backups'))? null : 'no backup folder on this machine.';
}
public function run(): array {
$count = count(glob(\MMO\filename('{db}/backups/*.gz')) ?: []);
if ($count === 0) {return static::Result(self::ABSENT, 'no backup.', [], ['{db}/backups']);}
return static::Result(self::CONFORM, '{count} backups kept.', ['count' => $count], ['{db}/backups']);
}
}
// the library's bootstrap, after the class
\MMO\core\compliance\Checks::Register(BackupCheck::class);
```
- **Results** (`aCheck::RESULTS`, French because the statement of applicability is): `conforme`, `partiel`, `absent`,
`manuel` (only a person can tell: say what to look at), `erreur` (the check threw: said, the others still run),
`non disponible` (`unavailable()` gave a reason: its tool, its data, its site is not here -- not an error).
- `Result($result, $detail, $vars, $evidence, $data)`: the detail is an English sentence with `{placeholders}`,
translated by the library's dictionaries; the evidence are paths with their aliases (`{root}/...`, `{hubFolder}/...`)
and commands; `data` goes into the report.
- **A check only reads.** It never changes a setting nor a record, never runs anything on a server, never names a
person (counts, not accounts) nor prints a secret (the hosts of a database, not its uri).
- `SCOPE`: `application` (the default) runs in the application, `hub` in the hub's `iso27001` (@see the hub's
`src/compliance/HubChecks.php`: the dependency audit, the secrets, the security rules, the inventory).
- `aCheck::Combine(...$results)`: the result of a measure from those of its checks -- conform when all are, absent when
all are, partial otherwise; `manuel`, `erreur` and `non disponible` say nothing of the measure.
## Running them
`php admin.php compliance [--only=oauth.,core.log-chain] [--skip=oviepro.perimeter] [-m]` (mmo.core's `AdminController`):
one line per check, or the json the hub reads. Read only.
```
partiel core.csp (8.26, 8.28): Content-Security-Policy envoyée en Report-Only : les violations sont signalées, pas bloquées.
conforme core.log-chain (8.15, 5.28): le journal est entier : 745 lignes chaînées, tête 745:89b892f70676.
absent oauth.mfa (5.17, 8.2, 8.5): le second facteur n'est exigé de personne (mfa.required est vide) : 0 des 14 comptes à privilèges en ont un.
```
The hub's `php tools/mmo.php iso27001 --project=` runs it with `-m`, adds its own checks, and writes the dated
report and the project's `docs/isms/soa.json` (the hub's `docs/iso27001.md`).
## The checks of the libraries
| Check | Library | Measures | What it reads |
|---|---|---|---|
| `core.csp` | mmo.core | 8.26, 8.28 | the Application's `contentSecurityPolicy`: none, Report-Only, enforced (docs/ContentSecurityPolicy.md) |
| `core.classification` | mmo.core | 5.12 | `#[Classification]` of the collections (docs/Schema.md) |
| `core.log-chain` | mmo.core | 8.15, 5.28 | the hash chain of each journal that chains (docs/Journal.md) |
| `core.read-journal` | mmo.core | 8.15, 5.34 | RepositoryController's `reads` and the collections classified so |
| `core.retention` | mmo.core | 8.10, 5.33 | `Retention`'s durations (docs/DataLifecycle.md) |
| `core.field-cipher` | mmo.core | 8.24 | `FieldCipher`: fields declared, enabled, key readable (docs/FieldEncryption.md) |
| `oauth.mfa` | mmo.oauth | 5.17, 8.2, 8.5 | the privileged accounts with a second factor, `mfa.required` (objective O1) |
| `oauth.inactive-accounts` | mmo.oauth | 5.16, 5.18 | the active accounts without a login for 90 days, their archiving (objective O4) |
| `oauth.keys` | mmo.oauth | 8.24 | the age of the key signing the tokens (a year at most), the retired keys |
| `mongodb.tls` | mmo.mongodb | 8.21, 5.14 | TLS and its certificate to each host that is not this machine |
| `edms.antivirus` | mmo.edms | 8.7 | the types allowed, the antivirus |
| `edms.encryption` | mmo.edms | 8.24 | the labels of health files, their encryption at rest |
| `admin.restore-test` | mmo.admin | 8.13, 5.30 | the last restore test that passed, kept by the project's hub (objective O3) |
| `admin.harden` | mmo.admin | 8.9, 8.20-8.22 | the last hardening check the hub kept -- never run: `manuel` without |
| `admin.command-journal` | mmo.admin | 8.18 | `CommandJournal`: on, and its approvals |
| `admin.release-gate` | mmo.admin | 8.32, 8.19 | the ProductionController's `releasePolicy` when the application's configuration has it |
| `admin.local-copies` | mmo.admin | 8.33, 8.31, 7.9 | the databases of a workstation in clear, unregistered or expired (dev mode only) |
| `metrics.alerts` | mmo.metrics | 8.16, 5.25 | the alert rules, a dry run of them, the channels (docs/Security.md) |