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

[BUG/FIX] Azure RBAC fix refresh token logic #398

Merged
merged 15 commits into from
Dec 4, 2024

Conversation

saisankargochhayat
Copy link
Contributor

@saisankargochhayat saisankargochhayat commented Nov 28, 2024

This PR aims to fix the refresh token logic for Azure RBAC.
The existing refresh token logic relies on the expires_in value from the token response -
{"access_token":"","expires_in":"86700","refresh_token":"","expires_on":"1732881796","not_before":"1732795096","resource":"https://management.azure.com","token_type":"Bearer"}
However in the case when the token is not fresh and returned from cache, the expires_in value misleads Guard to think the token doesn't need refreshing since it adds the current_time + expires_in to set the new expiry time.
In this PR we directly use the expires_on to set the expiry time accurately.

The PR also increases the tokenExpiryDelta to 5 minutes to ensure the token is refreshed 5 mins earlier than actual expiry. This is done on both AuthZ (rbac.go) and AuthN (graph.go) flow.

Removed expires_in to be returned from msi_adapter in favor of expires_on

Using the current implementation guard now sets the expires property correctly, i.e. knows it expires at 2024-11-29 21:05:56 +0000 UTC in the below example rather than doing - current-time + 86700

Guard log -

│ I1202 20:38:40.019063       1 graph.go:331] Token received with expires_in 86700 and expires_at 1733258179            

││ I1202 20:38:40.019114       1 graph.go:337] Token refreshed successfully at 2024-12-02 20:38:40.019110448 +0000 UTC m=+444.823514368. Expire at set to: 2024-12-03 20:31:19 +0000 UTC 

Tested KAP flow -

image

RBAC non proxy flow -
image

@saisankargochhayat saisankargochhayat changed the title TODO Azure RBAC fix refresh token logic Nov 29, 2024
@saisankargochhayat saisankargochhayat marked this pull request as ready for review November 29, 2024 00:13
@saisankargochhayat saisankargochhayat requested a review from a team as a code owner November 29, 2024 00:13
auth/providers/azure/graph/graph.go Outdated Show resolved Hide resolved
auth/providers/azure/graph/types.go Outdated Show resolved Hide resolved
auth/providers/azure/graph/graph.go Outdated Show resolved Hide resolved
auth/providers/azure/graph/msi_tokenprovider.go Outdated Show resolved Hide resolved
auth/providers/azure/graph/types.go Outdated Show resolved Hide resolved
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
auth/providers/azure/graph/graph.go Show resolved Hide resolved
auth/providers/azure/graph/graph_test.go Outdated Show resolved Hide resolved
authz/providers/azure/rbac/rbac.go Show resolved Hide resolved
authz/providers/azure/rbac/rbac_test.go Outdated Show resolved Hide resolved
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Copy link
Contributor

@julienstroheker julienstroheker left a comment

Choose a reason for hiding this comment

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

LGTM, I'll let you decide if you want to apply my comment about the returned payload from MSI adapter

@julienstroheker
Copy link
Contributor

Also rename the PR with [BUG/FIX] in the title

Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
@saisankargochhayat saisankargochhayat changed the title Azure RBAC fix refresh token logic [BUG/FIX] Azure RBAC fix refresh token logic Dec 3, 2024
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
@vineeth-thumma
Copy link
Contributor

vineeth-thumma commented Dec 4, 2024

LGTM overall, PTAL at couple of comments on UTs

Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Copy link
Contributor

@julienstroheker julienstroheker left a comment

Choose a reason for hiding this comment

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

LGTM on Arc Side but need review on AKS Side since we are touching the token interface.

auth/providers/azure/graph/graph_test.go Outdated Show resolved Hide resolved
authz/providers/azure/rbac/rbac_test.go Outdated Show resolved Hide resolved
Signed-off-by: Sai Sankar Gochhayat <saisankargochhayat@gmail.com>
Copy link
Contributor

@vineeth-thumma vineeth-thumma left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@weinong weinong left a comment

Choose a reason for hiding this comment

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

LGTM

@weinong weinong merged commit b512fe6 into kubeguard:master Dec 4, 2024
3 checks passed
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.

6 participants