Skip to content
Snippets Groups Projects
auth.pp 4.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • # @summary
    
    #   Authentication service for the communication module.
    
    #   Sets up the authentication service for the communication module in the
    #   new exam system. Connects to the broker to authenticate users.
    
    #
    #
    # @param keytab_production_base64
    
    #   Keytab contents (in base64) for the Kerberos host key used to authenticate
    #   in the production environment (aes-devel.edu.liu.se).
    
    #
    # @param keytab_devel_base64
    
    #   Keytab contents (in base64) for the Kerberos host key used to authenticate
    #   in the development environment (aes-devel.edu.liu.se).
    
    Mika Perälä's avatar
    Mika Perälä committed
    class aes::auth (
    
      Optional[String] $keytab_production_base64 = undef,
      Optional[String] $keytab_devel_base64 = undef
    
    Magnus Svensson's avatar
    Magnus Svensson committed
    ) {
    
    Magnus Svensson's avatar
    Magnus Svensson committed
      $auth_group = $auth_user
    
      $auth_home = "/srv/${auth_user}"
    
    Magnus Svensson's avatar
    Magnus Svensson committed
      $auth_service = 'aes_auth'
    
      # Decode base64 encoded keytabs
      $keytab_production  = Binary.new($keytab_production_base64, '%b')
      $keytab_devel = Binary.new($keytab_devel_base64, '%b')
    
    
      # Pick the right keytab for the current environment. We use the fqdn rather than 
      # $environment since the keys are tied to the domain name rather than what 
      # environment the machine is configured in.
      if $facts[fqdn] == 'aes.edu.liu.se' {
    
        # The AD service account for this key is: ida_sys002_srv
    
        $auth_keytab_data = $keytab_production
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        $server_type = 'production'
    
      } elsif $facts[fqdn] == 'aes-devel.edu.liu.se' {
    
        # The AD service account for this key is: ida_sys004_srv
    
        $auth_keytab_data = $keytab_devel
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        $server_type = 'devel'
    
        $auth_keytab_data = undef
    
      # Note: We rely on Boost being installed by the broker. It seems Puppet does not like
      # that we specify "boost" multiple times, even though it would look nice, modularity-wise
      # since both the auth server and the broker requires boost.
    
    Magnus Svensson's avatar
    Magnus Svensson committed
          'krb5-libs',
          'krb5-devel',
          'openssl-devel',
    
      # Group for local authentication. All accounts that are members
      # of this group are considered trusted by the authentication system.
    
    Magnus Svensson's avatar
    Magnus Svensson committed
      group { 'aes_local_auth' :
        ensure => present,
    
    Magnus Svensson's avatar
    Magnus Svensson committed
      user { $auth_user :
        ensure     => present,
        home       => $auth_home,
        comment    => 'Authentication server for AES',
    
        managehome => false,
        membership => inclusive,
    
    Mika Perälä's avatar
    Mika Perälä committed
        groups     => ['aes_local_auth'],
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        system     => true,
        shell      => '/sbin/nologin',
    
    Magnus Svensson's avatar
    Magnus Svensson committed
      file { $auth_home :
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        owner  => $auth_user,
        group  => $auth_group,
        mode   => '0755',
    
      }
    
      file { "/etc/systemd/system/${auth_service}.service" :
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        ensure => file,
    
        owner  => root,
        group  => root,
        mode   => '0644',
        source => "puppet:///modules/${module_name}/auth/auth.service",
      }
    
      file { "${auth_home}/on_update.sh" :
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        ensure => file,
    
        owner  => $auth_user,
        group  => $auth_group,
        mode   => '0755',
    
        source => "puppet:///modules/${module_name}/auth/on_update.sh",
      }
    
      file { "${auth_home}/config.json" :
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        ensure => file,
        owner  => $auth_user,
        group  => $auth_group,
    
        mode   => '0644',
        source => "puppet:///modules/${module_name}/auth/config.json",
      }
    
      file { "${auth_home}/start.sh" :
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        ensure => file,
        owner  => $auth_user,
        group  => $auth_group,
    
        mode   => '0755',
        source => "puppet:///modules/${module_name}/auth/start.sh",
      }
    
    
      file { "${auth_home}/keys" :
        ensure => directory,
    
    Magnus Svensson's avatar
    Magnus Svensson committed
        owner  => $auth_user,
        group  => $auth_group,
        mode   => '0700',
    
      if $auth_keytab_data {
        file { "${auth_home}/keys/kerberos.keytab" :
    
    Magnus Svensson's avatar
    Magnus Svensson committed
          ensure  => file,
          owner   => root,
          group   => $auth_group,
          mode    => '0640',
          content => $auth_keytab_data,
    
      vcsrepo { "${auth_home}/src":
        ensure   => latest,
        provider => git,
        source   => 'https://oauth2:F-agHaRXCdyFy38q4c-N@gitlab.liu.se/upp-aes/communication.git',
        revision => $server_type,
        owner    => $auth_user,
        group    => $auth_group,
        notify   => Exec['compile-auth-repo'],
      }
    
      exec { 'compile-auth-repo':
        user        => $auth_user,
        group       => $auth_group,
    
        cwd         => $auth_home,
        path        => '/bin:/usr/bin',
    
        command     => "${auth_home}/on_update.sh",
    
        environment => ["HOME=${auth_home}"],
    
        refreshonly => true,
    
        require     => File["${auth_home}/on_update.sh"],
    
        notify      => Service[$auth_service],
    
    Magnus Svensson's avatar
    Magnus Svensson committed
      service { $auth_service :
        ensure => 'running',
    
        enable => true,
    
    Magnus Svensson's avatar
    Magnus Svensson committed
    }