Defined Type: secrets::file
- Defined in:
- manifests/file.pp
Summary
Manages a file with sensitive content, optional POSIX ACLs, and SELinux context attributes.Overview
The namevar is a logical descriptor (e.g. ‘krb5 keytab for host foo’). Set $path explicitly when the title is descriptive rather than a file path. Defaults to $title when $title is an absolute path. Will always produce a File resource
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 |
# File 'manifests/file.pp', line 66
define secrets::file (
Variant[String, Sensitive[String]] $content,
Variant[String,Integer] $owner = 'root',
Variant[String,Integer] $group = 'root',
Array $notify_services = [],
Hash $posix_acl = {},
Boolean $selinux_ignore_defaults = false,
Optional[Stdlib::Absolutepath] $path = undef,
# lint:ignore:optional_default
Optional[Pattern[/^[0-7]{4}$/]] $mode = '0400',
# lint:endignore
Optional[String[1]] $seluser = undef,
Optional[String[1]] $selrole = undef,
Optional[String[1]] $seltype = undef,
Optional[String[1]] $selrange = undef,
) {
# Resolve target path: explicit $path wins, else $title must be absolute.
$_path = pick($path, $title)
assert_type(Stdlib::Absolutepath, $_path) |$expected, $actual| {
fail("secrets::file[${title}]: 'path' must be an absolute path; got '${_path}'")
}
# show_diff and backup are hardcoded. Leaking secrets into reports or the
# filebucket is not a recoverable mistake.
file { $_path:
ensure => 'file',
owner => $owner,
group => $group,
mode => $mode,
content => Sensitive($content.unwrap),
seluser => $seluser,
selrole => $selrole,
seltype => $seltype,
selrange => $selrange,
selinux_ignore_defaults => $selinux_ignore_defaults,
force => true,
show_diff => false,
backup => false,
}
unless empty($notify_services) {
File[$_path] ~> $notify_services.map |$srv| { Service <| title == $srv |> }
}
unless empty($posix_acl) {
$my_acls = { $_path => $posix_acl }
create_resources(posix_acl, $my_acls, { 'require' => File[$_path] })
}
}
|