-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added Google Workload Identity Federation test
- Loading branch information
1 parent
566fc7f
commit dd6420e
Showing
7 changed files
with
329 additions
and
4 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
44 changes: 44 additions & 0 deletions
44
tests/authentication/test-gcp-workload-identity-federation-creds.sh
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,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Test novops Google Workload Identity Federation authentication using Azure credentials | ||
# - Run authentication steps in container to avoid side-effect with locally configured accounts | ||
# - Generate an Azure token with Google credential file which Novops can read | ||
# - Run Novops and check authentication happens properly | ||
|
||
set -e | ||
|
||
AZ_STACK_OUTPUTS=$(pulumi -C tests/setup/pulumi/azure/ -s test stack output --json --show-secrets) | ||
AZ_TENANT=$(echo $AZ_STACK_OUTPUTS | jq -r .tenantId) | ||
AZ_USERNAME=$(echo $AZ_STACK_OUTPUTS | jq -r .servicePrincipalClientId) | ||
AZ_PASSWORD=$(echo $AZ_STACK_OUTPUTS | jq -r .password) | ||
AZ_IDENTIFIER_URI=$(echo $AZ_STACK_OUTPUTS | jq -r .identifierUri) | ||
|
||
echo "Login to Azure using Tenant ID '$AZ_TENANT' Service Principal '$AZ_USERNAME' to get token for Identifier URI '$AZ_IDENTIFIER_URI'" | ||
|
||
mkdir -p ./tmp | ||
|
||
# Authenticate with Azure in a container (to avoid side effect with local Azure config) | ||
# And save token to file via bind mount | ||
podman run -u 0 --rm -it -v $PWD:/novops --entrypoint bash bitnami/azure-cli:2.67.0 -c \ | ||
"az login --service-principal --username $AZ_USERNAME --password $AZ_PASSWORD --tenant $AZ_TENANT && \ | ||
az account get-access-token --resource $AZ_IDENTIFIER_URI --query accessToken --output tsv > /novops/tmp/az-token.txt" | ||
|
||
# Generate Google credential JSON file for our Azure token | ||
GCP_STACK_OUTPUTS=$(pulumi -C tests/setup/pulumi/gcp/ -s test stack output --json) | ||
WIF_NAME=$(echo $GCP_STACK_OUTPUTS | jq -r .workloadIdentityPoolProviderName) | ||
GCP_PROJECT_NAME=$(echo $GCP_STACK_OUTPUTS | jq -r .projectName) | ||
|
||
echo "Using Workload Identity Federation provider: $WIF_NAME" | ||
|
||
# Project name is asked but actually not used | ||
gcloud iam workload-identity-pools create-cred-config \ | ||
--project "dummy" \ | ||
$WIF_NAME \ | ||
--credential-source-file=$PWD/tmp/az-token.txt \ | ||
--output-file=$PWD/tmp/gcp-auth.json | ||
|
||
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/tmp/gcp-auth.json" | ||
|
||
echo "Google auth file ready in $GOOGLE_APPLICATION_CREDENTIALS" | ||
|
||
RUST_LOG=novops=debug cargo run -- load -c tests/.novops.gcloud_secretmanager.yml --skip-tty-check |
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
Oops, something went wrong.