-
Notifications
You must be signed in to change notification settings - Fork 181
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
adding identity token as an approximate alias of password #1040
Changes from all commits
c226617
f1ea0e5
d2b598a
976db98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -55,6 +55,7 @@ | |||||||
Username string | ||||||||
PasswordFromStdin bool | ||||||||
Password string | ||||||||
IdentityToken string | ||||||||
Comment on lines
56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, So should I add a field secret that will hold the Identity Token, Instead of Password? |
||||||||
|
||||||||
resolveFlag []string | ||||||||
applyDistributionSpec bool | ||||||||
|
@@ -87,14 +88,15 @@ | |||||||
// Commonly used for non-unary remote targets. | ||||||||
func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) { | ||||||||
var ( | ||||||||
shortUser string | ||||||||
shortPassword string | ||||||||
shortHeader string | ||||||||
flagPrefix string | ||||||||
notePrefix string | ||||||||
qweeah marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
shortUser string | ||||||||
shortPassword string | ||||||||
shortIdentityToken string | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not enable shorthand for |
||||||||
shortHeader string | ||||||||
flagPrefix string | ||||||||
notePrefix string | ||||||||
) | ||||||||
if prefix == "" { | ||||||||
shortUser, shortPassword = "u", "p" | ||||||||
shortUser, shortPassword, shortIdentityToken = "u", "p", "i" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not enable shorthand for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure will do it |
||||||||
shortHeader = "H" | ||||||||
} | ||||||||
flagPrefix, notePrefix = applyPrefix(prefix, description) | ||||||||
|
@@ -104,6 +106,7 @@ | |||||||
} | ||||||||
fs.StringVarP(&opts.Username, flagPrefix+"username", shortUser, "", notePrefix+"registry username") | ||||||||
fs.StringVarP(&opts.Password, flagPrefix+"password", shortPassword, "", notePrefix+"registry password or identity token") | ||||||||
fs.StringVarP(&opts.IdentityToken, flagPrefix+"identity-token", shortIdentityToken, "", notePrefix+"identity token for registry") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not enable shorthand for
Suggested change
|
||||||||
fs.BoolVarP(&opts.Insecure, flagPrefix+"insecure", "", false, "allow connections to "+notePrefix+"SSL registry without certs") | ||||||||
plainHTTPFlagName := flagPrefix + "plain-http" | ||||||||
plainHTTP := fs.Bool(plainHTTPFlagName, false, "allow insecure connections to "+notePrefix+"registry without SSL check") | ||||||||
|
@@ -124,10 +127,16 @@ | |||||||
return opts.readPassword() | ||||||||
} | ||||||||
|
||||||||
// readPassword tries to read password with optional cmd prompt. | ||||||||
// readPassword tries to read password and identity-token with optional cmd prompt. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: make line length less than 80
Suggested change
|
||||||||
func (opts *Remote) readPassword() (err error) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with this, but there is a Cobra feature for mutually exclusive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, thanks for the info. I will check it and get back on this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW |
||||||||
if opts.Password != "" && opts.IdentityToken != "" { | ||||||||
return fmt.Errorf("both --password and --identity-token cannot be used together") | ||||||||
} | ||||||||
|
||||||||
if opts.Password != "" { | ||||||||
fmt.Fprintln(os.Stderr, "WARNING! Using --password via the CLI is insecure. Use --password-stdin.") | ||||||||
} else if opts.IdentityToken != "" { | ||||||||
fmt.Fprintln(os.Stderr, "WARNING! Using --identity-token via the CLI is insecure.") | ||||||||
} else if opts.PasswordFromStdin { | ||||||||
// Prompt for credential | ||||||||
password, err := io.ReadAll(os.Stdin) | ||||||||
|
@@ -267,7 +276,19 @@ | |||||||
|
||||||||
// Credential returns a credential based on the remote options. | ||||||||
func (opts *Remote) Credential() auth.Credential { | ||||||||
return credential.Credential(opts.Username, opts.Password) | ||||||||
if opts.IdentityToken != "" { | ||||||||
// If IdentityToken is provided, use it as the credential without a username | ||||||||
return auth.Credential{ | ||||||||
Username: "", | ||||||||
Password: opts.IdentityToken, | ||||||||
} | ||||||||
} else { | ||||||||
// If IdentityToken is not provided, use the username and password as credentials | ||||||||
return auth.Credential{ | ||||||||
Username: opts.Username, | ||||||||
Password: opts.Password, | ||||||||
} | ||||||||
} | ||||||||
Comment on lines
+279
to
+291
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code should be reverted since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, will fix it. |
||||||||
} | ||||||||
|
||||||||
func (opts *Remote) handleWarning(registry string, logger logrus.FieldLogger) func(warning remote.Warning) { | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ | |
Example - Log in with username and password from command line flags: | ||
oras login -u username -p password localhost:5000 | ||
|
||
Example - Log in with identity token from the command line flags: | ||
oras login -i token localhost:5000 | ||
|
||
Example - Log in with username and password from stdin: | ||
oras login -u username --password-stdin localhost:5000 | ||
|
||
|
@@ -79,25 +82,34 @@ | |
func runLogin(ctx context.Context, opts loginOptions) (err error) { | ||
ctx, logger := opts.WithContext(ctx) | ||
|
||
// prompt for credential | ||
if opts.Password == "" { | ||
// Check if both '--username' and '--identity-token' are provided | ||
if opts.Username != "" && opts.IdentityToken != "" { | ||
return fmt.Errorf("both --username and --identity-token cannot be used together") | ||
} | ||
|
||
// If IdentityToken is provided, use it as the credential without a username | ||
if opts.IdentityToken != "" { | ||
opts.Username = "" // Set the username to empty since it's not required when using identity token | ||
opts.Password = opts.IdentityToken // Use the identity token as the password | ||
} else if opts.Password == "" { | ||
Comment on lines
+90
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those part of code should be reverted if we introduce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh Okay. I will revert them. Let me know should I go with Secrets and SecretFromStdin or identity-token-stdin and password. |
||
// If both '--password' and '--username' are not provided, prompt for credentials | ||
if opts.Username == "" { | ||
// prompt for username | ||
// Prompt for username | ||
username, err := readLine("Username: ", false) | ||
if err != nil { | ||
return err | ||
} | ||
opts.Username = strings.TrimSpace(username) | ||
} | ||
if opts.Username == "" { | ||
// prompt for token | ||
// Prompt for token | ||
if opts.Password, err = readLine("Token: ", true); err != nil { | ||
return err | ||
} else if opts.Password == "" { | ||
return errors.New("token required") | ||
} | ||
} else { | ||
// prompt for password | ||
// Prompt for password | ||
if opts.Password, err = readLine("Password: ", true); err != nil { | ||
return err | ||
} else if opts.Password == "" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this new value, the
--registry-token
can be applied toPassword
directly. The tricky part is whether we need--registry-token-stdin
? Please wait for #742 (comment) to be answered?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I will remove the field and would implement identity-token-stdin instead.