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 support for templated values in SSH CA DefaultExtensions. #11495

Merged

Conversation

robison
Copy link
Contributor

@robison robison commented Apr 29, 2021

This PR adds support for using identity templates in values used in Default Extensions. The primary focus here is to allow the Vault SSH CA backend to function as a point of identity/authentication for GitHub Enterprise (and Github.com) users, by supporting their identity semantics, as documented here.

I've based a large chunk of this on #7548 - happy to make changes as requested/needed to get this into the tree.

@hashicorp-cla
Copy link

hashicorp-cla commented Apr 29, 2021

CLA assistant check
All committers have signed the CLA.

@vercel vercel bot temporarily deployed to Preview – vault April 29, 2021 16:27 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 29, 2021 16:27 Inactive
Copy link
Member

@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.

Thanks for submitting this enhancement!

return nil, fmt.Errorf("extensions %v are not on allowed list", notAllowed)
if role.DefaultExtensionsTemplate {
templatedExtensions := make(map[string]string)
for extensionKey, extensionValue := range extensions {
Copy link
Member

Choose a reason for hiding this comment

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

At this point in time the extensions map could contain user provided extensions (from the data.Get("extensions") call above). The boolean you added only (by name) covers the DefaultExtensions. It may be safer to only allow default extensions to be templated so users cannot query unintended identity data. We could return early above if user provided extensions are passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, excllent point. Let me re-think this portion; originally I had struggled a bit with working out all of the possible unintended consequences (like this).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I'm going to send an additional commit here, to demonstrate my thought process. Ideally, I think we'd want to have Default Extensions that are configured by the role (and templated, if the flag is enabled), but also if there are Allowed Extensions configured, then take user input and override the Default Extensions (sans templating). Is that a more reasonable approach?

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 that sounds right. The existing logic prioritizes user input and does not try to merge it with the default extensions. I think we should continue to have the same semantics. So if user supplied extensions exist process those (without templating), else use the defaults with optional templating.

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 the feedback - I've sent a commit to rework the logic, and also add a basic test - can extend this test structure, if it looks acceptable.

@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 3e86485 to 80133b8 Compare May 3, 2021 21:16
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 3, 2021 21:16 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 3, 2021 21:16 Inactive
@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 80133b8 to 9733066 Compare May 3, 2021 21:53
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 3, 2021 21:53 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 3, 2021 21:53 Inactive
@robison robison requested a review from briankassouf May 4, 2021 22:21
@robison
Copy link
Contributor Author

robison commented May 6, 2021

@briankassouf Is there anything else I can do on this PR?

@vercel vercel bot temporarily deployed to Preview – vault-storybook May 6, 2021 18:08 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 6, 2021 18:08 Inactive
@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from bd85e05 to b3958b3 Compare May 6, 2021 18:27
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 6, 2021 18:27 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 6, 2021 18:27 Inactive
@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from b3958b3 to 54b6591 Compare May 6, 2021 21:12
@vercel vercel bot temporarily deployed to Preview – vault May 6, 2021 21:12 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 6, 2021 21:12 Inactive
@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 54b6591 to 3d72d77 Compare May 6, 2021 22:29
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 6, 2021 22:29 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 6, 2021 22:29 Inactive
@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 3d72d77 to b3cccd7 Compare May 11, 2021 18:09
@vercel vercel bot temporarily deployed to Preview – vault May 11, 2021 18:09 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 11, 2021 18:09 Inactive
extensions := make(map[string]string)

if len(unparsedExtensions) > 0 {
parsedExtensions := convertMapToStringValue(unparsedExtensions)
Copy link
Member

Choose a reason for hiding this comment

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

I believe there is a behavior change here. If the role has no AllowedExtensions the below branch will be skipped and nothing will be added to the extensions map. Should we assign extensions here like we were previously?

The docs for AllowedExtensions state:

Specifies a comma-separated list of extensions that certificates can have when signed. To allow any extensions, set this to an empty string. Will default to allowing any extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it - added a commit to fix up this inadvertent change in behavior, and added a test case to cover it.

Copy link
Member

@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.

Thanks for adding the test and Changelog entry! Everything is looking great except for this one comment

@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from b3cccd7 to 61dff11 Compare May 12, 2021 16:34
@vercel vercel bot temporarily deployed to Preview – vault May 12, 2021 16:34 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 12, 2021 16:34 Inactive
@robison
Copy link
Contributor Author

robison commented May 12, 2021

As an aside: any thoughts/preferences on cleaning up the tests I've introduced here? I think they've gotten to the point of needing to be broken out into separate cases, but also don't want to start crowding backend_test.go with a ton of additional helper functions. Feedback requested!

@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 61dff11 to 80ffa2d Compare May 12, 2021 16:57
@vercel vercel bot temporarily deployed to Preview – vault May 12, 2021 16:57 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 12, 2021 16:57 Inactive
@briankassouf
Copy link
Member

Thank you for the latest commit. My only feedback on the test would be the user supplied tests could be broken into a separate test from the templating tests

@robison
Copy link
Contributor Author

robison commented May 13, 2021

I'll do that right now, and send an additional commit shortly.

@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 80ffa2d to 1d37190 Compare May 13, 2021 01:56
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 13, 2021 01:56 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 13, 2021 01:56 Inactive
@robison robison force-pushed the robison/add-ssh-ca-extension-templating branch from 1d37190 to f112d34 Compare May 13, 2021 03:17
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 13, 2021 03:17 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 13, 2021 03:17 Inactive
@briankassouf briankassouf added this to the 1.8 milestone May 13, 2021
Copy link
Member

@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.

Looks great! Thanks for submitting this enhancement

@briankassouf briankassouf merged commit 0ef6145 into hashicorp:master May 13, 2021
AndreyZamyslov pushed a commit to yandex-cloud/vault that referenced this pull request Jun 10, 2021
…orp#11495)

* Add support for templated values in SSH CA DefaultExtensions.

* Reworking the logic per feedback, adding basic test.

* Adding test, so we cover both default extension templating & ignoring default when user-provided extensions are present.

* Fixed up an unintentional extension handling defect, added test to cover the case.

* Refactor Default Extension tests into `enabled` and `disabled`.
jartek pushed a commit to jartek/vault that referenced this pull request Sep 11, 2021
…orp#11495)

* Add support for templated values in SSH CA DefaultExtensions.

* Reworking the logic per feedback, adding basic test.

* Adding test, so we cover both default extension templating & ignoring default when user-provided extensions are present.

* Fixed up an unintentional extension handling defect, added test to cover the case.

* Refactor Default Extension tests into `enabled` and `disabled`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants