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
  - nemunaire/fic-frontend-ui:latest

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

    # 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: ntp
#    image: linuxkit/openntpd:dd353cac6cbd816008c565041cec6650090d0ad0
  - name: nginx-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.1.2/24 dev vethin-nginx; ip link set vethin-nginx up;" ]
    net: new
    runtime:
      interfaces:
        - name: vethin-nginx
          add: veth
          peer: veth-nginx
      bindNS:
        net: /run/netns/nginx
  - name: frontal-ip-setup # without bonding
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip link set name bond-frontal eth3; ip link set bond-frontal up; ip a add 10.42.192.3/24 dev bond-frontal; ip a add 91.243.117.240/32 dev bond-frontal; ip r add default via 10.42.192.1; ip link add link bond-frontal name internet type vlan id 4; ip a add 10.10.10.2/29 dev internet; ip link set internet up;" ]
    net: /run/netns/nginx
    runtime:
      interfaces:
#        - name: eth1
#        - name: eth2
        - name: eth3
#        - name: eth4
#  - name: frontal-ip-setup # with bonding
#    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
#    command: ["/bin/sh", "-c", "ip link set dev bond-frontal type bond mode balance-alb; ip link set bond-frontal up; ifenslave bond-frontal eth1 eth2 eth3 eth4; ip a add 172.23.42.254/24 dev bond-frontal; ip a add 172.23.42.1/24 dev bond-frontal; ip a add 91.243.117.240/32 dev bond-frontal; ip link add link bond-frontal name internet type vlan id 4; ip link set internet up; sysctl -w net.ipv4.ip_forward=1;" ]
#    net: /run/netns/nginx
#    runtime:
#      interfaces:
#        - name: eth1
#        - name: eth2
#        - name: eth3
#        - name: eth4
#        - name: bond-frontal
#          add: bond
  - name: receiver-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.1.3/24 dev vethin-receiver; ip link set vethin-receiver up;" ]
    net: new
    runtime:
      interfaces:
        - name: vethin-receiver
          add: veth
          peer: veth-receiver
      bindNS:
        net: /run/netns/fic-receiver
  - name: sshd-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 10.10.10.2/29 dev eth2; ip link set eth2 up;" ]
    net: new
    runtime:
      interfaces:
        - name: eth2
      bindNS:
        net: /run/netns/sshd
  - name: auth-ip-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.1.4/24 dev vethin-auth; ip link set vethin-auth up;" ]
    net: new
    runtime:
      interfaces:
        - name: vethin-auth
          add: veth
          peer: veth-auth
      bindNS:
        net: /run/netns/auth
  - name: bridge-setup
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/sh", "-c", "ip a add 172.17.1.1/24 dev br0; ip link set veth-nginx master br0; ip link set veth-receiver master br0; ip link set veth-auth master br0; ip link set br0 up; ip link set veth-nginx up; ip link set veth-receiver up; ip link set veth-auth up;" ]
    runtime:
      interfaces:
        - name: br0
          add: bridge

  - name: firewall-frontal
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/bash", "-c", "/sbin/iptables-restore < /etc/iptables/rules-frontal.v4; /sbin/ip6tables-restore < /etc/iptables/rules.v6" ]
    binds:
      - /etc/iptables/rules-frontal.v4:/etc/iptables/rules-frontal.v4:ro
      - /etc/iptables/rules.v6:/etc/iptables/rules.v6:ro
    net: /run/netns/nginx
  - name: firewall-sshd
    image: linuxkit/ip:c88e3272e3b12edec454e4720da8bb70a7655bc7
    command: ["/bin/bash", "-c", "/sbin/iptables-restore < /etc/iptables/rules-sshd.v4; /sbin/ip6tables-restore < /etc/iptables/rules.v6" ]
    binds:
      - /etc/iptables/rules-sshd.v4:/etc/iptables/rules-sshd.v4:ro
      - /etc/iptables/rules.v6:/etc/iptables/rules.v6:ro
    net: /run/netns/sshd

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: dhcpcd
    image: linuxkit/dhcpcd:2a8ed08fea442909ba10f950d458191ed3647115
    net: /run/netns/nginx
    binds:
      - /etc/dhcpcd.conf:/dhcpcd.conf:ro
  - name: nginx
    image: nginx:alpine
    capabilities:
     - CAP_NET_BIND_SERVICE
     - CAP_CHOWN
     - CAP_SETUID
     - CAP_SETGID
     - CAP_DAC_OVERRIDE
    tmpfs:
      - /var/cache
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /etc/resolv.conf:/etc/resolv.conf:ro
      - /etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro
      - /run/config/tls_config/:/etc/nginx/ssl/:ro
      - /etc/nginx/fic-auth.conf:/etc/nginx/fic-auth.conf:ro
      - /etc/nginx/fic-get-team.conf:/etc/nginx/fic-get-team.conf:ro
      - /www/htdocs-frontend:/srv/htdocs-frontend:ro
      - /var/lib/fic/files:/srv/FILES:ro
      - /var/lib/fic/pki:/srv/PKI:ro
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST:ro
      - /var/lib/fic/startingblock:/srv/startingblock:ro
      - /var/lib/fic/teams:/srv/TEAMS:ro
    net: /run/netns/nginx
    pid: new
    ipc: new
    uts: new
    runtime:
      mkdir:
        - /var/lib/fic/files
        - /var/lib/fic/pki
        - /var/lib/fic/startingblock
        - /var/lib/fic/settingsdist
        - /var/lib/fic/teams
  - name: fic-receiver
    image: nemunaire/fic-receiver:latest
    command: ["/srv/receiver", "-bind=:8080", "-startedFile=/srv/startingblock/started"]
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/files:/srv/FILES:ro
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST:ro
      - /var/lib/fic/startingblock:/srv/startingblock
      - /var/lib/fic/submissions:/srv/submissions
      - /var/lib/fic/teams:/srv/TEAMS:ro
    net: /run/netns/fic-receiver
    runtime:
      mkdir:
        - /var/lib/fic/files
        - /var/lib/fic/settingsdist
        - /var/lib/fic/startingblock
        - /var/lib/fic/submissions
        - /var/lib/fic/teams
  - name: fic-remote-challenge-sync-airbus
#    image: nemunaire/fic-remote-challenge-sync-airbus:latest
    image: alpine:latest
    command: ["/bin/ash", "-c", "while true; do sleep 300; done"]
    env:
      - AIRBUS_BASEURL=https://....
      - AIRBUS_TOKEN=abcdef0123456789abcdef0123456789
      - AIRBUS_SESSIONID=42
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/teams:/srv/TEAMS:ro
      - /var/lib/fic/remote:/srv/REMOTE
    runtime:
      mkdir:
        - /var/lib/fic/remote
    net: /run/netns/nginx
  - name: sshd
    image: nemunaire/rsync:a3d76b2dd0a9ad73be44dc77ad765b20d96a3285
    capabilities:
      - all
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/ssh:/etc/ssh:ro
      - /run/config/synchro/id_ed25519.pub:/root/.ssh/authorized_keys:ro
      - /var/lib/fic/files:/srv/FILES
      - /var/lib/fic/pki:/srv/PKI
      - /var/lib/fic/settingsdist:/srv/SETTINGSDIST
      - /var/lib/fic/submissions:/srv/submissions
      - /var/lib/fic/teams:/srv/TEAMS
      - /var/log:/var/log:ro
    net: /run/netns/sshd
    runtime:
      mkdir:
        - /var/lib/fic/files
        - /var/lib/fic/pki
        - /var/lib/fic/settingsdist
        - /var/lib/fic/ssh
        - /var/lib/fic/submissions
        - /var/lib/fic/teams

#  - 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/nginx
#    pid: new
#    ipc: new
#    uts: new
#  - name: dns-server
#    image: nemunaire/unbound:8a5c8b7be1392fea9300bc884926141cb6db6792
#    binds:
#      - /etc/unbound/unbound.d:/etc/unbound/unbound.d:ro
#    net: /run/netns/nginx

  - name: dexidp
    image: ghcr.io/dexidp/dex:v2.37.0
    net: /run/netns/auth
    binds:
      - /etc/hosts:/etc/hosts:ro
      - /var/lib/fic/pki/shared/dex-config.yaml:/etc/dex/config.docker.yaml:ro
      - /var/lib/fic/dex:/var/dex
      - /www/dex-templates/theme/styles.css:/srv/dex/web/themes/light/styles.css
      - /www/dex-templates/templates/header.html:/srv/dex/web/templates/header.html
      - /var/lib/fic/pki/shared/dex-password.tpl:/srv/dex/web/templates/password.html
      - /www/htdocs-frontend/img/fic.png:/srv/dex/web/themes/light/favicon.png
    runtime:
      mkdir:
        - /var/lib/fic/dex
  - name: vouch-proxy
    image: quay.io/vouch/vouch-proxy:alpine-0.39
    env:
      - VOUCH_ALLOWALLUSERS=true
      - VOUCH_COOKIE_DOMAIN=fic.srs.epita.fr
      - VOUCH_DOCUMENT_ROOT=/challenge_access
      - VOUCH_LOGLEVEL=debug
      - OAUTH_PROVIDER=oidc
      - OAUTH_CLIENT_ID=epita-challenge
      - OAUTH_CLIENT_SECRET=N4n7AXzK9kpXt3TmSn8wAgtxqxhGORgcubLaE2g
      - OAUTH_CALLBACK_URL=https://fic.srs.epita.fr/challenge_access/auth
      - OAUTH_AUTH_URL=https://fic.srs.epita.fr/auth
      - OAUTH_TOKEN_URL=http://127.0.0.1:5556/token
      - OAUTH_USER_INFO_URL=http://127.0.0.1:5556/userinfo
      - OAUTH_SCOPES=openid,email
    net: /run/netns/auth


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

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

  - path: etc/init.d/015-setup-sshd
    source: configs/sshd-setup.sh
    mode: "0555"
  - path: etc/init.d/016-copy-dex-config
    contents: |
      #!/bin/sh
      [ -f /var/lib/fic/pki/shared/dex-config.yaml ] || {
          cp /etc/dex/config.auth.yaml /var/lib/fic/pki/shared/dex-config.yaml
      }
      [ -f /var/lib/fic/pki/shared/dex-password.tpl ] || {
          cp /www/dex-templates/templates/password.html /var/lib/fic/pki/shared/dex-password.tpl
      }
    mode: "0555"

  - path: /containers/onboot/000-sysctl/rootfs/etc/sysctl.d/01-fic.conf
    source: configs/sysctl-frontend.conf
    mode: "0444"

  - path: etc/hosts
    source: configs/hosts
    mode: "0644"

  - path: etc/dhcp/dhcpd.conf
    source: configs/dhcpd.conf
    mode: "0400"
  - path: etc/nginx/conf.d/default.conf
    source: configs/nginx/base/prod.conf
    mode: "0400"
  - path: etc/nginx/fic-auth.conf
    source: configs/nginx/auth/oidc.conf
    mode: "0400"
  - path: etc/nginx/fic-get-team.conf
    source: configs/nginx/get-team/oidc.conf
    mode: "0400"
  - path: etc/nginx/conf.d/qa.fic-conf
    contents: |
      location /qa {
          include    fic-get-team.conf;

          proxy_pass        http://deimos:8083;
          proxy_set_header  X-Forwarded-For  $remote_addr;
          proxy_set_header  X-FIC-Team       $team;
          proxy_redirect    off;
      }
    mode: "0400"

  - path: etc/dex/config.auth.yaml
    source: configs/dex.yaml
    mode: "0400"
  - path: www/dex-templates/theme/styles.css
    source: configs/dex-templates/theme/styles.css
    mode: "0444"
  - path: www/dex-templates/templates/header.html
    source: configs/dex-templates/templates/header.html
    mode: "0444"
  - path: www/dex-templates/templates/password.html
    source: configs/dex-templates/templates/password.html
    mode: "0444"

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

  - path: etc/resolv.conf
    contents: |
      nameserver 9.9.9.9
    mode: "0444"

  - path: etc/dhcpcd.conf
    contents: |
      allowinterfaces internet
      hostname
      clientid
      persistent
      option rapid_commit
      option domain_name_servers, domain_name, domain_search, host_name
      option classless_static_routes
      option interface_mtu
      require dhcp_server_identifier
      slaac private
      nodelay
      noarp
      waitip 4
    mode: "0440"
  - path: etc/unbound/unbound.d/tmp-user.conf
    contents: |
        username: ""
    mode: "0440"
#  - path: etc/unbound/unbound.d/forwarder.conf
#    contents: |
#        forward-zone:
#          name: "."
#          forward-addr: 9.9.9.9
#          forward-addr: 1.1.1.1
#    mode: "0440"
  - path: etc/unbound/unbound.d/access-control.conf
    contents: |
        access-control: 172.23.0.0/16 allow
    mode: "0440"
  - path: etc/unbound/unbound.d/local-zone.conf
    contents: |
      local-zone: "srs.epita.fr" typetransparent
      local-data: "fic.srs.epita.fr A 172.23.42.1"
      local-data-ptr: "172.23.42.1 fic.srs.epita.fr"
    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-sshd.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 -i eth2 -s 10.10.10.0/29 -p tcp -m conntrack --ctstate NEW -m tcp --dport ssh -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 -j LOG
      [0:0] -A OUTPUT -j REJECT
      COMMIT
    mode: "0440"
  - path: etc/iptables/rules-frontal.v4
    contents: |
      *nat
      :PREROUTING ACCEPT [0:0]
      :INPUT ACCEPT [0:0]
      :OUTPUT ACCEPT [0:0]
      :POSTROUTING ACCEPT [0:0]
      [0:0] -A POSTROUTING -o internet -j MASQUERADE
      COMMIT
      *filter
      :INPUT DROP [0:0]
      :FORWARD ACCEPT [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 -i bond-frontal -p udp -m udp --dport domain -j ACCEPT
      [0:0] -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
      [0:0] -A INPUT -i bond-frontal -p tcp -m conntrack --ctstate NEW -m tcp --dport domain -j ACCEPT
      [0:0] -A INPUT -i bond-frontal -p tcp -m conntrack --ctstate NEW -m tcp --dport http -j ACCEPT
      [0:0] -A INPUT -i bond-frontal -p tcp -m conntrack --ctstate NEW -m tcp --dport https -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 -o bond-frontal -p udp -m udp --sport domain -j ACCEPT
      [0:0] -A OUTPUT -o bond-frontal -d 9.9.9.9 -p udp -m udp --dport domain -j ACCEPT
      [0:0] -A OUTPUT -o bond-frontal -d 9.9.9.9 -p tcp -m tcp --dport domain -j ACCEPT
      [0:0] -A OUTPUT -o bond-frontal -d 94.23.5.143 -p tcp -m tcp --dport https -j ACCEPT
      [0:0] -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
      [0:0] -A OUTPUT -o vethin-nginx -d 172.17.1.3 -p tcp -m conntrack --ctstate NEW -m tcp --dport 8080 -j ACCEPT
      [0:0] -A OUTPUT -o vethin-nginx -d 172.17.1.4 -p tcp -m conntrack --ctstate NEW -m tcp --dport 5556 -j ACCEPT
      [0:0] -A OUTPUT -o vethin-nginx -d 172.17.1.4 -p tcp -m conntrack --ctstate NEW -m tcp --dport 9090 -j ACCEPT
      [0:0] -A OUTPUT -o internet -j ACCEPT
      [0:0] -A OUTPUT -j LOG
      [0:0] -A OUTPUT -j REJECT
      COMMIT
    mode: "0440"

trust:
  org:
    - linuxkit
    - library
