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

feat: Implement TLS for interactions between agent and manager #19

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

UgOrange
Copy link
Member

No description provided.

@@ -117,7 +117,7 @@ func NewAgent(
stopCh: stopCh,
log: log,
}

varmorutils.InitAndStartTokenRotation(time.Hour, log)
Copy link
Collaborator

Choose a reason for hiding this comment

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

"The kubelet will start trying to rotate the token if the token is older than 80 percent of its time to live or if the token is older than 24 hours."

We should check and reload the token more frequently. How about 5 minutes? I'm not sure if there are any best practices. Or we can just reload the token when the server returns 401.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm willing to change the token refresh interval to 5 minutes. The reason is that while the default interval is 7200 seconds (2 hours), a shorter interval can enhance security.

func updateToken(filePath string, logger logr.Logger) {
newToken, err := os.ReadFile(filePath)
if err != nil {
logger.Error(err, "update agent bind token error")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a fatal error. Perhaps we should consider restarting the agent immediately?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will use os.Exit instead to fix it.

defer httpRsp.Body.Close()
if httpRsp.StatusCode == http.StatusOK {
return nil
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we need to reload the token if the service returns 401.

tr := &authv1.TokenReview{
Spec: authv1.TokenReviewSpec{
Token: token,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

"If no audiences are provided, the audience will default to the audience of the Kubernetes apiserver."

It is necessary to explicitly declare audiences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Understood, I will make the modifications.

@Danny-Wei Danny-Wei merged commit 5d6791c into bytedance:main Jan 12, 2024
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.

2 participants