Skip to content

Feature/user login#43

Open
ewassef wants to merge 5 commits intomainfrom
feature/user-login
Open

Feature/user login#43
ewassef wants to merge 5 commits intomainfrom
feature/user-login

Conversation

@ewassef
Copy link
Contributor

@ewassef ewassef commented Aug 27, 2025

This pull request introduces authentication to the Vega CLI, requiring users to log in before executing most commands. It adds support for OAuth2 device code flow using Ory Hydra, including login/logout commands and multi-profile token management. The cluster creation workflow now records the authenticated user's TenantId in Kubernetes for downstream tooling. The codebase is refactored to integrate authentication checks and services throughout the CLI.

Authentication and Identity Management

  • Added LoginCommand and LogoutCommand to the CLI, supporting device code flow authentication and multi-profile management. Credentials are stored locally, and refresh tokens are used for automatic renewal. [1] [2]
  • Implemented AuthService and HydraDeviceFlowClient for OAuth2 device flow, token storage, refresh handling, and JWT claim extraction (TenantId). [1] [2] [3]
  • Updated dependency injection to register authentication services and HTTP client.

Command and Workflow Changes

  • Modified AppCommand to include login/logout commands, and updated Program.cs to enforce authentication before running most commands. [1] [2]
  • Refactored CreateClusterCommand to require authentication and write a ConfigMap containing the user's TenantId in the vega-system namespace during cluster creation. [1] [2] [3] [4]

Documentation Updates

  • Updated ReadMe.md with new authentication instructions, login/logout usage, and details about token storage and TenantId propagation. [1] [2]

Configuration

  • Added OAuth2/Hydra endpoint and claim settings to GlobalConfiguration for easy customization.

Dependency Injection

  • Registered new commands and services in the CLI's service provider for seamless integration.

These changes collectively introduce robust authentication, improve security, and enable user identity propagation throughout the Vega CLI and cluster lifecycle.

Introduces login/logout commands and device code flow authentication using Ory Hydra. Most CLI commands now require authentication; tokens are stored per profile and refreshed automatically. During cluster creation, the authenticated TenantId is extracted and written to a ConfigMap in the vega-system namespace. Documentation and command references updated to reflect authentication and new CLI usage.
Added the 'grant_type' parameter to the device flow authorization request to comply with OAuth device flow requirements.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces comprehensive authentication capabilities to the Vega CLI, transitioning from an open-access tool to one requiring OAuth2 device code flow authentication before executing most commands. The authentication system supports multi-profile management and integrates user identity into the cluster lifecycle.

  • OAuth2 device code flow authentication with token management and refresh capabilities
  • Multi-profile credential storage supporting multiple user identities
  • User identity propagation to Kubernetes clusters via TenantId ConfigMaps during cluster creation

Reviewed Changes

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

Show a summary per file
File Description
cli/src/Vdk/Services/AuthService.cs Core authentication service implementing login/logout, token management, and JWT claim extraction
cli/src/Vdk/Services/HydraDeviceFlowClient.cs OAuth2 device code flow client for Ory Hydra integration
cli/src/Vdk/Services/TokenStoreFile.cs File-based token storage with multi-profile support
cli/src/Vdk/Commands/LoginCommand.cs CLI login command with optional profile parameter
cli/src/Vdk/Commands/LogoutCommand.cs CLI logout command with optional profile parameter
cli/src/Vdk/Commands/CreateClusterCommand.cs Enhanced cluster creation to inject user TenantId into Kubernetes ConfigMap
cli/src/Vdk/Program.cs Modified program entry point to enforce authentication for most commands
cli/src/Vdk/GlobalConfiguration.cs Added OAuth2 endpoint and claim configuration
cli/src/Vdk/ServiceProviderBuilder.cs Registered authentication services in dependency injection
ReadMe.md Updated documentation with authentication instructions and workflow changes
docs/ Updated command references and usage examples to reflect new CLI name and authentication requirements

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +27 to +28
["client_id"] = _config.OAuthClientId,

Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Remove the empty line (line 27) between the dictionary entries for consistency with the rest of the file's formatting.

Suggested change
["client_id"] = _config.OAuthClientId,

Copilot uses AI. Check for mistakes.
Comment on lines +207 to +209
cfg = client.Get<V1ConfigMap>("vega-tenant", "vega-system");
}
catch { /* not found, will create */ }
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

The empty catch block should specify the expected exception type (e.g., catch (HttpOperationException) or catch (KubernetesException)) to avoid catching unexpected exceptions that should be handled differently.

Suggested change
cfg = client.Get<V1ConfigMap>("vega-tenant", "vega-system");
}
catch { /* not found, will create */ }
catch (k8s.KubernetesException) { /* not found, will create */ }

Copilot uses AI. Check for mistakes.
Comment on lines +41 to 43
# If/when a config file flag is added, document here
```
```
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

There are mismatched code block markers - the line has both closing and opening backticks. Remove the extra backticks on line 43.

Suggested change
# If/when a config file flag is added, document here
```
```

Copilot uses AI. Check for mistakes.
Introduces a new --Labels option to CreateClusterCommand for specifying cluster labels, including validation and application to cluster configuration. Also adds proxy server configurations for vdk and vdk-1 in vega.conf.
Refactors LoginCommand and LogoutCommand to use the new Options.Add and SetAction APIs from System.CommandLine 2.x, updating option construction and handler assignment accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant