kernel:
  #image: nemunaire/kernel:5.10.62-0b705d955f5e283f62583c4e227d64a7924c138f-amd64
  image: linuxkit/kernel:5.15.110
  cmdline: "console=ttyS0 console=tty0"

init:
  - linuxkit/init:144c9cee8aed9e30a16940f2bf1d3813883aceda
  - linuxkit/runc:436357ce16dd663e24f595bcec26d5ae476c998e
  - linuxkit/containerd:d445de33c7f08470187b068d247b1c0dea240f0a
  - linuxkit/ca-certificates:4de36e93dc87f7ccebd20db616ed10d381911d32
  - linuxkit/getty:06f34bce0facea79161566d67345c3ea49965437
  - nemunaire/mdadm:8c8a476336087b395878e02e1d89008da6a38044
  - nemunaire/kexec:839b4eedfce02a56c581dec2383dc6faff120855

onboot:
  - name: mod
    image: linuxkit/modprobe:5dd4d7238f760bcd9f91b9166f414da953242f43
    command: ["/bin/sh", "-c", "modprobe xhci_pci ahci intel_lpss_pci i2c_i801 megaraid_sas tg3 bnxt_en"]

  - name: sysctl
    image: linuxkit/sysctl:a88a50c104d538b58da5e1441f6f0b4b738f76a6
    binds:
      - /etc/sysctl.d/01-fic.conf:/etc/sysctl.d/01-fic.conf:ro

    # Metadata
  - name: metadata
    image: linuxkit/metadata:501144d47215671e77b9cac44748a04f21236195
    command: ["/usr/bin/metadata", "-v"]

    # Filesystem
  - name: swap
    image: linuxkit/swap:d17a7f1c26ff768c26b3c206ccf3aa72349568df
    command: ["/sbin/swapon", "/dev/sda3"]
  - name: dm-crypt
    image: linuxkit/dm-crypt:526d32351c8246431be8e1a168cb514ff3c365af
    command: ["/usr/bin/crypto", "-l", "crypt_fic", "/dev/sda4"]
    binds:
      - /dev:/dev
      - /run/config/dm-crypt:/etc/dm-crypt
  - name: mount
    image: linuxkit/mount:f671cb94a8999a65e33b3fe79f3def58e3d58b07
    command: ["/usr/bin/mountie", "-device", "/dev/mapper/crypt_fic", "/var/lib/fic" ]

    # Network
#  - name: dhcpcd
#    image: linuxkit/dhcpcd:2a8ed08fea442909ba10f950d458191ed3647115
#    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
#  - name: ntp
#    image: linuxkit/openntpd:dd353cac6cbd816008c565041cec6650090d0ad0
  - name: synchro-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 10.10.10.1/29 dev eth2; ip link set eth2 up;" ]
    net: new
    runtime:
      interfaces:
        - name: eth2
      bindNS:
        net: /run/netns/synchro
  - name: qa-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 10.10.10.1/29 dev eth1; ip link set eth1 up; ip a add 172.17.0.6/24 dev vethin-qa; ip link set vethin-qa up" ]
    net: new
    runtime:
      interfaces:
        - name: eth1
        - name: vethin-qa
          add: veth
          peer: veth-qa
      bindNS:
        net: /run/netns/fic-qa
  - name: admin-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    #command: ["/bin/sh", "-c", "ip link add link eth3 name adminiface type vlan id 99; ip a add 172.16.99.219/24 dev adminiface; ip link set eth3 up; ip link set adminiface up; ip r add default via 172.16.99.1; ip a add 172.17.0.2/24 dev vethin-admin; ip link set vethin-admin up; ping -W 10 -c 1 172.16.99.1;" ]
    command: ["/bin/sh", "-c", "ip a add 192.168.3.92/24 dev eth3; ip a add 192.168.4.92/24 dev eth3; ip link set eth3 up; ip r add default via 192.168.3.1; ip a add 172.17.0.2/24 dev vethin-admin; ip link set vethin-admin up; ping -W 10 -c 1 192.168.3.1;" ]
    net: new
    runtime:
      interfaces:
        - name: eth3
        - name: vethin-admin
          add: veth
          peer: veth-admin
      bindNS:
        net: /run/netns/fic-admin
  - name: checker-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.0.3/24 dev vethin-checker; ip link set vethin-checker up;" ]
    net: new
    runtime:
      interfaces:
        - name: vethin-checker
          add: veth
          peer: veth-checker
      bindNS:
        net: /run/netns/fic-checker
  - name: generator-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.0.5/24 dev vethin-generat; ip link set vethin-generat up;" ]
    net: new
    runtime:
      interfaces:
        - name: vethin-generat
          add: veth
          peer: veth-generator
      bindNS:
        net: /run/netns/fic-generator
  - name: mysql-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.0.4/24 dev vethin-db; ip link set vethin-db up;" ]
    net: new
    runtime:
      interfaces:
        - name: vethin-db
          add: veth
          peer: veth-db
      bindNS:
        net: /run/netns/db
  - name: bridge-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.0.1/24 dev br0; ip link set veth-admin master br0; ip link set veth-checker master br0; ip link set veth-generator master br0; ip link set veth-db master br0; ip link set veth-qa master br0; ip link set br0 up; ip link set veth-admin up; ip link set veth-checker up; ip link set veth-generator up; ip link set veth-db up; ip link set veth-qa up;" ]
    runtime:
      interfaces:
        - name: br0
          add: bridge

  - name: firewall-synchro
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/bash", "-c", "/sbin/iptables-restore < /etc/iptables/rules-synchro.v4; /sbin/ip6tables-restore < /etc/iptables/rules.v6" ]
    binds:
      - /etc/iptables/rules-synchro.v4:/etc/iptables/rules-synchro.v4:ro
      - /etc/iptables/rules.v6:/etc/iptables/rules.v6:ro
    net: /run/netns/synchro
    runtime:
      mkdir:
        - /var/lib/fic/teams
  - name: firewall-admin
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/bash", "-c", "/sbin/iptables-restore < /etc/iptables/rules-admin.v4; /sbin/ip6tables-restore < /etc/iptables/rules.v6" ]
    binds:
      - /etc/iptables/rules-admin.v4:/etc/iptables/rules-admin.v4:ro
      - /etc/iptables/rules.v6:/etc/iptables/rules.v6:ro
    net: /run/netns/fic-admin

services:
#  - name: getty
#    image: linuxkit/getty:06f34bce0facea79161566d67345c3ea49965437
#    env:
#      - INSECURE=true

  # Enable acpi to shutdown on power events
  - name: acpid
    image: linuxkit/acpid:548f8f1c8bda31cdbefb65bdb0747f97c17639d2
  - name: rngd
    image: linuxkit/rngd:331294919ba6d953d261a2694019b659a98535a4
  - name: db
    image: mariadb:latest
    command: ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh", "mysqld"]
    capabilities:
     - CAP_CHOWN
     - CAP_SETUID
     - CAP_SETGID
     - CAP_DAC_OVERRIDE
    env:
      - MYSQL_DATABASE=fic
      - MYSQL_USER=fic
      - MYSQL_PASSWORD=fic
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /etc/mysql/conf.d:/etc/mysql/conf.d:ro
      - /var/lib/fic/mysql:/var/lib/mysql
    net: /run/netns/db
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/mysql
  - name: db-backup
    image: nemunaire/mariadb-client:a77db996e46335c35c74ba8dbef3c65286386c6d
    command: ["/bin/sh", "/root/mysql_backup.sh"]
    env:
      - MYSQL_HOST=db
      - MYSQL_DATABASE=fic
      - MYSQL_USER=fic
      - MYSQL_PASSWORD=fic
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /root/mysql_backup.sh:/root/mysql_backup.sh:ro
      - /var/lib/fic/backups/:/var/lib/fic/backups/
    net: /run/netns/db
    runtime:
      mkdir:
        - /var/lib/fic/backups
  - name: fic-admin
    image: nemunaire/fic-admin:latest
    command: ["/srv/admin", "-4real", "-bind=127.0.0.1:8081", "-baseurl=/admin/", "-localimport=/mnt/fic", "-timestampCheck=/srv/submissions", "-git-import-remote=git@gitlab.cri.epita.fr:ing/majeures/srs/fic/2024/challenges.git"]
    env:
      - PATH=/usr/sbin:/usr/bin:/sbin:/bin
      - MYSQL_HOST=db
      - FICCA_PASS=jee8AhloAith1aesCeQu5ahgIegaeM4K
      - FICOIDC_SECRET=N4n7AXzK9kpXt3TmSn8wAgtxqxhGORgcubLaE2g
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/raw_files:/mnt/fic
      - /var/lib/fic/dashboard:/srv/DASHBOARD
      - /var/lib/fic/files:/srv/FILES
      - /var/lib/fic/generator:/srv/GENERATOR:ro
      - /var/lib/fic/pki:/srv/PKI
      - /var/lib/fic/settings:/srv/SETTINGS
      - /var/lib/fic/submissions:/srv/submissions:ro
      - /var/lib/fic/teams:/srv/TEAMS
    net: /run/netns/fic-admin
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/dashboard
        - /var/lib/fic/files
        - /var/lib/fic/generator
        - /var/lib/fic/raw_files
        - /var/lib/fic/pki
        - /var/lib/fic/settings
        - /var/lib/fic/submissions
        - /var/lib/fic/teams
  - name: fic-evdist
    image: nemunaire/fic-evdist:latest
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/settings:/srv/SETTINGS
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST
    net: new
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/settings
        - /var/lib/fic/settingsdist
  - name: fic-checker
    image: nemunaire/fic-checker:latest
    env:
      - MYSQL_HOST=db
      - MYSQL_PASSWORD=fic
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/generator:/srv/GENERATOR:ro
      - /var/lib/fic/teams:/srv/TEAMS:ro
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST:ro
      - /var/lib/fic/submissions:/srv/submissions
    net: /run/netns/fic-checker
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/generator
        - /var/lib/fic/settingsdist
        - /var/lib/fic/submissions
        - /var/lib/fic/teams
  - name: fic-dashboard
    image: nemunaire/fic-dashboard:latest@sha256:1466b7d5acdaf43943fac9b0804b5d9b3a27ae4f83613f2df289401fafd8da35
    command: ["/srv/dashboard", "-bind=:8082", "-restrict-to-ips=/srv/DASHBOARD/restricted-ips.json"]
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/dashboard:/srv/DASHBOARD:ro
      - /var/lib/fic/files:/srv/FILES:ro
      - /var/lib/fic/teams:/srv/TEAMS:ro
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST:ro
    net: /run/netns/fic-admin
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/dashboard
        - /var/lib/fic/teams
        - /var/lib/fic/settingsdist
  - name: fic-generator
    image: nemunaire/fic-generator:latest
    command: ["/srv/generator", "-bind=/srv/GENERATOR/generator.socket"]
    env:
      - MYSQL_HOST=db
      - MYSQL_PASSWORD=fic
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/generator:/srv/GENERATOR
      - /var/lib/fic/teams:/srv/TEAMS
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST:ro
    net: /run/netns/fic-generator
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/generator
        - /var/lib/fic/settingsdist
        - /var/lib/fic/teams
  - name: fic-qa
    image: nemunaire/fic-qa:latest
    env:
      - MYSQL_HOST=db
      - MYSQL_PASSWORD=fic
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/teams:/srv/TEAMS
    net: /run/netns/fic-qa
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/teams
  - name: fic-synchro
    image: nemunaire/rsync:a3d76b2dd0a9ad73be44dc77ad765b20d96a3285
    command: ["/bin/ash", "/root/synchro.sh"]
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/ssh:/etc/ssh:ro
      - /run/config/synchro/id_ed25519:/root/.ssh/id_ed25519:ro
      - /root/synchro.sh:/root/synchro.sh:ro
      - /var/lib/fic/files:/srv/FILES:ro
      #- /var/lib/fic/pki/ca.key:/srv/PKI/ca.key:ro
      - /var/lib/fic/pki/shared:/srv/PKI/shared:ro
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST:ro
      - /var/lib/fic/submissions:/srv/submissions
      - /var/lib/fic/teams:/srv/TEAMS:ro
      - /var/log/frontend:/var/log/frontend
    net: /run/netns/synchro
    runtime:
      mkdir:
        - /var/lib/fic/files
        - /var/lib/fic/pki/shared
        - /var/lib/fic/settingsdist
        - /var/lib/fic/ssh
        - /var/lib/fic/submissions
        - /var/lib/fic/teams
        - /var/log/frontend
  - name: sshd
    image: nemunaire/rsync:a3d76b2dd0a9ad73be44dc77ad765b20d96a3285
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /run/config/ssh/authorized_keys:/root/.ssh/authorized_keys:ro
      - /usr/bin/iptables:/usr/bin/iptables:ro
      - /usr/bin/mysql:/usr/bin/mysql:ro
      - /usr/bin/pnsenter:/usr/bin/pnsenter:ro
      - /var/lib/fic/outofsync:/var/lib/fic/outofsync
      - /var/lib/fic/raw_files:/mnt/fic
      - /var/log:/var/log:ro
    capabilities:
      - all
    net: /run/netns/fic-admin
    pid: host
    runtime:
      mkdir:
        - /var/lib/fic/outofsync
#  - name: dhcp-server
#    image: joebiellik/dhcpd
#    binds:
#      - /etc/dhcp/dhcpd.conf:/etc/dhcp/dhcpd.conf:ro
#    capabilities:
#     - CAP_NET_BIND_SERVICE
#     - CAP_NET_RAW
#     - CAP_DAC_OVERRIDE
#    net: /run/netns/fic-admin
#    pid: new
#    ipc: new
#    uts: new

files:
  - path: etc/init.d/001-hostname
    contents: |
      #!/bin/sh
      /bin/hostname deimos
    mode: "0555"

  - path: etc/profile.d/color_prompt.sh
    contents: |
      PS1='\[\e[1;33m\]'$PS1'\[\e[0m\]'
    mode: "0444"

  - path: etc/init.d/015-setup-sshd
    source: configs/sshd-setup.sh
    mode: "0555"

  - path: etc/sysctl.d/01-fic.conf
    source: configs/sysctl-backend.conf
    mode: "0444"

  - path: root/synchro.sh
    source: configs/synchro.sh
    mode: "0755"
  - path: root/mysql_backup.sh
    source: configs/mysql_backup.sh
    mode: "0755"
  - path: etc/hosts
    source: configs/hosts
    mode: "0644"

  - path: usr/bin/iptables
    source: configs/nsenter_iptables.sh
    mode: "0755"
  - path: usr/bin/mysql
    source: configs/nsenter_mysql.sh
    mode: "0755"
  - path: usr/bin/pnsenter
    source: configs/nsenter_process.sh
    mode: "0755"

  - path: etc/mysql/conf.d/max-conn.cnf
    contents: |
      [mysqld]
      max_connections = 99999
    mode: "0444"
  - path: etc/dhcp/dhcpd.conf
    contents: |
      default-lease-time 600;
      max-lease-time 7200;
      option subnet-mask 255.255.255.0;
      option broadcast-address 192.168.3.255;
      subnet 192.168.3.0 netmask 255.255.255.0 {
        range  192.168.3.11  192.168.3.250;
      }
    mode: "0440"
  - path: etc/iptables/rules.v6
    contents: |
      *filter
      :INPUT DROP [0:0]
      :FORWARD DROP [0:0]
      :OUTPUT DROP [0:0]
      COMMIT
    mode: "0440"
  - path: etc/iptables/rules-admin.v4
    contents: |
      *filter
      :INPUT DROP [0:0]
      :FORWARD DROP [0:0]
      :OUTPUT DROP [0:0]
      [0:0] -A INPUT -i lo -j ACCEPT
      [0:0] -A INPUT -m conntrack --ctstate INVALID -j DROP
      [0:0] -A INPUT -p icmp -j ACCEPT
      [0:0] -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
      [0:0] -A INPUT -p tcp -m conntrack --ctstate NEW -m tcp --dport ssh -j ACCEPT
      [0:0] -A INPUT -p tcp -m conntrack --ctstate NEW -m tcp --dport 8082 -j ACCEPT
      [0:0] -A INPUT -i vethin-admin -s 172.17.0.0/24 -p tcp -m conntrack --ctstate NEW -j ACCEPT
      [0:0] -A INPUT -j LOG
      [0:0] -A FORWARD -j LOG
      [0:0] -A OUTPUT -o lo -j ACCEPT
      [0:0] -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
      [0:0] -A OUTPUT -p icmp -j ACCEPT
      [0:0] -A OUTPUT -o vethin-admin -d 172.17.0.0/24 -p tcp -m conntrack --ctstate NEW -j ACCEPT
      [0:0] -A OUTPUT -j LOG
      [0:0] -A OUTPUT -j REJECT
      COMMIT
    mode: "0440"
  - path: etc/iptables/rules-synchro.v4
    contents: |
      *filter
      :INPUT DROP [0:0]
      :FORWARD DROP [0:0]
      :OUTPUT DROP [0:0]
      [0:0] -A INPUT -i lo -j ACCEPT
      [0:0] -A INPUT -m conntrack --ctstate INVALID -j DROP
      [0:0] -A INPUT -p icmp --icmp-type 8 -j ACCEPT
      [0:0] -A INPUT -p icmp --icmp-type 0 -j ACCEPT
      [0:0] -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
      [0:0] -A INPUT -j LOG
      [0:0] -A FORWARD -j LOG
      [0:0] -A OUTPUT -o lo -j ACCEPT
      [0:0] -A OUTPUT -p icmp --icmp-type 0 -j ACCEPT
      [0:0] -A OUTPUT -p icmp --icmp-type 8 -j ACCEPT
      [0:0] -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
      [0:0] -A OUTPUT -o eth2 -d 10.10.10.2 -p tcp -m conntrack --ctstate NEW -m tcp --dport ssh -j ACCEPT
      [0:0] -A OUTPUT -j LOG
      [0:0] -A OUTPUT -j REJECT
      COMMIT
    mode: "0440"

trust:
  org:
    - linuxkit
    - library
