Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 1b4b1c4

Browse files
authored
loosen rbac for get cert - avoid checking every DNS in SAN (#444)
Previous rbac for get certificate: * CN, and all DNS in SAN needs to match a single regex, and the outcome of 'service_name' needs to be matched to the kms auth identity. Problem: this limits a lot of the freedom of how DNS in SAN can be defined, especially when 'service_name' does not need to be existent in SAN DNS, even just missing in one of the entries. Change: loosen the rbac of get cert to just match against CN. For DNS list in SAN, we will skip checking against kms auth identity.
1 parent bb8cdf5 commit 1b4b1c4

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

confidant/authnz/rbac.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,15 @@ def default_acl(*args, **kwargs):
4444
if not ca_object.settings['name_regex']:
4545
return False
4646
cert_pattern = re.compile(ca_object.settings['name_regex'])
47-
domains = [resource_id]
48-
domains.extend(resource_kwargs.get('san', []))
49-
# Ensure the CN and every value in the SAN is allowed for this
50-
# user.
51-
for domain in domains:
52-
match = cert_pattern.match(domain)
53-
if not match:
54-
return False
55-
service_name = match.group('service_name')
56-
if not service_name:
57-
return False
58-
if not authnz.user_is_service(service_name):
59-
return False
47+
domain = resource_id
48+
match = cert_pattern.match(domain)
49+
if not match:
50+
return False
51+
service_name = match.group('service_name')
52+
if not service_name:
53+
return False
54+
if not authnz.user_is_service(service_name):
55+
return False
6056
return True
6157
return False
6258
else:

tests/unit/confidant/authnz/rbac_test.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,16 @@ def test_default_acl(mocker: MockerFixture):
8585
kwargs={'ca': 'development'},
8686
) is False
8787
# Test for user type is service, with certificate resource and get
88-
# action, with a valid CN, but an invalid SAN
89-
assert rbac.default_acl(
90-
resource_type='certificate',
91-
action='get',
92-
resource_id='test-service.example.com',
93-
kwargs={
94-
'ca': 'development',
95-
'san': ['bad-service.example.com'],
96-
},
97-
) is False
98-
# Test for user type is service, with certificate resource and get
99-
# action, with a valid CN, but a mix of valid and invalid SAN values
88+
# action, with a valid CN
10089
assert rbac.default_acl(
10190
resource_type='certificate',
10291
action='get',
10392
resource_id='test-service.example.com',
10493
kwargs={
10594
'ca': 'development',
106-
'san': [
107-
'bad-service.example.com',
108-
'test-service.example.com',
109-
],
95+
'san': ['test-service.sub.example.com'],
11096
},
111-
) is False
97+
) is True
11298
# Test for user type is service, and an allowed resource, with
11399
# disallowed fake action
114100
assert rbac.default_acl(resource_type='service', action='fake') is False

0 commit comments

Comments
 (0)