Go lang API for userpass auth

680 views
Skip to first unread message

Venkata S S Krishna Manikeswaram C

unread,
Jul 2, 2018, 11:21:54 AM7/2/18
to Vault
How to use the Userpass auth method for the Vault Golang API

Chris Hoffman

unread,
Jul 2, 2018, 11:52:37 AM7/2/18
to Vault
You can find the documentation for the auth method’s APIs here https://www.vaultproject.io/api/auth/userpass/index.html and for configuring and using the auth method here https://www.vaultproject.io/docs/auth/userpass.html.  The Golang API client is a simple wrapper around these API methods.

Hope this helps!
Chris
On Jul 2, 2018, 11:21 AM -0400, Venkata S S Krishna Manikeswaram C <vman...@gmail.com>, wrote:
How to use the Userpass auth method for the Vault Golang API

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/hashicorp/vault/issues
IRC: #vault-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Vault" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vault-tool+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vault-tool/2bbfb90e-288d-48d9-b847-9e1a5c151f52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Venkata S S Krishna Manikeswaram C

unread,
Jul 2, 2018, 2:58:38 PM7/2/18
to Vault
Hi Chris,
Thanks for the reply, HTTP API is great but I am using the go client of Vault and in the GoDocs (https://godoc.org/github.com/hashicorp/vault/api), there is no specification on how to user the userpass auth method

Chris Hoffman

unread,
Jul 2, 2018, 3:44:35 PM7/2/18
to Vault
The go client just lightly wraps the API.  Most API methods can read/write directly from Logical().  Here is a quick program that returns the generated token from a login request using userpass.

package main

import (
    "fmt"

    "github.com/hashicorp/vault/api"
)

func main() {
    config := &api.Config{
        Address: "http://localhost:8200",
    }
    client, err := api.NewClient(config)
    if err != nil {
        panic(err)
    }
    client.SetToken("token")

    auth, err := client.Logical().Write("auth/userpass/login/chris", map[string]interface{}{
        "password": "superSecret",
    })
    if err != nil {
        panic(err)
    }

    fmt.Printf("token: %s\n", auth.Auth.ClientToken)
}

Chris


On

 Jul 2, 2018, 2:58 PM -0400, Venkata S S Krishna Manikeswaram C <vman...@gmail.com>, wrote:
Hi Chris,
Thanks for the reply, HTTP API is great but I am using the go client of Vault and in the GoDocs (https://godoc.org/github.com/hashicorp/vault/api), there is no specification on how to user the userpass auth method

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/hashicorp/vault/issues
IRC: #vault-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Vault" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vault-tool+...@googlegroups.com.

Venkata S S Krishna Manikeswaram C

unread,
Jul 2, 2018, 3:47:32 PM7/2/18
to Vault
Ah That's kind of tricky but solves my problem though. Thanks Chris, for the sample

Venkata S S Krishna Manikeswaram C

unread,
Jul 2, 2018, 7:04:27 PM7/2/18
to Vault
Is there a way to specify the values for LeaseDuration and Renewable parts that come with this request? I just want to avoid stale tokens as I will be creating new tokens for each request

Chris Hoffman

unread,
Jul 3, 2018, 8:43:19 AM7/3/18
to Vault
You can control the values of the lease duration with the ttl and max_ttl values for the user or by tuning the mount to different values.

See

Chris
On Jul 2, 2018, 7:04 PM -0400, Venkata S S Krishna Manikeswaram C <vman...@gmail.com>, wrote:
Is there a way to specify the values for LeaseDuration and Renewable parts that come with this request? I just want to avoid stale tokens as I will be creating new tokens for each request

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/hashicorp/vault/issues
IRC: #vault-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Vault" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vault-tool+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages