Skip to content

Commit 792eace

Browse files
authored
Merge branch 'master' into bugfix/dw_add_number_challeng
2 parents 39b9163 + f8af25e commit 792eace

34 files changed

+1322
-215
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.buildtemp

.github/workflows/go.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424

2525
- name: Test
2626
run: |
27-
go run github.com/playwright-community/playwright-go/cmd/playwright install
2827
go test -v ./... -coverprofile=${{ matrix.os }}_coverage.txt -covermode=atomic
2928
3029
- name: Upload coverage report
@@ -53,7 +52,8 @@ jobs:
5352
- name: golangci-lint
5453
uses: golangci/golangci-lint-action@v3
5554
with:
56-
version: v1.51.2
55+
version: v1.53.2
56+
args: --timeout=2m
5757

5858
coverage:
5959
name: coverage
@@ -81,6 +81,7 @@ jobs:
8181
matrix:
8282
os:
8383
- ubuntu-latest
84+
- ubuntu-20.04
8485
- macos-latest
8586
runs-on: ${{ matrix.os }}
8687
steps:
@@ -93,7 +94,7 @@ jobs:
9394
uses: actions/checkout@v3
9495

9596
- name: Install dependency required for linux builds
96-
if: matrix.os == 'ubuntu-latest'
97+
if: matrix.os == 'ubuntu-20.04'
9798
run: sudo apt-get update && sudo apt-get install -y libudev-dev
9899

99100
- name: GoReleaser

.github/workflows/release.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ jobs:
2020
matrix:
2121
os:
2222
- ubuntu-latest
23+
- ubuntu-20.04
2324
- macos-latest
2425
runs-on: ${{ matrix.os }}
2526
if: github.event_name != 'workflow_dispatch'
27+
permissions: write-all
2628
steps:
2729

2830
- name: Set up Go 1.x
@@ -34,20 +36,33 @@ jobs:
3436
uses: actions/checkout@v3
3537

3638
- name: Install dependency required for linux builds
37-
if: matrix.os == 'ubuntu-latest'
39+
if: matrix.os == 'ubuntu-20.04'
3840
run: sudo apt-get update && sudo apt-get install -y libudev-dev
3941

42+
- name: Add Lowercase Repository Name to Environment
43+
run: |
44+
echo REPOSITORY_NAME_LOWERCASE=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
45+
46+
- uses: "docker/login-action@v2"
47+
if: matrix.os == 'ubuntu-20.04'
48+
with:
49+
registry: "ghcr.io"
50+
username: "${{ github.actor }}"
51+
password: "${{ secrets.GITHUB_TOKEN }}"
4052
- name: GoReleaser
4153
uses: goreleaser/goreleaser-action@v4
4254
with:
4355
version: latest
4456
args: release --clean --config .goreleaser.${{ matrix.os }}.yml
4557
env:
4658
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
IMAGE_NAME: ${{ env.REPOSITORY_NAME_LOWERCASE }}
4760

4861
windows-msi:
4962
name: Build Windows MSI and upload to release
5063
runs-on: ubuntu-latest
64+
permissions:
65+
contents: write
5166
needs: [release]
5267
if: >- # https://github.com/actions/runner/issues/491
5368
always() &&
@@ -76,7 +91,7 @@ jobs:
7691

7792
- name: Retrieve the release asset
7893
id: asset
79-
uses: robinraju/release-downloader@768b85c8d69164800db5fc00337ab917daf3ce68 # v1.7
94+
uses: robinraju/release-downloader@efa4cd07bd0195e6cc65e9e30c251b49ce4d3e51 # v1.8
8095
with:
8196
repository: ${{ github.repository }}
8297
tag: ${{ env.VER_TAG }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ bin/
2020

2121
# direnv
2222
.envrc
23+
.buildtemp

.golangci.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ linters:
22
disable-all: true
33
enable:
44
- goimports
5-
- deadcode
65
- errcheck
76
- gosimple
87
- govet
98
- ineffassign
109
- staticcheck
11-
- structcheck
1210
- typecheck
1311
- unused
14-
- varcheck

.goreleaser.macos-latest.yml

-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ builds:
1515
- amd64
1616
- arm64
1717
- arm
18-
overrides:
19-
- goos: linux
20-
goarch: amd64
21-
goamd64: v1
22-
tags:
23-
- hidraw
24-
env:
25-
- CGO_ENABLED=1
2618
archives:
2719
- format: tar.gz
2820
wrap_in_directory: false

.goreleaser.ubuntu-20.04.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
project_name: saml2aws-u2f
3+
4+
builds:
5+
- id: saml2aws
6+
main: ./cmd/saml2aws/main.go
7+
binary: saml2aws
8+
flags:
9+
- -trimpath
10+
- -v
11+
ldflags:
12+
- -s -w -X main.Version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
13+
goos:
14+
- linux
15+
goarch:
16+
- amd64
17+
overrides:
18+
- goos: linux
19+
goarch: amd64
20+
goamd64: v1
21+
tags:
22+
- hidraw
23+
env:
24+
- CGO_ENABLED=1
25+
- id: saml2aws-static
26+
main: ./cmd/saml2aws/main.go
27+
binary: saml2aws
28+
flags:
29+
- -trimpath
30+
- -v
31+
ldflags:
32+
- -s -w -X main.Version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -extldflags "-static"
33+
goos:
34+
- linux
35+
goarch:
36+
- amd64
37+
- arm64
38+
- arm
39+
env:
40+
- CGO_ENABLED=0
41+
archives:
42+
- id: saml2aws
43+
format: tar.gz
44+
builds: [saml2aws]
45+
wrap_in_directory: false
46+
# remove README and LICENSE
47+
files:
48+
- LICENSE.md
49+
- README.md
50+
- id: saml2aws-static
51+
format: tar.gz
52+
builds: [saml2aws-static]
53+
wrap_in_directory: false
54+
# remove README and LICENSE
55+
files:
56+
- LICENSE.md
57+
- README.md
58+
name_template: "{{ .ProjectName }}_static_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
59+
checksum:
60+
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"
61+
dockers:
62+
- id: amd64
63+
goos: linux
64+
goarch: amd64
65+
use: buildx
66+
ids:
67+
- saml2aws-static
68+
image_templates:
69+
- ghcr.io/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64
70+
- ghcr.io/{{ .Env.IMAGE_NAME }}:latest-amd64
71+
build_flag_templates:
72+
- "--build-arg=BASE_IMAGE_ARCH=static-debian11"
73+
- "--platform=linux/amd64"
74+
- id: arm64
75+
goos: linux
76+
goarch: arm64
77+
use: buildx
78+
ids:
79+
- saml2aws-static
80+
image_templates:
81+
- ghcr.io/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64
82+
- ghcr.io/{{ .Env.IMAGE_NAME }}:latest-arm64
83+
build_flag_templates:
84+
- "--build-arg=BASE_IMAGE_ARCH=static:latest-arm64"
85+
- "--platform=linux/arm64"
86+
docker_manifests:
87+
- name_template: ghcr.io/{{ .Env.IMAGE_NAME }}:{{ .Version }}
88+
image_templates:
89+
- ghcr.io/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64
90+
- ghcr.io/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64
91+
- name_template: ghcr.io/{{ .Env.IMAGE_NAME }}:latest
92+
image_templates:
93+
- ghcr.io/{{ .Env.IMAGE_NAME }}:latest-amd64
94+
- ghcr.io/{{ .Env.IMAGE_NAME }}:latest-arm64

.goreleaser.ubuntu-latest.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ builds:
2020
- goos: linux
2121
goarch: amd64
2222
goamd64: v1
23-
tags:
24-
- hidraw
2523
env:
26-
- CGO_ENABLED=1
24+
- CGO_ENABLED=0
2725
archives:
2826
- format: tar.gz
2927
wrap_in_directory: false

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ARG BASE_IMAGE_ARCH=static-debian11
2+
FROM gcr.io/distroless/$BASE_IMAGE_ARCH
3+
COPY saml2aws /
4+
ENTRYPOINT ["/saml2aws"]

Dockerfile.build

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# base image
2+
FROM ubuntu:jammy
3+
ENV TZ=Australia/Sydney
4+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
5+
6+
# add arm64 architecture
7+
RUN apt-get update
8+
RUN dpkg --add-architecture arm64
9+
10+
## arch-qualify the current repositories
11+
RUN sed -i "s/deb h/deb [arch=amd64] h/g" /etc/apt/sources.list
12+
13+
## add arm64's repos
14+
RUN echo "# arm64 repositories" >> /etc/apt/sources.list
15+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted" >> /etc/apt/sources.list
16+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted" >> /etc/apt/sources.list
17+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy universe" >> /etc/apt/sources.list
18+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates universe" >> /etc/apt/sources.list
19+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy multiverse" >> /etc/apt/sources.list
20+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates multiverse" >> /etc/apt/sources.list
21+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list
22+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted" >> /etc/apt/sources.list
23+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security universe" >> /etc/apt/sources.list
24+
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse" >> /etc/apt/sources.list
25+
26+
RUN apt-get update && apt-get install -y build-essential git ca-certificates golang libudev-dev curl gnupg lsb-release curl gcc-arm* binutils-arm-linux-gnueabi crossbuild-essential-arm64 wget
27+
28+
RUN echo \
29+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
30+
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
31+
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
32+
RUN apt-get update && apt-get install -y docker-ce-cli
33+
# Replicate install of the same version of Golang that we are using in Github actions
34+
RUN wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.20.2.linux-amd64.tar.gz && rm go1.20.2.linux-amd64.tar.gz
35+
RUN go install github.com/goreleaser/goreleaser@latest
36+
ENV GOROOT="/usr/local/go"
37+
ENV PATH="/root/go/bin:$GOROOT/bin:${PATH}"

Makefile

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
NAME=saml2aws
22
ARCH=$(shell uname -m)
3-
OS=$(shell uname)
3+
OS?=$(shell uname)
44
ITERATION := 1
55

66
GOLANGCI_VERSION = 1.45.2
7-
87
GORELEASER := $(shell command -v goreleaser 2> /dev/null)
98

109
SOURCE_FILES?=$$(go list ./... | grep -v /vendor/)
@@ -13,6 +12,15 @@ TEST_OPTIONS?=
1312

1413
BIN_DIR := $(CURDIR)/bin
1514

15+
# Choose the right config file for the OS
16+
ifeq ($(OS),Darwin)
17+
CONFIG_FILE?=$(CURDIR)/.goreleaser.macos-latest.yml
18+
else ifeq ($(OS),Linux)
19+
CONFIG_FILE?=$(CURDIR)/.goreleaser.ubuntu-20.04.yml
20+
else
21+
$(error Unsupported build OS: $(OS))
22+
endif
23+
1624
ci: prepare test
1725

1826
mod:
@@ -41,16 +49,13 @@ build:
4149
ifndef GORELEASER
4250
$(error "goreleaser is not available please install and ensure it is on PATH")
4351
endif
44-
45-
ifeq ($(OS),Darwin)
46-
goreleaser build --snapshot --clean --config $(CURDIR)/.goreleaser.macos-latest.yml
47-
else ifeq ($(OS),Linux)
48-
goreleaser build --snapshot --clean --config $(CURDIR)/.goreleaser.ubuntu-latest.yml
49-
else
50-
$(error Unsupported build OS: $(OS))
51-
endif
52+
goreleaser build --snapshot --clean --config $(CONFIG_FILE)
5253
.PHONY: build
5354

55+
release-local: $(BIN_DIR)/goreleaser
56+
goreleaser release --snapshot --rm-dist --config $(CONFIG_FILE)
57+
.PHONY: release-local
58+
5459
clean:
5560
@rm -fr ./build
5661
.PHONY: clean
@@ -64,3 +69,15 @@ test:
6469
@echo "--- test all the things"
6570
@go test -cover ./...
6671
.PHONY: test
72+
73+
# It can be difficult to set up and test everything locally. Using this target you can build and run a docker container
74+
# that has all the tools you need to build and test saml2aws. This is particularly useful on Mac as it allows the Linux
75+
# and Docker builds to be tested.
76+
# Note: By necessity, this target mounts the Docker socket into the container. This is a security risk and should not
77+
# be used on a production system.
78+
# Note: Files written by the container will be owned by root. This is a limitation of the Docker socket mount.
79+
# You may need to run `docker run --privileged --rm tonistiigi/binfmt --install all` to enable the buildx plugin.
80+
docker-build-environment:
81+
docker build --platform=amd64 -t saml2aws/build -f Dockerfile.build .
82+
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -e BUILDX_CONFIG=$(PWD)/.buildtemp -e GOPATH=$(PWD)/.buildtemp -e GOTMPDIR=$(PWD)/.buildtemp -e GOCACHE=$(PWD)/.buildtemp/.cache -e GOENV=$(PWD)/.buildtemp/env -v $(PWD):$(PWD) -w $(PWD) saml2aws/build:latest
83+
.PHONY: docker-build-environment

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ saml2aws --version
114114
While brew is available for Linux you can also run the following without using a package manager.
115115

116116
```
117+
mkdir -p ~/.local/bin
117118
CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
118119
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
119120
chmod u+x ~/.local/bin/saml2aws
120121
hash -r
121122
saml2aws --version
122123
```
124+
If U2F support is required then there are separate builds for this - use the following download URL instead:
125+
```
126+
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
127+
```
123128

124129
#### Using Make
125130

@@ -244,6 +249,7 @@ Commands:
244249
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)
245250
--cache-saml Caches the SAML response (env: SAML2AWS_CACHE_SAML)
246251
--cache-file=CACHE-FILE The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)
252+
--download-browser-driver Automatically download browsers for Browser IDP. (env: SAML2AWS_AUTO_BROWSER_DOWNLOAD)
247253
--disable-sessions Do not use Okta sessions. Uses Okta sessions by default. (env: SAML2AWS_OKTA_DISABLE_SESSIONS)
248254
--disable-remember-device Do not remember Okta MFA device. Remembers MFA device by default. (env: SAML2AWS_OKTA_DISABLE_REMEMBER_DEVICE)
249255
@@ -540,6 +546,18 @@ region = us-east-1
540546

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

549+
### Playwright Browser Drivers for Browser IDP
550+
551+
If you are using the Browser Identity Provider, on first invocation of `saml2aws login` you need to remember to install
552+
the browser drivers in order for playwright-go to work. Otherwise you will see the following error message:
553+
554+
`Error authenticating to IDP.: could not start driver: fork/exec ... no such file or directory`
555+
556+
To install the drivers, you can:
557+
* Pass `--download-browser-driver` to `saml2aws login`
558+
* Set in your shell environment `SAML2AWS_AUTO_BROWSER_DOWNLOAD=true`
559+
* Set `download_browser_driver = true` in your saml2aws config file, i.e. `~/.saml2aws`
560+
543561
## Advanced Configuration (Multiple AWS account access but SAML authenticate against a single 'SSO' AWS account)
544562

545563
Example:

0 commit comments

Comments
 (0)