sparse-intern-71089
11/03/2021, 1:06 PMmillions-furniture-75402
11/03/2021, 1:37 PMcredential_process
script I've written that might help you?
#!/usr/bin/env bash
# Generate a profile with temporary credentials for the role
# Add to your AWS profile:
# credential_process = /usr/local/bin/aws_sso.sh my-profile arn:aws:iam::1234567890:role/CoolRole-us-east-1 write
# In application use the profile name: <profile_name>-temp
function aws_sso () {
local AWS_PROFILE=$1
local AWS_PROFILE_SSO="${AWS_PROFILE}-sso"
local ROLE_ARN=$2
local SSO_ROLE_NAME=$(aws configure get profile.${AWS_PROFILE_SSO}.sso_role_name)
local SSO_ROLE_SESSION_NAME=$(aws configure get profile.${AWS_PROFILE_SSO}.role_session_name)
if [[ -n ${SSO_ROLE_NAME} ]]; then
local AWS_ROLE_USER_ID=$(aws --profile ${AWS_PROFILE_SSO} sts get-caller-identity |jq -r '.UserId' || exit 0)
if [[ -z ${AWS_ROLE_USER_ID} ]]; then
$(aws sso login --profile=${AWS_PROFILE}-sso &>/dev/null)
fi
local AWS_CREDENTIALS=$(aws --profile ${AWS_PROFILE_SSO} sts assume-role --role-arn ${ROLE_ARN} --role-session-name ${SSO_ROLE_SESSION_NAME})
local AWS_ACCESS_KEY_ID=$(echo ${AWS_CREDENTIALS} | jq -r '.Credentials.AccessKeyId')
local AWS_SECRET_ACCESS_KEY=$(echo ${AWS_CREDENTIALS} | jq -r '.Credentials.SecretAccessKey')
local AWS_SESSION_TOKEN=$(echo ${AWS_CREDENTIALS} | jq -r '.Credentials.SessionToken')
local AWS_EXPIRATION=$(echo ${AWS_CREDENTIALS} | jq -r '.Credentials.Expiration')
local RESPONSE_TEMPLATE='{"Version": 1,
"AccessKeyId": "%s",
"SecretAccessKey": "%s",
"SessionToken": "%s",
"Expiration": "%s"
}'
if [[ ${3} == "write" ]]; then
aws configure set profile.${AWS_PROFILE}-temp.aws_access_key_id ${AWS_ACCESS_KEY_ID}
aws configure set profile.${AWS_PROFILE}-temp.aws_secret_access_key ${AWS_SECRET_ACCESS_KEY}
aws configure set profile.${AWS_PROFILE}-temp.aws_session_token ${AWS_SESSION_TOKEN}
fi
echo $(printf "${RESPONSE_TEMPLATE}" "${AWS_ACCESS_KEY_ID}" "${AWS_SECRET_ACCESS_KEY}" "${AWS_SESSION_TOKEN}" "${AWS_EXPIRATION}")
else
echo "Profile not found, or missing sso_role_name"
fi
}
aws_sso $1 $2 $3
clever-painter-96148
11/03/2021, 2:10 PMclever-painter-96148
11/03/2021, 2:48 PMbillowy-army-68599
aws sso login
for Pulumi and it works fine, what issue are you seeing?billowy-army-68599
clever-painter-96148
11/03/2021, 4:29 PMbillowy-army-68599
env | grep -i AWS
clever-painter-96148
11/03/2021, 4:31 PMbillowy-army-68599
billowy-army-68599
AWS_PROFILE
var?clever-painter-96148
11/03/2021, 4:43 PMclever-painter-96148
11/03/2021, 4:43 PMI1103 17:42:21.679702 151402 eventsink.go:59] Attempting to use session-derived credentials
I1103 17:42:21.679724 151402 eventsink.go:62] eventSink::Debug(<{%reset%}>Attempting to use session-derived credentials<{%reset%}>)
I1103 17:42:21.680392 151402 provider_plugin.go:511] Provider[aws, 0xc000f08960].Configure() failed: err=unable to discover AWS AccessKeyID and/or SecretAccessKey - see <https://pulumi.io/install/aws.html> for details on configuration
But there is no reason that explain why...clever-painter-96148
11/03/2021, 5:13 PMbroad-gold-44713
11/03/2021, 5:13 PMeval `aws-sso-creds export --profile <profile>`
broad-gold-44713
11/03/2021, 5:14 PMaws-sso-creds set --profile <sso-profile> <temp_profile>
AWS_PROFILE=<temp_profile>
clever-painter-96148
11/03/2021, 5:15 PMfaint-table-42725
11/03/2021, 5:22 PMAWS_PROFILE
faint-table-42725
11/03/2021, 5:23 PM/.aws/config
:
[profile pulumi-ci]
sso_start_url = <https://xxxxxxx.awsapps.com/start>
sso_region = us-west-2
sso_account_id = 12345678901
sso_role_name = FooRole
region = us-west-2
faint-table-42725
11/03/2021, 5:23 PMaws sso login
and then i’ll do a AWS_PROFILE=my-profile pulumi up
faint-table-42725
11/03/2021, 5:24 PMAWS_SDK_LOAD_CONFIG=true
set in my env vars since I believe you need that in order for the SDK to pick up ~/.aws/config
clever-painter-96148
11/03/2021, 5:29 PM[profile foo]
sso_start_url=<https://foo.awsapps.com/start>
sso_region=eu-west-1
sso_account_id=42
sso_role_name=AWSAdministratorAccess
Then I run aws sso login --profile foo
and finally AWS_PROFILE=foo pulumi up
.
I also tried to set AWS_SDK_LOAD_CONFIG=true
, but it did not change the result:
error: unable to discover AWS AccessKeyID and/or SecretAccessKey - see <https://pulumi.io/install/aws.html> for details on configuration
clever-painter-96148
11/03/2021, 5:46 PMbillowy-army-68599
clever-painter-96148
11/03/2021, 5:49 PMpulumi up
on the wrong stack on the wrong account 🥲rapid-raincoat-36492
11/03/2021, 5:56 PMclever-painter-96148
11/03/2021, 6:22 PMbored-activity-40468
11/03/2021, 8:29 PMcredential_process
in conjunction with aws-vault works really well 🙂faint-table-42725
11/03/2021, 8:32 PMI’d love to have this, so I could set aws:profile in Pulumi.stackName.yaml and ensure I will never again runIrrespective of getting this to work, one thing I’ve seen as a pattern is along the lines of:on the wrong stack on the wrong accountpulumi up
aws.getCallerIdentity().then(identity => {
if (identity.accountId != expectedAccountId)
throw new Error("uh-oh");
});
as a way to add a guard directly to your programfaint-table-42725
11/03/2021, 8:36 PMfaint-table-42725
11/03/2021, 8:37 PMaws sso login
without specifying --profile
faint-table-42725
11/03/2021, 8:46 PMclever-painter-96148
11/03/2021, 10:42 PMIrrespective of getting this to work, one thing I’ve seen as a pattern is along the lines of:Simple, efficient, I like this idea a lot! All my pulumi projects have multiple stacks (usually 1 per environment). I'll write a PoC using an account ID stored in the stack's config. Thanks!
clever-painter-96148
11/03/2021, 10:44 PMI guess the only difference I can observe is I login purely withGuess that means "use the default profile"?without specifyingaws sso login
--profile
Looking at what you’ve described so far, I’d expect that to work, so I’m not sure what I’m doing differently or what’s different on your end.Yep. Unfortunately, I have no idea how I could troubleshoot this further. I'm open to suggestions. 🙂
faint-table-42725
11/04/2021, 1:59 AMclever-painter-96148
11/04/2021, 8:08 AM$ pulumi stack export | grep providers:aws:: | sort -u
"provider": "urn:pulumi:dev::yarn-monorepo-pulumi-lambda::pulumi:providers:aws::default_4_25_0::801f221c-0186-470c-bd95-87d67531d813",
"urn": "urn:pulumi:dev::yarn-monorepo-pulumi-lambda::pulumi:providers:aws::default_4_25_0",