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

Add globbing support to the PKI backend's allowed_domains list #2517

Merged
merged 6 commits into from
May 1, 2017

Conversation

spectrumjade
Copy link
Contributor

@spectrumjade spectrumjade commented Mar 21, 2017

This change adds simple glob support to the "allowed_domains" list in the PKI backend. This is useful if you would like role policies to allow more flexible name patterns without allowing any name or any subdomain.

It uses an asterisk as the glob character, which I think works for this use case because an asterisk cannot be used in a DNS domain name and in a certificate the wildcard can only be in one specific place (a single wildcard can be present in the left-most name position, and it must be the only component of the dot boundary). A PKI policy of "*.domain.com" will still allow the explicit name "*.domain.com". It will also allow anything ending in ".domain.com", however this is consistent with threat modeling around the DNS hierarchy.

@jefferai jefferai added this to the 0.7.1 milestone Mar 22, 2017
@jefferai
Copy link
Member

@justintime32 I think for now I'd prefer not to make these changes to email addresses, unless you have a particular use-case in mind. Both the operational and threat model are different for email vs. DNS and I don't see a need for it so would prefer to avoid expanding its scope.

@spectrumjade
Copy link
Contributor Author

Hey @jefferai - I don't have a use case for email domain globbing. I'll go ahead and revert that part of the change.

Copy link
Member

@jefferai jefferai left a comment

Choose a reason for hiding this comment

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

I think this is good to go after that change.

@@ -330,8 +331,8 @@ func validateNames(req *logical.Request, names []string, role *roleEntry) string
}
}

if strings.HasSuffix(sanitizedName, "."+req.DisplayName) ||
Copy link
Member

Choose a reason for hiding this comment

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

I think this use case is also not needed. It's difficult to reason about a use-case where you would want to make a token display name a globbing CN.

@spectrumjade
Copy link
Contributor Author

Done!

@spectrumjade
Copy link
Contributor Author

@jefferai any other thoughts?

@jefferai
Copy link
Member

jefferai commented Apr 3, 2017

No, just haven't gotten back to this yet.

@jefferai
Copy link
Member

Hi @spectrumjade ,

I've taken a while to get back to this because every time I look at it something about it eats away at me and makes me really uncomfortable, mostly for two reasons:

  1. It changes behavior for the end user in a way they may not be expecting
  2. It works around the point of the checks; e.g. if you're doing a check on the bare domain, checking for a glob of the bare domain is really no longer respecting the AllowBareDomains flag.

I want to go a slightly different direction instead: adding an explicit role parameter AllowGlobbedDomains. If this parameter is set to true, then along with the existing checks as-is, we simply have another check in the verify logic that does a straight-up glob check against the given role domain and the supplied SAN.

This is much less magic, is explicit to the user, and makes it easier to reason about the right thing to do in the BareDomain/Subdomain checking code.

It's a little extra work but not much. Hopefully it's understandable why I want to go this way.

@michaelansel
Copy link
Contributor

@jefferai What do you think about instead adding an allowed_names parameter that is a comma-separated list of globs? Basically a PKI complement to #2595. That seems to me like it would protect backwards-compatibility, maintain the meaning of allowed_domains, and provide the functionality @spectrumjade is looking for (full name matching on all requested names).

@jefferai
Copy link
Member

I think that will be very confusing, honestly. If we're going to add a parameter in either case, what does it buy you over simply explicitly enabling globbing of the existing fields with a bool?

@michaelansel
Copy link
Contributor

Reading through the code closer, I think I was misunderstanding the scope of allowed_domains -- it appears to be matching the full name and not just the domain portion. I'll go with "I was confused" and retract my comment ;-)

@jefferai
Copy link
Member

@michaelansel what it matches basically depends on what flags you have toggled as acceptable things to match (bare domain, subdomains, etc.). But yeah, it doesn't remove hostnames or anything.

@spectrumjade
Copy link
Contributor Author

spectrumjade commented Apr 17, 2017

Hey @jefferai I think that's a fine approach. I'm preparing the change now. One thought I have, I think we should require that allow_bare_domains be enabled for globbing support to be enabled, because performing a glob check on an allowed_domain with no glob pattern in it would implicitly allow bare domains.

@jefferai
Copy link
Member

@spectrumjade That can be worked around by using .example.com as the name to match rather than example.com. Or we can just not glob-match if there is no asterisk contained within the name.

@spectrumjade
Copy link
Contributor Author

@jefferai Oops, I missed your comment before adding the new commit. Do you think one of those options would be better than the current approach (requiring allow_bare_domains to be set)?

Could you elaborate on the .example.com approach? I'm not sure I understand that part.

@jefferai
Copy link
Member

I don't like the idea of requiring bare domains to be allowed just to enable globbing, because then you are...allowing bare domains, which you may not want to do.

Why not just require any glob check to have an asterisk in it? Then if there isn't an asterisk, you treat it like a non-globbed domain (must match the allowed subdomains/bare domains settings). That way you can easily mix and match bare domains and allowed globs but control their acceptability separately.

@spectrumjade
Copy link
Contributor Author

@jefferai I've implemented the wildcard check and removed the allow_bare_domains requirement. What are you thoughts on the current change?

@jefferai
Copy link
Member

I like it. Super simple, super understandable.

Copy link
Contributor

@chrishoffman chrishoffman left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me. The only think I would like to see is a few unit tests to cover the new globbing use case.

@jefferai
Copy link
Member

@spectrumjade Can you add some unit tests?

@jefferai
Copy link
Member

@spectrumjade we're looking to release 0.7.1 next week, so please keep that in mind if you want to see this in that release!

Copy link
Contributor

@briankassouf briankassouf left a comment

Choose a reason for hiding this comment

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

Code looks good to me, as soon as there is a unit test I'd say this is ready to go!

@@ -361,6 +362,13 @@ func validateNames(req *logical.Request, names []string, role *roleEntry) string
break
}
}

if role.AllowGlobDomains &&
strings.Contains(currDomain, "*") &&
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need the strings.Contains(currDomain, "*") check here?

Copy link
Member

@vishalnayak vishalnayak Apr 30, 2017

Choose a reason for hiding this comment

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

Read back on the conversation on the PR and understood how not having this check would implicitly allow bare domain. Ignore my previous comment.

@jefferai
Copy link
Member

jefferai commented May 1, 2017

Thanks for all of your work on this!

@jefferai jefferai merged commit 2e8e9ed into hashicorp:master May 1, 2017
@spectrumjade spectrumjade deleted the pki_glob branch May 1, 2017 17:03
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.

6 participants