Console Login

Data Sovereignty After Schrems II: Hosting and Encrypting in Norway

The problem

On 16 July 2020 the Court of Justice of the European Union (CJEU) ruled in Schrems II (case C-311/18) that the EU-US Privacy Shield decision is invalid. Many teams had treated Privacy Shield as the legal basis for keeping personal data with US-owned cloud providers. That basis is gone.

Two reactions are common, and both break down in practice:

  • Region labels as compliance. The team picks an EU region such as eu-central-1 and treats the question as closed.
  • Location as the whole answer. The team moves to a host in Norway and leaves the rest of the stack unchanged: plaintext volumes, plaintext database files, old TLS versions and unencrypted traffic between servers.

Neither reaction produces a defensible position in an audit or a data-protection assessment.

Why it happens

Personal data may flow freely inside the EEA. Norway is an EEA member and applies the GDPR through the EEA Agreement, so a transfer from the EU to a Norwegian operator is not a third-country transfer. Transfers to a third country need a valid mechanism, and the judgment removed one of the most widely used.

The underlying concern is access by public authorities. US laws such as FISA section 702 and the CLOUD Act can reach providers that fall under US jurisdiction. Where the data is physically stored does not change that. A European region operated by a US-controlled company can therefore still be a transfer risk. The judgment itself did not declare such setups illegal. It requires the data exporter to assess, case by case, whether the protection is essentially equivalent.

The reverse assumption is also wrong. A Norwegian address does not remove risk if the operator is a subsidiary of a US group, if keys are held by the operator, or if data crosses the network unencrypted. Legal control and technical control have to be considered together.

Source of truth

The following references are the basis for the legal and technical statements in this article:

Fix options

OptionWhat it addressesWeakness
Stay with a US-controlled provider and rely on standard contractual clausesGives a contractual basis for the transferThe exporter must still assess foreign access in practice. Contracts do not bind foreign authorities.
Move to an EEA operator with no US parentRemoves the third-country transfer and most of the foreign-jurisdiction exposureDoes not protect against theft, misconfiguration or interception inside the network.
Encrypt with keys the customer controlsMakes copied disks, backups and snapshots unreadableThe host operator can still read memory and data while the volume is unlocked and the service is running.
Client-side or application-level encryption, pseudonymisationKeeps readable data away from the host entirelyNeeds application changes, and the data is harder to search and process.
Encrypt traffic between serversProtects data on the wire inside the provider networkDoes not protect data at rest.

Why this fix

The chosen approach combines an EEA operator with layered technical controls. Jurisdiction is the foundation, and the technical layers limit the damage if that foundation is not enough. The layers are:

  1. LUKS2 on the volume that holds personal data.
  2. MariaDB encryption for tables, logs and temporary files.
  3. TLS 1.2 and 1.3 only on public endpoints.
  4. WireGuard between application and database servers.

Each layer covers a different failure. A stolen disk or snapshot is covered by LUKS and database encryption. Interception between servers is covered by WireGuard, and interception towards clients by TLS. None of the layers needs application changes, which keeps the migration small. Client-side encryption is stronger against the host, but it is usually too invasive for an existing application, so it stays as an option for the most sensitive fields.

Step by step

The commands below are a typical sequence on a Linux server with MariaDB 10.4, nginx built against OpenSSL 1.1.1 or newer, and a spare block device /dev/vdb1. Adjust device names, paths and IP addresses to the environment. The first cryptsetup command destroys any existing data on the device.

1. Encrypted volume with LUKS2

systemctl stop mariadb
cryptsetup luksFormat --type luks2 /dev/vdb1
cryptsetup luksOpen /dev/vdb1 secure_data
mkfs.ext4 /dev/mapper/secure_data
mkdir -p /mnt/secure_store
mount /dev/mapper/secure_data /mnt/secure_store
cryptsetup status secure_data
cryptsetup luksHeaderBackup /dev/vdb1 --header-backup-file /root/vdb1-header.img

Keep the header backup off the server. A damaged LUKS header makes the data unrecoverable. Do not store the passphrase or a key file on the unencrypted boot disk, because that defeats the purpose. Enter the passphrase manually after a reboot, or fetch the key from a separate key server. After mounting, move the MariaDB data directory onto the volume (for example with rsync -a /var/lib/mysql/ /mnt/secure_store/mysql/), set ownership to the mysql user and point datadir at the new path.

2. MariaDB encryption at rest

Data-at-rest encryption exists in MariaDB since 10.1.3. It is not specific to 10.4. MySQL Community uses a different mechanism (keyring plugins), and the configuration below does not apply to it. Create a key file and encrypt it with a separate passphrase file:

mkdir -p /etc/mysql/encryption
echo "1;$(openssl rand -hex 32)" > /etc/mysql/encryption/keys.txt
openssl rand -hex 128 > /etc/mysql/encryption/keyfile.key
openssl enc -aes-256-cbc -md sha1 -pass file:/etc/mysql/encryption/keyfile.key -in /etc/mysql/encryption/keys.txt -out /etc/mysql/encryption/keyfile.enc
shred -u /etc/mysql/encryption/keys.txt
chown -R mysql:mysql /etc/mysql/encryption
chmod 600 /etc/mysql/encryption/keyfile.enc /etc/mysql/encryption/keyfile.key

Then add the following to a file such as /etc/mysql/mariadb.conf.d/encryption.cnf:

[mysqld]
plugin_load_add = file_key_management
file_key_management_filename = /etc/mysql/encryption/keyfile.enc
file_key_management_filekey = FILE:/etc/mysql/encryption/keyfile.key
file_key_management_encryption_algorithm = AES_CTR

innodb_encrypt_tables = FORCE
innodb_encrypt_log = ON
innodb_encryption_threads = 4
encrypt_binlog = ON
aria_encrypt_tables = ON
encrypt_tmp_files = ON

The original recipe encrypted only InnoDB tables and the redo log. Binary logs, Aria tables and temporary files can also hold personal data, which is why the last three settings are added here. The number of encryption threads only controls background encryption of existing tablespaces. It is not a performance setting tied to the core count, so a small value is enough. Start the service and check the state of the tablespaces:

systemctl start mariadb
mysql -e "SELECT SPACE, NAME, ENCRYPTION_SCHEME FROM information_schema.INNODB_TABLESPACES_ENCRYPTION;"

The key file and its passphrase file sit on the same host, so this protects copied data files and backups, not a compromised running system. Keep both files outside backups of the data directory, or place them on the unlocked LUKS volume's separate parent mount.

3. TLS 1.2 and 1.3 in nginx

TLS 1.3 needs nginx 1.13.0 or newer built against OpenSSL 1.1.1 or newer. The ssl_ciphers list applies to TLS 1.2 only, because TLS 1.3 cipher suites are not configured through it. The original list included DHE suites. These fall back to weak default Diffie-Hellman parameters unless ssl_dhparam is set, so they are left out here. ECDSA suites require an ECDSA certificate, so the list below uses RSA-compatible ECDHE suites plus the ECDSA ones for certificates that are ECDSA.

server {
    listen 443 ssl http2;
    server_name secure.example.no;

    ssl_certificate     /etc/nginx/tls/fullchain.pem;
    ssl_certificate_key /etc/nginx/tls/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
    ssl_prefer_server_ciphers off;

    add_header Strict-Transport-Security "max-age=63072000" always;
}
nginx -t
systemctl reload nginx
openssl s_client -connect secure.example.no:443 -tls1_3

4. WireGuard between application and database servers

WireGuard is part of the mainline kernel from Linux 5.6. Older kernels need the out-of-tree module from the distribution or the project. Generate a key pair on each server:

umask 077
wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey

Configuration on the database server, /etc/wireguard/wg0.conf:

[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = <DB_PRIVATE_KEY>

[Peer]
PublicKey = <APP_PUBLIC_KEY>
AllowedIPs = 10.10.0.2/32

Configuration on the application server. It needs an Endpoint, because it initiates the connection:

[Interface]
Address = 10.10.0.2/24
PrivateKey = <APP_PRIVATE_KEY>

[Peer]
PublicKey = <DB_PUBLIC_KEY>
Endpoint = <DB_PUBLIC_IP>:51820
AllowedIPs = 10.10.0.1/32
PersistentKeepalive = 25

Bring the tunnel up on both hosts and bind MariaDB to the tunnel address only:

systemctl enable --now wg-quick@wg0
wg show
[mysqld]
bind-address = 10.10.0.1
iptables -A INPUT -p udp --dport 51820 -j ACCEPT
iptables -A INPUT -i wg0 -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j DROP

The application then connects to 10.10.0.1:3306. MySQL traffic travels inside the tunnel, and the database port is closed on the public interface.

Limits and alternatives

  • What the layers achieve. Copied disks, snapshots and database files stay unreadable. Traffic between servers and to clients is encrypted. The data stays under EEA jurisdiction when the operator has no US parent.
  • What they do not achieve. A host operator with hypervisor access can inspect memory and data while the volume is unlocked and the database is running. Disk encryption does not change that.
  • Key handling is the weak point. A key file on the same server as the data protects against copied files only. Remote key management, or a passphrase entered at boot, gives stronger protection but costs automation, since a reboot then needs a person or a key service.
  • Not legal advice. Whether a particular setup satisfies the GDPR after Schrems II remains a documented, case-by-case assessment by the data controller. Technical measures support that assessment but do not replace it.
  • When to choose another method. For highly sensitive fields, use application-level encryption with keys that never reach the host. For an existing US-based provider that cannot be replaced soon, standard contractual clauses with documented supplementary measures are the transitional option.
  • Performance claims. Encryption cost depends on the CPU, and AES hardware acceleration is the main factor. Measure on the target system rather than assuming a fixed overhead.