root / lib / utils / security.py @ 3338a9ce
History | View | Annotate | Download (2.6 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2013 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
"""Utility functions for security features of Ganeti.
|
22 |
|
23 |
"""
|
24 |
|
25 |
import logging |
26 |
|
27 |
|
28 |
def AddNodeToCandidateCerts(node_uuid, cert_digest, candidate_certs, |
29 |
info_fn=logging.info, warn_fn=logging.warn): |
30 |
"""Adds an entry to the candidate certificate map.
|
31 |
|
32 |
@type node_uuid: string
|
33 |
@param node_uuid: the node's UUID
|
34 |
@type cert_digest: string
|
35 |
@param cert_digest: the digest of the node's client SSL certificate
|
36 |
@type candidate_certs: dict of strings to strings
|
37 |
@param candidate_certs: map of node UUIDs to the digests of their client
|
38 |
SSL certificates, will be manipulated in this function
|
39 |
@type info_fn: function
|
40 |
@param info_fn: logging function for information messages
|
41 |
@type warn_fn: function
|
42 |
@param warn_fn: logging function for warning messages
|
43 |
|
44 |
"""
|
45 |
assert candidate_certs is not None |
46 |
|
47 |
if node_uuid in candidate_certs: |
48 |
old_cert_digest = candidate_certs[node_uuid] |
49 |
if old_cert_digest == cert_digest:
|
50 |
info_fn("Certificate digest for node %s already in config."
|
51 |
"Not doing anything." % node_uuid)
|
52 |
return
|
53 |
else:
|
54 |
warn_fn("Overriding differing certificate digest for node %s"
|
55 |
% node_uuid) |
56 |
candidate_certs[node_uuid] = cert_digest |
57 |
|
58 |
|
59 |
def RemoveNodeFromCandidateCerts(node_uuid, candidate_certs, |
60 |
warn_fn=logging.warn): |
61 |
"""Removes the entry of the given node in the certificate map.
|
62 |
|
63 |
@type node_uuid: string
|
64 |
@param node_uuid: the node's UUID
|
65 |
@type candidate_certs: dict of strings to strings
|
66 |
@param candidate_certs: map of node UUIDs to the digests of their client
|
67 |
SSL certificates, will be manipulated in this function
|
68 |
@type warn_fn: function
|
69 |
@param warn_fn: logging function for warning messages
|
70 |
|
71 |
"""
|
72 |
if node_uuid not in candidate_certs: |
73 |
warn_fn("Cannot remove certifcate for node %s, because it's not in the"
|
74 |
"candidate map." % node_uuid)
|
75 |
return
|
76 |
del candidate_certs[node_uuid]
|