MCPcopy Create free account
hub / github.com/Netflix/bless / lambda_handler_host

Function lambda_handler_host

bless/aws_lambda/bless_lambda_host.py:19–102  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

17
18
19def lambda_handler_host(
20 event, context=None, ca_private_key_password=None,
21 entropy_check=True,
22 config_file=None):
23 """
24 This is the function that will be called when the lambda function starts.
25 :param event: Dictionary of the json request.
26 :param context: AWS LambdaContext Object
27 http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
28 :param ca_private_key_password: For local testing, if the password is provided, skip the KMS
29 decrypt.
30 :param entropy_check: For local testing, if set to false, it will skip checking entropy and
31 won't try to fetch additional random from KMS.
32 :param config_file: The config file to load the SSH CA private key from, and additional settings.
33 :return: the SSH Certificate that can be written to id_rsa-cert.pub or similar file.
34 """
35 bless_cache = setup_lambda_cache(ca_private_key_password, config_file)
36
37 # Load the deployment config values
38 config = bless_cache.config
39
40 logger = set_logger(config)
41
42 certificate_validity_before_seconds = config.getint(BLESS_OPTIONS_SECTION,
43 SERVER_CERTIFICATE_VALIDITY_BEFORE_SEC_OPTION)
44 certificate_validity_after_seconds = config.getint(BLESS_OPTIONS_SECTION,
45 SERVER_CERTIFICATE_VALIDITY_AFTER_SEC_OPTION)
46
47 ca_private_key = config.getprivatekey()
48
49 # Process cert request
50 schema = BlessHostSchema(strict=True)
51 schema.context[HOSTNAME_VALIDATION_OPTION] = config.get(BLESS_OPTIONS_SECTION, HOSTNAME_VALIDATION_OPTION)
52
53 try:
54 request = schema.load(event).data
55 except ValidationError as e:
56 return error_response('InputValidationError', str(e))
57
58 # todo: You'll want to bring your own hostnames validation.
59 logger.info('Bless lambda invoked by [public_key: {}] for hostnames[{}]'.format(request.public_key_to_sign,
60 request.hostnames))
61
62 # Make sure we have the ca private key password
63 if bless_cache.ca_private_key_password is None:
64 return error_response('ClientError', bless_cache.ca_private_key_password_error)
65 else:
66 ca_private_key_password = bless_cache.ca_private_key_password
67
68 # if running as a Lambda, we can check the entropy pool and seed it with KMS if desired
69 if entropy_check:
70 check_entropy(config, logger)
71
72 # cert values determined only by lambda and its configs
73 current_time = int(time.time())
74 valid_before = current_time + certificate_validity_after_seconds
75 valid_after = current_time - certificate_validity_before_seconds
76

Calls 15

setup_lambda_cacheFunction · 0.90
set_loggerFunction · 0.90
BlessHostSchemaClass · 0.90
error_responseFunction · 0.90
check_entropyFunction · 0.90
success_responseFunction · 0.90
getprivatekeyMethod · 0.80
getMethod · 0.80
add_valid_principalMethod · 0.80
set_valid_beforeMethod · 0.80

Tested by 3

test_basic_local_requestFunction · 0.72
test_invalid_requestFunction · 0.72