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

manager: improve handling of custom domains #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

etnguyen03
Copy link
Contributor

  • Validate custom domains with the same regexes as the orchestrator
  • Check if a domain is CNAMEd properly before it is added for non-superusers

@etnguyen03 etnguyen03 added the enhancement New feature or request label Dec 22, 2020
@etnguyen03 etnguyen03 requested a review from a team December 22, 2020 01:13
@coveralls
Copy link

coveralls commented Dec 22, 2020

Coverage Status

Coverage decreased (-0.008%) to 27.231% when pulling 7f15618 on etnguyen03:manager-check-cnames into ca9044d on tjcsl:master.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

A few suggestions based on a quick review.

try:
# Attempt to resolve this domain (check for CNAME records)
result = dns.resolver.resolve(
cleaned_data["domain"], "CNAME", raise_on_no_answer=False
Copy link

Choose a reason for hiding this comment

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

From glancing through dnspython's documentation, it looks like you don't need raise_on_no_answer=False because you handle dns.resolver.NoAnswer later. Am I missing something, or is this just left over from previous versions of the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was left over, I forgot about that. Removed.

@@ -161,6 +171,35 @@ def clean(self) -> Dict[str, Any]:
if "domain" in cleaned_data and cleaned_data["domain"].endswith("tjhsst.edu"):
self.add_error("domain", "Only administrators can add tjhsst.edu domains")

# Check if this domain CNAMEs to the proper value
if "domain" in cleaned_data and cleaned_data["domain"] and not self.user_is_superuser:
Copy link

Choose a reason for hiding this comment

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

Suggested change
if "domain" in cleaned_data and cleaned_data["domain"] and not self.user_is_superuser:
if cleaned_data.get("domain") and not self.user_is_superuser:

This is what I would probably do. I think it's a little more readable because it helps cut down the line length, but that's just my opinion. Feel free to ignore this.

# point to the CNAME configured in settings, raise a ValueError (which is caught)
if result.rrset is None or not any(
[
settings.DIRECTOR_CUSTOM_DOMAIN_FQDN_CNAME in response.to_text()
Copy link

Choose a reason for hiding this comment

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

This validation seems a little loose (for example, somebody could set director.csl.tjhsst.eduXXX and it would be accepted). I'm guessing you did this to handle the trailing dot in CNAME records; couldn't that be done with .rstrip(".")?

@etnguyen03 etnguyen03 force-pushed the manager-check-cnames branch 2 times, most recently from f164c12 to dcfa36b Compare December 22, 2020 15:42
@@ -143,10 +143,17 @@ class DomainForm(forms.Form):
required=False,
validators=[
validators.RegexValidator(
regex=r"^(?!(.*\.)?sites\.tjhsst\.edu$)[0-9a-zA-Z_\- .]+$",
regex=r"^.*sites\.tjhsst\.edu$",
Copy link

Choose a reason for hiding this comment

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

The previous regex specifically did (.*\.)?sites\.tjhsst\.edu$ to allow things like test-sites.tjhsst.edu while blocking sites.tjhsst.edu and a.sites.tjhsst.edu. I'd recommend keeping that.

Nice work with inverse_match, though. I didn't know about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants