
أداة CLI التي تمكنك من تسجيل الدخول واسترداد بيانات الاعتماد المؤقتة AWS باستخدام ADFs أو مزودي هوية PingFederate.
يعتمد هذا على رمز Python من كيفية تنفيذ حل عام للوصول إلى API/CLI Federated باستخدام SAML 2.0.
العملية تسير على هذا النحو:
saml2aws scriptsaml2aws execبصرف النظر عن OKTA ، يستخدم معظم مقدمي الخدمات في هذا المشروع تجريف الشاشة لتسجيل المستخدمين في SAML ، وهذا ليس مثاليًا ونأمل أن يجعل البائعون هذا أسهل في المستقبل. بالإضافة إلى ذلك ، هناك بعض الأشياء التي تحتاج إلى معرفتها:
--session-duration .AWS_STS_REGIONAL_ENDPOINTS ENVIORNMENT إلى regional عند الاتصال saml2aws بحيث تستخدم AWS-SDK-GO نقطة نهاية STS الإقليمية بدلاً من النقطة العالمية. راجع الملاحظة في أسفل التوقيع على طلبات AWS API ونقاط النهاية الإقليمية AWS STS. إذا كنت على MacOS ، فيمكنك تثبيت Saml2aws باستخدام Homebrew!
brew install saml2aws
saml2aws --version
إذا كنت على Windows ، يمكنك تثبيت Saml2Aws باستخدام الشوكولاتة!
choco install saml2aws
saml2aws --version
بينما يتوفر Brew لـ Linux ، يمكنك أيضًا تشغيل ما يلي دون استخدام مدير الحزمة.
أبلغ بعض مستخدمي Ubuntu عن مشكلة مع تعليمات تثبيت الآخرين وأبلغوا ما يلي العمل (قد يطلب ذلك باستخدام أمر SUDO مثل وظيفة "MV")
CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
wget https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz
tar -xzvf saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz
mv saml2aws /usr/local/bin/
chmod u+x /usr/local/bin/saml2aws
saml2aws --version
للحصول على دعم U2F ، استبدل خط WGET أعلاه بـ wget https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz
mkdir -p ~/.local/bin
CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
wget -c "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz" -O - | tar -xzv -C ~/.local/bin
chmod u+x ~/.local/bin/saml2aws
hash -r
saml2aws --version
إذا كان saml2aws --version على النحو المقصود ، فقد تحتاج إلى تحديث ملف التكوين الطرفي الخاص بك (مثل ~/.bashrc ، ~/.profile ، ~/.zshrc) لتضمين export PATH="$PATH:$HOME/.local/bin/" في نهاية الملف.
للحصول على دعم U2F ، استبدل خط WGET أعلاه بـ wget -c "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz" -O - | tar -xzv -C ~/.local/bin
ستحتاج إلى أدوات GO (يمكنك التحقق من مشرف الحزمة أيضًا) مثبتة وأداة GO LINT
استنساخ هذا الريبو إلى دليل $GOPATH/src
الآن يمكنك التثبيت عن طريق التشغيل
make
make install
تتوفر أداة saml2aws في AUR (Saml2Aws-Bin) ، بحيث يمكنك تثبيتها باستخدام مساعد AUR المتاح:
$ pamac build saml2aws-bin إذا كنت على Linux void ، يمكنك استخدام XBPS لتثبيت حزمة Saml2Aws!
xbps-install saml2aws
يمكن لـ saml2aws توليد نصوص الانتهاء.
أضف السطر التالي إلى .bash_profile (أو ما يعادله):
eval " $( saml2aws --completion-script-bash ) " أضف السطر التالي إلى .zshrc (أو ما يعادله):
eval " $( saml2aws --completion-script-zsh ) " قم بتثبيت AWS CLI ، في حالتنا ، نستخدم Homebrew على MacOS.
brew install awscli
usage: saml2aws [<flags>] <command> [<args> ...]
A command line tool to help with SAML access to the AWS token service.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--version Show application version.
--verbose Enable verbose logging
--quiet silences logs
-i, --provider=PROVIDER This flag is obsolete. See: https://github.com/Versent/saml2aws#configuring-idp-accounts
--config=CONFIG Path/filename of saml2aws config file (env: SAML2AWS_CONFIGFILE)
-a, --idp-account="default" The name of the configured IDP account. (env: SAML2AWS_IDP_ACCOUNT)
--idp-provider=IDP-PROVIDER
The configured IDP provider. (env: SAML2AWS_IDP_PROVIDER)
--mfa=MFA The name of the mfa. (env: SAML2AWS_MFA)
-s, --skip-verify Skip verification of server certificate. (env: SAML2AWS_SKIP_VERIFY)
--url=URL The URL of the SAML IDP server used to login. (env: SAML2AWS_URL)
--username=USERNAME The username used to login. (env: SAML2AWS_USERNAME)
--password=PASSWORD The password used to login. (env: SAML2AWS_PASSWORD)
--mfa-token=MFA-TOKEN The current MFA token (supported in Keycloak, ADFS, GoogleApps). (env: SAML2AWS_MFA_TOKEN)
--role=ROLE The ARN of the role to assume. (env: SAML2AWS_ROLE)
--aws-urn=AWS-URN The URN used by SAML when you login. (env: SAML2AWS_AWS_URN)
--skip-prompt Skip prompting for parameters during login.
--session-duration=SESSION-DURATION
The duration of your AWS Session. (env: SAML2AWS_SESSION_DURATION)
--disable-keychain Do not use keychain at all. This will also disable Okta sessions & remembering MFA device. (env: SAML2AWS_DISABLE_KEYCHAIN)
-r, --region=REGION AWS region to use for API requests, e.g. us-east-1, us-gov-west-1, cn-north-1 (env: SAML2AWS_REGION)
--prompter=PROMPTER The prompter to use for user input (default, pinentry)
Commands:
help [<command>...]
Show help.
configure [<flags>]
Configure a new IDP account.
--app-id=APP-ID OneLogin app id required for SAML assertion. (env: ONELOGIN_APP_ID)
--client-id=CLIENT-ID OneLogin client id, used to generate API access token. (env: ONELOGIN_CLIENT_ID)
--client-secret=CLIENT-SECRET
OneLogin client secret, used to generate API access token. (env: ONELOGIN_CLIENT_SECRET)
--subdomain=SUBDOMAIN OneLogin subdomain of your company account. (env: ONELOGIN_SUBDOMAIN)
--mfa-ip-address=MFA-IP-ADDRESS
IP address whitelisting defined in OneLogin MFA policies. (env: ONELOGIN_MFA_IP_ADDRESS)
-p, --profile=PROFILE The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
--resource-id=RESOURCE-ID F5APM SAML resource ID of your company account. (env: SAML2AWS_F5APM_RESOURCE_ID)
--credentials-file=CREDENTIALS-FILE
The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
--cache-saml Caches the SAML response (env: SAML2AWS_CACHE_SAML)
--cache-file=CACHE-FILE The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)
--disable-sessions Do not use Okta sessions. Uses Okta sessions by default. (env: SAML2AWS_OKTA_DISABLE_SESSIONS)
--disable-remember-device Do not remember Okta MFA device. Remembers MFA device by default. (env: SAML2AWS_OKTA_DISABLE_REMEMBER_DEVICE)
login [<flags>]
Login to a SAML 2.0 IDP and convert the SAML assertion to an STS token.
-p, --profile=PROFILE The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
--duo-mfa-option=DUO-MFA-OPTION
The MFA option you want to use to authenticate with (supported providers: okta). (env: SAML2AWS_DUO_MFA_OPTION)
--client-id=CLIENT-ID OneLogin client id, used to generate API access token. (env: ONELOGIN_CLIENT_ID)
--client-secret=CLIENT-SECRET
OneLogin client secret, used to generate API access token. (env: ONELOGIN_CLIENT_SECRET)
--mfa-ip-address=MFA-IP-ADDRESS
IP address whitelisting defined in OneLogin MFA policies. (env: ONELOGIN_MFA_IP_ADDRESS)
--force Refresh credentials even if not expired.
--credential-process Enables AWS Credential Process support by outputting credentials to STDOUT in a JSON message.
--credentials-file=CREDENTIALS-FILE
The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
--cache-saml Caches the SAML response (env: SAML2AWS_CACHE_SAML)
--cache-file=CACHE-FILE The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)
--download-browser-driver Automatically download browsers for Browser IDP. (env: SAML2AWS_AUTO_BROWSER_DOWNLOAD)
--disable-sessions Do not use Okta sessions. Uses Okta sessions by default. (env: SAML2AWS_OKTA_DISABLE_SESSIONS)
--disable-remember-device Do not remember Okta MFA device. Remembers MFA device by default. (env: SAML2AWS_OKTA_DISABLE_REMEMBER_DEVICE)
exec [<flags>] [<command>...]
Exec the supplied command with env vars from STS token.
-p, --profile=PROFILE The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
--exec-profile=EXEC-PROFILE
The AWS profile to utilize for command execution. Useful to allow the aws cli to perform secondary role assumption. (env: SAML2AWS_EXEC_PROFILE)
--credentials-file=CREDENTIALS-FILE
The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
console [<flags>]
Console will open the aws console after logging in.
--exec-profile=EXEC-PROFILE
The AWS profile to utilize for console execution. (env: SAML2AWS_EXEC_PROFILE)
-p, --profile=PROFILE The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
--force Refresh credentials even if not expired.
--link Present link to AWS console instead of opening browser
--credentials-file=CREDENTIALS-FILE
The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
list-roles
List available role ARNs.
--cache-saml Caches the SAML response (env: SAML2AWS_CACHE_SAML)
--cache-file=CACHE-FILE The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)
script [<flags>]
Emit a script that will export environment variables.
-p, --profile=PROFILE The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
--credentials-file=CREDENTIALS-FILE
The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
--shell=bash Type of shell environment. Options include: bash, /bin/sh, powershell, fish, env
saml2aws script إذا تم استدعاء المجموعة الفرعية script ، فسوف يقوم saml2aws بإخراج بيانات اعتماد الأمان المؤقتة التالية:
export AWS_ACCESS_KEY_ID="ASIAI....UOCA"
export AWS_SECRET_ACCESS_KEY="DuH...G1d"
export AWS_SESSION_TOKEN="AQ...1BQ=="
export AWS_SECURITY_TOKEN="AQ...1BQ=="
export AWS_CREDENTIAL_EXPIRATION="2016-09-04T38:27:00Z00:00"
SAML2AWS_PROFILE=saml
يتم دعم قذائف PowerShell و SH و Fish أيضًا. ENV مفيد لجميع أدوات AWS SDK المتوافقة التي يمكن أن تصدر ملف ENV. إنه مزيج قوي مع Docker ومعلمة --env-file .
إذا كنت تستخدم eval $(saml2aws script) بشكل متكرر ، فقد ترغب في إنشاء اسم مستعار لذلك:
Zsh:
alias s2a="function(){eval $( $(command saml2aws) script --shell=bash --profile=$@);}"
سحق:
function s2a { eval $( $(which saml2aws) script --shell=bash --profile=$@); }
البيئة:
docker run -ti --env-file <(saml2aws script --shell=env) amazon/aws-cli s3 ls
saml2aws exec إذا تم استدعاء المجموعة الفرعية exec ، فسيقوم saml2aws بتنفيذ الأمر المعطى كوسيطة: بشكل افتراضي ، ستقوم Saml2aws بتنفيذ الأمر مع بيانات اعتماد Temp التي تم إنشاؤها عبر saml2aws login .
يسمح العلم- --exec-profile بتنفيذ الأمر باستخدام ملف تعريف AWS الذي قد يكون قد يكون بسلاسل إجراءات "تفترض دور". (عبر 'source_profile' في ~/.aws/config)
options:
--exec-profile Execute the given command utilizing a specific profile from your ~/.aws/config file
هذه هي الطريقة الجديدة لإضافة حسابات مزودات IDP ، فهي تمكنك من تسمية حسابات مع أي إعدادات تريدها وتدعم وجود حساب افتراضي واحد يتم استخدامه إذا حذفت علامة الحساب. هذا يحل محل -العلم المحترم وملف التكوين القديم في 1.x.
لإضافة حساب IDP الافتراضي إلى Saml2aws ، قم فقط بتشغيل الأمر التالي واتبع المطالبات.
$ saml2aws configure
? Please choose a provider: Ping
? AWS Profile myaccount
? URL https://example.com
? Username [email protected]
? Password
No password supplied
account {
URL: https://example.com
Username: [email protected]
Provider: Ping
MFA: Auto
SkipVerify: false
AmazonWebservicesURN: urn:amazon:webservices
SessionDuration: 3600
Profile: myaccount
Region: us-east-1
}
Configuration saved for IDP account: default
ثم لتسجيل الدخول باستخدام هذا الحساب.
saml2aws login
يمكنك أيضًا إضافة حسابات مسماة ، فيما يلي مثال حيث أقوم بإعداد حساب ضمن الاسم المستعار wolfeidau ، مرة أخرى فقط اتبع المطالبات.
saml2aws configure -a wolfeidau
يمكنك أيضًا تكوين الاسم المستعار للحساب دون مطالبات.
saml2aws configure -a wolfeidau --idp-provider KeyCloak --username [email protected] -r cn-north-1
--url https://keycloak.wolfe.id.au/auth/realms/master/protocol/saml/clients/amazon-aws --skip-prompt
ثم جاهز لاستخدام saml2aws.
تسجيل الدخول إلى خدمة (بدون MFA).
$ saml2aws login
Using IDP Account default to access Ping https://id.example.com
To use saved password just hit enter.
Username [[email protected]]:
Password: ************
Authenticating as [email protected] ...
Selected role: arn:aws:iam::123123123123:role/AWS-Admin-CloudOPSNonProd
Requesting AWS credentials using SAML assertion
Saving credentials
Logged in as: arn:aws:sts::123123123123:assumed-role/AWS-Admin-CloudOPSNonProd/[email protected]
Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2016-09-19 15:59:49 +1000 AEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances).
تسجيل الدخول إلى خدمة (مع MFA).
$ saml2aws login
Using IDP Account default to access Ping https://id.example.com
To use saved password just hit enter.
Username [[email protected]]:
Password: ************
Authenticating as [email protected] ...
Enter passcode: 123456
Selected role: arn:aws:iam::123123123123:role/AWS-Admin-CloudOPSNonProd
Requesting AWS credentials using SAML assertion
Saving credentials
Logged in as: arn:aws:sts::123123123123:assumed-role/AWS-Admin-CloudOPSNonProd/[email protected]
Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2016-09-19 15:59:49 +1000 AEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances --region us-east-1).
إذا كنت تستخدم WSL1 أو WSL2 ، فقد تحصل على الخطأ التالي عند محاولة حفظ بيانات الاعتماد في سلسلة المفاتيح
No such interface “org.freedesktop.DBus.Properties” on object at path /
يحدث هذا لأن الواجهة الخلفية للمفاتيح المفضلة - يستخدم gnome-keyring افتراضيًا - والذي يتطلب X11 - وإذا كنت لا تستخدم Windows 11 بدعم من تطبيقات Linux GUI - فقد يكون ذلك صعبًا دون تكوين X11 إلى الأمام.
هناك نهجان مفضلان للتسلل هذه المشكلة:
يمكنك تطبيق علامة- --disable-keychain عند استخدام أوامر configure login . يعني استخدام هذه العلامة أن بيانات الاعتماد الخاصة بك (مثل كلمة المرور الخاصة بك إلى IDP الخاص بك ، أو في حالة Okta the Okta Session Token) لن يتم حفظها في سلسلة المفاتيح الخاصة بك - وتخطيها بشكل رهيب. هذا يعني أنك ستُطلب منك إدخال اسم المستخدم وكلمة المرور في كل مرة تستدعي الأمر login .
هناك بعض الخطوات التي ينطوي عليها هذا الخيار - ومع ذلك سيؤدي هذا الخيار إلى حفظ بيانات الاعتماد الخاصة بك (مثل كلمة المرور الخاصة بك إلى IDP ، ورموز الجلسة ، إلخ) في pass [https://www.passwordstore.org/] Keyring. مفاتيح pass هو Manager Unix Password Manager القياسي. كان هذا الخيار مستوحى بشدة من قضية مماثلة في AWS-Vault
لتكوين تمريرة لتكون المفاتيح الافتراضية ، يجب إكمال الخطوات التالية (على افتراض أنك تستخدم Ubuntu 20.04 LTS):
sudo apt-get update && sudo apt-get install -y pass gnupggpg --gen-keyسيؤدي إخراج الأمر GPG إلى إخراج شيء مشابه لما يلي:
public and secret key created and signed.
pub rsa3072 2021-04-22 [SC] [expires: 2023-04-22]
844E426A53A64C2A916CBD1F522014D5FDBF6E3D
uid Meir Gabay <[email protected]>
sub rsa3072 2021-04-22 [E] [expires: 2023-04-22]
pass init < GPG_PUBLIC_KEY > أثناء عملية init ، يُطلب منك إدخال عبارة المرور المتوفرة في الخطوة 2
saml2aws لاستخدام مفاتيح pass . يمكن القيام بذلك عن طريق تعيين متغير البيئة SAML2AWS_KEYRING_BACKEND ليتم pass . ستحتاج أيضًا إلى تعيين GPG_TTY على tty الحالي الخاص بك مما يعني أنه يمكنك تعيين المتغير إلى "$( tty )"مما يعني أنه يمكن إضافة ما يلي إلى ملف التعريف الخاص بك
export SAML2AWS_KEYRING_BACKEND=pass
export GPG_TTY="$( tty )"
تكوين حسابات متعددة مع دور مخصص وملف تعريف في ~/.aws/config مع الهدف هو العزلة بين رمز INFRA عند النشر في هذه البيئات. يفترض هذا الإعداد أنك تستخدم أدوارًا منفصلة وربما حسابات AWS لـ dev test ومصممة لمساعدة موظفي العمليات على تجنب النشر عن طريق الخطأ في حساب AWS الخاطئ في بيئات معقدة. لاحظ أن هذه الطريقة تقوم بتكوين مصادقة SAML لكل حساب AWS مباشرة (في هذه الحالة حسابات AWS مختلفة). في المثال أدناه ، يتم تكوين قيم المصادقة المنفصلة لحسابات AWS 'ملف تعريف = عميل-DEV/AWSAccount = كان 121234567890 "و" profile = اختبار العميل/AWSAccount = 121234567891 "
لإعداد حساب DEV ، قم بتشغيل ما يلي وإدخال عنوان URL واسم المستخدم وكلمة المرور ، وتعيين دور قياسي ليتم تحديده تلقائيًا على تسجيل الدخول.
saml2aws configure -a customer-dev --role=arn:aws:iam::121234567890:role/customer-admin-role -p customer-dev
سيؤدي ذلك إلى التكوين التالي في ~/.saml2aws .
[customer-dev]
url = https://id.customer.cloud
username = [email protected]
provider = Ping
mfa = Auto
skip_verify = false
timeout = 0
aws_urn = urn:amazon:webservices
aws_session_duration = 28800
aws_profile = customer-dev
role_arn = arn:aws:iam::121234567890:role/customer-admin-role
region = us-east-1
لاستخدام هذا ، ستحتاج إلى تصدير AWS_DEFAULT_PROFILE=customer-dev لاستهداف dev .
لإعداد حساب الاختبار ، قم بتشغيل ما يلي وإدخال عنوان URL واسم المستخدم وكلمة المرور.
saml2aws configure -a customer-test --role=arn:aws:iam::121234567891:role/customer-admin-role -p customer-test
ينتج عن هذا التكوين التالي في ~/.saml2aws .
[customer-test]
url = https://id.customer.cloud
username = [email protected]
provider = Ping
mfa = Auto
skip_verify = false
timeout = 0
aws_urn = urn:amazon:webservices
aws_session_duration = 28800
aws_profile = customer-test
role_arn = arn:aws:iam::121234567891:role/customer-admin-role
region = us-east-1
لاستخدام هذا ، ستحتاج إلى تصدير AWS_DEFAULT_PROFILE=customer-test لاستهداف test .
إذا كنت تستخدم مزود هوية المتصفح ، في أول الاحتجاج saml2aws login ، تحتاج إلى تذكر تثبيت برامج تشغيل المتصفح حتى يعمل الكاتب المسرحي. وإلا سترى رسالة الخطأ التالية:
Error authenticating to IDP.: please install the driver (vx.xx) and browsers first: %!w(<nil>)
لتثبيت برامج التشغيل ، يمكنك:
--download-browser-driver إلى saml2aws loginSAML2AWS_AUTO_BROWSER_DOWNLOAD=truedownload_browser_driver = true في ملف تكوين saml2aws الخاص بك ، أي ~/.saml2aws مثال: (أتوافق مع حساب "SSO" AWS الخاص بي. مع هذا الإعداد ، ليست هناك حاجة للمصادقة مرة أخرى. يمكننا الآن الاعتماد على IAM لتولي حساب الأدوار المتقاطع)
~/.aws/بيانات الاعتماد: #(يتم إنشاؤها بواسطة saml2aws login . قم بإعداد مصادقة SAML في حساب AWS الخاص بي)
[saml]
aws_access_key_id = AAAAAAAAAAAAAAAAB
aws_secret_access_key = duqhdZPRjEdZPRjE=dZPRjEhKjfB
aws_session_token = #REMOVED#
aws_security_token = #REMOVED#
x_principal_arn = arn:aws:sts::000000000123:assumed-role/myInitialAccount
x_security_token_expires = 2019-08-19T15:00:56-06:00
(استخدم ملفات تعريف AWS لتولي حساب AWS المتبادل) (لاحظ أن "Source_Profile" تم تعيينه على SAML وهو حساب SSO AWS الخاص بي لأنه تم مصادق عليه بالفعل)
~/.aws/config:
[profile roleIn2ndAwsAccount]
source_profile=saml
role_arn=arn:aws:iam::123456789012:role/OtherRoleInAnyFederatedAccount # Note the different account number here
role_session_name=myAccountName
[profile extraRroleIn2ndAwsAccount]
# this profile uses a _third_ level of role assumption
source_profile=roleIn2ndAwsAccount
role_arn=arn:aws:iam::123456789012:role/OtherRoleInAnyFederatedAccount
تشغيل saml2aws بدون-العلم الإنصاف:
saml2aws exec aws sts get-caller-identity
{
"UserId": "AROAYAROAYAROAYOO:myInitialAccount",
"Account": "000000000123",
"Arn": "arn:aws:sts::000000000123:assumed-role/myInitialAccount" # This shows my 'SSO' account (SAML profile)
}
تشغيل saml2aws مع-العلم exec-profile:
عند استخدام "-exec-profile" ، يمكنني أن أفترض دورًا في حساب AWS مختلف دون إعادة صياغة. لاحظ أنه لا يتم إعادة صياغته نظرًا لأننا قد تمت مصادقة بالفعل عبر حساب SSO.
saml2aws exec --exec-profile roleIn2ndAwsAccount aws sts get-caller-identity
{
"UserId": "YOOYOOYOOYOOYOOA:/myAccountName",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/myAccountName"
}
كمثال
saml2aws login
aws s3 ls --profile saml
An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
# This is denied in this example because there are no S3 buckets in the 'SSO' AWS account
saml2aws exec --exec-profile roleIn2ndAwsAccount aws s3 ls # Runs given CMD with environment configured from --exec-profile role
# If we check env variables we see that our environment is configured with temporary credentials for our 'assumed role'
env | grep AWS
AWS_SESSION_TTL=12h
AWS_FEDERATION_TOKEN_TTL=12h
AWS_ASSUME_ROLE_TTL=1h
AWS_ACCESS_KEY_ID=AAAAAAAASORTENED
AWS_SECRET_ACCESS_KEY=secretShortened+6jJ5SMqsM5CkYi3Gw7
AWS_SESSION_TOKEN=ShortenedTokenXXX=
AWS_SECURITY_TOKEN=ShortenedSecurityTokenXXX=
AWS_CREDENTIAL_EXPIRATION=2016-09-04T38:27:00Z00:00
# If we desire to execute multiple commands utilizing our assumed profile, we can obtain a new shell with Env variables configured for access
saml2aws exec --exec-profile roleIn2ndAwsAccount $SHELL # Get a new shell with AWS env vars configured for 'assumed role' account access
# We are now able to execute AWS cli commands with our assume role permissions
# Note that we do not need a --profile flag because our environment variables were set up for this access when we obtained a new shell with the --exec-profile flag
aws s3 ls
2019-07-30 01:32:59 264998d7606497040-sampleBucket
aws iam list-groups
{
"Groups": [
{
"Path": "/",
"GroupName": "MyGroup",
"GroupId": "AGAGTENTENTENGOCQFK",
"Arn": "arn:aws:iam::123456789012:group/MyGroup",
"CreateDate": "2019-05-13T16:12:19Z"
]
}
}
هناك عدد قليل من المعلمات الإضافية التي تسمح بتخصيص تكوين SAML2AWS. استخدم المعلمات التالية في ملف ~/.saml2aws :
http_attempts_count - يقوم بتكوين عدد محاولات إرسال طلبات HTTP من أجل التصريح مع SAML Provider. الإعدادات الافتراضية إلى 1http_retry_delay - يقوم بتكوين المدة (بالثواني) من المهلة بين محاولات إرسال طلبات HTTP إلى مزود SAML. الإعدادات الافتراضية إلى 1region - تكوين نقاط نهاية المنطقة التي يجب استخدامها ، انظر الجمهور والقسمtarget_url - ابحث عن نقطة نهاية مستهدفة بخلاف signin.aws.amazon.com/saml. يحتاج مقدمو خدمات OKTA و PINGFED و PINGONE و SHIBBOLETH ECP إلى إرسال أو البحث عن عنوان URL بشكل صريح هذا في استجابة من أجل الحصول على استجابة مصادقة مناسبة أو تحديدها. يمكن تجاوز هذا هنا إذا كنت ترغب في المصادقة لشيء آخر غير AWS.مثال: سيبدو التكوين النموذجي مع مثل هذه المعلمات: يلي:
[default]
url = https://id.customer.cloud
username = [email protected]
provider = Ping
mfa = Auto
skip_verify = false
timeout = 0
aws_urn = urn:amazon:webservices
aws_session_duration = 28800
aws_profile = customer-dev
role_arn = arn:aws:iam::121234567890:role/customer-admin-role
http_attempts_count = 3
http_retry_delay = 1
region = us-east-1
بالنسبة إلى keycloak ، تتوفر معلمتان إضافيتان لإنهاء عملية المصادقة الفاشلة.
kc_auth_error_element - تكوين ما يبحث عنه عنصر HTTP SAML2AWS في استجابات خطأ المصادقة. الإعدادات الافتراضية لـ "span#error-error" وتبحث عن <span id=input-error>xxx</span> . يستخدم Goquery. يبحث "span#id-name" عن <span id=id-name>xxx</span> . "span.class-name" يبحث عن <span class=class-name>xxx</span> .kc_auth_error_message - يعمل مع kc_auth_error_element وتكوين ما يبحث عنه رسالة HTTP SAML2AWS في استجابات خطأ المصادقة. الإعدادات الافتراضية إلى "اسم المستخدم غير الصالح أو كلمة المرور." والبحث عن <xxx>Invalid username or password.</xxx> . يتم قبول التعبيرات العادية. مثال: إذا قام خادم keycloak بإرجاع رسالة خطأ المصادقة "اسم المستخدم غير الصالح أو كلمة المرور". بلغة مختلفة في العنصر <span class=kc-feedback-text>xxx</span> ، ستبدو هذه المعلمات:
[default]
url = https://id.customer.cloud
username = [email protected]
provider = KeyCloak
...
kc_auth_error_element = span.kc-feedback-text
kc_auth_error_message = "Ungültiger Benutzername oder Passwort."
إذا قام خادم KeyCloak بإرجاع رسالة خطأ مختلفة اعتمادًا على نوع خطأ المصادقة ، فاستخدم أنبوبًا كفاصل وأضف رسائل متعددة إلى kc_auth_error_message :
[default]
url = https://id.customer.cloud
username = [email protected]
provider = KeyCloak
...
kc_auth_error_message = "Invalid username or password.|Account is disabled, contact your administrator."
لبناء هذا البرنامج على MacOS ، استنساخ repo إلى $GOPATH/src/github.com/versent/saml2aws والتأكد من أن لديك $GOPATH/bin في $PATH الخاص بك. ستحتاج أيضًا إلى تثبيت GoreleAser.
make mod
تثبيت الثنائي إلى $GOPATH/bin .
make install
ثم لاختبار البرنامج فقط تشغيل.
make test
قبل رفع العلاقات العامة ، يرجى تشغيل linter.
make lint-fix
لبناء هذا البرنامج على Debian/Ubuntu ، تحتاج إلى تثبيت تبعية بناء:
sudo apt install libudev-dev
تحتاج أيضًا إلى تثبيت goreleaser ، والثنائي (أو symlink) في bin/goreleaser .
ln -s $(command -v goreleaser) bin/goreleaser
ثم يمكنك البناء:
make build
سيقوم الأمر Sub Exec بتصدير متغيرات البيئة التالية.
ملاحظة: تمكنك متغيرات بيئة الملف الشخصي من استخدام exec مع برنامج نصي أو أمر يتطلب ملف تعريف صريح.
لن تكون هذه الأداة ممكنة دون بعض مكتبات OpenSource الرائعة.
git tag -as vX.XXmake builddist/ جذر المشروعgit push origin vX.XXهناك مستويان من تصحيح الأخطاء ، وينبعث أول معلومات تصحيح العنوان / عنوان URL / Method / Status Line للطلبات.
saml2aws login --verbose
ينبعث الثاني من محتوى الطلبات والاستجابات ، ويشمل ذلك المعلومات المتعلقة بالمصادقة ، لذا لا تقم بنسخها ولصقها في الدردشة أو التذاكر!
DUMP_CONTENT=true saml2aws login --verbose
عملية الاعتماد هي وسيلة مريحة لتواصل مزودي بيانات الاعتماد مع AWS CLI.
يمكنك استخدام saml2aws كمزود بيانات اعتماد بمجرد تكوينه ثم إضافة ملف تعريف إلى تكوين AWS. لدى saml2aws علامة --credential-process تولد إخراجًا بتنسيق JSON الصحيح ، بالإضافة إلى العلم --quiet من شأنه أن يمنع التسجيل من عرضه. يتمتع ملف بيانات الاعتماد AWS (عادةً/. هذا يعني أنه إذا كانت بيانات الاعتماد موجودة في الملف ، فلن تؤدي عملية الاعتماد إلى تشغيلها. لمواجهة أنه يمكنك تجاوز موقع بيانات AWS لـ saml2aws إلى ملف آخر باستخدام --credential-file أو تحديده أثناء configure .
يتمتع ملف بيانات الاعتماد AWS (عادةً/. هذا يعني أنه إذا كانت بيانات الاعتماد موجودة في الملف ، فلن تؤدي عملية الاعتماد إلى تشغيلها.
مثال على تكوين AWS ( ~/.aws/config ):
[profile mybucket]
region = us-west-1
credential_process = saml2aws login --credential-process --role <ROLE> --profile mybucket
يمكنك إضافة هذا يدويًا أو عبر AWSCLI ، أي
aws configure set credential_process "saml2aws login --credential-process --role <ROLE> --profile mybucket"
عند استخدام AWS CLI مع ملف تعريف mybucket ، سيتم تشغيل عملية المصادقة وسيتم تنفيذ AWS بناءً على بيانات الاعتماد التي تم إرجاعها.
يمكنك استخدام العلامة- --cache-saml من أجل تخزين تأكيد SAML في وقت المصادقة. يتمتع ذاكرة التخزين المؤقت لـ SAML Assertion بصلحة قصيرة جدًا (5 دقائق) ويمكن استخدامها للمصادقة على عدة أدوار مع التحقق من صحة MFA واحدة.
يوجد ملف لكل ملف تعريف saml2aws ، ويسمى دليل ذاكرة التخزين المؤقت saml2aws ويقع في دليل .aws في homedir المستخدم.
يمكنك التبديل- --cache-saml أثناء login أو أثناء list-roles ، ويمكنك تعيينه مرة واحدة أثناء configure واستخدامه ضمنيًا.
هذا يتطلب استخدام سلسلة المفاتيح (متجر بيانات الاعتماد المحلي). إذا قمت بتعطيل سلسلة المفاتيح باستخدام- --disable-keychain ، فسيتم تعطيل جلسات Okta أيضًا.
يتم تمكين جلسات Okta افتراضيًا. سيؤدي ذلك إلى تخزين جلسة OKTA محليًا وحفظ جهازك لـ MFA. هذا يعني أنه إذا لم تنتهي الجلسة بعد ، فلن تتم مطالبتك باجباعة فرنك إفا.
--disable-remember-device أثناء login أو configure الأوامر.--disable-sessions أثناء login أو configure الأوامر. استخدم علامة --force أثناء تسجيل login للمطالبة باختيار دور AWS.
إذا تم تعطيل جلسات OKTA من خلال أي من الطرق المذكورة أعلاه ، فستكون عملية تسجيل الدخول افتراضيًا لعملية المصادقة القياسية (دون استخدام الجلسات).
يرجى ملاحظة أن مدة جلسة OKTA الخاصة بك وسياسات MFA تحكمها مؤسستك المضيفة OKTA.
هذا الرمز هو حقوق الطبع والنشر (ج) 2024 مقابل وإصدار تحت رخصة معهد ماساتشوستس للتكنولوجيا. جميع الحقوق غير الممنوحة بشكل صريح في ترخيص معهد ماساتشوستس للتكنولوجيا محفوظة. راجع ملف الترخيص.