Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
083ffb6e
Unverified
Commit
083ffb6e
authored
Jan 19, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: clean up RBAC grants
parent
e3f79588
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
22 deletions
+20
-22
apiclient.go
cmd/kubeadm/app/master/apiclient.go
+1
-2
manifests.go
cmd/kubeadm/app/master/manifests.go
+1
-1
tokens.go
cmd/kubeadm/app/master/tokens.go
+8
-1
clusterroles.go
cmd/kubeadm/app/phases/apiconfig/clusterroles.go
+10
-18
No files found.
cmd/kubeadm/app/master/apiclient.go
View file @
083ffb6e
...
@@ -73,11 +73,10 @@ func CreateClientAndWaitForAPI(file string) (*clientset.Clientset, error) {
...
@@ -73,11 +73,10 @@ func CreateClientAndWaitForAPI(file string) (*clientset.Clientset, error) {
cs
,
err
:=
client
.
ComponentStatuses
()
.
List
(
v1
.
ListOptions
{})
cs
,
err
:=
client
.
ComponentStatuses
()
.
List
(
v1
.
ListOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
if
apierrs
.
IsForbidden
(
err
)
{
if
apierrs
.
IsForbidden
(
err
)
{
fmt
.
Print
(
"
\r
[apiclient] Waiting for the API server to create RBAC policies
"
)
fmt
.
Print
ln
(
"[apiclient] Waiting for API server authorization
"
)
}
}
return
false
,
nil
return
false
,
nil
}
}
fmt
.
Println
(
"
\n
[apiclient] RBAC policies created"
)
// TODO(phase2) must revisit this when we implement HA
// TODO(phase2) must revisit this when we implement HA
if
len
(
cs
.
Items
)
<
3
{
if
len
(
cs
.
Items
)
<
3
{
fmt
.
Println
(
"[apiclient] Not all control plane components are ready yet"
)
fmt
.
Println
(
"[apiclient] Not all control plane components are ready yet"
)
...
...
cmd/kubeadm/app/master/manifests.go
View file @
083ffb6e
...
@@ -369,7 +369,7 @@ func getControllerManagerCommand(cfg *kubeadmapi.MasterConfiguration) []string {
...
@@ -369,7 +369,7 @@ func getControllerManagerCommand(cfg *kubeadmapi.MasterConfiguration) []string {
"--service-account-private-key-file="
+
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
+
"/apiserver-key.pem"
,
"--service-account-private-key-file="
+
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
+
"/apiserver-key.pem"
,
"--cluster-signing-cert-file="
+
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
+
"/ca.pem"
,
"--cluster-signing-cert-file="
+
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
+
"/ca.pem"
,
"--cluster-signing-key-file="
+
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
+
"/ca-key.pem"
,
"--cluster-signing-key-file="
+
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
+
"/ca-key.pem"
,
"--insecure-experimental-approve-all-kubelet-csrs-for-group=
kubeadm:kubelet-bootstrap"
,
"--insecure-experimental-approve-all-kubelet-csrs-for-group=
"
+
KubeletBootstrapGroup
,
)
)
if
cfg
.
CloudProvider
!=
""
{
if
cfg
.
CloudProvider
!=
""
{
...
...
cmd/kubeadm/app/master/tokens.go
View file @
083ffb6e
...
@@ -27,12 +27,19 @@ import (
...
@@ -27,12 +27,19 @@ import (
"k8s.io/kubernetes/pkg/util/uuid"
"k8s.io/kubernetes/pkg/util/uuid"
)
)
const
(
// TODO: prefix with kubeadm prefix
KubeletBootstrapUser
=
"kubeadm-node-csr"
KubeletBootstrapGroup
=
"kubeadm:kubelet-bootstrap"
)
func
CreateTokenAuthFile
(
bt
string
)
error
{
func
CreateTokenAuthFile
(
bt
string
)
error
{
tokenAuthFilePath
:=
path
.
Join
(
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
,
"tokens.csv"
)
tokenAuthFilePath
:=
path
.
Join
(
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
,
"tokens.csv"
)
if
err
:=
os
.
MkdirAll
(
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
,
0700
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
,
0700
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create directory %q [%v]"
,
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
,
err
)
return
fmt
.
Errorf
(
"failed to create directory %q [%v]"
,
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
,
err
)
}
}
serialized
:=
[]
byte
(
fmt
.
Sprintf
(
"%s,
kubeadm-node-csr,%s,kubeadm:kubelet-bootstrap
\n
"
,
bt
,
uuid
.
NewUUID
()
))
serialized
:=
[]
byte
(
fmt
.
Sprintf
(
"%s,
%s,%s,%s
\n
"
,
bt
,
KubeletBootstrapUser
,
uuid
.
NewUUID
(),
KubeletBootstrapGroup
))
// DumpReaderToFile create a file with mode 0600
// DumpReaderToFile create a file with mode 0600
if
err
:=
cmdutil
.
DumpReaderToFile
(
bytes
.
NewReader
(
serialized
),
tokenAuthFilePath
);
err
!=
nil
{
if
err
:=
cmdutil
.
DumpReaderToFile
(
bytes
.
NewReader
(
serialized
),
tokenAuthFilePath
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to save token auth file (%q) [%v]"
,
tokenAuthFilePath
,
err
)
return
fmt
.
Errorf
(
"failed to save token auth file (%q) [%v]"
,
tokenAuthFilePath
,
err
)
...
...
cmd/kubeadm/app/phases/apiconfig/clusterroles.go
View file @
083ffb6e
...
@@ -38,7 +38,7 @@ func CreateBootstrapRBACClusterRole(clientset *clientset.Clientset) error {
...
@@ -38,7 +38,7 @@ func CreateBootstrapRBACClusterRole(clientset *clientset.Clientset) error {
Name
:
"system:node-bootstrapper"
,
Name
:
"system:node-bootstrapper"
,
},
},
Subjects
:
[]
rbac
.
Subject
{
Subjects
:
[]
rbac
.
Subject
{
rbac
.
Subject
{
Kind
:
"Group"
,
Name
:
"kubeadm:kubelet-bootstrap"
},
{
Kind
:
"Group"
,
Name
:
master
.
KubeletBootstrapGroup
},
},
},
}
}
if
_
,
err
:=
clientset
.
Rbac
()
.
ClusterRoleBindings
()
.
Create
(
&
clusterRoleBinding
);
err
!=
nil
{
if
_
,
err
:=
clientset
.
Rbac
()
.
ClusterRoleBindings
()
.
Create
(
&
clusterRoleBinding
);
err
!=
nil
{
...
@@ -76,7 +76,7 @@ func CreateKubeDNSRBACClusterRole(clientset *clientset.Clientset) error {
...
@@ -76,7 +76,7 @@ func CreateKubeDNSRBACClusterRole(clientset *clientset.Clientset) error {
RoleRef
:
rbac
.
RoleRef
{
RoleRef
:
rbac
.
RoleRef
{
APIGroup
:
"rbac.authorization.k8s.io"
,
APIGroup
:
"rbac.authorization.k8s.io"
,
Kind
:
"ClusterRole"
,
Kind
:
"ClusterRole"
,
Name
:
"kubeadm:"
+
master
.
KubeDNS
,
Name
:
clusterRole
.
Name
,
},
},
Subjects
:
[]
rbac
.
Subject
{
subject
},
Subjects
:
[]
rbac
.
Subject
{
subject
},
}
}
...
@@ -88,32 +88,24 @@ func CreateKubeDNSRBACClusterRole(clientset *clientset.Clientset) error {
...
@@ -88,32 +88,24 @@ func CreateKubeDNSRBACClusterRole(clientset *clientset.Clientset) error {
return
nil
return
nil
}
}
// CreateKubeProxyClusterRoleBinding creates the necessary ClusterRole for kube-dns
// CreateKubeProxyClusterRoleBinding grants the system:node-proxier role to the nodes group,
// since kubelet credentials are used to run the kube-proxy
// TODO: give the kube-proxy its own credential and stop requiring this
func
CreateKubeProxyClusterRoleBinding
(
clientset
*
clientset
.
Clientset
)
error
{
func
CreateKubeProxyClusterRoleBinding
(
clientset
*
clientset
.
Clientset
)
error
{
systemKubeProxySubject
:=
rbac
.
Subject
{
Kind
:
"User"
,
Name
:
"system:kube-proxy"
,
Namespace
:
api
.
NamespaceSystem
,
}
systemNodesSubject
:=
rbac
.
Subject
{
Kind
:
"Group"
,
Name
:
"system:nodes"
,
Namespace
:
api
.
NamespaceSystem
,
}
clusterRoleBinding
:=
rbac
.
ClusterRoleBinding
{
clusterRoleBinding
:=
rbac
.
ClusterRoleBinding
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"
syste
m:node-proxier"
,
Name
:
"
kubead
m:node-proxier"
,
},
},
RoleRef
:
rbac
.
RoleRef
{
RoleRef
:
rbac
.
RoleRef
{
APIGroup
:
"rbac.authorization.k8s.io"
,
APIGroup
:
"rbac.authorization.k8s.io"
,
Kind
:
"ClusterRole"
,
Kind
:
"ClusterRole"
,
Name
:
"system:node-proxier"
,
Name
:
"system:node-proxier"
,
},
},
Subjects
:
[]
rbac
.
Subject
{
systemKubeProxySubject
,
systemNodesSubject
},
Subjects
:
[]
rbac
.
Subject
{
{
Kind
:
"Group"
,
Name
:
"system:nodes"
},
},
}
}
if
_
,
err
:=
clientset
.
Rbac
()
.
ClusterRoleBindings
()
.
Upd
ate
(
&
clusterRoleBinding
);
err
!=
nil
{
if
_
,
err
:=
clientset
.
Rbac
()
.
ClusterRoleBindings
()
.
Cre
ate
(
&
clusterRoleBinding
);
err
!=
nil
{
return
err
return
err
}
}
fmt
.
Println
(
"[apiconfig] Created kube-proxy RBAC rules"
)
fmt
.
Println
(
"[apiconfig] Created kube-proxy RBAC rules"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment