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

Make secrets at cluster startup. #5470

Merged
merged 1 commit into from
Apr 3, 2015
Merged

Conversation

erictune
Copy link
Member

@zmerlynn
Copy link
Member

Whatever you're trying to do with that script, it needs to go in kube-addons instead, because I'm going to bounce out anything that's at the tail of kube-up.sh. (I guess I need to get around to publishing the GKE manifesto, but #3579 is part of it.) Also, if you're generating variables like this, it'll require GKE side changes, too, so we need to talk.

@erictune
Copy link
Member Author

Is it a kube-addon if it is an absolutely essential component of a k8s cluster?

@zmerlynn
Copy link
Member

Good question on naming, but the original intent of having it created on the master still holds. I was originally thinking of calling these things "system objects" and not "addon objects", so maybe this would precipitate that change.

@erictune
Copy link
Member Author

@ArtfulCoder

The pod json/yaml for the scheduler and the controller-manager should go into, say:
cluster/addons/scheduler and cluster/addons/controller-manager.
Then near the top of cluster/saltbase/salt/kube-addons/init.sls, add a file.recurse to copy those files to the master via salt. Make it unconditional.

I don't believe that any change is needed in cluster/saltbase/salt/kube-addons/kube-addons.sh.

Right now, there is no ordering between the different addon objects. This should still "just work". That is, create all the object in any order. Without a scheduler, none of the objects will start except the scheduler, which has a Host field set. Without a controller-manager, none of the replication controllers will run, until it does. Then they should just work. Etc.

@zmerlynn tell me if above is correct.

@erictune
Copy link
Member Author

The question is how to get the variables we need (tokens) from kube-up to kube-addons.

Option 1: In the kube-addons.sh script, read the tokens from the known_tokens.csv file, and then create secret objects for each one. Pros: less plumbing. Cons: requires full filesystem access for the `kube-addons.sh script. I think it has this

Option 2: Actually generates the tokens in kube-addons.sh script, and append them to known_tokens.csv at that point. Pros: less shipping-around of secrets. Cons: Have to restart apiserver to pick up the new tokens.

@zmerlynn
Copy link
Member

The part where you're adding the env variable and generation of the token to kube-up.sh is fine. I'd actually prefer keeping that out of kube-addons.sh.

Why do you need two more tokens, btw?

@erictune
Copy link
Member Author

I want each system component to have its own identity so each component can have only the privileges it needs.

@erictune erictune changed the title WIP: Sketch of making scheduler from pod with secret Make secrets at cluster startup. Mar 27, 2015
@erictune
Copy link
Member Author

@zmerlynn I've moved most of my changes into kube-addons.sh

@ArtfulCoder you can use these secrets to authorize scheduler and replication controller.

@vishh you can use these secrets to authorize monitoring pods that need to talk to the apiserver.

for a in scheduler controller_manager logging monitoring dns
do
token=$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=32 count=1 2>/dev/null)
echo "${token},kubernetes_builtin:$a,kubernetes_builtin:$a" >> "${known_tokens_file}"
Copy link
Member Author

Choose a reason for hiding this comment

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

@smarterclayton ISTR you suggesting a format for namespacing usernames but I can't find the issue now. Is there already a standard used in openshift? Here I used kubernetes_builtin:$USER, but I am open to whatever.

@liggitt

Copy link
Member

Choose a reason for hiding this comment

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

We ended up with normal usernames being unnamedspaced (so they can inherit the preferred username from the bedrock identity provider), and namespaced system/service account usernames with a "prefix:" (like "system:" or "project:"). That means ":" is disallowed in normal usernames for us.

Copy link
Contributor

Choose a reason for hiding this comment

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

We had very specific users names and we are using the system: prefix to scope deeper roles.

https://github.com/openshift/origin/blob/master/pkg/cmd/server/bootstrappolicy/constants.go
https://github.com/openshift/origin/blob/master/pkg/cmd/server/admin/default_certs.go

Would be good to settle on a pattern for prefixing as we go (don't have to change here).

On Mar 27, 2015, at 7:18 PM, Jordan Liggitt notifications@github.com wrote:

In cluster/gce/configure-vm.sh:

@@ -260,6 +260,13 @@ function create-salt-auth() {
kubelet_auth_file="/srv/salt-overlay/salt/kubelet/kubernetes_auth"
(umask 077;
echo "{"BearerToken": "${KUBELET_TOKEN}", "Insecure": true }" > "${kubelet_auth_file}")
+

  • Generate tokens for other "service accounts". Append to known_tokens.

  • for a in scheduler controller_manager logging monitoring dns
  • do
  • token=$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=32 count=1 2>/dev/null)
  • echo "${token},kubernetes_builtin:$a,kubernetes_builtin:$a" >> "${known_tokens_file}"
    We ended up with normal usernames being unnamedspaced (so they can inherit the preferred username from the bedrock identity provider), and namespaced system/service account usernames with a "prefix:" (like "system:" or "project:"). That means ":" is disallowed in normal usernames for us.


Reply to this email directly or view it on GitHub.

@erictune
Copy link
Member Author

A step to fixing #5921

@zmerlynn
Copy link
Member

This looks like it should work and actually require no GKE side changes.

@vishh
Copy link
Contributor

vishh commented Mar 28, 2015

@erictune: Ack. I will update heapster as soon as this PR is merged.

@erictune
Copy link
Member Author

erictune commented Apr 2, 2015

@zmerlynn would you mind reviewing?

@erictune erictune assigned zmerlynn and unassigned ArtfulCoder Apr 2, 2015
@zmerlynn
Copy link
Member

zmerlynn commented Apr 2, 2015

Happy to.

obj="$1"

for tries in {1..5}; do
if ( echo "${obj}" | ${KUBECTL} --server="127.0.0.1:8080" create -f - ); then
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to pass --validate here as well?

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. there was a bug in kubectl with validate and some objects, but it is since fixed.

@pmorie
Copy link
Member

pmorie commented Apr 2, 2015

@liggitt This seems relevant to your interests

@@ -19,6 +19,39 @@
# managed result is of that. Start everything below that directory.
KUBECTL=/usr/local/bin/kubectl

function create-kubernetesauth-secret() {
Copy link
Member

Choose a reason for hiding this comment

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

Blah, I didn't enforce it well in create-object, but you can fix it while you're in here. :)

These should all be local. Probably local -r token=$1, etc, since they look readonly.

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

for a in "system:scheduler" "system:controller_manager" "system:logging" "system:monitoring" "system:dns"
do
token=$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=32 count=1 2>/dev/null)
echo "${token},$a,$a" >> "${known_tokens_file}"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I try to follow ${foo} for all variables. (so ${a}. Or ${account}). And below.

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

@zmerlynn
Copy link
Member

zmerlynn commented Apr 2, 2015

I did my best to channel @filbranden. The actual code LGTM, it's just style nits.

@erictune
Copy link
Member Author

erictune commented Apr 2, 2015

Needs rebase onto #6384

@erictune erictune force-pushed the for-abhis branch 3 times, most recently from 930e8d6 to 59b3868 Compare April 2, 2015 22:58
These secrets will be used in subsequent PRs by:
scheduler, controller-manager, monitoring services,
logging services, and skydns.

Each of these services will then be able to stop using kubernetes-ro
or host networking.
@erictune
Copy link
Member Author

erictune commented Apr 2, 2015

Okay, rebased. Testing.

@erictune
Copy link
Member Author

erictune commented Apr 2, 2015

Okay, kube-up.sh works, and expected addons and new secrets are created.

@zmerlynn
Copy link
Member

zmerlynn commented Apr 3, 2015

LGTM.

zmerlynn added a commit that referenced this pull request Apr 3, 2015
Make secrets at cluster startup.
@zmerlynn zmerlynn merged commit 12cf768 into kubernetes:master Apr 3, 2015
@erictune
Copy link
Member Author

erictune commented Apr 3, 2015

Thanks.

erictune added a commit to erictune/kubernetes that referenced this pull request Apr 17, 2015
Changes approach taken in kubernetes#5470
Instead of creating a kubernetes_auth file,
which we are tring to get away from, creates
a kubeconfig file, which is the new hotness.

Instead of creating the kubeconfig file in the
kube-addon script on the master, it creates
it at the time of salt-overlay generation.
More information is available at this time.

In particular, the master certs and master address
are handy at this point, so those are included in
the kubeconfig file.

The kube-addons script is simplified because the secret objects
are now just plain olf yaml files, which it knows how to
create, just like it creates pods and services.

Kubectl is used to generate the kubeconfig file.
This ensures correct format and is more self-documenting,
and matches how the admin credentials are done.

TODO(erictune): do this for kubelet.
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.

8 participants