Skip to content

Commit

Permalink
Merge branch 'master' into Versentgh-36
Browse files Browse the repository at this point in the history
  • Loading branch information
dboitnot committed Jul 21, 2022
2 parents 8077598 + 6957a74 commit dfb81d0
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 87 deletions.
3 changes: 2 additions & 1 deletion .appveyor/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ environment:
secure: 3kWTz99Qj+ipyaR73CxcJeGRRbmk84MF2ERDu6MyY10cjHAi6s3AVZ2Ccoa+Ioyt
appName: saml2aws
install:
- set PATH=C:\msys64\mingw64\bin;%PATH%
- set PATH=C:\msys64\mingw64\bin;C:\go118\bin;%PATH%
- set GOROOT=C:\go118
- ps: >-
$VerbosePreference = 'Continue'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: 1.18.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: 1.18.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -56,7 +56,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: 1.18.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: 1.18.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,65 @@ To use this credential, call the AWS CLI with the --profile option (e.g. aws --p
```

## Advanced Configuration
### Windows Subsystem Linux (WSL) Configuration
If you are using WSL1 or WSL2, you might get the following error when attempting to save the credentials into the keychain

Configuring multiple accounts with custom role and profile in `~/.aws/config` with goal being isolation between infra code when deploying to these environments. This setup assumes you're using separate roles and probably AWS accounts for `dev` and `test` and is designed to help operations staff avoid accidentally deploying to the wrong AWS account in complex environments. Note that this method configures SAML authentication to each AWS account directly (in this case different AWS accounts). In the example below, separate authentication values are configured for AWS accounts 'profile=customer-dev/awsAccount=was 121234567890' and 'profile=customer-test/awsAccount=121234567891'
```
No such interface “org.freedesktop.DBus.Properties” on object at path /
```

This happens because the preferred keyring back-end - uses the `gnome-keyring` by default - which requires X11 - and if you are not using Windows 11 with support for Linux GUI applications - this can be difficult without [configuring a X11 forward](https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2).

There are 2 preferred approaches to workaround this issue:

#### Option 1: Disable Keychain
You can apply the `--disable-keychain` flag when using both the `configure` and `login` commands. Using this flag means that your credentials (such as your password to your IDP, or in the case of Okta the Okta Session Token) will not save to your keychain - and be skipped entierly. This means you will be required to enter your username and password each time you invoke the `login` command.

#### Option 2: Configure Pass to be the default keyring
There are a few steps involved with this option - however this option will save your credentials (such as your password to your IDP, and session tokens etc) into the `pass`[https://www.passwordstore.org/] keyring. The `pass` keyring is the standard Unix password manager. This option was *heavily inspired* by a similar issue in [aws-vault](https://github.com/99designs/aws-vault/issues/683)

To configure pass to be the default keyring the following steps will need to be completed (assuming you are using Ubuntu 20.04 LTS):

1. Install the pass backend and update gnupg, which encrypts passwords
```bash
sudo apt-get update && sudo apt-get install -y pass gnupg
```

2. Generate a key with gpg (gnupg) and take note of your public key
```bash
gpg --gen-key
```

### Dev Account Setup
The output of the gpg command will output the something similar to the following:
```
public and secret key created and signed.
pub rsa3072 2021-04-22 [SC] [expires: 2023-04-22]
844E426A53A64C2A916CBD1F522014D5FDBF6E3D
uid Meir Gabay <willy@wonka.com>
sub rsa3072 2021-04-22 [E] [expires: 2023-04-22]
```

3. Create a storage key in pass from the previously generated public (pub) key
```bash
pass init <GPG_PUBLIC_KEY>
```
during the `init` process you'll be requested to enter the passphrase provided in step 2

4. Now, configure `saml2aws` to use the `pass` keyring. This can be done by setting the `SAML2AWS_KEYRING_BACKEND` environment variable to be `pass`. You'll need to also set the `GPG_TTY` to your current tty which means you can set the variable to `"$( tty )"`

which means the following can be added into your profile
```
export SAML2AWS_KEYRING_BACKEND=pass
export GPG_TTY="$( tty )"
```

5. Profit! Now when you run login/configure commands - you'll be promoted once to enter your passphrase - and your credentials will be saved into your keyring!


### Configuring Multiple Accounts
Configuring multiple accounts with custom role and profile in `~/.aws/config` with goal being isolation between infra code when deploying to these environments. This setup assumes you're using separate roles and probably AWS accounts for `dev` and `test` and is designed to help operations staff avoid accidentally deploying to the wrong AWS account in complex environments. Note that this method configures SAML authentication to each AWS account directly (in this case different AWS accounts). In the example below, separate authentication values are configured for AWS accounts 'profile=customer-dev/awsAccount=was 121234567890' and 'profile=customer-test/awsAccount=121234567891'
#### Dev Account Setup

To setup the dev account run the following and enter URL, username and password, and assign a standard role to be automatically selected on login.

Expand All @@ -415,7 +470,7 @@ region = us-east-1

To use this you will need to export `AWS_DEFAULT_PROFILE=customer-dev` environment variable to target `dev`.

### Test Account Setup
#### Test Account Setup

To setup the test account run the following and enter URL, username and password.

Expand Down
9 changes: 8 additions & 1 deletion cmd/saml2aws/commands/login_linux.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package commands

import (
"os"

"github.com/versent/saml2aws/v2/helper/credentials"
"github.com/versent/saml2aws/v2/helper/linuxkeyring"
"github.com/versent/saml2aws/v2/pkg/cfg"
)

func init() {
if keyringHelper, err := linuxkeyring.NewKeyringHelper(); err == nil {
c := linuxkeyring.Configuration{
Backend: os.Getenv(cfg.KeyringBackEnvironmentVariableName),
}

if keyringHelper, err := linuxkeyring.NewKeyringHelper(c); err == nil {
credentials.CurrentHelper = keyringHelper
}
}
25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/versent/saml2aws/v2

go 1.17
go 1.18

require (
github.com/99designs/keyring v1.1.6
github.com/AlecAivazis/survey/v2 v2.3.2
github.com/99designs/keyring v1.2.1
github.com/AlecAivazis/survey/v2 v2.3.5
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e
github.com/PuerkitoBio/goquery v1.8.0
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.42.44
github.com/aws/aws-sdk-go v1.44.59
github.com/beevik/etree v1.1.0
github.com/danieljoos/wincred v1.1.2
github.com/google/uuid v1.3.0
Expand All @@ -18,22 +18,23 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mxschmitt/playwright-go v0.1400.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.0
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.13.0
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.14.1
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
gopkg.in/ini.v1 v1.66.3
gopkg.in/ini.v1 v1.66.6
)

require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/bearsh/hid v1.3.0 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
Expand All @@ -44,13 +45,13 @@ require (
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit dfb81d0

Please sign in to comment.