Skip to content

Commit f5ded51

Browse files
committed
Support specifying the principals in use
Allows you to change or add the user names that the user using this certificate is allowed to use. If you got creative with your systems you could use this to very finely control which nodes a certificate granted you access to.
1 parent 6f2d98a commit f5ded51

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

scripts/sign_key

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ if __name__ == '__main__':
3636

3737
parser = argparse.ArgumentParser(__doc__)
3838
parser.add_argument('-a', '--authority', dest='authority',
39-
default=default_authority, help='Pick one: s3')
39+
default=default_authority, help='Pick one: s3')
4040
parser.add_argument('-c', '--config', dest='config_file',
41-
default=default_config,
42-
help='The configuration file to use. Can also be '
43-
'specified in the SSH_CA_CONFIG environment '
44-
'variable. Default: %(default)s')
41+
default=default_config,
42+
help='The configuration file to use. Can also be '
43+
'specified in the SSH_CA_CONFIG environment '
44+
'variable. Default: %(default)s')
4545
parser.add_argument('-e', '--environment', required=True,
46-
help='Environment name')
46+
help='Environment name')
47+
parser.add_argument('--principal', action='append',
48+
help='A principal (username) that the user is allowed to use',)
4749
parser.add_argument(
4850
'-p', help='Path to public key. If set we try to upload this. '
4951
'Otherwise we try to download one.',
@@ -120,9 +122,14 @@ if __name__ == '__main__':
120122
print 'Reason is way too long. Type less.'
121123
sys.exit(1)
122124

125+
if args.principal:
126+
principal = args.principal
127+
else:
128+
principal = ['ec2-user', 'ubuntu']
129+
123130
# Sign the key
124-
cert_contents = ca.sign_public_key(
125-
public_path, username, args.expires_in, reason)
131+
cert_contents = ca.sign_public_user_key(
132+
public_path, username, args.expires_in, reason, principal)
126133

127134
print
128135
print 'Public key signed, certificate available for download here:'

ssh_ca/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def get_public_key(self, username, environment):
3737
def increment_serial_number(self):
3838
pass
3939

40-
def make_audit_log(
41-
self, serial, valid_for, username, ca_key_filename, reason):
40+
def make_audit_log(self,
41+
serial, valid_for, username, ca_key_filename, reason, principals):
4242
pass
4343

4444
def upload_public_key(self, username, public_path):
4545
pass
4646

47-
def sign_public_key(
48-
self, public_key_filename, username, expires_in, reason):
47+
def sign_public_user_key(self,
48+
public_key_filename, username, expires_in, reason, principals):
4949
serial = self.increment_serial_number()
5050

5151
subprocess.check_output([
@@ -54,10 +54,11 @@ def sign_public_key(
5454
'-s', self.ca_key,
5555
'-I', username,
5656
'-V', expires_in,
57-
'-n', 'ubuntu,ec2-user',
57+
'-n', ','.join(principals),
5858
public_key_filename])
5959

60-
self.make_audit_log(serial, expires_in, username, self.ca_key, reason)
60+
self.make_audit_log(
61+
serial, expires_in, username, self.ca_key, reason, principals)
6162

6263
if public_key_filename.endswith('.pub'):
6364
public_key_filename = public_key_filename[:-4]

ssh_ca/s3.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def upload_public_key_cert(self, username, cert_contents):
6969
)
7070
return k.generate_url(7200)
7171

72-
def make_audit_log(
73-
self, serial, valid_for, username, ca_key_filename, reason):
72+
def make_audit_log(self,
73+
serial, valid_for, username, ca_key_filename, reason, principals):
7474
timestamp = datetime.datetime.strftime(
7575
datetime.datetime.utcnow(), '%Y-%m-%d-%H:%M:%S.%f')
7676
k = self.ssh_bucket.new_key('audit_log/%d.json' % (serial,))
@@ -82,5 +82,6 @@ def make_audit_log(
8282
'access_key': self.s3_conn.access_key,
8383
'ca_key_filename': ca_key_filename,
8484
'reason': reason,
85+
'principals': principals,
8586
}
8687
k.set_contents_from_string(json.dumps(audit_info))

0 commit comments

Comments
 (0)