Skip to content

Conversation

@theoctopusperson
Copy link
Contributor

Users returning to the CLI after extended periods often have stale or invalid tokens. Currently, there's no mechanism to force re-authentication for users who haven't used flyctl in a long time, leading to cryptic errors or unexpected behavior with expired credentials.

Solution

Implement a 30-day session timeout that automatically prompts users to re-authenticate when their session has expired, while preserving CI/CD pipeline functionality.

Changes

  • Add last_login timestamp tracking in config.yml to track when users last authenticated
  • Implement token age validation in RequireSession preparer to check if tokens have expired (30-day timeout)
  • Skip timeout for CI/CD pipelines - when FLY_ACCESS_TOKEN orFLY_API_TOKEN environment variables are set, the timeout check is bypassed
  • Display styled "Welcome back!" message when session expires to provide clear user feedback
  • Handle migration gracefully - users without existing timestamps are prompted to login on first use
  • Support both interactive and non-interactive sessions - prompts in interactive mode, returns error in non-interactive mode
  • Include test fixes to ensure unit tests work with the new authentication flow

CI/CD Compatibility

No impact on automated pipelines - tokens provided via environment variables bypass the session timeout check entirely. This ensures existing CI/CD workflows continue working without modification.

Add 30-day session timeout for CLI authentication

  Addresses the issue where users returning to the CLI after extended periods
  may have stale or invalid tokens. Users are now automatically prompted to
  re-authenticate after 30 days of inactivity. Users with no existing timestamp    are immediately prompted to login.

  Changes:
  - Add last_login timestamp tracking in config.yml
  - Implement token age validation in RequireSession preparer
  - Display styled "Welcome back!" message when session expires
  - Handle migration for existing users without login timestamps
  - Gracefully prompt for re-login in interactive sessions

 Non-interactive sessions return appropriate error messages.
Add proper config setup with LastLogin timestamp in the deploy test
to satisfy the session timeout validation in RequireSession.

This ensures unit tests pass while maintaining the security feature
that forces users with expired tokens to re-authenticate.
When FLY_ACCESS_TOKEN or FLY_API_TOKEN environment variables are set,
skip the session timeout validation. This ensures CI/CD pipelines
continue to work without requiring manual re-authentication.

The timestamp check only applies to interactive users with file-based
config, protecting against stale sessions while not breaking automation.

Tested both scenarios:
- Without env var: timeout enforced after 30 days
- With env var: timeout bypassed for CI/CD use
Add 30-day session timeout for CLI authentication

  Addresses the issue where users returning to the CLI after extended periods
  may have stale or invalid tokens. Users are now automatically prompted to
  re-authenticate after 30 days of inactivity. Users with no existing timestamp    are immediately prompted to login.

  Changes:
  - Add last_login timestamp tracking in config.yml
  - Implement token age validation in RequireSession preparer
  - Display styled "Welcome back!" message when session expires
  - Handle migration for existing users without login timestamps
  - Gracefully prompt for re-login in interactive sessions

 Non-interactive sessions return appropriate error messages.
Add proper config setup with LastLogin timestamp in the deploy test
to satisfy the session timeout validation in RequireSession.

This ensures unit tests pass while maintaining the security feature
that forces users with expired tokens to re-authenticate.
When FLY_ACCESS_TOKEN or FLY_API_TOKEN environment variables are set,
skip the session timeout validation. This ensures CI/CD pipelines
continue to work without requiring manual re-authentication.

The timestamp check only applies to interactive users with file-based
config, protecting against stale sessions while not breaking automation.

Tested both scenarios:
- Without env var: timeout enforced after 30 days
- With env var: timeout bypassed for CI/CD use
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