8000 nomad_acl_auth_method: add pkce and client assertions by gulducat · Pull Request #523 · hashicorp/terraform-provider-nomad · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

nomad_acl_auth_method: add pkce and client assertions #523

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

Merged
merged 7 commits into from
Apr 16, 2025

Conversation

gulducat
Copy link
Member

Add support for enabling PKCE and using client assertions (private key JWT) instead of client secrets.

Also scope creeped a bit for a couple little things that were bothering me.

@gulducat
Copy link
Member Author
gulducat commented Apr 15, 2025

Pardon me, I still need to update the docs. done

Copy link
Member
@tgross tgross left a comment

Choose a reason for hiding this comment

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

This looks great! I don't have a OIDC setup handy to test it for myself this afternoon, but code is looking good.

Comment on lines +117 to +120
RequiredWith: []string{
"config.0.oidc_discovery_url", // if this is set,
"config.0.oidc_client_id", // client id must also be set
},
Copy link
Member

Choose a reason for hiding this comment

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

Not an issue, but when I went to look this validator up, it's... weird?

// RequiredWith is a set of attribute paths, including this attribute,
// that must be set simultaneously.

The docstring almost implies that we'd end up always needing oidc_discovery_url and oidc_client_id and oidc_client_secret and oidc_client_assertion if any of them are set. But obviously that's not how it works (fortunately).

Copy link
Member Author

Choose a reason for hiding this comment

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

A lot of the go docs on these fields have strained my brain cells a bit too, yeah. I took it to mean (and experimentation bears out) that "if I, myself, <my name here, explicitly> am set, then this other thing(s) must also be set."

So in total in this PR, from RequiredWiths:

  • if oidc_discovery_url is set, oidc_client_id is required, too (defined here in oidc_discovery_url)
  • if oidc_client_secret is set, oidc_client_id is required, too (defined below in oidc_client_secret)
  • if oidc_client_assertion is set, oidc_client_id is required, too (defined below in oidc_client_assertion)

oidc_discovery_url is required by virtue of ExactlyOneOf up in jwt_validation_pub_keys (unless one of the jwt/jwks options are set).

I could not for the life of me find a way to say "one of: client secret, or assertion must be provided if client id (or discovery url?) is set, otherwise we must be in jwt-land, so don't worry about it." And I think technically, one can have an unsecured OIDC setup without any secret material, so I opted to stop banging my head against that problem, and let reality sort it out.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's nice to give as much validation as we can but at some point you have to worry about drift anyways. LGTM

Comment on lines +131 to +134
RequiredWith: []string{
"config.0.oidc_client_secret",
"config.0.oidc_client_id",
},
Copy link
Member

Choose a reason for hiding this comment

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

Out of scope of this PR obviously, but I wanted to check the assertions here against the API docs and we don't have these requirements documented. Might not be a bad idea to follow-up with that.

if originalAuthMethod.Config.OIDCClientAssertion != nil &&
originalAuthMethod.Config.OIDCClientAssertion.PrivateKey != nil &&
originalAuthMethod.Config.OIDCClientAssertion.PrivateKey.PemKey != "" {
fetchedAuthMethod.Config.OIDCClientAssertion.PrivateKey.PemKey = originalAuthMethod.Config.OIDCClientAssertion.PrivateKey.PemKey
Copy link
Member

Choose a reason for hiding this comment

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

is fetchedAuthMethod.Config.OIDCClientAssertion guaranteed to be non-nil if fetchedAuthMethod.Config is? It doesn't look like it based on the nil check we do further down.

Copy link
Member Author

Choose a reason for hiding this comment

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

anecdotally, it doesn't get tripped in any tests, but I still like to guard against nil, so I'll do some extra checkin 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

the pile of conditions was feeling like a jenga tower, so I made a (pretty precious) wrapper to make this stretch of code easier to read (and safe). I could be convinced to pull back from that, but it does the thing. whatcha think?

Copy link
Member
@tgross tgross Apr 16, 2025

Choose a reason for hiding this comment

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

I'd have probably made those free functions but here in Terraform provider code it's not like we're instantiating this extra object a million times in a server or something, so that's just a matter of taste, not function. LGTM

Copy link
Member
@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM

@gulducat gulducat merged commit 04a2a4d into main Apr 16, 2025
3 checks passed
@gulducat gulducat deleted the auth-oidc-client-assertions branch April 16, 2025 14:07
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.

2 participants
0