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
6b0247fa
Commit
6b0247fa
authored
Jan 10, 2025
by
Brad Davidson
Committed by
Brad Davidson
Jan 10, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve flannel RBAC changes
Only wait for k3s-controller RBAC when AuthorizeNodeWithSelectors blocks kubelet from listing nodes Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
dde2fef0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
7 deletions
+42
-7
setup.go
pkg/agent/flannel/setup.go
+14
-7
api.go
pkg/util/api.go
+28
-0
No files found.
pkg/agent/flannel/setup.go
View file @
6b0247fa
...
@@ -69,14 +69,21 @@ func Prepare(ctx context.Context, nodeConfig *config.Node) error {
...
@@ -69,14 +69,21 @@ func Prepare(ctx context.Context, nodeConfig *config.Node) error {
func
Run
(
ctx
context
.
Context
,
nodeConfig
*
config
.
Node
)
error
{
func
Run
(
ctx
context
.
Context
,
nodeConfig
*
config
.
Node
)
error
{
logrus
.
Infof
(
"Starting flannel with backend %s"
,
nodeConfig
.
FlannelBackend
)
logrus
.
Infof
(
"Starting flannel with backend %s"
,
nodeConfig
.
FlannelBackend
)
if
err
:=
util
.
WaitForRBACReady
(
ctx
,
nodeConfig
.
AgentConfig
.
KubeConfigK3sController
,
util
.
DefaultAPIServerReadyTimeout
,
authorizationv1
.
ResourceAttributes
{
kubeConfig
:=
nodeConfig
.
AgentConfig
.
KubeConfigKubelet
Verb
:
"list"
,
resourceAttrs
:=
authorizationv1
.
ResourceAttributes
{
Verb
:
"list"
,
Resource
:
"nodes"
}
Resource
:
"nodes"
,
},
""
);
err
!=
nil
{
// Compatibility code for AuthorizeNodeWithSelectors feature-gate.
return
errors
.
Wrap
(
err
,
"flannel failed to wait for RBAC"
)
// If the kubelet cannot list nodes, then wait for the k3s-controller RBAC to become ready, and use that kubeconfig instead.
if
canListNodes
,
err
:=
util
.
CheckRBAC
(
ctx
,
kubeConfig
,
resourceAttrs
,
""
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to check if RBAC allows node list"
)
}
else
if
!
canListNodes
{
kubeConfig
=
nodeConfig
.
AgentConfig
.
KubeConfigK3sController
if
err
:=
util
.
WaitForRBACReady
(
ctx
,
kubeConfig
,
util
.
DefaultAPIServerReadyTimeout
,
resourceAttrs
,
""
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"flannel failed to wait for RBAC"
)
}
}
}
coreClient
,
err
:=
util
.
GetClientSet
(
nodeConfig
.
AgentConfig
.
KubeConfigK3sController
)
coreClient
,
err
:=
util
.
GetClientSet
(
kubeConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -90,7 +97,7 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
...
@@ -90,7 +97,7 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
return
errors
.
Wrap
(
err
,
"failed to check netMode for flannel"
)
return
errors
.
Wrap
(
err
,
"failed to check netMode for flannel"
)
}
}
go
func
()
{
go
func
()
{
err
:=
flannel
(
ctx
,
nodeConfig
.
FlannelIface
,
nodeConfig
.
FlannelConfFile
,
nodeConfig
.
AgentConfig
.
KubeConfigK3sController
,
nodeConfig
.
FlannelIPv6Masq
,
netMode
)
err
:=
flannel
(
ctx
,
nodeConfig
.
FlannelIface
,
nodeConfig
.
FlannelConfFile
,
kubeConfig
,
nodeConfig
.
FlannelIPv6Masq
,
netMode
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
context
.
Canceled
)
{
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
context
.
Canceled
)
{
logrus
.
Errorf
(
"flannel exited: %v"
,
err
)
logrus
.
Errorf
(
"flannel exited: %v"
,
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
...
...
pkg/util/api.go
View file @
6b0247fa
...
@@ -147,6 +147,34 @@ func WaitForRBACReady(ctx context.Context, kubeconfigPath string, timeout time.D
...
@@ -147,6 +147,34 @@ func WaitForRBACReady(ctx context.Context, kubeconfigPath string, timeout time.D
return
nil
return
nil
}
}
// CheckRBAC performs a single SelfSubjectAccessReview or SubjectAccessReview, returning a
// boolean indicating whether or not the requested access would be allowed. This is basically
// `kubectl auth can-i`.
func
CheckRBAC
(
ctx
context
.
Context
,
kubeconfigPath
string
,
ra
authorizationv1
.
ResourceAttributes
,
user
string
,
groups
...
string
)
(
bool
,
error
)
{
restConfig
,
err
:=
GetRESTConfig
(
kubeconfigPath
)
if
err
!=
nil
{
return
false
,
err
}
authClient
,
err
:=
authorizationv1client
.
NewForConfig
(
restConfig
)
if
err
!=
nil
{
return
false
,
err
}
var
reviewFunc
genericAccessReviewRequest
if
len
(
user
)
==
0
&&
len
(
groups
)
==
0
{
reviewFunc
=
selfSubjectAccessReview
(
authClient
,
ra
)
}
else
{
reviewFunc
=
subjectAccessReview
(
authClient
,
ra
,
user
,
groups
)
}
status
,
err
:=
reviewFunc
(
ctx
)
if
err
!=
nil
{
return
false
,
err
}
return
status
.
Allowed
,
nil
}
// selfSubjectAccessReview returns a function that makes SelfSubjectAccessReview requests using the
// selfSubjectAccessReview returns a function that makes SelfSubjectAccessReview requests using the
// provided client and attributes, returning a status or error.
// provided client and attributes, returning a status or error.
func
selfSubjectAccessReview
(
authClient
*
authorizationv1client
.
AuthorizationV1Client
,
ra
authorizationv1
.
ResourceAttributes
)
genericAccessReviewRequest
{
func
selfSubjectAccessReview
(
authClient
*
authorizationv1client
.
AuthorizationV1Client
,
ra
authorizationv1
.
ResourceAttributes
)
genericAccessReviewRequest
{
...
...
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