Michael
02/17/2024, 6:03 PMfunction role_name() {
local role_name
# Could be a primary or assumed role. If we have assumed a role, cut off the session name.
local current_role=$(gcloud auth list --filter=status:ACTIVE --format="value(account)" 2>/dev/null | cut -d '@' -f1)
if [[ -z $current_role ]]; then
unset ASSUME_ROLE
return 0
fi
export ASSUME_ROLE="$current_role"
}
role_name
Looking to incorporate Geodesic into our toolbox @Jeremy G (Cloud Posse)Jeremy G (Cloud Posse)
02/17/2024, 11:05 PMAWS_PROFILE on every prompt, and make further checks when it changes. The check (when it changes) takes about a second to complete, so we do not want to run any of this if you are using GCP.
We have other places where we just assume that ASSUME_ROLE is an AWS role, and I'm not sure what, if anything, needs to be adjusted there.
We have legacy support to help you switch roles via an assume-role command, and we would want that to work for GCP (if changing roles is a normal part of your workday under GCP) or be disabled (if not needed).
If you can help me out with use cases and testing, I can add this kind of support for GCP. Otherwise, I'm not sure exactly what to do or how to test it, even though your role_name prompt is a good start.
To start,
• How fast is gcloud auth list? Is it just processing a local file, or does it have to make a remote API call?
• Where does gcloud store configuration data? (AWS stores it in $HOME/.aws/
• How do you change roles? How often do you change roles?Jeremy G (Cloud Posse)
02/18/2024, 12:25 AMgcloud auth list takes 0.3s to run. That is too long to run on every prompt. So, like we do with AWS, we will want to have some quick way to cache the results and then check if the cache needs to be invalidated. (With AWS, we check to see if AWS_PROFILE has changed or if the modification timestamp on the AWS Credentials file has changed.) Can you help me out by figuring out what to use to invalidate the cache for gcloud auth list?Michael
02/18/2024, 1:58 AMgcloud or gsutil, they are stored in a DB file located at ~/.config/gcloud/credentials.db . Whenever someone runs gcloud auth login, it appends an entry to this file. I also found credentials inside of access_tokens.db, and was able to extrapolate them using sqlite.
When I look in ~/.config/gcloud/configurations/config_default :
I see:
[core]
account = <mailto:michael@gmail.com|michael@gmail.com>
project = projectexample
Maybe this is another starting point, because most of the gcloud commands I ran hovered around 0.22s for completion as well