Skip to content

Prompt for GitHub access token expiration duration during rotation#6644

Open
garath wants to merge 4 commits into
mainfrom
garath-github-token-expiration-input
Open

Prompt for GitHub access token expiration duration during rotation#6644
garath wants to merge 4 commits into
mainfrom
garath-github-token-expiration-input

Conversation

@garath

@garath garath commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

The github-access-token SecretManager secret type previously hard-coded a 90-day expiration (display only) and a fixed 30-day rotation, with ExpiresOn set to DateTimeOffset.MaxValue. Operators now enter the token's expiration duration in days interactively during rotation, and that value drives the on-screen GitHub instructions, the secret's real ExpiresOn, and its NextRotationOn.

Changes

  • SecretTypes/GitHubAccessToken.cs
    • Prompts for expiration duration via the existing PromptAndValidateAsync<int> helper.
    • Validates a whole number of days in 7–30 (we deliberately restrict below GitHub's allowed maximum); out-of-range/invalid input prints an error and re-prompts (3 attempts, then throws).
    • ExpiresOn = now + duration; NextRotationOn = now + duration * 2/3 (rotate when ~1/3 of the lifetime remains).
    • On-screen GitHub guidance and a "next rotation" line reflect the entered duration.
    • Non-interactive runs still throw HumanInterventionRequiredException; PAT length check and login flow unchanged.
    • Uses explicit types (no var).
  • Readme.md — documents the new prompt and the 7–30 day range.
  • New Microsoft.DncEng.SecretManager.Tests/GitHubAccessTokenTests.cs — 17 tests covering duration-bound validation (min/max/negative/non-numeric/non-integer) and the rotation/expiration date math.

Validation

dotnet test on Microsoft.DncEng.SecretManager.Tests (filtered to GitHubAccessTokenTests): 17 passed, 0 failed.

garath added 4 commits July 17, 2026 11:39
The github-access-token secret type hard-coded a 90-day expiration (display only) and a fixed 30-day rotation with ExpiresOn set to MaxValue. Operators now enter the token's expiration duration (1-366 days) interactively during rotation. The entered value drives the on-screen GitHub instructions, the secret's ExpiresOn (now + duration), and NextRotationOn (rotate when ~1/3 of the duration remains). Adds unit tests for the duration validation and rotation-date math and documents the prompt in the Readme.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: fa7e69fb-9fb8-400c-b4db-765ff4282ca4
Durations below 7 days are now rejected, printing the validation error and re-prompting.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: fa7e69fb-9fb8-400c-b4db-765ff4282ca4
GitHub permits longer lifetimes, but we deliberately cap access token expiration at 30 days. Durations above 30 are rejected with the validation error.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: fa7e69fb-9fb8-400c-b4db-765ff4282ca4
Use explicit types instead of var in GitHubAccessToken.cs and GitHubAccessTokenTests.cs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: fa7e69fb-9fb8-400c-b4db-765ff4282ca4
@garath
garath marked this pull request as ready for review July 17, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the github-access-token secret rotation flow to capture a user-entered expiration duration (in days) during interactive rotation, and uses it to compute the secret’s ExpiresOn and NextRotationOn along with updated operator guidance.

Changes:

  • Prompt for GitHub token expiration duration (7–30 days) during rotation and apply it to ExpiresOn / NextRotationOn.
  • Update operator guidance text to reflect the chosen expiration duration and scheduled next rotation date.
  • Add unit tests for expiration duration parsing and rotation scheduling math.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/SecretManager/Microsoft.DncEng.SecretManager/SecretTypes/GitHubAccessToken.cs Prompts for expiration duration, computes expiration/rotation dates, and prints updated instructions.
src/SecretManager/Microsoft.DncEng.SecretManager/Readme.md Documents the new expiration-duration prompt and rotation timing.
src/SecretManager/Microsoft.DncEng.SecretManager.Tests/GitHubAccessTokenTests.cs Adds tests for duration validation and NextRotationOn computation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +56 to +61
// Rotate once roughly two thirds of the way through the token's lifetime,
// i.e. when about one third of the entered duration remains before expiration.
protected static DateTimeOffset ComputeNextRotationOn(DateTimeOffset now, int expirationInDays)
{
return now.AddDays(expirationInDays * 2 / 3);
}
Comment on lines +344 to +347
During rotation you will be prompted to enter the token's expiration duration in
days (7-30). The entered duration is shown in the on-screen instructions for
creating the token on github.com and also sets the secret's expiration; the
secret is scheduled to rotate once about one third of that duration remains.
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