Inability to decrypt blob passwords only once in a while using amazon kms

import os, sys
AWS_DIRECTORY = '/home/jenkins/.aws'
certificates_folder = 'my_folder'

SUCCESS = 'success'

class AmazonKMS(object):


def __init__(self):
    # making sure boto3 has the certificates and region files
    result = os.system('mkdir -p ' + AWS_DIRECTORY)
    self._check_os_result(result)
    result = os.system('cp ' + certificates_folder + 'kms_config ' + AWS_DIRECTORY + '/config')
    self._check_os_result(result)
    result = os.system('cp ' + certificates_folder + 'kms_credentials ' + AWS_DIRECTORY + '/credentials')
    self._check_os_result(result)


    # boto3 is the amazon client package
    import boto3
    self.kms_client = boto3.client('kms', region_name='us-east-1')
    self.global_key_alias = 'alias/global'
    self.global_key_id = None

def _check_os_result(self, result):
    if result != 0 and raise_on_copy_error:
        raise FAILED_COPY


def decrypt_text(self, encrypted_text):
    response = self.kms_client.decrypt(
        CiphertextBlob = encrypted_text
    )

    return response['Plaintext']

when using amazon_kms = AmazonKMS () amazon_kms.decrypt_text (blob_password)

getting

E   ClientError: An error occurred (AccessDeniedException) when calling the Decrypt operation: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access.

stacktrace -

../keys_management/amazon_kms.py:77: in decrypt_text
    CiphertextBlob = encrypted_text
/home/jenkins/.virtualenvs/global_tests/local/lib/python2.7/site-packages/botocore/client.py:253: in _api_call
    return self._make_api_call(operation_name, kwargs)
/home/jenkins/.virtualenvs/global_tests/local/lib/python2.7/site-packages/botocore/client.py:557: in _make_api_call
    raise error_class(parsed_response, operation_name)

This happens in a script that runs once an hour.

it only works 2-3 times a day.

after retrying.

Tried to upgrade from boto3 1.2.3to1.4.4

What is the possible reason for this behavior?

+4
source share

Source: https://habr.com/ru/post/1675440/


All Articles