-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update example code links, remove unneeded comments
- Loading branch information
Showing
9 changed files
with
50 additions
and
127 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
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
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 |
---|---|---|
|
@@ -388,17 +388,6 @@ import ( | |
// Fetches a key-value secret (kv-v2) after authenticating to Vault | ||
// via GCP IAM, one of two auth methods used to authenticate with | ||
// GCP (the other is GCE auth). | ||
// | ||
// A role must first be created in Vault bound to the IAM user's service | ||
// account you wish to authenticate with, like so: | ||
// vault write auth/gcp/role/dev-role-iam \ | ||
// type="iam" \ | ||
// policies="dev-policy" \ | ||
// bound_service_accounts="[email protected]" | ||
// Your Vault instance must also be configured with GCP credentials to | ||
// perform API calls to IAM, like so: | ||
// vault write auth/gcp/config credentials=@path/to/server/creds.json | ||
// Learn more at https://www.vaultproject.io/docs/auth/gcp | ||
func getSecretWithGCPAuthIAM() (string, error) { | ||
config := vault.DefaultConfig() // modify for more granular configuration | ||
|
||
|
@@ -457,6 +446,7 @@ func getSecretWithGCPAuthIAM() (string, error) { | |
|
||
return value, nil | ||
} | ||
|
||
``` | ||
|
||
</CodeBlockConfig> | ||
|
@@ -481,19 +471,11 @@ using Data = Google.Apis.Iam.v1.Data; | |
|
||
namespace Examples | ||
{ | ||
public class GCPAuthExample | ||
public class GCPAuthExample | ||
{ | ||
/// <summary> | ||
/// Fetches a key-value secret (kv-v2) after authenticating to Vault via GCP IAM, | ||
/// one of two auth methods used to authenticate with GCP (the other is GCE auth). | ||
/// | ||
/// A role must first be created in Vault bound to the IAM user's service account you wish to authenticate with, like so: | ||
/// type="iam" \ | ||
/// policies="dev-policy" \ | ||
/// bound_service_accounts="[email protected]" | ||
/// Your Vault instance must also be configured with GCP credentials to perform API calls to IAM, like so: | ||
/// vault write auth/gcp/config credentials=@path/to/server/creds.json | ||
/// Learn more at https://www.vaultproject.io/docs/auth/gcp | ||
/// </summary> | ||
public string GetSecretGcp() | ||
{ | ||
|
@@ -503,10 +485,10 @@ namespace Examples | |
throw new System.ArgumentNullException("Vault Address"); | ||
} | ||
|
||
var roleName = Environment.GetEnvironmentVariable("GCP_ROLE"); | ||
var roleName = Environment.GetEnvironmentVariable("VAULT_ROLE"); | ||
if(String.IsNullOrEmpty(roleName)) | ||
{ | ||
throw new System.ArgumentNullException("GCP Role Name"); | ||
throw new System.ArgumentNullException("Vault Role Name"); | ||
} | ||
|
||
// Learn about authenticating to GCS with service account credentials at https://cloud.google.com/docs/authentication/production | ||
|
@@ -516,18 +498,18 @@ namespace Examples | |
} | ||
|
||
var jwt = SignJWT(); | ||
|
||
IAuthMethodInfo authMethod = new GoogleCloudAuthMethodInfo(roleName, jwt); | ||
var vaultClientSettings = new VaultClientSettings(vaultAddr, authMethod); | ||
|
||
IVaultClient vaultClient = new VaultClient(vaultClientSettings); | ||
IVaultClient vaultClient = new VaultClient(vaultClientSettings); | ||
|
||
// We can retrieve the secret after creating our VaultClient object | ||
Secret<SecretData> kv2Secret = null; | ||
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: "/creds").Result; | ||
|
||
var password = kv2Secret.Data.Data["password"]; | ||
|
||
return password.ToString(); | ||
} | ||
|
||
|
@@ -547,7 +529,7 @@ namespace Examples | |
}); | ||
|
||
string svcEmail = $"{svcAcctName}@{gcpProjName}.iam.gserviceaccount.com"; | ||
string name = $"projects/-/serviceAccounts/{svcEmail}"; | ||
string name = $"projects/-/serviceAccounts/{svcEmail}"; | ||
|
||
TimeSpan currentTime = (DateTime.UtcNow - new DateTime(1970, 1, 1)); | ||
int expiration = (int)(currentTime.TotalSeconds) + 900; | ||
|
@@ -563,7 +545,7 @@ namespace Examples | |
ProjectsResource.ServiceAccountsResource.SignJwtRequest request = iamService.Projects.ServiceAccounts.SignJwt(requestBody, name); | ||
|
||
Data.SignJwtResponse response = request.Execute(); | ||
|
||
return JsonConvert.SerializeObject(response.SignedJwt).Replace("\"", ""); | ||
} | ||
|
||
|
Oops, something went wrong.