Skip to content

Commit

Permalink
salt: Make check of the CN optional
Browse files Browse the repository at this point in the history
We now only check the CN in the kubeconfig
certificate if the `expected_cn` is not None.
This is needed in order to avoid checking
the CN in the kubeconfig beacon which will
rely on this method.

Refs: #1887
  • Loading branch information
alexandre-allard committed Dec 15, 2020
1 parent a28a5f6 commit 7f2e67a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions salt/_modules/metalk8s_kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __virtual__():
def validate(filename,
expected_ca_data,
expected_api_server,
expected_cn,
expected_cn=None,
days_remaining=90):
"""Validate a kubeconfig filename.
Expand Down Expand Up @@ -77,13 +77,14 @@ def validate(filename,
client_cert_detail = __salt__['x509.read_certificate'](client_cert)

# Verify client cn
try:
current_cn = client_cert_detail['Subject']['CN']
except KeyError:
return False
else:
if current_cn != expected_cn:
if expected_cn is not None:
try:
current_cn = client_cert_detail['Subject']['CN']
except KeyError:
return False
else:
if current_cn != expected_cn:
return False

# Verify client client cert expiration date is > 30days
try:
Expand Down

0 comments on commit 7f2e67a

Please sign in to comment.