Skip to content

make oc login kubeconfig permission error clearer #9968

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

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Jul 20, 2016

Related BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1332131

When logging in with a $KUBECONFIG variable, or --config flag pointing to a location that denies write access, oc login prints a non-specific error at the bottom of its output:

export KUBECONFIG=/src
oc login --token=<my_token> --insecure-skip-tls-verify

Logged into "https://localhost:8443" as "test" using the token provided.

You have one project on this server: "test-project"

Using project "test-project".
error: open /src.lock: permission denied

This updates the error to be more clear as to what has happened:

oc login -u test -p test --insecure-skip-tls-verify

Login successful.

You have one project on this server: "myproject"

Using project "myproject".
error: KUBECONFIG is set to a file that cannot be created or modified: /src
Solution:

You can unset the KUBECONFIG variable to use the default location for it:
   unset KUBECONFIG

Or you can set its value to a file that can be written to:
   export KUBECONFIG=/path/to/file

Caused By:
  open /src.lock: permission denied

Same output, but using a --config flag:

oc login -u test -p test --insecure-skip-tls-verify --config=/src

Login successful.

You have one project on this server: "myproject"

Using project "myproject".
error: KUBECONFIG is set to a file that cannot be created or modified: /src
Solution:

Make sure that the value of the --config flag passed contains a valid path:
        --config=/path/to/valid/file

Caused By:
  open /src.lock: permission denied

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch from ec5b7eb to 4510817 Compare July 21, 2016 15:14
@juanvallejo
Copy link
Contributor Author

[test]

@juanvallejo
Copy link
Contributor Author

@fabianofranz Could you please take a look? Thanks!

@@ -394,7 +394,11 @@ func (o *LoginOptions) SaveConfig() (bool, error) {
}

if err := kclientcmd.ModifyConfig(o.PathOptions, *configToWrite, true); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the only error that could come back from this a file permission error

Copy link
Contributor Author

@juanvallejo juanvallejo Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt hm, I could parse the error string to make sure it is a "permission denied" error before returning this message, and then otherwise return just the original error message. But I am not sure that the only error that comes back is file permission error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error strings is a code smell

Copy link
Contributor Author

@juanvallejo juanvallejo Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what if I type the errors in loader.go#WriteToFile and then return a message accordingly in loginoptions.go?

EDIT: turns out os.IsPermission works :p 0a85f23#diff-f260fb37cbe8b4d20167cc6bc6d4e51aR397

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch from 4510817 to 0a85f23 Compare July 21, 2016 17:14
@juanvallejo
Copy link
Contributor Author

[test]

@stevekuznetsov
Copy link
Contributor

Check with @csrwng, he implemented a similar feature in oc cluster up recently.

@csrwng
Copy link
Contributor

csrwng commented Jul 21, 2016

I added a check and error message in case your config is not writeable:
https://github.com/openshift/origin/blob/master/pkg/bootstrap/docker/up.go#L356

@juanvallejo
Copy link
Contributor Author

@csrwng @fabianofranz I think @csrwng's error message for kubeconfig not being writable definitely would work for oc login, do you think it'd be better to just import github.com/openshift/origin/pkg/bootstrap/docker/errors to use it here, or simply copy it over?

@fabianofranz
Copy link
Member

@juanvallejo importing works for me.

@liggitt
Copy link
Contributor

liggitt commented Jul 22, 2016

I would move it if we intend to reuse it. I don't want login depending on docker bootstrap packages.

@csrwng
Copy link
Contributor

csrwng commented Jul 22, 2016

@juanvallejo so in the cluster up code I check for the interfaces implemented by the error so I can print out additional details, solution, etc. In this case, it seems that would all make sense to be part of the error message, since that's what would get printed out, no?

@@ -275,6 +275,11 @@ os::cmd::expect_success_and_not_text 'oc get is' 'is/test1'
echo "resource printer: ok"
os::test::junit::declare_suite_end

os::test::junit::declare_suite_start "cmd/basicresources/login"
os::cmd::expect_failure_and_text "oc login ${KUBERNETES_MASTER} -u test -p test --config=/src --insecure-skip-tls-verify" 'Failed to create kubeconfig under'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote your vars

os::cmd::expect_failure_and_text "oc login '${KUBERNETES_MASTER}' -u test ...
                                           ^                    ^

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch from 2e003dd to ac74302 Compare July 22, 2016 20:06
@juanvallejo
Copy link
Contributor Author

@csrwng

@juanvallejo so in the cluster up code I check for the interfaces implemented by the error so I can print out additional details, solution, etc

Thanks for pointing this out! I went ahead and added that in the printer.go file, as well as a FormatError function for cases where you're returning the final error with its message, rather than passing a writer interface.

@csrwng
Copy link
Contributor

csrwng commented Jul 22, 2016

@juanvallejo you can implement FormatError by calling PrintError on a buffer and returning the buffer string.

One concern is that we don't usually display errors like this for other CLI commands.

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch from ac74302 to ea204df Compare July 22, 2016 20:46
@juanvallejo
Copy link
Contributor Author

juanvallejo commented Jul 22, 2016

@csrwng

you can implement FormatError by calling PrintError on a buffer and returning the buffer string.

Sounds good

One concern is that we don't usually display errors like this for other CLI commands.

I went ahead and changed the format so that it resembles more a standard error msg:

Login successful.

You have one project on this server: "myproject"

Using project "myproject".
error: KUBECONFIG is set to a file that cannot be created or modified: /src
open /src.lock: permission denied

You can unset the KUBECONFIG variable to use the default location for it:
   unset KUBECONFIG

Or you can set its value to a file that can be written to:
   export KUBECONFIG=/path/to/file

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch from ea204df to c9f443d Compare July 22, 2016 20:51
@juanvallejo
Copy link
Contributor Author

re[test]

@fabianofranz
Copy link
Member

Looks like parts of this new errors structure (the interface, printer, internalError, etc) are generic enough to be used not only by oc but also other commands (oadm, openshift, etc). Should then be in a parent package like pkg/cmd/errors?

@juanvallejo
Copy link
Contributor Author

@fabianofranz

Should then be in a parent package like pkg/cmd/errors?

I agree with this, I'll go ahead and update the PR

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch 3 times, most recently from aac0667 to 2e709a5 Compare July 26, 2016 19:13
os::test::junit::declare_suite_start "cmd/authentication"

os::test::junit::declare_suite_start "cmd/authentication/scopedtokens"
os::cmd::expect_success 'oadm policy add-role-to-user admin scoped-user'

# make sure we handle invalid config file destination
os::cmd::expect_failure_and_text "oc login '${KUBERNETES_MASTER}' -u test -p test --config=/src --insecure-skip-tls-verify" 'KUBECONFIG is set to a file that cannot be created or modified'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this belongs to the suite you started in line 13 (which is doing nothing).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of our tests for oc login are in the main body of hack/test-cmd.sh.

Although I have a PR in flight to move that location, I think it makes the most sense to colocate this test and those others. Whichever of us merges first will rebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I will update the PR with these changes

@juanvallejo
Copy link
Contributor Author

@deads2k @fabianofranz

If you're going to use this type to collapse the pkg/bootstrap/docker usage, then it can live here. If its only call site is pkg/cmd/cli/cmd, then it should live there.

Sounds good, since errors/login.go is only used by pkg/cmd/cli/cmd/loginoptions.go, I have moved it to pkg/cmd/cli/cmd/errors

@fabianofranz
Copy link
Member

@juanvallejo good to go?

@juanvallejo
Copy link
Contributor Author

@fabianofranz Yeah, everything looks good to me

@openshift-bot
Copy link
Contributor

openshift-bot commented Jul 27, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7026/) (Image: devenv-rhel7_4690)

@deads2k
Copy link
Contributor

deads2k commented Jul 27, 2016

@juanvallejo could use a squash

@juanvallejo juanvallejo force-pushed the jvallejo_update-kubeconfig-permission-error branch from f3354e7 to ce8595f Compare July 27, 2016 17:59
@juanvallejo
Copy link
Contributor Author

@deads2k

could use a squash

Done!

@fabianofranz
Copy link
Member

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to ce8595f

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7001/)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to ce8595f

@openshift-bot openshift-bot merged commit 75fce88 into openshift:master Jul 28, 2016
@juanvallejo juanvallejo deleted the jvallejo_update-kubeconfig-permission-error branch July 28, 2016 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants