Puppet Class: aix_tidy::nfs_options

Defined in:
manifests/nfs_options.pp

Overview

Aix_tidy::Nfs_options

Make sure NFS filesystems are mounted correctly * enforce specific set of options for all mounts * remove all instances of localhost and $fqdn from the exports file

Parameters:

  • options (String) (defaults to: "rw,bg,hard,intr,nosuid,sec=sys")

    Options force these options to exist for every NFS mount in its /etc/filesystems entry

  • default_root_squash (String) (defaults to: "-2")

    Value to set root_squash to if the entry is missing or not allowed

  • default_authentication (String) (defaults to: "sys")

    Value to set sec to if entry is missing or invalid

  • allowed_root_squash_re (String) (defaults to: "-2|-1")

    Quoted regular expression matching allowed values for the root_squash option

  • allowed_security_methods_re (String) (defaults to: "sys|dh|krb5|krb5p")

    Quoted regular expression matching allowed values for the sec option

  • manage_nfs_mounts (Boolean) (defaults to: true)

    True to enfoce the NFS mount options in /etc/filesystems else do nothing

  • manage_local_alias (Boolean) (defaults to: true)

    True to remove localhost and its aliases from the allow option else do nothing

  • manage_missing_access (Boolean) (defaults to: true)

    True to disable any entries that do not contain an access option otherwise do nothing

  • manage_root_squash (Boolean) (defaults to: true)

    True to fix any entries that are missing the root_squash option otherwise do nothing

  • manage_security (Boolean) (defaults to: true)

    True to fix any entries that are missing the sec option otherwise do nothing



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'manifests/nfs_options.pp', line 27

class aix_tidy::nfs_options(
  String  $options                      = "rw,bg,hard,intr,nosuid,sec=sys",
  String  $default_root_squash          = "-2",
  String  $default_authentication       = "sys",
  String  $allowed_root_squash_re       = "-2|-1",
  String  $allowed_security_methods_re  = "sys|dh|krb5|krb5p",
  Boolean $manage_nfs_mounts            = true,
  Boolean $manage_local_alias           = true,
  Boolean $manage_missing_access        = true,
  Boolean $manage_root_squash           = true,
  Boolean $manage_security              = true,
) {

  $exports = "/etc/exports"
  $replace_exports = " > ${exports}.tmp && mv ${exports}.tmp ${exports} && chgrp system ${exports}"

  if $manage_nfs_mounts {
    $nfs_mounts = dig($facts, 'mountpoints').then | $mountpoints | {
      $mountpoints.filter |$index, $values| {
        $values['filesystem'] =~ "nfs"
      }.map |$index, $value| {
        $index
      }
    }

    # enforce correct options for all nfs mounts
    if $nfs_mounts {
      mount { $nfs_mounts:
        options => $options,
      }
    }
  }
  # Ensure we have an exports file to work on...
  file { $exports:
    ensure => file,
    owner  => "root",
    group  => "system",
    mode   => "0644",
  }

  if $manage_local_alias {
    # remove all instances of 'localhost' and $fqdn from access= attribute in
    # /etc/exports - can't do this with augeas since AIX has its own whacked
    # exports format (sigh)
    $local_names_re = "(localhost|${facts['fqdn']}|${facts['hostname']})"
    $remove_localhost_alias =
  "awk '{
  if (match(\$0, /[^#].*access.*${$local_names_re}:?*/))
  	gsub(/${local_names_re}:?/, \"\", \$0);
  print \$0
  }' ${exports} ${replace_exports}"

    exec { "${exports} disable localhost alias":
      command => $remove_localhost_alias,
      onlyif  => "grep -E '^[^#].*access=.*${local_names_re}.*' ${exports}",
      path    => [ '/usr/bin', '/bin'],
      notify  => Exec["exportfs"],
      require => File[$exports]
    }
  }

  if $manage_missing_access {
    # disable all hosts entries lines without explicit access rules
    $comment_no_access =
  "awk '{ if (match(\$0, /[^#].*access=.*/))
  	print \$0
  else
  	print \"#\" \$0
  }' ${exports} ${replace_exports}"

    exec { "${exports} disable missing access":
      command => $comment_no_access,
      onlyif  => "grep -E '^[^#]+' ${exports} | grep -E -v '.*access=.*'",
      path    => [ '/usr/bin', '/bin'],
      notify  => Exec["exportfs"],
      require => File["/etc/exports"],
    }
  }

  if $manage_root_squash {
    # Ensure the root_squash option is set to -2 or -1 for each entry
    $fix_root_squash =
  "awk '{
    if (match(\$0, /[^#].*root_squash=(${allowed_root_squash_re}).*/)) {
    	print \$0
    } else {
      gsub(/,?root_squash=[^,]*/, \"\", \$2)
      printf \$1 \"\\t\" \"root_squash=${default_root_squash}\"
      if (match(\$2, /\\w/)) {
        printf \",\" \$2
      }
      printf \"\\n\"
    }
  }' ${exports} ${replace_exports}"
    exec { "${exports} enforce root squash":
      command => $fix_root_squash,
      onlyif  => "grep -E '^[^#].*root_squash=(${allowed_root_squash_re}).*' ${exports}",
      path    => [ '/usr/bin', '/bin'],
      notify  => Exec["exportfs"],
      require => File["/etc/exports"],
    }

  }

  if $manage_security {
    # Ensure the security option is set for each entry
    $fix_sec =
    "awk '{
      if (match(\$0, /[^#].*sec=(${allowed_security_methods_re}).*/)) {
      	print \$0
      } else {
        gsub(/,?sec=[^,]*/, \"\", \$2)
        printf \$1 \"\\t\" \"sec=${default_authentication}\"
        if (match(\$2, /\\w/)) {
          printf \",\" \$2
        }
        printf \"\\n\"
      }
    }' ${exports} ${replace_exports}"

    exec { "${exports} enforce security method":
      command => $fix_sec,
      onlyif  => "grep -E '^[^#]+' ${exports} | grep -E -v '.*sec=(${allowed_security_methods_re}).*'",
      path    => ['/usr/bin', '/bin'],
      notify  => Exec["exportfs"],
      require => File["/etc/exports"],
    }

  }

  exec { "exportfs":
    command     => "exportfs -a",
    refreshonly => true,
    path        => ['/usr/sbin', '/sbin', '/usr/bin', '/bin'],
  }
}