Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

compose-cli: fix PAT detection for PAT suggestion #2259

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cli/mobycli/pat_suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const (
// patSuggestMsg is a message to suggest the use of PAT (personal access tokens).
patSuggestMsg = `Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/`
)

// patPrefix represents a docker personal access token prefix.
patPrefix = "dckrp_"
var (
patPrefixes = []string{"dckrp_", "dckr_pat_"}
)

// displayPATSuggestMsg displays a message suggesting users to use PATs instead of passwords to reduce scope.
Expand Down Expand Up @@ -71,8 +72,10 @@ func isUsingPassword(pass string) bool {
if _, err := uuid.ParseUUID(pass); err == nil {
return false
}
if strings.HasPrefix(pass, patPrefix) {
return false
for _, patPrefix := range patPrefixes {
if strings.HasPrefix(pass, patPrefix) {
return false
}
}
return true
}
5 changes: 5 additions & 0 deletions cli/mobycli/pat_suggest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func TestIsUsingPassword(t *testing.T) {
"dckrp_ee5607c41bcd",
false,
},
{
"prefixed personal access token",
"dckr_pat_ee5607c41bcd",
false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
Expand Down