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

Allow identity templates in ssh backend default_user field #16351

Merged

Conversation

ianferguson
Copy link
Contributor

Fixes #16350 by enabling Identity attribute templating support for the default_user field on the SSH backend roles

Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

Thanks @ianferguson for the submission!

Overall this looks great! I do have a few little comments to bring this across the line, see individual other comments.

Additionally an update to the docs for the new field/behavior within ssh.mdx would be needed if you don't mind?

t.Errorf("signing request should fail when default_user is not in the allowed_users list, because allowed_users_template is true and default_user_template is not")
}

expectedErrStr := ":TKTKT"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we fix this test as it's failing now. I get the impression this expected error string was meant to be updated but was missed?

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 was, sorry about that! I've committed the expected value in 6ecf401

@@ -1893,6 +2034,66 @@ func getSshCaTestCluster(t *testing.T, userIdentity string) (*vault.TestCluster,
return cluster, userpassToken
}

// TKTK
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this comment be removed please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that! I've removed it in 6ecf401

@ianferguson
Copy link
Contributor Author

@stevendpclark Thanks for the review - I've addressed the comments (sorry about both of those!) in 6ecf401 and added the requested docs in 44ad5d4

allowedPrincipals = append(allowedPrincipals, principal)
rendered, err := b.renderPrincipal(principal, req)
if err != nil {
return nil, fmt.Errorf("template '%s' could not be rendered -> %s", principal, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is inconsistent with above (lines 77) -- I believe the err should be returned here and this message should be preserved as-is as we already contain a copy of the error message prefix you have here (so it'll be duplicated).

IOW, I think 77 is wrong too (return nil, err) to preserve existing behavior-ish.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops good catch @cipherboy. I'll merge this PR and address this in another myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously (when only the allowed_users field could be templated) the template rendering happened in calculateValidPrincipals and the error on this line (return nil, fmt.Errorf("template '%s' could not be rendered -> %s", principal, err), on line 163 in the previous version) could be returned by that func,

That return value would then be caught on the previous version's line 74 which contained the logical.ErrorResponse wrapping, i.e. lines 73-76 prior to my changes were:

parsedPrincipals, err = b.calculateValidPrincipals(data, req, role, role.DefaultUser, role.AllowedUsers, strutil.StrListContains)
if err != nil {
	return logical.ErrorResponse(err.Error()), nil
} 

I was aiming to match the failure behaviors for templating errors in default_user to the existing behavior for allowed_users -- that all said, 👍 with any changes to it, y'all know the details on that better than me!

@stevendpclark stevendpclark merged commit 11b5e07 into hashicorp:main Jul 29, 2022
@stevendpclark
Copy link
Contributor

Thanks @ianferguson for the contribution!

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.

Allow the user of identity templates in secret/ssh roles default_user field
4 participants