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
Add lookup plugin option (file_mode) to store secret in a file #51
Merged
diverdane
merged 6 commits into
cyberark:master
from
jcosteatcyberark:feature/lookup-secret-in-file
Dec 16, 2020
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9cd442f
Add lookup option to store the secret in file and returns its path.
jcosteatcyberark ad5862b
Add new file_mode option in CHANGELOG.md.
jcosteatcyberark 82bc6ca
Add unit test for newly added file_mode option.
jcosteatcyberark 501df6a
Various fixes from PR feedback.
jcosteatcyberark 7402d1f
Improve retrieve-into-file test code readability.
jcosteatcyberark 7271d12
Add an example for the as_file lookup parameter in README.md.
jcosteatcyberark File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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
1 change: 1 addition & 0 deletions
1
tests/conjur_variable/test_cases/retrieve-variable-into-file/env
This file contains 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 @@ | ||
export CONJUR_CERT_FILE=./conjur.pem |
14 changes: 14 additions & 0 deletions
14
tests/conjur_variable/test_cases/retrieve-variable-into-file/playbook.yml
This file contains 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,14 @@ | ||
--- | ||
- name: Retrieve Conjur variable into file | ||
hosts: localhost | ||
connection: local | ||
tasks: | ||
- name: Clean artifact path | ||
file: | ||
state: absent | ||
path: /conjur_secret_path.txt | ||
|
||
- name: Retrieve Conjur variable into file using as_file option | ||
vars: | ||
secret_path: "{{lookup('conjur_variable', 'ansible/test-secret-in-file', as_file=True)}}" | ||
shell: echo "{{secret_path}}" > /conjur_secret_path.txt |
21 changes: 21 additions & 0 deletions
21
tests/conjur_variable/test_cases/retrieve-variable-into-file/tests/test_default.py
This file contains 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,21 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
|
||
__metaclass__ = type | ||
|
||
import os | ||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = [os.environ['COMPOSE_PROJECT_NAME'] + '_ansible_1'] | ||
|
||
|
||
def test_retrieved_secret(host): | ||
secret_path_file = host.file('/conjur_secret_path.txt') | ||
assert secret_path_file.exists | ||
|
||
secret_path = host.check_output("cat /conjur_secret_path.txt", shell=True) | ||
secret_file = host.file(secret_path) | ||
assert secret_file.exists | ||
assert secret_file.mode == 0o600 | ||
|
||
secret = host.check_output("cat {0}".format(secret_path), shell=True) | ||
assert secret == "test_secret_in_file_password" |
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.
@jcosteatcyberark, just for my own understanding... Can you explain what this line is doing? I know it's doing a level of indirection (taking
secret_path
andcat
ing the file that it points to), but I'd like to understand better.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.
Hi @diverdane, the test playbook stores the lookup output in
/conjur_secret_path.txt
. This file contains the path to the file that contains the secret (secret_path
).To resume this test asserts that
cat (cat /conjur_secret_path) = secret
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.
since it wasn't clear to Dane from the code, is it worth writing this in a more-verbose-but-more-clear way or at least adding a code comment?
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.
Hi @izgeri I cleaned up the code and commented. It should be easier to understand now.