> Source: https://docs.cyberelements.io/bastion/4.7/lv/Security/SystemHardening/SystemFilesystem/

# File system and permissions

*ANSSI-BP-028 v2.0 reference: R50 to R57 (M/I levels, R for some points).*

This section covers the **review of file system permissions** and the protection of configuration files and sensitive directories.

## R11. Control of permissions and sensitive files

**Applies to**: Mediation Controller ✅ · Edge Gateway ✅

Files or directories with overly permissive permissions can allow a local user, or an attacker who has obtained limited access, to elevate their privileges, to modify sensitive files or to drop malicious code.

> **Warning!**
>
> This recommendation must be applied after installing CyberElements Bastion and after validating that the solution works correctly.

Files and directories with 777-type permissions:

```
1
2
```

Files and directories that all users can modify:

```
1
2
```

Some directories (`/tmp`, `/var/tmp`) can legitimately be writable by several users:

```
1
```

Files with no known owner or group, which may reveal account deletions or configuration anomalies:

```
1
```

Files carrying the SUID or SGID bits must be given particular review, since they allow a program to be run with the privileges of the owner or of the group of the file:

```
1
```

Any unexpected SUID or SGID file found must be analysed. Legitimate system binaries must not be modified without prior validation: an incorrect fix can make the system unstable or prevent some administration functions. The results should be compared with a known baseline validated for the role of the server concerned.

## R12. Hardening of configuration files and sensitive directories

**Applies to**: Mediation Controller ✅ · Edge Gateway ✅

Some files and directories of the system contain sensitive information or make it possible to change the behaviour of the server. Access to them must be limited to the users and groups with a legitimate need. The values below are the target permissions recommended in the context of CyberElements Bastion.

| Path | Owner:Group | Octal mode | Recommendation |
|---|---|---|---|
| `/etc/passwd` | `root:root` | `0644` | Readable by everyone; modification reserved for root. |
| `/etc/shadow` | `root:shadow` | `0640` | Access limited to root and to the shadow group. |
| `/etc/group` | `root:root` | `0644` | Readable by everyone; modification reserved for root. |
| `/etc/gshadow` | `root:shadow` | `0640` | Access limited to root and to the shadow group. |
| `/etc/sudoers` | `root:root` | `0440` | Editing only through `visudo`. |
| `/etc/sudoers.d/*` | `root:root` | `0440` | Each file must be protected and checked individually. |
| `/etc/ssh/sshd_config` | `root:root` | `0600` | SSH configuration modifiable only by root. |
| `/etc/ssh/ssh_host_*_key` | `root:root` | `0600` | SSH private keys accessible only to root. |
| `/root` | `root:root` | `0700` | Directory accessible only to root. |
| `/root/.ssh` | `root:root` | `0700` | SSH directory accessible only to root. |
| `/etc/crontab` | `root:root` | `0644` | Modification reserved for root. |
| `/boot/System.map*` | `root:root` | `0600` | Not readable by unprivileged accounts. |
| `/boot` | Depending on the system | To be validated | Keep rights compatible with Debian and with the boot mechanism. |
| `/var/log` | Depending on the service | To be validated | Do not impose a global mode; the rights depend on the services and on monitoring. |

> **Information**
>
> The modes are shown with four digits (for example `0644`, `0600` or `0700`) so as to make the absence of special bits explicit. For the common permissions shown here, `chmod` also accepts the form without a leading zero (`644`, `600`, `700`).

The effective permissions can be checked with the `stat` command, which directly displays the octal mode, the symbolic permissions, the owner and the group:

```
1
2
3
4
```

For information, the following commands restore the target permissions of the files explicitly identified above:

```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
```

> **Information**
>
> The restriction on `/boot/System.map*` answers the control on the protection of kernel symbols: that file exposes the mapping between kernel symbols and addresses. Its being read by an unprivileged account can provide information useful in exploiting kernel vulnerabilities; this measure is consistent with `kernel.kptr_restrict`, configured in recommendation [R13](https://docs.cyberelements.io/bastion/4.7/lv/Security/SystemHardening/SystemKernelAndNetwork/#r13).

Log directories and cron directories must not be given a generic recursive `chmod`. Their permissions may depend on the services, on the Debian packages installed and on monitoring needs. For scheduled tasks, it is preferable to look for the files abnormally modifiable by the group or by other users:

```
1
2
3
```

> **Warning!**
>
> The values shown are the target permissions recommended for the files explicitly identified. The rights of directories or files managed by Debian services and packages must not be modified globally or recursively. Before any correction, check the owner, the group, any ACLs and the Debian package the file comes from (`dpkg -S <file_path>`). An incorrect change can disrupt a service or prevent it from starting.

The permissions of sensitive files should be checked regularly, notably after an initial installation, a major update, a backup restore, a maintenance operation or a security incident.
