Puppet Function: ssl_ciphersuite

Defined in:
puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb
Function type:
Ruby 3.x API

Overview

ssl_ciphersuite()Any

Outputs the ssl configuration part of the webserver config. Function parameters are:

server - either nginx or apache
encryption_type - strong, mid, or compat
hsts - optional boolean, true emits our standard public HSTS

Examples:

ssl_ciphersuite('apache', 'compat', true) # Compatible config for apache
ssl_ciphersuite('apache', 'mid', true) # FS-only for apache
ssl_ciphersuite('nginx', 'strong', true) # FS-only, AEAD-only, TLSv1.2-only

Returns:

  • (Any)


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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb', line 124

newfunction(
            :ssl_ciphersuite,
            :type => :rvalue,
            :doc  => <<-END
Outputs the ssl configuration part of the webserver config.
Function parameters are:
 server - either nginx or apache
 encryption_type - strong, mid, or compat
 hsts - optional boolean, true emits our standard public HSTS

Examples:

 ssl_ciphersuite('apache', 'compat', true) # Compatible config for apache
 ssl_ciphersuite('apache', 'mid', true) # FS-only for apache
 ssl_ciphersuite('nginx', 'strong', true) # FS-only, AEAD-only, TLSv1.2-only
END
            ) do |args|

  Puppet::Parser::Functions.function(:os_version)
  Puppet::Parser::Functions.function(:notice)

  if args.length < 2 || args.length > 3
    fail(ArgumentError, 'ssl_ciphersuite() requires at least 2 arguments')
  end

  server = args.shift
  if server != 'apache' && server != 'nginx'
    fail(ArgumentError, "ssl_ciphersuite(): unknown server string '#{server}'")
  end

  ciphersuite = args.shift
  unless ciphersuites.key?(ciphersuite)
    fail(ArgumentError, "ssl_ciphersuite(): unknown ciphersuite '#{ciphersuite}'")
  end

  do_hsts = false
  if args.length == 1
    do_hsts = args.shift
  end

  # OS / Server -dependant feature flags:
  nginx_always_ok = true
  dhe_ok = true
  libssl_has_x25519 = true
  if !function_os_version(['debian >= jessie'])
    nginx_always_ok = false
    libssl_has_x25519 = false
    if server == 'apache'
      dhe_ok = false
    end
  end

  if !dhe_ok && ciphersuite != 'compat'
    function_notice([
      'ssl_ciphersuite(): OS needs upgrade to Jessie!  Downgrading SSL ciphersuite to "compat"'
    ])
    ciphersuite = 'compat'
  end

  if dhe_ok
    cipherlist = ciphersuites[ciphersuite].join(":")
  else
    cipherlist = ciphersuites[ciphersuite].reject{|x| x =~ /^(DHE|EDH)-/}.join(":")
  end

  output = []

  if server == 'apache'
    if ciphersuite == 'strong'
      output.push('SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1')
    else
      output.push('SSLProtocol all -SSLv2 -SSLv3')
    end
    output.push("SSLCipherSuite #{cipherlist}")
    # Note: missing config to restrict ECDH curves
    output.push('SSLHonorCipherOrder On')
    if dhe_ok
      output.push('SSLOpenSSLConfCmd DHParameters "/etc/ssl/dhparam.pem"')
    end
    if do_hsts
      output.push("Header always set Strict-Transport-Security \"#{hsts_val}\"")
    end
  else # nginx
    if ciphersuite == 'strong'
      output.push('ssl_protocols TLSv1.2;')
    else
      output.push('ssl_protocols TLSv1 TLSv1.1 TLSv1.2;')
    end
    output.push("ssl_ciphers #{cipherlist};")
    if libssl_has_x25519
      output.push("ssl_ecdh_curve X25519:prime256v1;")
    else
      output.push("ssl_ecdh_curve prime256v1;")
    end
    output.push('ssl_prefer_server_ciphers on;')
    if dhe_ok
      output.push('ssl_dhparam /etc/ssl/dhparam.pem;')
    end
    if do_hsts
      if nginx_always_ok
          output.push("add_header Strict-Transport-Security \"#{hsts_val}\" always;")
      else
          output.push("add_header Strict-Transport-Security \"#{hsts_val}\";")
      end
    end
  end
  return output
end