-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description: This change enables GitHub users over Docker to authorize with Kurtosis CLI so that Kurtosis can perform git operations such as cloning packages in private repositories. This primarily enables the use of private GitHub locators for package runs, `import_module`, and `upload_files`. This is accomplished via an OAuth flow where `kurtosis github login` directs the user to authorize Kurtosis CLI to take actions on their behalf. A token is retrieved upon success and is used by Kurtosis for subsequent git operations. Kurtosis attempts to store the token in secure system storage, but if not found, the token is stored in a plain text file at `kurtosis config path`. Github commands added: - `kurtosis github login` - `kurtosis github logout` - `kurtosis github token` - `kurtosis github status` Flags added (these override existing GitHub login for one off authorization use cases): - `kurtosis engine start --github-auth-token=< token.txt` - `kurtosis engine restart --github-auth-token=< token.txt` ## Is this change user facing? YES ## References: #2020
- Loading branch information
Showing
45 changed files
with
1,847 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package github | ||
|
||
import ( | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/commands/github/login" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/commands/github/logout" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/commands/github/status" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/commands/github/token" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GitHubCmd Suppressing exhaustruct requirement because this struct has ~40 properties | ||
// nolint: exhaustruct | ||
var GitHubCmd = &cobra.Command{ | ||
Use: command_str_consts.GitHubCmdStr, | ||
Short: "Manage GitHub login", | ||
RunE: nil, | ||
} | ||
|
||
func init() { | ||
GitHubCmd.AddCommand(login.LoginCmd.MustGetCobraCommand()) | ||
GitHubCmd.AddCommand(logout.LogoutCmd.MustGetCobraCommand()) | ||
GitHubCmd.AddCommand(status.StatusCmd.MustGetCobraCommand()) | ||
GitHubCmd.AddCommand(token.TokenCmd.MustGetCobraCommand()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package login | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/github_auth_store" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/oauth" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/out" | ||
"github.com/kurtosis-tech/stacktrace" | ||
) | ||
|
||
var LoginCmd = &lowlevel.LowlevelKurtosisCommand{ | ||
CommandStr: command_str_consts.GitHubLoginCmdStr, | ||
ShortDescription: "Authorizes Kurtosis CLI on behalf of a Github user.", | ||
LongDescription: "Authorizes Kurtosis CLI to perform git operations on behalf of a GitHub user such as retrieving packages in private repositories.", | ||
Args: nil, | ||
Flags: nil, | ||
PreValidationAndRunFunc: nil, | ||
RunFunc: run, | ||
PostValidationAndRunFunc: nil, | ||
} | ||
|
||
func run(_ context.Context, _ *flags.ParsedFlags, _ *args.ParsedArgs) error { | ||
githubAuthStore, err := github_auth_store.GetGitHubAuthStore() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred retrieving GitHub auth store.") | ||
} | ||
username, err := githubAuthStore.GetUser() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred getting user to see if user already exists.") | ||
} | ||
if username != "" { | ||
out.PrintOutLn(fmt.Sprintf("Logged in as GitHub user: %v", username)) | ||
return nil | ||
} | ||
authToken, username, err := oauth.AuthFlow() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred in the Github OAuth flow.") | ||
} | ||
err = githubAuthStore.SetUser(username, authToken) | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred setting GitHub user: %v", username) | ||
} | ||
out.PrintOutLn(fmt.Sprintf("Successfully logged in GitHub user: %v", username)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package logout | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/github_auth_store" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/out" | ||
"github.com/kurtosis-tech/stacktrace" | ||
) | ||
|
||
var LogoutCmd = &lowlevel.LowlevelKurtosisCommand{ | ||
CommandStr: command_str_consts.GitHubLogoutCmdStr, | ||
ShortDescription: "Logs out a GitHub user from Kurtosis CLI", | ||
LongDescription: "Logs out a GitHub user from Kurtosis CLI by removing their GitHub user info and auth token from Kurtosis CLI config", | ||
Args: nil, | ||
Flags: nil, | ||
PreValidationAndRunFunc: nil, | ||
RunFunc: run, | ||
PostValidationAndRunFunc: nil, | ||
} | ||
|
||
func run(_ context.Context, _ *flags.ParsedFlags, _ *args.ParsedArgs) error { | ||
githubAuthStore, err := github_auth_store.GetGitHubAuthStore() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred retrieving GitHub auth configuration.") | ||
} | ||
username, err := githubAuthStore.GetUser() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred getting user to see if user already exists.") | ||
} | ||
if username == "" { | ||
out.PrintOutLn("No GitHub user logged into Kurtosis CLI: %v") | ||
return nil | ||
} | ||
err = githubAuthStore.RemoveUser() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred logging out GitHub user: %v", username) | ||
} | ||
out.PrintOutLn(fmt.Sprintf("Successfully logged GitHub user '%v' out of Kurtosis CLI", username)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package status | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/github_auth_store" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/out" | ||
"github.com/kurtosis-tech/stacktrace" | ||
) | ||
|
||
var StatusCmd = &lowlevel.LowlevelKurtosisCommand{ | ||
CommandStr: command_str_consts.GitHubStatusCmdStr, | ||
ShortDescription: "Displays GitHub auth info", | ||
LongDescription: "Displays GitHub auth info by showing a logged in user's info or whether no GitHub user is logged into Kurtosis CLI", | ||
Args: nil, | ||
Flags: nil, | ||
PreValidationAndRunFunc: nil, | ||
RunFunc: run, | ||
PostValidationAndRunFunc: nil, | ||
} | ||
|
||
func run(_ context.Context, _ *flags.ParsedFlags, _ *args.ParsedArgs) error { | ||
githubAuthStore, err := github_auth_store.GetGitHubAuthStore() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred retrieving GitHub auth configuration.") | ||
} | ||
username, err := githubAuthStore.GetUser() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred getting user to see if user already exists.") | ||
} | ||
if username == "" { | ||
out.PrintOutLn("No GitHub user logged into Kurtosis CLI") | ||
return nil | ||
} | ||
out.PrintOutLn(fmt.Sprintf("Logged in as GitHub user: %v", username)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package token | ||
|
||
import ( | ||
"context" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/github_auth_store" | ||
"github.com/kurtosis-tech/kurtosis/cli/cli/out" | ||
"github.com/kurtosis-tech/stacktrace" | ||
) | ||
|
||
var TokenCmd = &lowlevel.LowlevelKurtosisCommand{ | ||
CommandStr: command_str_consts.GitHubTokenCmdStr, | ||
ShortDescription: "Displays GitHub auth token used if a user is logged in", | ||
LongDescription: "Displays GitHub auth token used if a user is logged in", | ||
Args: nil, | ||
Flags: nil, | ||
PreValidationAndRunFunc: nil, | ||
RunFunc: run, | ||
PostValidationAndRunFunc: nil, | ||
} | ||
|
||
func run(_ context.Context, _ *flags.ParsedFlags, _ *args.ParsedArgs) error { | ||
githubAuthStore, err := github_auth_store.GetGitHubAuthStore() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred retrieving GitHub auth store.") | ||
} | ||
username, err := githubAuthStore.GetUser() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred getting user to see if user already exists.") | ||
} | ||
if username == "" { | ||
out.PrintOutLn("No GitHub user currently logged in.") | ||
return nil | ||
} | ||
authToken, err := githubAuthStore.GetAuthToken() | ||
if err != nil { | ||
return stacktrace.Propagate(err, "An error occurred retrieving GitHub auth token for user: %v.", username) | ||
} | ||
out.PrintOutLn(authToken) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.