prepare_security.sh 1.1 KB
Newer Older
1 2
#!/bin/bash

3
set -u
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

SELINUX="
SELINUX=disabled
"

LIMITS="
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
"

main() {
  if [[ -z ${VERIFY:-} ]]; then
    apply
  else
    verify
  fi
}

apply() {
  echo "Configuring Security"

  echo "$LIMITS" > /etc/security/limits.d/99_overrides.conf
  echo "$SELINUX" > /etc/selinux/config

  disable_iptables

  create_gpadmin

  generate_keys

36 37
  ensure_connectivity

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  echo "Configuration Done"
}

disable_iptables() {
  /sbin/service iptables stop
  /sbin/chkconfig iptables off
}

create_gpadmin() {
  getent passwd gpadmin || useradd -m gpadmin
}

generate_keys() {
  for U in root gpadmin; do
    su $U -c "mkdir -p ~${U}/.ssh"
    su $U -c "[[ -f ~${U}/.ssh/id_rsa ]] || ssh-keygen -N '' -f ~${U}/.ssh/id_rsa"

    su $U -c "touch ~${U}/.ssh/authorized_keys"
    su $U -c "chmod 600 ~${U}/.ssh/authorized_keys"
  done
}

60 61 62 63 64 65
ensure_connectivity() {
  for U in root gpadmin; do
    su $U -c "cat ~$U/.ssh/id_rsa.pub >> ~$U/.ssh/authorized_keys"
  done
}

66 67 68 69 70 71
verify() {
  echo "Running ulimit to verify changes to limits"
  ulimit -a
}

main "$@"