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

kubeadm-init: add --copy-credentials-for-user #55901

Closed
wants to merge 1 commit into from

Conversation

neolit123
Copy link
Member

@neolit123 neolit123 commented Nov 16, 2017

What this PR does / why we need it:

Using this new parameter the administrator's credentials
for the cluster will be copied to the specified
user's home directory.

WARNING: existing files will be overwritten.

Usage:
kubeadm init --copy-credentials-for-user=

It automates a step that the user needs to perform either manually each time or by scripting. If the flag is not set the old behavior is preserved - i.e. show info how / where to copy the config.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Related to #235
Fixes kubernetes/kubeadm#416

Special notes for your reviewer:

Release note:

Add `--copy-credentials-for-user` to `kubeadm init`. The flag can be used to automatically copy the administrator's credentials to the specified user's home directory.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 16, 2017
@neolit123
Copy link
Member Author

/area kubeadm

@dims
Copy link
Member

dims commented Nov 16, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 16, 2017
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 17, 2017
@neolit123
Copy link
Member Author

@timothysc i was trying to speak about this during the SIG meeting today, but looks like my MIC decided to not work for some reason. :(

@timothysc timothysc added the sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. label Nov 21, 2017
Copy link
Member

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

I'm generally ok with it, but we should talk with @luxas about what he thinks because it's so late in the cycle.

} else {
ctx["KubeConfigInfo"] = ""
if err := copyConfigForDefaultUser(i.defaultUser, adminKubeConfigPath); err != nil {
return fmt.Errorf("error copying configuration for user %q: %v", i.defaultUser, err)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we still have the previous instructions for a failure?

Copy link
Member Author

Choose a reason for hiding this comment

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

seems like the correct thing to do. i will amend the commit.

@neolit123
Copy link
Member Author

@timothysc @luxas
updated.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2017
Copy link
Member

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

/lgtm - to get you in before the freeze, but definitely redux the logic per-comments b4 approve.


if _, err := os.Stat(kubeDir); err != nil {
if os.IsNotExist(err) {
err = os.Mkdir(kubeDir, 0700)
Copy link
Member

Choose a reason for hiding this comment

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

You could probably just make the dir and check ignore the error if it exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, makes sense.

}
defer dest.Close()

_, err = io.Copy(src, dest)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see why you couldn't just copy vs. open.

Copy link
Member Author

Choose a reason for hiding this comment

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

could you please clarify this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

@timothysc TMK, golang does not provide means to copy files on os level with a single command. thus, one has to os.Open() and use io.Copy().

Copy link
Member Author

Choose a reason for hiding this comment

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

issue: reversed src / dest in the recent amend!

@timothysc timothysc added this to the v1.9 milestone Nov 22, 2017
@timothysc timothysc added status/approved-for-milestone lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Nov 22, 2017
@neolit123
Copy link
Member Author

should i include the above change in my commit?

@neolit123 - yes

@timothysc ok, done.

@timothysc
Copy link
Member

/retest

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

@neolit123 , if we are extending how kubeconfig file are created in kubeadm init, IMO it is necessary to ensure a consistent behaviour also in kubeadm alpha phase kubeconfig. WDYT?

@neolit123
Copy link
Member Author

@fabianofranz hi,
i'm not sure i understand how to relate --copy-credentials-for-user with kubeadm alpha phase kubeconfig. could you please elaborate?

perhaps you mean to allow alpha phase to generate directly in a user folder in the lines of "generate config files for this user" (e.g. add new flag --generate-config-for-user)?

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neolit123, timothysc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@neolit123
Copy link
Member Author

got the bazel tests to pass but the uni test now spills a pile of warnings / errors that seem unrelated.
could someone please explain the situation, please?

@neolit123
Copy link
Member Author

/test pull-kubernetes-unit

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request Labels Incomplete

@luxas @neolit123 @timothysc

Action required: This pull request requires label changes. If the required changes are not made within 3 days, the pull request will be moved out of the v1.10 milestone.

priority: Must specify exactly one of priority/critical-urgent, priority/important-longterm or priority/important-soon.

Help

@timothysc timothysc removed this from the v1.10 milestone Mar 2, 2018
@neolit123 neolit123 force-pushed the config branch 4 times, most recently from 73921ce to b6d6dc5 Compare March 24, 2018 14:25
@timothysc timothysc removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 7, 2018
@timothysc timothysc changed the title [WIP] kubeadm-init: add --copy-credentials-for-user kubeadm-init: add --copy-credentials-for-user Apr 7, 2018

usr, err = user.Lookup(copyCredentialsForUser)
if err != nil {
return fmt.Errorf(InitErrorNoSuchUser)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of recasting the errors here. Could you use the errors.Wrap utility if you want to put your output change on it.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, i can rebase this next Monday (AFK this week).

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to always include the relevant error in the Errorf() format.

)

// InitCopyCredentialsForUser will copy the cluster admin credentials to the home path of a non-root user
func InitCopyCredentialsForUser(copyCredentialsForUser string, adminKubeConfigPath string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Why can you use ENV-var's or some other platform agnostic library to determine $HOMEDIR.

/cc @kubernetes/sig-windows-misc

Copy link
Member Author

@neolit123 neolit123 Apr 11, 2018

Choose a reason for hiding this comment

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

this targets any Windows user. the env. variable %HOME% can only be used for the current user. also some user might have decided to move his home dir outside of default user path on Windows - e.g. /users/.

cc @luxas
some related changes of mine got accepted in the user package of the Go standard libarary...
https://github.com/golang/go/commits?author=neolit123

Copy link
Member Author

Choose a reason for hiding this comment

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

^ these are going to make it in go 1.11 in August i would guess.

Copy link
Member

Choose a reason for hiding this comment

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

I'm generally not ok with this change todo the last step which folks automate to add this platform specific code which can/will be obviated.

Copy link
Member Author

Choose a reason for hiding this comment

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

even with my contribs to the user package in the go std lib that can eventually replace the above code, this change would still need the _unix, _windows files, because:

  • there is no chown on windows
  • the way to check if a user is root/admin differs between platforms

@k8s-ci-robot k8s-ci-robot added the sig/windows Categorizes an issue or PR as relevant to SIG Windows. label Apr 10, 2018
Using this new parameter the administrator's credentials
for the cluster will be copied to the specified
user's home directory.

WARNING: existing files will be overwritten.

Usage:
    kubeadm init --copy-credentials-for-user=<someuser>

Windows requires a different approach for copying the
credentials than Unix, thus a new package is added -
`platform` in `kubeadm/app/cmd`. It contains `init_unix.go`
and `init_windows.go` that define the exported function -
InitCopyCredentialsForUser(). The function works differently
on Unix and Windows.

The same package can be re-used for other multiplatform code.
@timothysc timothysc removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 18, 2018
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Apr 18, 2018

@neolit123: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gce f67a150 link /test pull-kubernetes-e2e-gce

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@neolit123
Copy link
Member Author

/test pull-kubernetes-verify

@timothysc
Copy link
Member

I'm going to close this one per comment kubernetes/kubeadm#416 (comment) .

Also, due to the other dependencies that we would drag in. If you feel like we can do this and trim it down feel free to ping me on slack.

@timothysc timothysc closed this Apr 20, 2018
@neolit123
Copy link
Member Author

i'm perfectly fine with the close in the aspect of this not being a cmd flag. having this in the configuration is better.
in terms of actually installing the kubeconfig for a certain user i don't think this can go without the os/user package and without a small OS abstraction layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. milestone/incomplete-labels release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to configure user and cluster name in AdminKubeConfigFile
9 participants