Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): handle ENOTDIR when opening cert config #10697

Merged
Merged
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
10 changes: 5 additions & 5 deletions auth/internal/transport/cert/secureconnect_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func NewSecureConnectProvider(configFilePath string) (Provider, error) {

file, err := os.ReadFile(configFilePath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// Config file missing means Secure Connect is not supported.
return nil, errSourceUnavailable
}
return nil, err
// Config file missing means Secure Connect is not supported.
// There are non-os.ErrNotExist errors that may be returned.
// (e.g. if the home directory is /dev/null, *nix systems will
// return ENOTDIR instead of ENOENT)
return nil, errSourceUnavailable
codyoss marked this conversation as resolved.
Show resolved Hide resolved
}

var metadata secureConnectMetadata
Expand Down
30 changes: 30 additions & 0 deletions auth/internal/transport/cert/secureconnect_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package cert
import (
"bytes"
"errors"
"os"
"path/filepath"
"testing"
)

Expand All @@ -30,6 +32,34 @@ func TestSecureConnectSource_ConfigMissing(t *testing.T) {
}
}

func TestSecureConnectSource_ConfigNotDirMissing(t *testing.T) {
source, err := NewSecureConnectProvider("/dev/null/missing.json")
if got, want := err, errSourceUnavailable; !errors.Is(err, errSourceUnavailable) {
t.Fatalf("got %v, want %v", got, want)
}
if source != nil {
t.Errorf("got %v, want nil source", source)
}
}

func TestSecureConnectSource_ConfigMissingPerms(t *testing.T) {
if os.Getuid() == 0 {
t.Skip("skipping permissions-related test because UID is 0 (reads never get EPERM while running as root in the current namespace)")
}
td := t.TempDir()
tmpFilePath := filepath.Join(td, "unreadable.json")
if wrErr := os.WriteFile(tmpFilePath, []byte{}, 0000); wrErr != nil {
t.Fatalf("failed to write temp file with permissions 000: %s", wrErr)
}
source, err := NewSecureConnectProvider(tmpFilePath)
if got, want := err, errSourceUnavailable; !errors.Is(err, errSourceUnavailable) {
t.Fatalf("got %v, want %v", got, want)
}
if source != nil {
t.Errorf("got %v, want nil source", source)
}
}

func TestSecureConnectSource_GetClientCertificateSuccess(t *testing.T) {
source, err := NewSecureConnectProvider("testdata/context_aware_metadata.json")
if err != nil {
Expand Down
Loading