Skip to content

Add Credential File support#200

Merged
dadgar merged 3 commits intomainfrom
f-cred-file
Jul 31, 2023
Merged

Add Credential File support#200
dadgar merged 3 commits intomainfrom
f-cred-file

Conversation

@dadgar
Copy link
Copy Markdown

@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 requested review from bcmdarroch and rselbach July 31, 2023 00:03
@dadgar dadgar merged commit 00cd508 into main Jul 31, 2023
@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