Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tools/gomodcheck/.gomodcheck
credentials
# Authentication credential sources are code, not local credential files.
!/pkg/auth/credentials/
!/pkg/auth/providers/aws/saml2aws/helper/credentials/

# Tool version managers
.tool-versions
Expand Down
23 changes: 23 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,29 @@ linters:
- lintroller
path: ^magefiles/
text: "perf\\.Track"
# Vendored fork of the unmaintained saml2aws library (MIT, see its ATTRIBUTIONS.md).
# Atmos style and convention linters are relaxed for the upstream code; correctness
# linters (govet, staticcheck, unused, errorlint, bodyclose, nilerr, gosec) still apply.
- linters:
- cyclop
- depguard
- dogsled
- dupl
- err113
- forbidigo
- funlen
- gocognit
- gocritic
- godot
- importas
- lintroller
- nestif
- paralleltest
- revive
- tparallel
- unparam
- whitespace
path: ^pkg/auth/providers/aws/saml2aws/
paths:
- experiments/.*
- third_party$
Expand Down
24 changes: 8 additions & 16 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,6 @@ BSD LICENSED DEPENDENCIES
License: BSD-3-Clause
URL: https://github.com/go-git/gcfg/blob/3a3c6141e376/LICENSE

- github.com/go-jose/go-jose/v3/json
License: BSD-3-Clause
URL: https://github.com/go-jose/go-jose/blob/v3.0.5/json/LICENSE

- github.com/go-jose/go-jose/v4/json
License: BSD-3-Clause
URL: https://github.com/go-jose/go-jose/blob/v4.1.6/json/LICENSE
Expand Down Expand Up @@ -1524,10 +1520,6 @@ MIT LICENSED DEPENDENCIES
License: MIT
URL: https://github.com/Azure/azure-sdk-for-go/blob/sdk/storage/azblob/v1.7.0/sdk/storage/azblob/LICENSE.txt

- github.com/Azure/go-ntlmssp
License: MIT
URL: https://github.com/Azure/go-ntlmssp/blob/v0.1.1/LICENSE

- github.com/AzureAD/microsoft-authentication-library-for-go/apps
License: MIT
URL: https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/v1.7.2/LICENSE
Expand Down Expand Up @@ -1720,6 +1712,10 @@ MIT LICENSED DEPENDENCIES
License: MIT
URL: https://github.com/clipperhouse/uax29/blob/v2.7.0/LICENSE

- github.com/cloudposse/atmos/pkg/auth/providers/aws/saml2aws
License: MIT
URL: https://github.com/cloudposse/atmos/blob/HEAD/pkg/auth/providers/aws/saml2aws/LICENSE.md

- github.com/cloudposse/atmos/pkg/config/homedir
License: MIT
URL: https://github.com/cloudposse/atmos/blob/HEAD/pkg/config/homedir/LICENSE
Expand Down Expand Up @@ -2168,6 +2164,10 @@ MIT LICENSED DEPENDENCIES
License: MIT
URL: https://github.com/muesli/termenv/blob/v0.16.0/LICENSE

- github.com/mxschmitt/playwright-go
License: MIT
URL: https://github.com/mxschmitt/playwright-go/blob/v0.6401.0/LICENSE

- github.com/otiai10/copy
License: MIT
URL: https://github.com/otiai10/copy/blob/v1.14.1/LICENSE
Expand All @@ -2180,10 +2180,6 @@ MIT LICENSED DEPENDENCIES
License: MIT
URL: https://github.com/peterbourgon/diskv/blob/v2.0.1/LICENSE

- github.com/playwright-community/playwright-go
License: MIT
URL: https://github.com/playwright-community/playwright-go/blob/v0.5700.1/LICENSE

- github.com/posthog/posthog-go
License: MIT
URL: https://github.com/posthog/posthog-go/blob/v1.17.4/LICENSE.md
Expand Down Expand Up @@ -2320,10 +2316,6 @@ MIT LICENSED DEPENDENCIES
License: MIT
URL: https://github.com/vektah/gqlparser/blob/v2.5.33/LICENSE

- github.com/versent/saml2aws/v2
License: MIT
URL: https://github.com/versent/saml2aws/blob/v2.36.19/LICENSE.md

- github.com/wlynxg/chardet
License: MIT
URL: https://github.com/wlynxg/chardet/blob/v1.0.5/LICENSE
Expand Down
108 changes: 108 additions & 0 deletions cmd/auth/exec_child_process_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package auth

import (
"context"
"encoding/json"
"errors"
"os"
"path/filepath"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

errUtils "github.com/cloudposse/atmos/errors"
)

const (
// Turns the test binary into the child process `auth exec` runs.
authExecChildEnv = "_ATMOS_TEST_AUTH_EXEC_CHILD"
// Names the file the child writes its observations to.
authExecChildReportEnv = "_ATMOS_TEST_AUTH_EXEC_REPORT"
// Exit code the child terminates with.
authExecChildExitEnv = "_ATMOS_TEST_AUTH_EXEC_EXIT"
)

// authExecChildReport is what the child process observed.
type authExecChildReport struct {
Args []string `json:"args"`
Identity string `json:"identity"`
}

// runAuthExecChild records the child's argv and authenticated identity, then
// exits with the requested code. It is invoked from TestMain.
func runAuthExecChild() int {
report, err := json.Marshal(authExecChildReport{Args: os.Args[1:], Identity: os.Getenv("ATMOS_IDENTITY")})
if err != nil {
return 98
}
if err := os.WriteFile(os.Getenv(authExecChildReportEnv), report, 0o600); err != nil {
return 99
}
code, err := strconv.Atoi(os.Getenv(authExecChildExitEnv))
if err != nil {
return 97
}
return code
}

// TestExecuteAuthExecCommand_ChildArgsAndExitCode runs a real child process
// through `auth exec` and verifies that arguments after "--" reach it verbatim
// (no shell interpretation, no Atmos flag parsing), that it runs with the
// authenticated identity's environment, and that its exit status propagates.
func TestExecuteAuthExecCommand_ChildArgsAndExitCode(t *testing.T) {
executable, err := os.Executable()
require.NoError(t, err)

childArgs := []string{
"two words",
`it's "quoted"`,
"$HOME and $(whoami) and `id`",
"line1\nline2",
"--identity=not-an-atmos-flag",
"",
}

for _, tt := range []struct {
name string
exitCode int
}{
{name: "success", exitCode: 0},
{name: "failure exit code propagates", exitCode: 7},
} {
t.Run(tt.name, func(t *testing.T) {
setupMockAuthFixture(t)
reportPath := filepath.Join(t.TempDir(), "child-report.json")
t.Setenv(authExecChildEnv, "1")
t.Setenv(authExecChildReportEnv, reportPath)
t.Setenv(authExecChildExitEnv, strconv.Itoa(tt.exitCode))

cmd := authExecCmd
resetAuthCmdFlags(t, cmd)
cmd.SetContext(context.Background())
require.NoError(t, cmd.ParseFlags(append([]string{"--", executable}, childArgs...)))

err := executeAuthExecCommand(cmd, cmd.Flags().Args())

if tt.exitCode == 0 {
require.NoError(t, err)
} else {
var exitErr errUtils.ExitCodeError
require.True(t, errors.As(err, &exitErr), "expected ExitCodeError, got %v", err)
assert.Equal(t, tt.exitCode, exitErr.Code)
assert.Equal(t, tt.exitCode, errUtils.GetExitCode(err))
}

raw, readErr := os.ReadFile(reportPath)
require.NoError(t, readErr, "the child process must have run")
var report authExecChildReport
require.NoError(t, json.Unmarshal(raw, &report))
assert.Equal(t, childArgs, report.Args, "arguments after -- must reach the child verbatim")
require.Len(t, report.Args, len(childArgs))
assert.Equal(t, childArgs[0], report.Args[0])
assert.Equal(t, childArgs[len(childArgs)-1], report.Args[len(report.Args)-1])
assert.Equal(t, "mock-identity", report.Identity, "the child must run as the resolved default identity")
})
}
}
5 changes: 5 additions & 0 deletions cmd/auth/testmain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
// package so tests that exercise printWhoamiJSON, printWhoamiHuman, list
// renderers, etc. don't panic with "data.InitWriter() must be called".
func TestMain(m *testing.M) {
// Act as the child process of `auth exec` tests (see exec_child_process_test.go).
if os.Getenv(authExecChildEnv) == "1" {
os.Exit(runAuthExecChild())
}

ioCtx, err := iolib.NewContext()
if err != nil {
// Tests cannot run without an IO context; fail loud.
Expand Down
Loading
Loading