
ADFS 또는 Pingfederate Identity 제공 업체를 사용하여 AWS 임시 자격 증명을 로그인하고 검색 할 수있는 CLI 도구.
이는 SAML 2.0을 사용하여 Federated API/CLI 액세스에 대한 일반적인 솔루션을 구현하는 방법의 파이썬 코드를 기반으로합니다.
프로세스는 다음과 같습니다.
saml2aws scriptsaml2aws execOKTA 외에도이 프로젝트의 대부분의 공급자는 화면 스크래핑을 사용하여 사용자를 SAML에 로그인하고 있으며, 이는 이상적이지 않으며 공급 업체가 향후이를 더 쉽게 만들 수 있기를 바랍니다. 이 외에도 알아야 할 사항이 있습니다.
--session-duration 플래그를 사용하여 최대 12 시간 동안 AWS 리소스에 대한 연합 API 액세스에 따라 구성 할 수 있습니다.saml2aws 호출 할 때 AWS_STS_REGIONAL_ENDPOINTS ENVIORNMENT 변수를 전 세계 대신 지역 STS 엔드 포인트를 사용하도록 설정할 때 AWS_STS_REGIONAL_ENDPOINTS Enviornment 변수를 regional 로 설정해야합니다. AWS API 요청 및 AWS STS 지역 엔드 포인트에 서명하는 맨 아래의 메모를 참조하십시오. MacOS에있는 경우 Homebrew를 사용하여 Saml2aws를 설치할 수 있습니다!
brew install saml2aws
saml2aws --version
창문에 있다면 초콜릿을 사용하여 saml2aws를 설치할 수 있습니다!
choco install saml2aws
saml2aws --version
Linux에서는 Brew를 사용할 수 있지만 패키지 관리자를 사용하지 않고 다음을 실행할 수도 있습니다.
Ubuntu의 일부 사용자는 다른 설치 명령에 대한 문제를보고했으며 다음과 같은 작업을보고했습니다 ( "MV"기능에 대해 Sudo 명령을 사용해야 할 수도 있음).
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 의도 한대로 작동하지 않는 경우, export PATH="$PATH:$HOME/.local/bin/" 포함시키기 위해 터미널 구성 파일 (~/.bashrc, ~/.profile, ~/.zshrc)을 업데이트해야 할 수도 있습니다.
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 도우미를 사용하여 설치할 수 있습니다.
$ pamac build saml2aws-bin void linux에있는 경우 XBP를 사용하여 Saml2aws 패키지를 설치할 수 있습니다!
xbps-install saml2aws
saml2aws 완료 스크립트를 생성 할 수 있습니다.
.bash_profile (또는 동등한)에 다음 줄을 추가하십시오.
eval " $( saml2aws --completion-script-bash ) " .zshrc (또는 동등한)에 다음 줄을 추가하십시오.
eval " $( saml2aws --completion-script-zsh ) " AWS CLI 참조를 설치하십시오. 우리의 경우 우리는 MacOS에서 Homebrew를 사용하고 있습니다.
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=$@);}"
세게 때리다:
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 통해 생성 된 온도 자격 증명으로 명령을 실행합니다.
--exec-profile 플래그를 사용하면 "역할을 수행하는"동작을 묶을 수있는 AWS 프로파일을 사용하여 명령을 실행할 수 있습니다. (~/.aws/config에서 'source_profile'을 통해)
options:
--exec-profile Execute the given command utilizing a specific profile from your ~/.aws/config file
이것은 IDP 제공 업체 계정을 추가하는 새로운 방법입니다. 원하는 설정으로 이름을 지정할 수 있으며 계정 플래그를 생략하면 사용되는 기본 계정 하나를 갖는 것을 지원할 수 있습니다. 이것은 -provider 플래그 및 기존 구성 파일을 1.x로 대체합니다.
saml2aws에 기본 IDP 계정을 추가하려면 다음 명령을 실행하고 프롬프트를 따르십시오.
$ 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 /
선호하는 키 링 백엔드는 기본적으로 X11이 필요한 gnome-keyring 사용하고 Linux GUI 애플리케이션을 지원하는 Windows 11을 사용하지 않는 경우 X11을 앞으로 구성하지 않으면 어려울 수 있습니다.
이 문제를 해결하기위한 2 가지 선호되는 접근법이 있습니다.
configure 및 login 명령을 모두 사용할 때는 --disable-keychain 플래그를 적용 할 수 있습니다. 이 플래그를 사용한다는 것은 자격 증명 (예 : IDP에 대한 비밀번호 또는 Okta의 경우 Okta 세션 토큰)이 Keychain에 저장되지 않음을 의미합니다. 즉, login 명령을 호출 할 때마다 사용자 이름과 비밀번호를 입력해야합니다.
이 옵션과 관련된 몇 단계가 있습니다. 그러나이 옵션은 자격 증명 (예 : IDP에 대한 비밀번호 및 세션 토큰 등)을 pass [https://www.passwordstore.org/] 키링에 저장합니다. pass Keyring은 표준 UNIX 암호 관리자입니다. 이 옵션은 AWS-Gault의 비슷한 문제에서 크게 영감을 받았습니다.
패스를 기본 키트로 구성하려면 다음 단계를 완료해야합니다 (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 로 여러 계정을 구성하여 이러한 환경에 배포 할 때 인프라 코드 간의 고리 인 목표를 포함하여 여러 계정을 구성합니다. 이 설정은 별도의 역할과 dev 및 test 에 대한 AWS 계정을 사용하고 있다고 가정하며 운영 직원이 실수로 복잡한 환경에서 잘못된 AWS 계정에 배포되는 것을 피하도록 설계되었습니다. 이 메소드는 각 AWS 계정에 직접 SAML 인증을 구성합니다 (이 경우 다른 AWS 계정). 아래의 예에서, 별도의 인증 값은 AWS 계정 '프로파일 = 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 login 으로 통과하십시오SAML2AWS_AUTO_BROWSER_DOWNLOAD=truedownload_browser_driver = true saml2aws 구성 파일, 즉 ~/.saml2aws 예 : (내 'SSO'AWS 계정에 인증.이 설정을 사용하면 다시 인증 할 필요가 없습니다. 이제 우리는 역할 크로스 계정을 가정하기 위해 IAM에 의존 할 수 있습니다).
~/.aws/credentials : #( saml2aws login 에 의해 생성됩니다. 내 AWS의 SSO 계정에 SAML 인증을 설정합니다)
[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"은 이미 인증 된 이후 SSO AWS 계정 인 SAML로 설정되어 있음).
~/.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 플래그없이 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)
}
-exec-profile 플래그로 saml2aws 실행 :
'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 SAML 제공 업체와 함께 승인하기 위해 HTTP 요청을 보내려는 시도 수를 구성합니다. 기본값은 1입니다http_retry_delay HTTP 요청을 SAML 제공 업체에 보내려는 시도간에 시간 초과 지속 시간 (초)을 구성합니다. 기본값은 1입니다region - 사용할 영역 엔드 포인트를 구성하고, 청중 및 파티션을 참조하십시오.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-ercror"의 기본값은 <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 로 복제하고 $PATH 에 $GOPATH/bin 있는지 확인하십시오. Goreleaser 설치도 필요합니다.
make mod
이진을 $GOPATH/bin 에 설치하십시오.
make install
그런 다음 소프트웨어를 테스트하려면 실행됩니다.
make test
PR을 올리기 전에 Linter를 실행하십시오.
make lint-fix
Debian/Ubuntu 에이 소프트웨어를 구축하려면 빌드 종속성을 설치해야합니다.
sudo apt install libudev-dev
또한 GoreLeaser를 설치하고 bin/goreleaser 에 Binary (또는 Symlink)가 필요합니다.
ln -s $(command -v goreleaser) bin/goreleaser
그런 다음 빌드 할 수 있습니다.
make build
EXEC 하위 명령은 다음 환경 변수를 내 보냅니다.
참고 : 프로파일 환경 변수를 사용하면 명시 적 프로필이 필요한 스크립트 또는 명령과 함께 exec 사용할 수 있습니다.
이 도구는 훌륭한 OpenSource 라이브러리가 없으면 불가능합니다.
git tag -as vX.XX 로 로컬로 GIT 태그 생성make build 와 함께 빌드를 실행하십시오dist/ 에 중첩 된 새로 생성 된 이진을 테스트하십시오.git push origin vX.XX 누릅니다.디버깅의 두 가지 수준이 있으며, 먼저 디버그 정보와 URL / 메소드 / 상태 요청 라인이 있습니다.
saml2aws login --verbose
두 번째는 요청 및 응답의 내용을 제시합니다. 여기에는 인증 관련 정보가 포함되므로 채팅이나 티켓에 복사하여 붙여 넣지 마십시오!
DUMP_CONTENT=true saml2aws login --verbose
자격 증명 프로세스는 AWS CLI와 자격 증명 제공 업체를 인터페이스하는 편리한 방법입니다.
Saml2aws를 간단히 구성한 다음 AWS 구성에 프로파일을 추가하여 saml2aws 자격 증명 제공 업체로 사용할 수 있습니다. saml2aws 에는 오른쪽 JSON 형식의 출력을 생성하는 플래그와 로깅이 표시되는 것을 막을 수있는 깃발 --credential-process --quiet 이 있습니다. AWS 자격 증명 파일 (일반적으로 ~/.aws/credentials)은 Credential_Process 제공 업체보다 우선합니다. 즉, 자격 증명이 파일에 있으면 자격 증명 프로세스가 트리거되지 않습니다. 반대하려면 saml2aws 의 AWS 자격 증명 위치를 --credential-file 사용하여 다른 파일로 재정의하거나 configure 중에 지정할 수 있습니다.
AWS 자격 증명 파일 (일반적으로 ~/.aws/credentials)은 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"
mybucket 프로파일과 함께 AWS CLI를 사용하면 인증 프로세스가 실행되고 반환 된 자격 증명에 따라 AWS가 실행됩니다.
인증 시간에 Saml Assertion을 캐시하기 위해 플래그 --cache-saml 사용할 수 있습니다. SAML Assertion Cache는 매우 짧은 유효성 (5 분)을 가지며 단일 MFA 검증으로 여러 역할을 인증하는 데 사용될 수 있습니다.
saml2aws 프로파일 당 파일이 있으며, 캐시 디렉토리는 saml2aws 라고하며 사용자 HomeDir의 .aws 디렉토리에 있습니다.
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 라이센스에 따라 릴리스됩니다. MIT 라이센스에 명시 적으로 부여되지 않은 모든 권리는 예약되어 있습니다. 자세한 내용은 포함 된 license.md 파일을 참조하십시오.