-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration vault to delegator (#1465)
* delegator pk * add vault hashcorp to mod and sum * text cgo env for image for unning IDC k8s * add readme * fixed readme * changed fee payer charator
- Loading branch information
1 parent
2268213
commit e3be629
Showing
8 changed files
with
201 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# Go Delegator | ||
|
||
- Go implementation for delegator | ||
- Uses GSM (setup env vars) | ||
- Go implementation for delegator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package secrets | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
vault "github.com/hashicorp/vault/api" | ||
auth "github.com/hashicorp/vault/api/auth/kubernetes" | ||
) | ||
|
||
type SecretEnv struct { | ||
VaultRole string | ||
JwtPath string | ||
VaultSecretPath string | ||
VaultKeyName string | ||
} | ||
|
||
type Secrets struct { | ||
FeePayer string | ||
} | ||
|
||
func (s *SecretEnv) GetSecretFromVaultWithKubernetesAuth() (*Secrets, error) { | ||
ctx := context.Background() | ||
config := vault.DefaultConfig() | ||
client, err := vault.NewClient(config) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to initialize Vault client: %w", err) | ||
} | ||
|
||
k8sAuth, err := auth.NewKubernetesAuth( | ||
s.VaultRole, | ||
auth.WithServiceAccountTokenPath(s.JwtPath), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to initialize Kubernetes auth method: %w", err) | ||
} | ||
|
||
authInfo, err := client.Auth().Login(ctx, k8sAuth) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to log in with Kubernetes auth: %w", err) | ||
} | ||
if authInfo == nil { | ||
return nil, fmt.Errorf("no auth info was returned after login") | ||
} | ||
|
||
secrets, err := client.KVv2(s.VaultSecretPath).Get(context.Background(), s.VaultKeyName) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to read secret: %w", err) | ||
} | ||
|
||
secretDataSet := &Secrets{ | ||
FeePayer: secrets.Data["FEE_PAYER"].(string), | ||
} | ||
|
||
return secretDataSet, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters