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

ARO-9263: Add ACR token issue date and check validity #3778

Conversation

edisonLcardenas
Copy link
Collaborator

@edisonLcardenas edisonLcardenas commented Aug 19, 2024

Which issue this PR addresses:

Jira https://issues.redhat.com/browse/ARO-8472
https://issues.redhat.com/browse/ARO-9263

What this PR does / why we need it:

  • Add issue date in registry profile for ACR Token.
  • Check the issue date if still valid or needs to be rotated.

Test plan for issue:

Unit tests.
Manual validation.

Is there any documentation that needs to be updated for this PR?

Part of MIMO M1

How do you know this will function as expected in production?

Unit tests.

@edisonLcardenas edisonLcardenas changed the base branch from master to hawkowl/mimo-m1 August 19, 2024 06:45
pkg/util/mocks/env/core.go Outdated Show resolved Hide resolved
@edisonLcardenas
Copy link
Collaborator Author

/azp run ci, e2e

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

Copy link

Please rebase pull request.

@github-actions github-actions bot removed the needs-rebase branch needs a rebase label Sep 16, 2024
Copy link

Please rebase pull request.

@github-actions github-actions bot added the needs-rebase branch needs a rebase label Sep 23, 2024
@edisonLcardenas edisonLcardenas force-pushed the ecardena/ARO-9263-mimo-m1-add-acr-token-expiration-checker branch from e22da94 to c80d941 Compare September 23, 2024 05:00
@github-actions github-actions bot removed the needs-rebase branch needs a rebase label Sep 23, 2024
Copy link
Contributor

@jaitaiwan jaitaiwan left a comment

Choose a reason for hiding this comment

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

A couple things to improve and a couple of nits. Overall good work!

pkg/mimo/tasks/cluster/acrtoken_checker.go Outdated Show resolved Hide resolved
Comment on lines 46 to 48
if issueDate == nil {
return mimo.TerminalError(errors.New("no issue date detected"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't have an issue date we've probably got a token that will never expire. Shouldn't we remove it anyway?

return mimo.TerminalError(errors.New("no issue date detected"))
}

daysInterval := int32(now.Sub(issueDate.Time).Hours() / 24)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should just be making use of golang's inbuilt duration funcs for this. Something like this:

now := time.Now().UTC()
lastValidIssue := now.Sub(daysShouldRotate * time.Day)
lastValidRotation := now.Sub(daysValid * time.Day)

if issueDate.Time.Before(lastValidIssue) {
  return mimo.TerminalError(fmt.Errorf("%d days have passed since azure container registry (acr) token was issued, please rotate the token now", daysInterval))
}

if issueDate.Time.Before(lastValidRotation) {
  return mimo.TerminalError(fmt.Errorf("azure container registry (acr) token is not valid, %d days have passed", daysInterval))
}

pkg/mimo/tasks/cluster/acrtoken_checker.go Show resolved Hide resolved
@github-actions github-actions bot added the needs-rebase branch needs a rebase label Sep 24, 2024
Copy link

Please rebase pull request.

@edisonLcardenas edisonLcardenas force-pushed the ecardena/ARO-9263-mimo-m1-add-acr-token-expiration-checker branch from 1546e57 to 9a51858 Compare September 24, 2024 06:13
@github-actions github-actions bot removed the needs-rebase branch needs a rebase label Sep 24, 2024
@hawkowl hawkowl merged commit f19a2ca into hawkowl/mimo-m1 Sep 25, 2024
16 checks passed
@hawkowl hawkowl deleted the ecardena/ARO-9263-mimo-m1-add-acr-token-expiration-checker branch September 25, 2024 00:13
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.

4 participants