Skip to content
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 azure KMS as another option in refs #410

Closed
wants to merge 4 commits into from

Conversation

anirban1c
Copy link

Fixes issue #
Add azure kms as another backend as described here
https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-keys#cryptographic-operations

this requires a key vault with a key and a service principal with - GET, ENCRYPT and DECRYPT added to it

Proposed Changes

add another module azkms
update cli with --vault option
add in azure pip dependencies

TODO: add a test module for azkms

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

.gitignore Outdated Show resolved Hide resolved
kapitan/cli.py Outdated Show resolved Hide resolved
kapitan/cli.py Outdated Show resolved Hide resolved
kapitan/cli.py Outdated Show resolved Hide resolved

logger = logging.getLogger(__name__)

# We are using default credentials as defined in the link:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good candidate have in documentation instead of comments. I'd suggest adding this and any other needed docs for azkms to docs/secrets.md :) That way they are also searchable/indexed in the website https://kapitan.dev

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

kapitan/refs/secrets/azkms.py Outdated Show resolved Hide resolved
kapitan/refs/secrets/azkms.py Show resolved Hide resolved
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@anirban1c
Copy link
Author

@googlebot I signed it!

kapitan/cli.py Outdated
secret_obj = AzureKMSSecret(data, vault, key, encode_base64=args.base64)
raise KapitanError("No KMS vault specified. Use --azure-vault or specify it in parameters.kapitan.secrets.azkms.vault and use --target-name")
if not encryption_algorithm:
raise KapitanError("No KMS vault specified. Use --azure-key-algo or specify it in parameters.kapitan.secrets.azkms.vault and use --target-name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No KMS Key algorithm specified* The msg here should be updated.

Copy link
Contributor

@uberspot uberspot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good! 👍
Don't forget to add some docs under docs/secrets.md.

kapitan/cli.py Show resolved Hide resolved
kapitan/cli.py Outdated
#
# Azure KMS marker -- remove it
#
# TODO: same key but in a different vault (check ..)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO should either be fixed before merging or be more detailed so that if needed someone else can also take over. :)

rsa_oaep_256 = "RSA-OAEP-256"
rsa1_5 = "RSA1_5"

# an old classic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In comments, we need an explanation of what the code below does or other edge cases.
This comment seems unclear.

# an old classic
@staticmethod
def value_of(value):
for m, mm in EncryptionAlgorithm.__members__.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is m and what is mm in this context?
One of them is algorithm members probably. But it helps readability a lot if we use longer-named variables here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _attribute_name, _ in EncryptionAlgorithm.members.items():

@uberspot
Copy link
Contributor

----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_binary
Traceback (most recent call last):
  File "/opt/python/3.7.1/lib/python3.7/unittest/loader.py", line 434, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/python/3.7.1/lib/python3.7/unittest/loader.py", line 375, in _get_module_from_name
    __import__(name)
  File "/home/travis/build/deepmind/kapitan/tests/test_binary.py", line 29, in <module>
    from kapitan.cli import main
  File "/home/travis/build/deepmind/kapitan/kapitan/cli.py", line 37, in <module>
    from kapitan.refs.secrets.azkms import AzureKMSSecret
  File "/home/travis/build/deepmind/kapitan/kapitan/refs/secrets/azkms.py", line 29, in <module>
    from azure.keyvault.keys import KeyClient
ModuleNotFoundError: No module named 'azure.keyvault.keys'

Travis is failing because No module named 'azure.keyvault.keys'
Is there a pip dependency missing from requirements.txt?
I might be wrong but https://docs.microsoft.com/en-us/python/api/overview/azure/key-vault?view=azure-python mentions using from azure.keyvault import KeyVaultClient instead?

# See the License for the specific language governing permissions and
# limitations under the License.

"gkms secrets module"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to azkms

"""
#TODO : import the module so that it depends on

rsa_oaep = "RSA-OAEP"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not turn this into a dict?

# an old recepie using java style attribuet access for Enum's
@staticmethod
def value_of(value):
for _attribute_name, _ in EncryptionAlgorithm.__members__.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use dict instead?

@pievalentin
Copy link

Would be interested in seeing this merged. Is forking and doing a PR good practice?

@uberspot
Copy link
Contributor

uberspot commented Dec 2, 2019

If you maintain the other authors' commits I don't see why not. :)

@ramaro ramaro closed this Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants