Skip to content

Vault Userpass auth method initial implementation#2859

Open
harshit-nema wants to merge 15 commits intomainfrom
VAULT-43413-Userpass-Initial-Implementation
Open

Vault Userpass auth method initial implementation#2859
harshit-nema wants to merge 15 commits intomainfrom
VAULT-43413-Userpass-Initial-Implementation

Conversation

@harshit-nema
Copy link
Copy Markdown
Contributor

@harshit-nema harshit-nema commented Mar 31, 2026

Description

The PR contains initial implementation of Vault Userpass auth method. It introduces :

  • vault_userpass_auth_backend_user for managing Userpass users (Creating/Deletion) along with policy and password update capabilities.

  • vault_userpass_auth_login as an ephemeral resource for authenticating with Userpass and using ephemeral token data during Terraform operations.

Checklist

  • Added CHANGELOG entry (only for user-facing changes)
  • Acceptance tests where run against all supported Vault Versions

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'
$TF_ACC=1 go test -v ./internal/vault/auth/userpass -run TestAccUserpassAuthBackendUser 
$TF_ACC=1 go test -v ./internal/vault/auth/userpass -run TestAccUserpassAuthLogin
...
AcceptanceTest_login AcceptanceTest_user

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@harshit-nema harshit-nema requested review from a team as code owners March 31, 2026 11:47
@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch from 93a078b to d578f6f Compare March 31, 2026 12:20
Comment thread internal/vault/auth/userpass/user_resource.go Outdated
Comment thread internal/vault/auth/userpass/user_resource.go
Comment thread internal/vault/auth/userpass/user_resource.go Outdated
Comment thread internal/vault/auth/userpass/user_resource.go
Comment thread internal/vault/auth/userpass/user_resource.go
Comment thread internal/vault/auth/userpass/user_resource.go Outdated
Comment thread internal/vault/auth/userpass/user_resource.go Outdated
Comment thread internal/vault/auth/userpass/user_resource_test.go Outdated
Comment thread internal/vault/auth/userpass/user_resource_test.go
Comment thread website/docs/r/userpass_auth_backend_user.md Outdated
Comment thread website/docs/r/userpass_auth_backend_user.md Outdated
@harshit-nema harshit-nema requested a review from Copilot April 9, 2026 06:17
@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch from d578f6f to 1f6749a Compare April 9, 2026 06:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Initial implementation of Vault’s Userpass auth method support in the Terraform Vault provider, adding management of Userpass users and an ephemeral login mechanism for short-lived tokens during Terraform operations.

Changes:

  • Added vault_userpass_auth_backend_user resource (create/delete user; manage token-related settings; support password updates including bcrypt hash in Vault 1.17+).
  • Added vault_userpass_auth_login ephemeral resource to authenticate via Userpass and expose token details without storing the token in state.
  • Registered the new resource/ephemeral resource with the framework provider and added acceptance tests + docs + changelog entry.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
website/docs/r/userpass_auth_backend_user.md New docs for the Userpass user resource (examples, arguments, import)
website/docs/ephemeral-resources/userpass_auth_login.md New docs for the Userpass login ephemeral resource
internal/vault/auth/userpass/user_resource.go Implements the Userpass user resource using the Plugin Framework
internal/vault/auth/userpass/user_resource_test.go Acceptance tests for the Userpass user resource
internal/vault/auth/userpass/login_ephemeral_resource.go Implements the Userpass login ephemeral resource with token revocation on close
internal/vault/auth/userpass/login_ephemeral_resource_test.go Acceptance tests for the login ephemeral resource
internal/provider/fwprovider/provider.go Registers the new resource + ephemeral resource
internal/consts/consts.go Adds the password_hash_wo field constant
CHANGELOG.md Adds a feature entry for Userpass auth support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread website/docs/r/userpass_auth_backend_user.md Outdated
Comment thread website/docs/r/userpass_auth_backend_user.md Outdated
Comment thread website/docs/r/userpass_auth_backend_user.md Outdated
Comment thread website/docs/r/userpass_auth_backend_user.md Outdated
Comment thread website/docs/ephemeral-resources/userpass_auth_login.md Outdated
Comment thread website/docs/ephemeral-resources/userpass_auth_login.md Outdated
Comment thread internal/vault/auth/userpass/user_resource.go
Comment thread internal/vault/auth/userpass/login_ephemeral_resource.go
Comment thread CHANGELOG.md Outdated
Comment thread internal/vault/auth/userpass/user_resource_test.go Outdated
@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch from 1c39702 to 52c14f3 Compare April 9, 2026 14:51
Comment thread internal/vault/auth/userpass/login_ephemeral_resource.go
statecheck.ExpectKnownValue(
"echo.test_userpass",
tfjsonpath.New("data").AtMapKey(consts.FieldPolicies),
knownvalue.NotNull(),
Copy link
Copy Markdown
Contributor

@sanvikam79 sanvikam79 Apr 10, 2026

Choose a reason for hiding this comment

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

Instead of only checking that  is non-null, can we verify the actual expected value here?
check in all places where policies used for the same

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Setting the expected value check in Policy field. Other fields where values are obtained in the response from vault end like 'renewable' and 'lease_duration', better not provide value check, as if there is any change in default values, these test cases will fail in future.

@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch 2 times, most recently from 90108b0 to 56a0cc9 Compare April 15, 2026 04:32
@tejashwiniingalagi tejashwiniingalagi self-requested a review April 15, 2026 10:12
@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch from 46ec2cb to a98b1e8 Compare April 16, 2026 15:19
sanvikam79
sanvikam79 previously approved these changes Apr 17, 2026
Comment thread CHANGELOG.md Outdated
}

// Read version fields from config to ensure they're stored in state
var configData UserpassAuthUserModel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems be to duplicate with line 137. Could you remove either of one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code is refactored. Placing common code in helper function.

})
}

func TestAccUserpassAuthBackendUser_passwordWOVersion(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we also need a test to verify behavior when password changes without incrementing version counter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added test to verify the behaviour when password changes without version increment.


var userRegexp = regexp.MustCompile(`^auth/(.+)/users/(.+)$`)
var bcryptHashRegexp = regexp.MustCompile(`^\$2[abxy]?\$\d{2}\$[./A-Za-z0-9]{53}$`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we check how this is handled in Vault side?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Validation check as present in Vault side implemented.

}

// updatePasswordAndPoliciesEndpoints writes legacy compatibility endpoints when needed.
func (r *UserpassAuthUserResource) updatePasswordAndPoliciesEndpoints(ctx context.Context, vaultClient *api.Client, data *UserpassAuthUserModel, password, passwordHash string) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason why password and poilcy updates are handled in the user resource? It looks like these are calling different endpoints.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Password and policy updates are still part of the Userpass user lifecycle, so handling them in the user resource looks to be the appropriate design.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are calling a sub-path in the API endpoint, not the one that Update calls. The password on the user resource should probably be Create Only if that's how it's designed in vault. And the user will need to use the sub-path to udpate the password.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Redudant sub-endponits call removed.

@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch 2 times, most recently from 76cd10d to c38e811 Compare April 22, 2026 11:07
@harshit-nema harshit-nema force-pushed the VAULT-43413-Userpass-Initial-Implementation branch from cb2ddaf to 96054d8 Compare April 24, 2026 05:52
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.

5 participants