Skip to content

Commit a7fc1a9

Browse files
committed
feat(facts): add facts about certificates
Add readme entry for facts Add readme entry puppet function
1 parent 0b7b620 commit a7fc1a9

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,27 @@ letsencrypt::renew_deploy_hook_commands:
347347
- '...'
348348
```
349349

350+
## Facts
351+
352+
Facts about your live certificates are available through facter. You can query the list of live certificates from puppet using `$::letsencrypt_directory` in your puppet code, hiera data or from the command line.
353+
354+
```
355+
facter -p letsencrypt_directory
356+
{
357+
legacyfiles.ijc.org => "/etc/letsencrypt/live/legacyfiles.ijc.org",
358+
static.ijc.org => "/etc/letsencrypt/live/static.ijc.org",
359+
ijc.org => "/etc/letsencrypt/live/ijc.org",
360+
new.ijc.org => "/etc/letsencrypt/live/new.ijc.org",
361+
www.ijc.org => "/etc/letsencrypt/live/ijc.org",
362+
training.ijc.org => "/etc/letsencrypt/live/training.ijc.org"
363+
}
364+
```
365+
366+
## Puppet Functions
367+
368+
This module profiles a custom puppet function `letsencrypt_lookup` which allows you to load information about your certificates into puppet.
369+
This returns the same information as in the facts but for a particular domain. It accepts a single argument for your domain or wildcard domain.
370+
350371
## Development
351372
352373
1. Fork it
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'openssl'
2+
require 'pathname'
3+
4+
Facter.add(:letsencrypt_directory) do
5+
confine kernel: %w[FreeBSD Linux OpenBSD]
6+
7+
setcode do
8+
certs = {}
9+
10+
# locate the certificate repository
11+
livedir = ['/etc/letsencrypt/live', '/etc/certbot/live'].
12+
map { |path| Pathname.new path }.
13+
find(&:directory?)
14+
15+
unless livedir.nil?
16+
Pathname.new(livedir).children.select(&:directory?).each do |path|
17+
pem = File.join(path, 'cert.pem')
18+
cert = OpenSSL::X509::Certificate.new(File.new(pem).read)
19+
san = cert.extensions.find { |e| e.oid == 'subjectAltName' }
20+
names = san.value.split(',').map { |entry| entry.split(':')[1] }
21+
names.each do |n|
22+
certs[n] = path.to_s
23+
end
24+
end
25+
end
26+
27+
certs
28+
end
29+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Puppet::Functions.create_function(:letsencrypt_lookup) do
2+
def letsencrypt_lookup(cn)
3+
domain = cn.split('.', 2)[1]
4+
wildcard = "*.#{domain}"
5+
certs = closure_scope['facts'].fetch('letsencrypt_directory', nil)
6+
certs.fetch(cn, certs.fetch(wildcard, nil)) unless certs.nil?
7+
end
8+
end

0 commit comments

Comments
 (0)