
เครื่องมือ CLI ซึ่งช่วยให้คุณสามารถเข้าสู่ระบบและดึงข้อมูลรับรองชั่วคราวของ AWS โดยใช้ ADFs หรือ Pingfederate Identity ผู้ให้บริการ
สิ่งนี้ขึ้นอยู่กับรหัส Python จากวิธีการใช้โซลูชันทั่วไปสำหรับการเข้าถึง API/CLI แบบสหพันธรัฐโดยใช้ SAML 2.0
กระบวนการนี้เป็นแบบนี้:
saml2aws scriptsaml2aws execนอกเหนือจาก Okta ผู้ให้บริการส่วนใหญ่ในโครงการนี้กำลังใช้การขูดหน้าจอเพื่อบันทึกผู้ใช้ลงใน SAML สิ่งนี้ไม่เหมาะและผู้ขายหวังว่าจะทำให้เรื่องนี้ง่ายขึ้นในอนาคต นอกจากนี้ยังมีบางสิ่งที่คุณต้องรู้:
--session-durationAWS_STS_REGIONAL_ENDPOINTS ตัวแปร Enviornment เป็น regional เมื่อเรียก saml2aws เพื่อให้ AWS-SDK-GO ใช้จุดสิ้นสุด STS ระดับภูมิภาคแทนระดับโลก ดูหมายเหตุที่ด้านล่างของการลงนามคำขอ AWS API และจุดสิ้นสุดของ AWS STS regionalized หากคุณอยู่ใน 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
โคลน repo นี้ไปยังไดเรกทอรี $GOPATH/src ของคุณ
ตอนนี้คุณสามารถติดตั้งได้โดยใช้งาน
make
make install
เครื่องมือ saml2aws มีอยู่ใน AUR (SAML2AWS-BIN) ดังนั้นคุณสามารถติดตั้งได้โดยใช้ AUR HELPER ที่มีอยู่:
$ pamac build saml2aws-bin หากคุณอยู่ในโมฆะ Linux คุณสามารถใช้ XBPS เพื่อติดตั้งแพ็คเกจ SAML2AWS!
xbps-install saml2aws
saml2aws สามารถสร้างสคริปต์ที่สมบูรณ์
เพิ่มบรรทัดต่อไปนี้ใน .bash_profile (หรือเทียบเท่า) ของคุณ:
eval " $( saml2aws --completion-script-bash ) " เพิ่มบรรทัดต่อไปนี้ใน .zshrc ของคุณ (หรือเทียบเท่า):
eval " $( saml2aws --completion-script-zsh ) " ติดตั้ง AWS CLI SEE ในกรณีของเราเราใช้ 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=$@); }
env:
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 ช่วยให้คุณมีชื่อบัญชีที่มีการตั้งค่าใด ๆ ที่คุณต้องการและสนับสนุนการมีบัญชี เริ่ม ต้นหนึ่งบัญชีซึ่งใช้ถ้าคุณละเว้นการตั้งค่าสถานะบัญชี สิ่งนี้จะแทนที่ -Flag -Provider และไฟล์การกำหนดค่าเก่าใน 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 /
สิ่งนี้เกิดขึ้นเนื่องจาก Keyring Back -end ที่ต้องการ - ใช้ gnome-keyring โดยค่าเริ่มต้น - ซึ่งต้องใช้ X11 - และหากคุณไม่ได้ใช้ Windows 11 พร้อมรองรับแอปพลิเคชัน Linux GUI - อาจเป็นเรื่องยากโดยไม่ต้องกำหนดค่า X11 ไปข้างหน้า
มี 2 วิธีที่ต้องการในการแก้ไขปัญหานี้:
คุณสามารถใช้ธง --disable-keychain เมื่อใช้ทั้งคำสั่ง configure และ login การใช้ธงนี้หมายความว่าข้อมูลประจำตัวของคุณ (เช่นรหัสผ่านของคุณไปยัง IDP ของคุณหรือในกรณีของโทเค็นเซสชัน Okta ของ Okta) จะไม่บันทึกลงในพวงกุญแจของคุณ - และถูกข้ามไป ซึ่งหมายความว่าคุณจะต้องป้อนชื่อผู้ใช้และรหัสผ่านของคุณทุกครั้งที่คุณเรียกใช้คำสั่ง login
มีขั้นตอนไม่กี่อย่างที่เกี่ยวข้องกับตัวเลือกนี้ - อย่างไรก็ตามตัวเลือกนี้จะบันทึกข้อมูลประจำตัวของคุณ (เช่นรหัสผ่านของคุณไปยัง IDP ของคุณและโทเค็นเซสชัน ฯลฯ ) ลงใน pass [https://www.passwordstore.org/] Keyring พาย pass เป็นตัวจัดการรหัสผ่านมาตรฐาน UNIX มาตรฐาน ตัวเลือกนี้ได้ รับแรงบันดาลใจอย่างมาก จากปัญหาที่คล้ายกันใน 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 'โปรไฟล์ = customer-dev/awsaccount = คือ 121234567890' และ 'โปรไฟล์ = การทดสอบลูกค้า/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 ในไฟล์ config saml2aws ของคุณเช่น ~/.saml2aws ตัวอย่าง: (รับรองความถูกต้องในบัญชี 'SSO' AWS ของฉันด้วยการตั้งค่านี้ไม่จำเป็นต้องตรวจสอบสิทธิ์อีกครั้งตอนนี้เราสามารถพึ่งพา IAM เพื่อรับบัญชี Cross Cross)
~/.aws/credentials: #(สิ่งเหล่านี้ถูกสร้างขึ้นโดย saml2aws login ค่าการตรวจสอบ SAML ในบัญชี AWS 'SSO' ของฉัน)
[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 ด้วย-Flag-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 ค่าเริ่มต้นเป็น 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 จะมีพารามิเตอร์เพิ่มเติม 2 พารามิเตอร์เพื่อยุติกระบวนการตรวจสอบที่ล้มเหลว
kc_auth_error_element - กำหนดค่าองค์ประกอบ HTTP SAML2AWS ที่ค้นหาในการตอบสนองข้อผิดพลาดการตรวจสอบความถูกต้อง ค่าเริ่มต้นเป็น "span#input-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
คำสั่ง Exec Sub จะส่งออกตัวแปรสภาพแวดล้อมต่อไปนี้
หมายเหตุ: ตัวแปรสภาพแวดล้อมโปรไฟล์นั้นช่วยให้คุณใช้ exec ด้วยสคริปต์หรือคำสั่งซึ่งต้องการโปรไฟล์ที่ชัดเจน
เครื่องมือนี้จะเป็นไปไม่ได้หากไม่มีไลบรารี OpenSource ที่ยอดเยี่ยม
git tag -as vX.XXmake builddist/ ของไดเรกทอรีรากโครงการgit push origin vX.XXมีการดีบักสองระดับปล่อยข้อมูลการดีบักก่อนและสาย URL / Method / สถานะของคำขอ
saml2aws login --verbose
ครั้งที่สองปล่อยเนื้อหาของคำขอและการตอบกลับซึ่งรวมถึงข้อมูลที่เกี่ยวข้องกับการรับรองความถูกต้องดังนั้นอย่าคัดลอกและวางลงในแชทหรือตั๋ว!
DUMP_CONTENT=true saml2aws login --verbose
กระบวนการรับรองเป็นวิธีที่สะดวกในการเชื่อมต่อผู้ให้บริการข้อมูลรับรองกับ AWS CLI
คุณสามารถใช้ saml2aws เป็นผู้ให้บริการข้อมูลรับรองได้เพียงแค่กำหนดค่าและจากนั้นเพิ่มโปรไฟล์ลงในการกำหนดค่า AWS saml2aws มีการสร้างธง --credential-process ที่สร้างผลลัพธ์ด้วยรูปแบบ JSON ที่ถูกต้องรวมถึงธง --quiet ที่จะปิดกั้นการบันทึกจากการแสดง ไฟล์รับรอง AWS (โดยทั่วไป ~/.AWS/ข้อมูลรับรอง) มีความสำคัญเหนือกว่าผู้ให้บริการ credential_process นั่นหมายความว่าหากข้อมูลประจำตัวมีอยู่ในไฟล์กระบวนการรับรองจะไม่ทริกเกอร์ ในการตอบโต้ที่คุณสามารถแทนที่ตำแหน่งข้อมูลรับรอง AWS ของ saml2aws ไปยังไฟล์อื่นโดยใช้ --credential-file หรือระบุในระหว่าง configure
ไฟล์รับรอง AWS (โดยทั่วไป ~/.AWS/ข้อมูลรับรอง) มีความสำคัญเหนือกว่าผู้ให้บริการ credential_process นั่นหมายความว่าหากข้อมูลประจำตัวมีอยู่ในไฟล์กระบวนการรับรองจะไม่ทริกเกอร์
ตัวอย่างของการกำหนดค่า 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 ในเวลาตรวจสอบ แคช Assertion SAML มีความถูกต้องสั้นมาก (5 นาที) และสามารถใช้เพื่อตรวจสอบความถูกต้องของหลายบทบาทที่มีการตรวจสอบ MFA เดียว
มีไฟล์ต่อโปรไฟล์ SAML2AWS ไดเรกทอรีแคชเรียกว่า saml2aws และอยู่ในไดเรกทอรี .aws ของคุณใน Homedir ผู้ใช้ของคุณ
คุณสามารถสลับ --cache-saml ระหว่าง login หรือระหว่าง list-roles และคุณสามารถตั้งค่าได้หนึ่งครั้งในระหว่าง configure และใช้โดยปริยาย
สิ่งนี้ต้องการการใช้พวงกุญแจ (ร้านค้ารับรองท้องถิ่น) หากคุณปิดการใช้งานพวงกุญแจโดยใช้ --disable-keychain เซสชัน Okta จะถูกปิดใช้งานด้วย
Okta Sessions เปิดใช้งานโดยค่าเริ่มต้น สิ่งนี้จะจัดเก็บเซสชัน OKTA ในเครื่องและบันทึกอุปกรณ์ของคุณสำหรับ MFA ซึ่งหมายความว่าหากเซสชันยังไม่หมดอายุคุณจะไม่ได้รับแจ้งสำหรับ MFA
--disable-remember-device ระหว่าง login หรือ configure คำสั่ง--disable-sessions ในระหว่าง login หรือ configure คำสั่ง ใช้ --force FLAG ระหว่างคำสั่ง login เพื่อแจ้งการเลือกบทบาท AWS
หากเซสชัน OKTA ถูกปิดใช้งานผ่านวิธีการใด ๆ ที่กล่าวถึงข้างต้นกระบวนการเข้าสู่ระบบจะเริ่มต้นกับกระบวนการตรวจสอบความถูกต้องมาตรฐาน (โดยไม่ต้องใช้เซสชัน)
โปรดทราบว่าระยะเวลาเซสชัน OKTA ของคุณและนโยบาย MFA อยู่ภายใต้การควบคุมโดยองค์กรโฮสต์ OKTA ของคุณ
รหัสนี้เป็นลิขสิทธิ์ (c) 2024 Versent และเปิดตัวภายใต้ใบอนุญาต MIT สิทธิ์ทั้งหมดที่ไม่ได้รับอย่างชัดเจนในใบอนุญาต MIT สงวนไว้ ดูไฟล์ Licence.md ที่ให้มารวมกันสำหรับรายละเอียดเพิ่มเติม