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 Credential File support #200

Merged
merged 3 commits into from
Jul 31, 2023
Merged

Add Credential File support #200

merged 3 commits into from
Jul 31, 2023

Conversation

dadgar
Copy link
Contributor

@dadgar dadgar commented Jul 31, 2023

πŸ› οΈ Description

SDK can authenticate using a credential file. The credential file can specify service principal credentials or workload identity provided credentials.

πŸ”— External Links

HCP-378 RFC

πŸ‘ Definition of Done

  • SDK added
  • SDK updated
  • Tests added?
  • Docs updated?

Ran the following test program:

package main

import (
	"crypto/tls"
	"log"

	"github.com/hashicorp/hcp-sdk-go/config"
)

func main() {
	cfg, err := config.NewHCPConfig(config.WithAPI("alex01-XXX.hashicorp.services", &tls.Config{}))
	if err != nil {
		log.Fatal(err)
	}

	t, err := cfg.Token()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("token: %#v", t)
}

I wrote a valid config file to ~/.config/hcp/cred_file.json:

{
  "scheme": "workload",
  "workload": {
    "provider_resource_name": "iam/project/58967b2f-bc68-464e-8fb7-8e7d65b377f8/service-principal/test/workload-identity-provider/aws",
    "aws": {
      "imds_v2": true
    }
  }
}

Running the program printed a valid token.

I then moved the cred_file.json to cred_file2.json and ran the program again. It tried to retrieve the token via the browser as expected.

I then ran HCP_CRED_FILE=~/.config/hcp/cred_file2.json ./aws and it again printed a valid token from workload identity federation.

@dadgar dadgar merged commit 00cd508 into main Jul 31, 2023
2 checks passed
@dadgar dadgar deleted the f-cred-file branch July 31, 2023 17:21
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.

2 participants