From 19177fd62428c43c0672cdb02d1dd0dafaa33c3f Mon Sep 17 00:00:00 2001 From: Joshua Casey Date: Thu, 21 Sep 2023 10:37:26 -0500 Subject: [PATCH] Use only the basename (filename) and not the full path for the pinniped binary --- cmd/pinniped/cmd/kubeconfig.go | 6 ++- cmd/pinniped/cmd/kubeconfig_test.go | 57 ++++++++++++++++------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/cmd/pinniped/cmd/kubeconfig.go b/cmd/pinniped/cmd/kubeconfig.go index 9e4a53b59c..930c673c37 100644 --- a/cmd/pinniped/cmd/kubeconfig.go +++ b/cmd/pinniped/cmd/kubeconfig.go @@ -12,6 +12,7 @@ import ( "io" "net/http" "os" + "path/filepath" "strconv" "strings" "time" @@ -268,7 +269,10 @@ func newExecConfig(deps kubeconfigDeps, flags getKubeconfigParams) (*clientcmdap execConfig.InstallHint = flags.installHint var err error - execConfig.Command, err = deps.getPathToSelf() + execConfig.Command, err = func() (string, error) { + command, err := deps.getPathToSelf() + return filepath.Base(command), err + }() if err != nil { return nil, fmt.Errorf("could not determine the Pinniped executable path: %w", err) } diff --git a/cmd/pinniped/cmd/kubeconfig_test.go b/cmd/pinniped/cmd/kubeconfig_test.go index d0d4220b3d..6151367e63 100644 --- a/cmd/pinniped/cmd/kubeconfig_test.go +++ b/cmd/pinniped/cmd/kubeconfig_test.go @@ -97,6 +97,7 @@ func TestGetKubeconfig(t *testing.T) { name string args func(string, string) []string env map[string]string + getPathToSelf string getPathToSelfErr error getClientsetErr error conciergeObjects func(string, string) []runtime.Object @@ -1368,7 +1369,7 @@ func TestGetKubeconfig(t *testing.T) { - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - --upstream-identity-provider-flow=cli_password - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1383,7 +1384,8 @@ func TestGetKubeconfig(t *testing.T) { }, }, { - name: "valid static token", + name: "valid static token", + getPathToSelf: "../../other/path/other-executable", args: func(issuerCABundle string, issuerURL string) []string { return []string{ "--kubeconfig", "./testdata/kubeconfig.yaml", @@ -1437,7 +1439,7 @@ func TestGetKubeconfig(t *testing.T) { - --concierge-endpoint=https://fake-server-url-value - --concierge-ca-bundle-data=ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YS12YWx1ZQ== - --token=test-token - command: '.../path/to/pinniped' + command: other-executable env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1502,7 +1504,7 @@ func TestGetKubeconfig(t *testing.T) { - --concierge-ca-bundle-data=ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YS12YWx1ZQ== - --credential-cache= - --token-env=TEST_TOKEN - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1572,7 +1574,7 @@ func TestGetKubeconfig(t *testing.T) { - --scopes=offline_access,openid,pinniped:request-audience,username,groups - --ca-bundle-data=%s - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1658,7 +1660,7 @@ func TestGetKubeconfig(t *testing.T) { - --session-cache=/path/to/cache/dir/sessions.yaml - --debug-session-cache - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1771,7 +1773,7 @@ func TestGetKubeconfig(t *testing.T) { - --scopes=offline_access,openid,pinniped:request-audience,username,groups - --ca-bundle-data=%s - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1880,7 +1882,7 @@ func TestGetKubeconfig(t *testing.T) { - --scopes=offline_access,openid,pinniped:request-audience,username,groups - --ca-bundle-data=%s - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -1959,7 +1961,7 @@ func TestGetKubeconfig(t *testing.T) { - --request-audience=test-audience - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2038,7 +2040,7 @@ func TestGetKubeconfig(t *testing.T) { - --request-audience=test-audience - --upstream-identity-provider-name=some-oidc-idp - --upstream-identity-provider-type=oidc - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2113,7 +2115,7 @@ func TestGetKubeconfig(t *testing.T) { - --scopes=offline_access,openid,pinniped:request-audience,username,groups - --ca-bundle-data=%s - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2186,7 +2188,7 @@ func TestGetKubeconfig(t *testing.T) { - --scopes=offline_access,openid,pinniped:request-audience,username,groups - --ca-bundle-data=%s - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2266,7 +2268,7 @@ func TestGetKubeconfig(t *testing.T) { - --scopes=offline_access,openid,pinniped:request-audience,username,groups - --ca-bundle-data=%s - --request-audience=test-audience - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2355,7 +2357,7 @@ func TestGetKubeconfig(t *testing.T) { - --request-audience=test-audience - --upstream-identity-provider-name=some-oidc-idp - --upstream-identity-provider-type=oidc - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2443,7 +2445,7 @@ func TestGetKubeconfig(t *testing.T) { - --request-audience=test-audience - --upstream-identity-provider-name=some-oidc-idp - --upstream-identity-provider-type=oidc - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2531,7 +2533,7 @@ func TestGetKubeconfig(t *testing.T) { - --request-audience=test-audience - --upstream-identity-provider-name=some-oidc-idp - --upstream-identity-provider-type=oidc - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2610,7 +2612,7 @@ func TestGetKubeconfig(t *testing.T) { - --upstream-identity-provider-name=some-oidc-idp - --upstream-identity-provider-type=oidc - --upstream-identity-provider-flow=foobar - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2693,7 +2695,7 @@ func TestGetKubeconfig(t *testing.T) { - --upstream-identity-provider-name=some-oidc-idp - --upstream-identity-provider-type=oidc - --upstream-identity-provider-flow=foobar - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2751,7 +2753,7 @@ func TestGetKubeconfig(t *testing.T) { - --ca-bundle-data=%s - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2812,7 +2814,7 @@ func TestGetKubeconfig(t *testing.T) { - --ca-bundle-data=%s - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2873,7 +2875,7 @@ func TestGetKubeconfig(t *testing.T) { - --ca-bundle-data=%s - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2935,7 +2937,7 @@ func TestGetKubeconfig(t *testing.T) { - --ca-bundle-data=%s - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -2998,7 +3000,7 @@ func TestGetKubeconfig(t *testing.T) { - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - --upstream-identity-provider-flow=foobar - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -3059,7 +3061,7 @@ func TestGetKubeconfig(t *testing.T) { - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - --upstream-identity-provider-flow=cli_password - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -3119,7 +3121,7 @@ func TestGetKubeconfig(t *testing.T) { - --upstream-identity-provider-name=some-ldap-idp - --upstream-identity-provider-type=ldap - --upstream-identity-provider-flow=cli_password - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details @@ -3185,7 +3187,7 @@ func TestGetKubeconfig(t *testing.T) { - --concierge-endpoint=https://fake-server-url-value - --concierge-ca-bundle-data=ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YS12YWx1ZQ== - --token=test-token - command: '.../path/to/pinniped' + command: pinniped env: [] installHint: Test installHint message provideClusterInfo: true @@ -3234,6 +3236,9 @@ func TestGetKubeconfig(t *testing.T) { if tt.getPathToSelfErr != nil { return "", tt.getPathToSelfErr } + if tt.getPathToSelf != "" { + return tt.getPathToSelf, nil + } return ".../path/to/pinniped", nil }, getClientset: func(clientConfig clientcmd.ClientConfig, apiGroupSuffix string) (conciergeclientset.Interface, error) {