Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per domain authorization for certificate issuance #3889

Merged
merged 10 commits into from
Jan 10, 2022

Conversation

charhate
Copy link
Contributor

@charhate charhate commented Dec 4, 2021

Introducing new Plugins AuthorizationPlugin(Plugin) and DomainAuthorizationPlugin(AuthorizationPlugin). One can implement a DomainAuthorizationPlugin and configure its slug as USER_DOMAIN_AUTHORIZATION_PROVIDER to check if caller is authorized to issue a certificate for a given Common Name and Subject Alternative Name (SAN) of type DNSName.

Users authenticate to Lemur either using the API Key or using one of the authentication providers. Over the time, we have seen API keys being used by applications to talk to Lemur instead of direct user interaction. It seems logical to persist this information in Lemur for tracking purpose. Also it can be used for authorization. e2d406ada25c_.py aims to add a new column application_name to api_keys table. Null values are allowed making sure this change in backward compatible.

docs/administration.rst Outdated Show resolved Hide resolved
docs/administration.rst Outdated Show resolved Hide resolved
lemur/domains/service.py Outdated Show resolved Hide resolved
"""
if current_app.config.get("USER_DOMAIN_AUTHORIZATION_PROVIDER") is None:
# nothing to check since USER_DOMAIN_AUTHORIZATION_PROVIDER is not configured
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we want to return True here, per above description

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching, modified description (additional details)

lemur/domains/service.py Outdated Show resolved Hide resolved

if error:
raise error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not returning the outcome if is_authorized()?

Copy link
Contributor Author

@charhate charhate Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding propagation of authz result, it instead relies on raising UnauthorizedError. Raising error with useful details within custom plugin implementation can be useful to return an actionable message when certificate issuance is denied. The exception will get caught at certificate create Post call to return 403 along with the error message.
I did some minor changes to above method

  1. look at authorized boolean, raise UnauthorizedError() if authz returns False
  2. update description to reflect behavior

if isinstance(san, x509.DNSName):
if san.value == common_name:
check_permission_for_cn = False
is_authorized_for_domain(san.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not returning the outcome of the AuthZ evaluation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It raises UnauthorizedError if authz fails (additional details)


# lemur UI copies CN as SAN (x509.DNSName). Permission check for CN might already be covered above.
if check_permission_for_cn:
is_authorized_for_domain(common_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not returning the outcome of the AuthZ evaluation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


data["creator"] = g.user
try:
service.allowed_issuance_for_domain(data["common_name"], data["extensions"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above about the outcome of the authZ eval

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It raises UnauthorizedError if authz fails (additional details), which gets caught below to return 403 along with error message

'lemur.certificates.service.is_authorized_for_domain', side_effect=mocked_is_authorized_for_domain
) as wrapper:
try:
allowed_issuance_for_domain(common_name, extensions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no return values being tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asserting on exception below (additional details)

Copy link
Contributor

@hosseinsh hosseinsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome improvement to Lemur's AuthZ features.

@charhate charhate merged commit 1b61194 into Netflix:master Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants