-
Notifications
You must be signed in to change notification settings - Fork 138
Add Service Account Impersonation + Secret Manager Filter #321
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
Open
upodroid
wants to merge
12
commits into
ansible-collections:master
Choose a base branch
from
borg-land:impersonation
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c62d826
Make `iap` field computed (#3814) (#272)
modular-magician 791e725
add source_image and source_snapshot to google_compute_image (#3799) …
modular-magician a6df432
Collection fixes for release (#3831) (#274)
modular-magician 8f8743e
Add new field filter to pubsub. (#3759) (#275)
modular-magician b255304
Add archive class to gcs (#3867) (#276)
modular-magician 74aa87d
Add support for gRPC healthchecks (#3825) (#277)
modular-magician 85e17ee
Add enableMessageOrdering to Pub/Sub Subscription (#3872) (#278)
modular-magician 30b00dc
use {product}.googleapis.com endpoints (#3755) (#279)
modular-magician 3dec692
Removed instances where input and output are both true (#3890) (#280)
modular-magician f997999
retrypolicy attribute added (#3843) (#281)
modular-magician 2bea5e7
add impersonation + kms filters
upodroid aa901b1
Merge branch 'master' of https://github.com/ansible-collections/googl…
upodroid 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,60 @@ | ||
| # (c) 2019, Eric Anderson <[email protected]> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this copyright is incorrect? seems like copy-pasted code from a separate file. It should reflect the author of the code. |
||
| # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
|
||
| # Usage: | ||
| # vars: | ||
| # encrypted_myvar: "{{ var | b64encode | gcp_kms_encrypt(projects='default', | ||
| # key_ring='key_ring', crypto_key='crypto_key') }}" | ||
| # decrypted_myvar: "{{ encrypted_myvar | gcp_kms_decrypt(projects='default', | ||
| # key_ring='key_ring', crypto_key='crypto_key') }}" | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
| __metaclass__ = type | ||
|
|
||
| from ansible.errors import AnsibleError | ||
| from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import GcpSession | ||
|
|
||
|
|
||
| class GcpMockModule(object): | ||
| def __init__(self, params): | ||
| self.params = params | ||
|
|
||
| def fail_json(self, *args, **kwargs): | ||
| raise AnsibleError(kwargs['msg']) | ||
|
|
||
|
|
||
| class GcpSecretFilter(): | ||
| def run(self, method, **kwargs): | ||
| params = { | ||
| 'secret': kwargs.get('secret', None), | ||
| 'versions': kwargs.get('version', 'latest'), | ||
| 'projects': kwargs.get('projects', None), | ||
| 'scopes': kwargs.get('scopes', None), | ||
| 'auth_kind': kwargs.get('auth_kind', 'application'), | ||
| 'service_account_file': kwargs.get('service_account_file', None), | ||
| 'service_account_email': kwargs.get('service_account_email', None), | ||
| } | ||
| if not params['scopes']: | ||
| params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] | ||
| fake_module = GcpMockModule(params) | ||
| if method == "decode": | ||
| return self.secret_decode(fake_module) | ||
|
|
||
| def secret_decode(self, module): | ||
| payload = {"ciphertext": module.params['ciphertext']} | ||
|
|
||
| auth = GcpSession(module, 'secretmanager') | ||
| url = "https://secretmanager.googleapis.com/v1/projects/{projects}/secrets/{secret}/" \ | ||
| "versions/{version}:access".format(**module.params) | ||
| response = auth.get(url, body=payload) | ||
| return response.json()['payload']['data'] | ||
|
|
||
| def gcp_secret_decode(plaintext, **kwargs): | ||
| return GcpKmsFilter().run('decode', plaintext=plaintext, **kwargs) | ||
|
|
||
| class FilterModule(object): | ||
|
|
||
| def filters(self): | ||
| return { | ||
| 'gcp_secret_decode': gcp_secret_decode, | ||
| } | ||
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
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.
this is technically a backwards-incompatible change (the default value of a field changing).
Is there a specific reason this needs to be done in this change?