-
-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: type/provider to manage secrets #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
trefzer
wants to merge
10
commits into
voxpupuli:master
Choose a base branch
from
cirrax:dev_cirrax
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f38e5e8
add quadlets_secret type and provider
trefzer 3c9a152
add quadlets_secrets for hiera to init.pp
trefzer aff6a2d
add acceptance tests
trefzer 81982b2
add spec test for quadlets_secret type
trefzer 05c15cd
update REFERENCE.md
trefzer e8b6ea1
add secret examples to README
trefzer f1d5d36
fix rubocop rants
trefzer ddd353c
fix acceptance tests
trefzer 64deaa2
add acceptance tests workaround
trefzer 9fe3dbd
acceptance tests, remove user secrets, since user do not seem to ling…
trefzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # | ||
| # This file contains a provider for the resource type `libvirt_nwfilter`, | ||
| # | ||
|
|
||
| require 'json' | ||
|
|
||
| Puppet::Type.type(:quadlets_secret).provide(:podman) do | ||
| desc "@summary provider for the resource type `quadlets_secret`, | ||
| which manages quadlet secrets | ||
| using the podman command." | ||
|
|
||
| commands podman: 'podman' | ||
|
|
||
| def should_user | ||
| @should_user || @should_user = resource[:name].split(':')[0] | ||
| end | ||
|
|
||
| def should_secretname | ||
| @should_secretname || @should_secretname = resource[:name].split(':')[1] | ||
| end | ||
|
|
||
| def hash_to_array(inhash) | ||
| res = [] | ||
| if inhash | ||
| inhash.keys.sort.each do |k| | ||
| res << "#{k}=#{inhash[k]}" | ||
| end | ||
| end | ||
| res | ||
| end | ||
|
|
||
| def run_podman(args, env = {}) | ||
| user_info = Etc.getpwnam(should_user) | ||
| runenv = { | ||
| cwd: user_info.dir, | ||
| failonfail: true, | ||
| uid: user_info.uid, | ||
| gid: user_info.gid, | ||
| combine: false, | ||
| custom_environment: env.merge({ 'HOME' => user_info.dir, 'XDG_RUNTIME_DIR' => "/run/user/#{user_info.uid}" }) | ||
| } | ||
| # test if user is logged in or lingering: | ||
| raise Puppet::Error, "user #{should_user} is not logged in, consider enable linger." unless File.directory?("/run/user/#{user_info.uid}") | ||
|
|
||
| execute([command('podman')] + args, runenv) | ||
| end | ||
|
|
||
| def create_secret(replace) | ||
| args = ['secret', 'create', should_secretname, '--env', 'psecret'] | ||
|
|
||
| if replace | ||
| args << "-d=#{@result['Spec']['Driver']['Name']}" | ||
| hash_to_array(@result['Spec']['Driver']['Options']).each do |d| | ||
| args << "--driver-opts=#{d}" | ||
| end | ||
| args << '--replace' | ||
| else | ||
| args << "-d=#{@resource[:driver]}" | ||
| hash_to_array(resource[:doptions]).each do |d| | ||
| args << "--driver-opts=#{d}" | ||
| end | ||
| end | ||
|
|
||
| resource[:labels]&.split('|')&.each do |l| | ||
| args << "-l=#{l}" | ||
| end | ||
|
|
||
| run_podman(args, { 'psecret' => @resource[:secret] }) | ||
| end | ||
|
|
||
| def create | ||
| create_secret(false) | ||
| end | ||
|
|
||
| def destroy | ||
| run_podman(['secret', 'rm', should_secretname]) | ||
| end | ||
|
|
||
| def labels=(_label) | ||
| create_secret(true) | ||
| end | ||
|
|
||
| def labels | ||
| hash_to_array(@result['Spec']['Labels']).join('|') if @result | ||
| end | ||
|
|
||
| def secret=(_secret) | ||
| create_secret(true) | ||
| end | ||
|
|
||
| def secret | ||
| @result['SecretData'] if @result | ||
| end | ||
|
|
||
| def exists? | ||
| begin | ||
| res = run_podman(['secret', 'inspect', should_secretname, '--showsecret']) | ||
| rescue Puppet::ExecutionFailure | ||
| return false | ||
| end | ||
| @result = JSON.parse(res)[0] | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Puppet::Type.newtype(:quadlets_secret) do | ||
| desc <<~DESC | ||
| Type for managing podman secrets (per user) | ||
|
|
||
| @example Define a secret mysecret for user blah | ||
| quadlets_secret{ 'blah:mysecret': | ||
| secret => '***secret***', | ||
| } | ||
| DESC | ||
|
|
||
| ensurable | ||
|
|
||
| newparam(:name, namevar: true) do | ||
| desc 'combination of user:secretname of the secret to administrate' | ||
|
|
||
| newvalues(%r{^\S+:\S+}) | ||
| end | ||
|
|
||
| newparam(:driver) do | ||
| desc 'driver to be used for secret creation' | ||
| defaultto 'file' | ||
| end | ||
|
|
||
| newparam(:doptions) do | ||
| desc 'driver options used for secret creation' | ||
| defaultto({}) | ||
|
|
||
| validate do |value| | ||
| raise ArgumentError, 'needs to be a Hash' unless value.is_a?(Hash) | ||
| end | ||
| end | ||
|
|
||
| newproperty(:labels) do | ||
| desc 'secret labels to set' | ||
| defaultto({}) | ||
|
|
||
| validate do |value| | ||
| raise ArgumentError, 'needs to be a Hash' unless value.is_a?(Hash) | ||
| end | ||
|
|
||
| munge do |value| | ||
| res = [] | ||
| value.keys.sort.each do |k| | ||
| res << "#{k}=#{value[k]}" | ||
| end | ||
| return res.join('|') | ||
| end | ||
| end | ||
|
|
||
| newproperty(:secret) do | ||
| desc 'the secret himself' | ||
|
|
||
| validate do |value| | ||
| raise ArgumentError, 'needs to be a string' unless value.is_a?(String) | ||
| end | ||
|
|
||
| def should_to_s(_value) | ||
| '*****' | ||
| end | ||
|
|
||
| def is_to_s(_value) | ||
| '*****' | ||
| end | ||
| end | ||
|
|
||
| autorequire(:class) { 'quadlets' } | ||
|
|
||
| autorequire(:user) do | ||
| [self[:name].split(':')[0]] | ||
| end | ||
|
|
||
| autorequire(:loginctl_user) do | ||
| [self[:name].split(':')[0]] | ||
| end | ||
|
|
||
| autorequire(:package) do | ||
| ['podman'] | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we uninventing composite namevars here?