
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'
要设置开发帐户运行以下内容并输入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许可发布。保留在麻省理工学院许可证中未明确授予的所有权利。有关更多详细信息,请参见随附的许可证文件。