Ir para o conteúdo

System logging and time synchronisation

ANSSI-BP-028 v2.0 reference: R71, R72 (M/I/R levels) for system logging; no dedicated recommendation for time synchronisation, a cross-cutting good practice (consistency of logs, certificates, authentication).

This section covers local system logging, the protection of logs and command histories, then time synchronisation. Log centralisation and the integration with fail2ban are covered in the dedicated chapters: Centralised logging and fail2ban.

R21. Configuration of the system logging service

Applies to: Mediation Controller · Edge Gateway

CyberElements Bastion servers must have an active and properly configured logging service. The rsyslog service can be used for the collection and management of system logs.

1
systemctl status rsyslog

The main configuration is generally located in /etc/rsyslog.conf and /etc/rsyslog.d/. Where the architecture does not provide for the use of IPv6, IPv4 should be forced in /etc/default/rsyslog:

1
RSYSLOGD_OPTIONS='-4'
1
systemctl restart rsyslog

It should be checked that the system logs are indeed generated, and that their permissions prevent any change or deletion by an unauthorised user:

1
2
ls -l /var/log/
journalctl -xe

The logs must be kept in line with the security and operational policy, with a rotation configured so as to avoid the /var and /var/log partitions filling up (/etc/logrotate.conf, /etc/logrotate.d/). Centralising logs towards a remote server or a monitoring solution, where the architecture allows it, is covered in Centralised logging.

It is recommended to monitor the state of the rsyslog service, the presence of recent logs, the space available on /var and /var/log, rotation errors and the critical errors reported by the system. Any change to the logging configuration must be documented.

R22. Protection and rotation of logs

Applies to: Mediation Controller · Edge Gateway

System and application logs may contain sensitive information: authentication traces, system errors, IP addresses, user names, administration events or information useful in analysing an incident. They must be protected against unauthorised access, illegitimate changes and accidental or malicious deletion.

1
ls -l /var/log/

The logs must only be modifiable by the authorised accounts and services; read access must be limited to administrators, to monitoring accounts or to explicitly authorised accounts. Membership of the groups that allow certain logs to be consulted must be reviewed regularly:

1
2
getent group sudo
getent group systemd-journal

The rotation configuration can be tested without being applied, using debug mode:

1
logrotate -d /etc/logrotate.conf

The partitions holding the logs must be watched so as to avoid them filling up:

1
2
df -h /var /var/log 2>/dev/null
du -sh /var/log/* 2>/dev/null

Where log centralisation is in place, the local logs do not necessarily have to be kept indefinitely, but a minimum local retention must be defined according to operational, support and investigation needs. It is recommended to monitor the space available, rotation errors, the absence of recent log generation and abnormal deletions or changes of log files. Any change to the retention or rotation policy must be documented.

R23. Protection of command histories and administration traces

Applies to: Mediation Controller · Edge Gateway

Command histories may contain sensitive information: file paths, user names, configuration parameters, IP addresses or, in some cases, secrets typed by mistake on the command line. The histories of the accounts with interactive access should be protected, notably the administration, maintenance and support accounts.

History files concerned:

1
2
3
4
5
6
~/.bash_history
~/.zsh_history
~/.lesshst
~/.mysql_history
~/.psql_history
~/.wget-hsts
1
2
3
ls -la /root/ /home/
find /root /home -name ".*history" -o -name ".lesshst" -o -name ".wget-hsts" 2>/dev/null
chmod 0600 ~/.bash_history

Typing secrets directly on the command line should be avoided (passwords, access tokens, private keys, API secrets, connection strings containing credentials). Where possible, secrets must be passed through the mechanisms intended for that: an interactive prompt, a protected file, a controlled temporary variable, a secret vault or a validated support procedure.

For accounts using bash, the history configuration can be reinforced in the profile file of the account (~/.bashrc):

1
2
3
4
HISTCONTROL=ignoredups:erasedups
HISTSIZE=5000
HISTFILESIZE=10000
HISTTIMEFORMAT="%F %T "

Warning!

Command histories must not be considered a reliable or sufficient audit mechanism: they can be modified by the user concerned and do not replace system logging, sudo logs or application logs. The maintenance accounts used as part of support must be given particular attention; the traces of an operation must be kept in line with the applicable support procedures, without exposing secrets or sensitive information.

R24. Time synchronisation with NTP

Applies to: Mediation Controller · Edge Gateway

Time synchronisation is essential to the correct operation and to the security of a CyberElements Bastion infrastructure. A time difference between components can affect the consistency of logs, the analysis of security events, authentication mechanisms, certificate validation, exchanges with external directories or services as well as support and investigation operations.

The Mediation Controller and Edge Gateway servers must have reliable, consistent and monitored time synchronisation.

As part of a CyberElements Bastion installation, the NTP service may be installed or configured by the packages of the solution. Before any change, its presence and state must therefore be checked:

1
2
dpkg -l | grep -E '^ii[[:space:]]+(ntp|ntpsec)'
systemctl status ntpsec

Information

The time synchronisation service used is based on NTPsec. The main configuration is located in /etc/ntpsec/ntp.conf, and the start-up options of the service in /etc/default/ntpsec.

The existing configuration must be backed up before any change:

1
2
cp -a /etc/ntpsec/ntp.conf /etc/ntpsec/ntp.conf.bak
cp -a /etc/default/ntpsec /etc/default/ntpsec.bak

Configuring the time sources

The Mediation Controller must be configured with the time sources defined by the operational policy, in line with the applicable product procedures.

The NTP servers used must be controlled and consistent with the network architecture. Where a server sits in a DMZ, NTP access must be limited to the explicitly authorised time sources.

Example configuration in /etc/ntpsec/ntp.conf with two internal NTP servers:

1
2
server <NTP_SERVER_1> iburst
server <NTP_SERVER_2> iburst

The iburst option speeds up the initial acquisition of synchronisation once the NTP source becomes reachable.

The configured sources can be checked with:

1
grep -E '^[[:space:]]*(server|pool)[[:space:]]' /etc/ntpsec/ntp.conf

Warning!

The public NTP sources present in the initial configuration must not be kept if the network policy requires the exclusive use of internal time servers. The configured sources must be documented and match the explicitly authorised flows.

Using IPv4 only

Where the CyberElements Bastion architecture does not use IPv6, the NTP service should be forced to use IPv4. In /etc/default/ntpsec, configure:

1
NTPD_OPTS="-4 -g"

The -4 option forces the service to use IPv4. The -g option allows the service to correct a large initial clock offset at start-up.

After the change:

1
2
systemctl restart ntpsec
systemctl status ntpsec

Mediation Controller / Edge Gateway architecture

In a CyberElements Bastion architecture, the Edge Gateway can use the Mediation Controller as its time source. In that case, the /etc/ntpsec/ntp.conf file of the Edge Gateway can for instance contain:

1
server <IP_MEDIATION_CONTROLLER> iburst

That architecture avoids opening direct NTP access from the Edge Gateway towards time servers that are external or located in other zones of the information system.

Warning!

Where the Mediation Controller provides the NTP service to the Edge Gateways, the filtering rules must authorise only the UDP/123 flows needed between the devices concerned. The Mediation Controller must itself remain synchronised with one or more reliable time sources.

Checking synchronisation

After configuring or restarting the service, check the NTP sources and their state:

1
ntpq -pn

The source currently selected for synchronisation can be identified in the first column of the ntpq output.

Detailed information on the state of the daemon can also be consulted with:

1
ntpq -c rv

The service can be checked with:

1
2
systemctl is-active ntpsec
systemctl is-enabled ntpsec

It is also possible to check that the service uses the expected NTP port:

1
ss -lunp | grep ':123'

The logs of the service must be checked in case of an anomaly:

1
journalctl -u ntpsec

or, for recent events:

1
journalctl -u ntpsec --since "1 hour ago"

Network flows

NTP flows must be authorised in line with the flow matrix of the deployment. The protocol mainly uses UDP/123, towards the authorised time sources only.

  • where an Edge Gateway is synchronised directly on the Mediation Controller: Edge Gateway → Mediation Controller: UDP/123;
  • for the Mediation Controller: Mediation Controller → authorised NTP server(s): UDP/123.

No NTP access towards an unplanned destination must be authorised.

Monitoring

Time synchronisation must be monitored so as to detect notably:

  • the loss of the selected NTP source;
  • the absence of reachable NTP sources;
  • an abnormal clock drift;
  • the ntpsec service stopping;
  • repeated errors present in the logs of the service.

Any change to the time sources, to the NTP configuration or to the associated filtering rules must be documented.

Information

The NTP configuration must be consistent across all CyberElements Bastion components. A common time source or a controlled synchronisation chain notably makes it easier to correlate logs between the Mediation Controller, the Edge Gateway and the security or monitoring devices.