Skip to content

Commit 80f3c1b

Browse files
Merge pull request #95 from russell-lewis/release-prep
Release prep
2 parents c03b8d1 + a207d1b commit 80f3c1b

3 files changed

Lines changed: 82 additions & 2 deletions

File tree

bless/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"sign SSH public keys.")
1010
__uri__ = "https://github.com/Netflix/bless"
1111

12-
__version__ = "0.3.0"
12+
__version__ = "0.4.0"
1313

1414
__author__ = "The BLESS developers"
1515
__email__ = "security@netflix.com"

bless/request/bless_request_host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BlessHostRequest:
5252
def __init__(self, hostnames, public_key_to_sign):
5353
"""
5454
A BlessRequest must have the following key value pairs to be valid.
55-
:param hostnames: Comma-separated list of hostnames (s) to include in this host certificate.
55+
:param hostnames: Comma-separated list of hostname(s) to include in this host certificate.
5656
:param public_key_to_sign: The id_XXX.pub that will be used in the SSH request. This is enforced in the issued certificate.
5757
"""
5858
self.hostnames = hostnames

bless_client/bless_client_host.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
3+
"""bless_client
4+
A sample client to invoke the BLESS Host SSH Cert Lambda function and save the signed SSH Certificate.
5+
6+
Usage:
7+
bless_client_host.py region lambda_function_name hostnames <id_rsa.pub to sign> <output id_rsa-cert.pub>
8+
9+
region: AWS region where your lambda is deployed.
10+
11+
lambda_function_name: The AWS Lambda function's alias or ARN to invoke.
12+
13+
hostnames: Comma-separated list of hostname(s) to include in this host certificate.
14+
15+
id_rsa.pub to sign: The id_rsa.pub that will be used in the SSH request. This is
16+
enforced in the issued certificate.
17+
18+
output id_rsa-cert.pub: The file where the certificate should be saved. Per man SSH(1):
19+
"ssh will also try to load certificate information from the filename
20+
obtained by appending -cert.pub to identity filenames" e.g. the <id_rsa.pub to sign>.
21+
"""
22+
import json
23+
import os
24+
import stat
25+
import sys
26+
27+
import boto3
28+
29+
30+
def main(argv):
31+
if len(argv) != 5:
32+
print(
33+
'Usage: bless_client_host.py region lambda_function_name hostnames <id_rsa.pub to sign> '
34+
'<output id_rsa-cert.pub>')
35+
print(len(argv))
36+
return -1
37+
38+
region, lambda_function_name, hostnames, public_key_filename, certificate_filename = argv
39+
40+
with open(public_key_filename, 'r') as f:
41+
public_key = f.read().strip()
42+
43+
payload = {'hostnames': hostnames, 'public_key_to_sign': public_key}
44+
45+
payload_json = json.dumps(payload)
46+
47+
print('Executing:')
48+
print('payload_json is: \'{}\''.format(payload_json))
49+
lambda_client = boto3.client('lambda', region_name=region)
50+
response = lambda_client.invoke(FunctionName=lambda_function_name,
51+
InvocationType='RequestResponse', LogType='None',
52+
Payload=payload_json)
53+
print('{}\n'.format(response['ResponseMetadata']))
54+
55+
if response['StatusCode'] != 200:
56+
print('Error creating cert.')
57+
return -1
58+
59+
payload = json.loads(response['Payload'].read())
60+
61+
if 'certificate' not in payload:
62+
print(payload)
63+
return -1
64+
65+
cert = payload['certificate']
66+
67+
with os.fdopen(os.open(certificate_filename, os.O_WRONLY | os.O_CREAT, 0o600),
68+
'w') as cert_file:
69+
cert_file.write(cert)
70+
71+
# If cert_file already existed with the incorrect permissions, fix them.
72+
file_status = os.stat(certificate_filename)
73+
if 0o600 != (file_status.st_mode & 0o777):
74+
os.chmod(certificate_filename, stat.S_IRUSR | stat.S_IWUSR)
75+
76+
print('Wrote Certificate to: ' + certificate_filename)
77+
78+
79+
if __name__ == '__main__':
80+
main(sys.argv[1:])

0 commit comments

Comments
 (0)