
CLI工具使您可以使用ADF或Pingfederate身份提供商登錄和檢索AWS臨時憑據。
這是基於Python代碼,從如何實現使用SAML 2.0的聯合API/CLI訪問的一般解決方案。
這個過程是這樣的:
saml2aws scriptsaml2aws exec除了OKTA外,該項目中的大多數提供商都使用屏幕刮擦將用戶登錄SAML,這不是理想的選擇,希望將來使這更容易。除此之外,您還需要了解一些事情:
--session-duration -Flag對AWS資源進行配置。saml2aws時設置AWS_STS_REGIONAL_ENDPOINTS ENVIORNMENT regional ,以便AWS-SDK-GO使用區域STS端點而不是全局。請參閱簽名AWS API請求和AWS STS區域化端點的底部的註釋。 如果您在MacOS上,可以使用Homebrew安裝SAML2AW!
brew install saml2aws
saml2aws --version
如果您在窗戶上,可以使用巧克力安裝SAML2AW!
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 https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz saml2aws-u2f_qur_qur-
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 LINE用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 如果您在Void Linux上,則可以使用XBPS安裝SAML2AWS軟件包!
xbps-install saml2aws
saml2aws可以生成完成腳本。
將以下行添加到您的.bash_profile (或等效):
eval " $( saml2aws --completion-script-bash ) "將以下行添加到您的.zshrc (或同等):
eval " $( saml2aws --completion-script-zsh ) " 安裝AWS CLI See,在我們的情況下,我們正在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和魚殼也得到了支持。 ENV對於所有可以源自Env文件的AWS SDK兼容工具都有用。它是與Docker和--env-file參數的強大組合。
如果您經常使用eval $(saml2aws script) ,則可能需要為其創建一個別名:
ZSH:
alias s2a="function(){eval $( $(command saml2aws) script --shell=bash --profile=$@);}"
bash:
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將使用通過saml2aws login生成的temp憑據執行命令。
--exec-profile Flag允許使用AWS配置文件執行命令,AWS配置文件可能已將“假定角色”動作束縛。 (通過〜/.aws/config中的“ source_profile”)
options:
--exec-profile Execute the given command utilizing a specific profile from your ~/.aws/config file
這是添加IDP提供商帳戶的新方法,它使您可以使用所喜歡的任何設置命名帳戶,並支持擁有一個默認帳戶,如果您省略了帳戶標誌。這將替換為1.x的舊配置文件。
要將默認的IDP帳戶添加到SAML2AW,只需運行以下命令並按照提示即可。
$ 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
然後您準備使用SAML2AW。
登錄服務(無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向前配置X11。
有兩種選擇解決此問題的首選方法:
同時使用configure和login命令時,您可以應用--disable-keychain標誌。使用此標誌意味著您的憑據(例如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-keyGPG命令的輸出將輸出類似於以下內容的內容:
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中的目標是隔離。該設置假定您使用的是單獨的角色,並且可能是AWS帳戶用於dev和test ,旨在幫助操作人員避免在復雜環境中意外部署到錯誤的AWS帳戶。請注意,此方法將SAML身份驗證直接為每個AWS帳戶(在這種情況下為不同的AWS帳戶)。在下面的示例中,為AWS帳戶配置了單獨的身份驗證值'profile = customer-dev/awsaccount =為121234567890'和'profile = customer-test/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時,您需要記住安裝瀏覽器驅動程序,以便playwright-go工作。否則,您將看到以下錯誤消息:
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 示例:(對我的“ SSO” AWS帳戶進行身份驗證。使用此設置,無需再次驗證。現在,我們可以依靠IAM來承擔角色跨帳戶)
〜/.aws/憑據:#(這些是由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
在沒有-Exec-Profile標誌的情況下運行SAML2AW:
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)
}
使用-Exec-Profile標誌運行SAML2AW:
當使用“ - 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元素SAML2AW所尋求的內容。默認為“跨度#input-error”,並尋找<span id=input-error>xxx</span> 。使用Goquery。 “跨度#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上構建此軟件,請將存儲庫推送到$GOPATH/src/github.com/versent/saml2aws ,並確保您在$PATH中擁有$GOPATH/bin 。您還將需要安裝Goreleaser。
make mod
將二進制二進制安裝到$GOPATH/bin 。
make install
然後測試軟件,只需運行即可。
make test
在提出公關之前,請運行襯裡。
make lint-fix
要在Debian/Ubuntu上構建此軟件,您需要安裝一個構建依賴性:
sudo apt install libudev-dev
您還需要安裝goreleaser,以及bin/goreleaser中的二進制(或符號鏈接)。
ln -s $(command -v goreleaser) bin/goreleaser
然後,您可以構建:
make build
Exec子命令將導出以下環境變量。
注意:該配置文件環境變量使您可以將exec與需要明確配置文件的腳本或命令一起使用。
沒有一些出色的開源庫,將無法使用此工具。
git tag -as vX.XX在本地創建一個git標籤make builddist/git push origin vX.XX調試有兩個級別,首先排放調試信息和請求的URL /方法 /狀態行。
saml2aws login --verbose
第二個發出請求和響應的內容,其中包括與身份驗證相關的信息,因此請勿將其複制並粘貼到聊天或門票中!
DUMP_CONTENT=true saml2aws login --verbose
憑證過程是將憑證提供商與AWS CLI連接的方便方式。
您可以通過簡單地配置saml2aws作為憑證提供商,然後將配置文件添加到AWS配置中。 saml2aws具有一個標誌--credential-process以右JSON格式生成輸出,以及一個標誌--quiet ,它將阻止顯示日誌記錄的顯示。 AWS憑據文件(通常〜/.aws/憑據)優先於recredential_process提供商。這意味著,如果文件中存在憑據,則憑據過程將不會觸發。為了解決您可以使用--credential-file或在configure過程中指定的saml2aws的AWS憑據位置。
AWS憑據文件(通常〜/.aws/憑據)優先於recredential_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主張。 SAML斷言緩存的有效性很短(5分鐘),可用於通過單個MFA驗證的多個角色進行身份驗證。
每個SAML2AWS配置文件都有一個文件,緩存目錄稱為saml2aws ,位於您的.aws目錄中的用戶Homedir中。
您可以在login過程中或list-roles期間切換--cache-saml ,並且可以在configure過程中設置一次並隱式使用。
這需要使用鑰匙扣(本地憑證存儲)。如果使用--disable-keychain禁用鍵鏈,則OKTA會話也將被禁用。
默認情況下啟用OKTA會話。這將在本地存儲Okta會話,並將您的設備保存為MFA。這意味著,如果會話尚未過期,則不會提示您獲得MFA。
login或configure命令期間切換--disable-remember-device 。login或configure命令期間切換--disable-sessions訪問。在login命令期間使用--force標誌來提示AWS角色選擇。
如果OKTA會話通過上述任何方法禁用,則登錄過程將默認為標準身份驗證過程(無需使用會話)。
請注意,您的OKTA會話持續時間和MFA政策由OKTA主機組織約束。
該代碼是版權(C)2024 Versent,並根據MIT許可發布。保留在麻省理工學院許可證中未明確授予的所有權利。有關更多詳細信息,請參見隨附的許可證文件。