2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-06-24 08:11:01 +00:00

Draft attempt at a tlscert self api

This commit is contained in:
Jarrod Johnson
2026-06-22 16:40:45 -04:00
parent 701a9a7268
commit d3f3242eea
+29
View File
@@ -7,6 +7,8 @@ import confluent.netutil as netutil
import confluent.noderange as noderange
import confluent.sshutil as sshutil
import confluent.util as util
from confluent import certutil
import ipaddress
import confluent.discovery.handlers.xcc as xcc
import confluent.discovery.handlers.tsm as tsm
import confluent.discovery.core as disco
@@ -54,6 +56,16 @@ def listdump(input):
return retval.encode()
def principals_to_san(principals):
san = []
for principal in principals:
try:
ipaddress.ip_address(principal)
san.append('IP:' + principal)
except ValueError:
san.append('DNS:' + principal)
return san
async def get_extra_names(nodename, cfg, myip=None, preferadjacent=False, addlocalhost=True):
if addlocalhost:
names = set(['127.0.0.1', '::1', 'localhost', 'localhost.localdomain'])
@@ -395,6 +407,23 @@ async def handle_request(req, make_response, mimetype):
dnsdomain = deployinfo.get('dns.domain', {}).get('value', None)
ncfg['dnsdomain'] = dnsdomain
return await make_response(mimetype, 200, 'OK', body=dumper(ncfg))
elif reqpath == '/self/tlscert' and reqbody:
csr = reqbody.decode('utf8')
pals = await get_extra_names(nodename, cfg, myip)
with tempfile.NamedTemporaryFile() as tmpfile:
tmpfile.write(csr.encode())
tmpfile.flush()
certfile = tempfile.NamedTemporaryFile(delete=False)
certname = certfile.name
certfile.close()
subj = '/CN={0}'.format(nodename)
await certutil.create_certificate(None, certname, tmpfile.name, subj, principals_to_san(pals), backdate=False,
days=3650)
with open(certname, 'rb') as certf:
cert = certf.read()
os.unlink(certname)
return await make_response('application/x-pem-file', 200, 'OK', body=cert.encode())
elif reqpath == '/self/sshcert' and reqbody:
if not sshutil.ca_exists():
return await make_response(mimetype, 500, 'Unconfigured', body='CA is not configured on this system (run ...)')