Skip to content

Commit 982e416

Browse files
authored
Merge pull request #9 from tonedefdev/rc-2.0.0
2 parents 44e14f8 + 7fc06a0 commit 982e416

File tree

21 files changed

+1711
-175
lines changed

21 files changed

+1711
-175
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
terraform/.terraform/*
18+
terraform/.terraform.tfstate.lock.info
19+
terraform/terraform.tfstate
20+
terraform/terraform.tfstate.backup
21+
terracreds

README.md

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img src="https://github.com/tonedefdev/terracreds/blob/main/img/terracreds.png?raw=true" align="right" width="350" height="350">
44

55
# Terracreds
6-
A credential helper for Terraform Cloud/Enterprise that allows secure storage of your API token within the operating system's vault instead of in a plain text configuration file
6+
A credential helper for Terraform Cloud/Enterprise, or to store other secrets, securely in the operating system's credential vault or through a third party vault. No longer keep secrets in a plain text configuration file!
77

88
We all know storing secrets in plain text can pose major security threats, and Terraform doesn't come pre-packaged with a credential helper, so we decided to create one and to share it with the greater Terraform/DevOps community to help enable stronger security practices
99

@@ -12,10 +12,16 @@ We all know storing secrets in plain text can pose major security threats, and T
1212
- [x] MacOS (Keychain)
1313
- [x] Linux (gnome-keyring) *Tested on Ubuntu 20.04*
1414

15+
#### Currently supported Vault providers:
16+
- [x] AWS Secrets Manager
17+
- [x] Azure Key Vault
18+
- [ ] Google Secret Manager
19+
- [x] HashiCorp Vault
20+
1521
## Windows Install via Chocolatey
1622
The fastest way to install `terracreds` on Windows is via our Chocolatey package:
1723
```powershell
18-
choco install terracreds -y
24+
choco install terracreds --version "2.0.0" -y
1925
```
2026

2127
Once installed run the following command to verify `terracreds` was installed properly:
@@ -25,7 +31,7 @@ terracreds -v
2531

2632
To upgrade `terracreds` to the latest version with Chocolatey run the the following command:
2733
```powershell
28-
choco upgrade terracreds -y
34+
choco upgrade terracreds --version "2.0.0" -y
2935
```
3036

3137
## macOS Install
@@ -36,10 +42,10 @@ extract the package, and then place it in a directory available on `$HOME`
3642
You'll need to download the latest binary from our release page and place it anywhere on `$PATH` of your system. You can also copy and run the following commands:
3743

3844
```bash
39-
wget https://github.com/tonedefdev/terracreds/releases/download/v1.1.1/terracreds_1.1.1_linux_amd64.tar.gz && \
40-
tar -xvf terracreds_1.1.1_linux_amd64.tar.gz && \
45+
wget https://github.com/tonedefdev/terracreds/releases/download/v2.0.0/terracreds_2.0.0_linux_amd64.tar.gz && \
46+
tar -xvf terracreds_2.0.0_linux_amd64.tar.gz && \
4147
sudo mv -f terracreds /usr/bin/terracreds && \
42-
rm -f terracreds_1.1.1_linux_amd64.tar.gz README.md
48+
rm -f terracreds_2.0.0_linux_amd64.tar.gz README.md
4349
```
4450

4551
The `terracreds` Linux implementation uses `gnome-keyring` in conjunction with `gnome-keyring-daemon`
@@ -179,8 +185,84 @@ Success! Terraform has removed the stored API token for app.terraform.io.
179185

180186
Additionally, you can check the `terracreds.log` if logging is enabled for more information
181187

188+
## Setting Up a Vault Provider
189+
> You can reference example configs in our [repo](https://github.com/tonedefdev/terracreds/blob/main/config.yaml) plus we have example [terraform](https://github.com/tonedefdev/terracreds/tree/main/terraform) code you can reference in order to setup your `AWS` or `Azure` VMs to use `terracreds` for a CI/CD piepline agent or a development workstation
190+
191+
### AWS Secrets Manager
192+
> Currently, we only support using an `EC2 Instance Role` for authentication. This ensures the highest level of security by alleviating the `secret zero` dilemma
193+
194+
In order to leverage `terracreds` to manage secrets in `AWS Secrets Manager` the following block needs to be provided in the configuration file:
195+
```yaml
196+
aws:
197+
description: my_terraform_api_token
198+
region: us-west-2
199+
secretName: my-secret-name
200+
```
201+
202+
| Value | Description | Required |
203+
| ----- | ----------- | -------- |
204+
| `description` | A brief description to provide for the secret object viewable in `Secrets Manager` | `yes` |
205+
| `region` | The `Secrets Manager` instance's region where the secret will be stored | `yes` |
206+
| `secretName` | A name for the secret. If omitted and using `terraform login` the hostname of the TFC\TFE server will be used for the name instead | `no` |
207+
208+
The following role permissions are required in order for the `EC2 Instance Role` to levearge `terracreds` with `AWS Secrets Manager`:
209+
```hcl
210+
Action = [
211+
"secretsmanager:CreateSecret",
212+
"secretsmanager:DeleteSecret",
213+
"secretsmanager:GetSecretValue",
214+
"secretsmanager:PutSecretValue"
215+
]
216+
```
217+
### Azure Key Vault
218+
> Currently, we only support using a `Managed Service Identity` for authentication. This ensures the highest level of security by alleviating the `secret zero` dilemma
219+
220+
In order to leverage `terracreds` to manage secrets in `Azure Key Vault` the following block needs to be provided in the configuration file:
221+
```yaml
222+
azure:
223+
secretName: my-secret-name
224+
useMSI: true
225+
vaultUri: https://keyvault.azure.net
226+
```
227+
228+
| Value | Description | Required |
229+
| ----- | ----------- | -------- |
230+
| `secretName` | A name for the secret. If omitted and using `terraform login` the hostname of the TFC\TFE server will be used for the name instead | `no` |
231+
| `useMSI` | A flag to choose whether or not to use `Manged Service Identity`. Currently, `true` is required | `yes` |
232+
| `vaultUri` | The URI for the `Azure Key Vault` where you want to store or retrieve your credentials | `yes` |
233+
234+
The following `Azure Key Vault Access Policies` are required to be given to the `Managed Service Identity` for it to leverage `terracreds`:
235+
```hcl
236+
secret_permissions = [
237+
"Get",
238+
"List",
239+
"Set",
240+
"Delete"
241+
]
242+
```
243+
> Since `Azure Key Vault` doesn't support the period character in a secret name a helper function will replace any periods with dashes so they can be successfully stored. This means a `terraform` API token name that would usually be `app.terraform.io` will become `app-terraform-io`
244+
245+
### HashiCorp Vault
246+
In order to leverage `terracreds` to manage secrets in `HashiCorp Vault` the following block needs to be provided in the configuration file:
247+
```yaml
248+
hcvault:
249+
environmentTokenName: HASHI_TOKEN
250+
keyVaultPath: kv
251+
secretName: my-secret-name
252+
secretPath: tfe
253+
vaultUri: http://localhost:8200
254+
```
255+
256+
| Value | Description | Required |
257+
| ----- | ----------- | -------- |
258+
| `environmentTokenName` | The name of the environment variable that contains the token value to authenticate with `HashiCorp Vault` | `yes` |
259+
| `keyVaultPath` | The path to the `Key Vault` object within the vault | `yes` |
260+
| `secretName` | A name for the secret. If omitted and using `terraform login` the hostname of the TFC\TFE server will be used for the name instead | `no` |
261+
| `secretPath` | The path of the secret within `HashiCorp Vault` | `yes` |
262+
| `vaultUri` | The URI for the `HashiCorp Vault` instance | `yes` |
263+
182264
## Protection
183-
In order to add some protection `terracreds` adds a username to the credential object, and checks to ensure that the user requesting access to the token is the same user as the token's creator. This means that only the user account used to create the token can view the token from `terracreds` which ensures that the token can only be read by the account used to create it. Any attempt to access or modify this token from `terracreds` outside of the user that created the credentail will lead to denial messages. Additionally, if the credential name is not found, the same access denied message will be provided in lieu of a generic not found message to help prevent brute force attempts
265+
In order to add some protection `terracreds` adds a username to the credential object to secrets stored in the local operating system, and checks to ensure that the user requesting access to the token is the same user as the token's creator. This means that only the user account used to create the token can view the token from `terracreds` which ensures that the token can only be read by the account used to create it. Any attempt to access or modify this token from `terracreds` outside of the user that created the credentail will lead to denial messages. Additionally, if the credential name is not found, the same access denied message will be provided in lieu of a generic not found message to help prevent brute force attempts
184266

185267
## Logging
186268
Wherever either binary is stored `terracreds` or `terraform-credential-terracreds` a `config.yaml` file is generated on first launch of the binary. Currently, this configuration file only enables/disables logging and sets the log path. If logging is enabled you'll find the log named `terracreds.log` at the provided path

api/api.go

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
11
package api
22

3+
// Aws is the configuration structure for the AWS vault provider
4+
type Aws struct {
5+
// Description (Optional) A description to provide to the secret
6+
Description string `yaml:"description,omitempty"`
7+
8+
// Region (Required) The region where AWS Secrets Manager is hosted
9+
Region string `yaml:"region,omitempty"`
10+
11+
// SecretName (Optional) The friendly name of the secret stored in AWS Secrets Manager
12+
// if omitted Terracreds will use the hostname value instead
13+
SecretName string `yaml:"secretName,omitempty"`
14+
}
15+
16+
// Azure is the configuration structure for the Azure vault provider
17+
type Azure struct {
18+
// SecretName (Optional) The name of the secret stored in Azure Key Vault
19+
// if omitted Terracreds will use the hostname value instead
20+
SecretName string `yaml:"secretName,omitempty"`
21+
22+
// UseMSI (Required) A flag to indicate if the Managed Identity of the Azure VM should be used for authentication
23+
UseMSI bool `yaml:"useMSI,omitempty"`
24+
25+
// VaultUri (Required) The FQDN of the Azure Key Vault resource
26+
VaultUri string `yaml:"vaultUri,omitempty"`
27+
}
28+
29+
// HCVault is the configuration structure for the Hashicorp Vault provider
30+
type HCVault struct {
31+
// EnvironmentTokenName (Required) The name of the environment variable that currently holds
32+
// the Vault token
33+
EnvironmentTokenName string `yaml:"environmentTokenName,omitempty"`
34+
35+
// KeyVaultPath (Required) The name of the Key Vault store inside of Vault
36+
KeyVaultPath string `yaml:"keyVaultPath,omitempty"`
37+
38+
// SecretName (Optional) The name of the secret stored inside of Vault
39+
// if omitted Terracreds will use the hostname value instead
40+
SecretName string `yaml:"secretName,omitempty"`
41+
42+
// SecretPath (Required) The path to the secret itself inside of Vault
43+
SecretPath string `yaml:"secretPath,omitempty"`
44+
45+
// VaultUri (Required) The URL of the Vault instance including its port
46+
VaultUri string `yaml:"vaultUri,omitempty"`
47+
}
48+
349
// Config struct for terracreds custom configuration
450
type Config struct {
5-
Logging struct {
6-
Enabled bool `yaml:"enabled"`
7-
Path string `yaml:"path"`
8-
} `yaml:"logging"`
51+
Logging Logging `yaml:"logging"`
52+
Aws Aws `yaml:"aws,omitempty"`
53+
Azure Azure `yaml:"azure,omitempty"`
54+
HashiVault HCVault `yaml:"hcvault,omitempty"`
55+
}
56+
57+
// Logging struct defines the parameters for logging
58+
type Logging struct {
59+
Enabled bool `yaml:"enabled"`
60+
Path string `yaml:"path"`
961
}
1062

1163
// CredentialResponse formatted for consumption by Terraform

config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
logging:
2+
enabled: true
3+
path: C:/temp/
4+
aws:
5+
description: my_secret_name
6+
region: us-west-2
7+
secretName: my-secret
8+
azure:
9+
secretName: my-secret-name
10+
useMSI: true
11+
vaultUri: https://keyvault.azure.net
12+
hcvault:
13+
environmentTokenName: HASHI_TOKEN
14+
keyVaultPath: kv
15+
secretName: something-dumb
16+
secretPath: tfe
17+
vaultUri: http://localhost:8200

go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ module github.com/tonedefdev/terracreds
33
go 1.15
44

55
require (
6+
github.com/Azure/azure-sdk-for-go v58.1.0+incompatible
7+
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8
8+
github.com/Azure/go-autorest/autorest/to v0.4.0
9+
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
610
github.com/MakeNowJust/heredoc v1.0.0
11+
github.com/aws/aws-sdk-go v1.41.0
712
github.com/danieljoos/wincred v1.1.0
8-
github.com/davecgh/go-spew v1.1.1 // indirect
913
github.com/fatih/color v1.9.0
10-
github.com/kr/pretty v0.1.0 // indirect
11-
github.com/stretchr/objx v0.1.1 // indirect
14+
github.com/google/go-cmp v0.5.6 // indirect
15+
github.com/hashicorp/vault/api v1.1.1
1216
github.com/urfave/cli/v2 v2.2.0
1317
github.com/zalando/go-keyring v0.1.0
1418
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
15-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
1619
gopkg.in/yaml.v2 v2.3.0
1720
)

0 commit comments

Comments
 (0)