This is the function that will be called when the lambda function starts. :param event: Dictionary of the json request. :param context: AWS LambdaContext Object http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html :param ca_private_key_password: For local testi
(
event, context=None, ca_private_key_password=None,
entropy_check=True,
config_file=None)
| 32 | |
| 33 | |
| 34 | def lambda_handler_user( |
| 35 | event, context=None, ca_private_key_password=None, |
| 36 | entropy_check=True, |
| 37 | config_file=None): |
| 38 | """ |
| 39 | This is the function that will be called when the lambda function starts. |
| 40 | :param event: Dictionary of the json request. |
| 41 | :param context: AWS LambdaContext Object |
| 42 | http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html |
| 43 | :param ca_private_key_password: For local testing, if the password is provided, skip the KMS |
| 44 | decrypt. |
| 45 | :param entropy_check: For local testing, if set to false, it will skip checking entropy and |
| 46 | won't try to fetch additional random from KMS. |
| 47 | :param config_file: The config file to load the SSH CA private key from, and additional settings. |
| 48 | :return: the SSH Certificate that can be written to id_rsa-cert.pub or similar file. |
| 49 | """ |
| 50 | bless_cache = setup_lambda_cache(ca_private_key_password, config_file) |
| 51 | |
| 52 | # AWS Region determines configs related to KMS |
| 53 | region = bless_cache.region |
| 54 | |
| 55 | # Load the deployment config values |
| 56 | config = bless_cache.config |
| 57 | |
| 58 | logger = set_logger(config) |
| 59 | |
| 60 | certificate_validity_before_seconds = config.getint(BLESS_OPTIONS_SECTION, |
| 61 | CERTIFICATE_VALIDITY_BEFORE_SEC_OPTION) |
| 62 | certificate_validity_after_seconds = config.getint(BLESS_OPTIONS_SECTION, |
| 63 | CERTIFICATE_VALIDITY_AFTER_SEC_OPTION) |
| 64 | ca_private_key = config.getprivatekey() |
| 65 | certificate_extensions = config.get(BLESS_OPTIONS_SECTION, CERTIFICATE_EXTENSIONS_OPTION) |
| 66 | |
| 67 | # Process cert request |
| 68 | schema = BlessUserSchema(strict=True) |
| 69 | schema.context[USERNAME_VALIDATION_OPTION] = config.get(BLESS_OPTIONS_SECTION, USERNAME_VALIDATION_OPTION) |
| 70 | schema.context[REMOTE_USERNAMES_VALIDATION_OPTION] = config.get(BLESS_OPTIONS_SECTION, |
| 71 | REMOTE_USERNAMES_VALIDATION_OPTION) |
| 72 | schema.context[REMOTE_USERNAMES_BLACKLIST_OPTION] = config.get(BLESS_OPTIONS_SECTION, |
| 73 | REMOTE_USERNAMES_BLACKLIST_OPTION) |
| 74 | |
| 75 | try: |
| 76 | request = schema.load(event).data |
| 77 | except ValidationError as e: |
| 78 | return error_response('InputValidationError', str(e)) |
| 79 | |
| 80 | logger.info('Bless lambda invoked by [user: {0}, bastion_ips:{1}, public_key: {2}, kmsauth_token:{3}]'.format( |
| 81 | request.bastion_user, |
| 82 | request.bastion_user_ip, |
| 83 | request.public_key_to_sign, |
| 84 | request.kmsauth_token)) |
| 85 | |
| 86 | # Make sure we have the ca private key password |
| 87 | if bless_cache.ca_private_key_password is None: |
| 88 | return error_response('ClientError', bless_cache.ca_private_key_password_error) |
| 89 | else: |
| 90 | ca_private_key_password = bless_cache.ca_private_key_password |
| 91 |