Skip to content
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

Remote Taskfiles: redact credentials of remote URLs in prompts and logs #2045

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

iwittkau
Copy link
Contributor

@iwittkau iwittkau commented Feb 6, 2025

This is to improve #1317.

I've implemented redaction support for the taskfile.Node interface, specifically for the taskfile.GitNode implementation which was logged with the clear-text user access tokens before.

@iwittkau iwittkau mentioned this pull request Feb 6, 2025
15 tasks
taskfile/node_git.go Show resolved Hide resolved
taskfile/node_git.go Show resolved Hide resolved
taskfile/node_git.go Outdated Show resolved Hide resolved
taskfile/node.go Outdated
Comment on lines 20 to 21
Location() string
RedactedLocation() string
Copy link
Member

Choose a reason for hiding this comment

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

Just had a quick look on my phone, not a full review.

Is the raw (non-redacted) location actually used outside of the git node implementation? You could make the argument that the credentials should never be exposed via the interface and that Location should just return the redacted version. This would save us having to add an interface method that only one of the implementations needs.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you @pd93 !
AFAIK, the Location is used only to reference it in the graph so, imho no objection to return the redacted version.
Also, the http node implementation could / should have the same behavior, as we can use http://USER:PASS@URL pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would make the whole change a lot simpler! I saw that the node.Location is used to provide the cache key.

I think ignoring the username and password combination for the cache should be fine since different combinations shouldn't yield different Taskfile contents.

Adding the HTTP node redaction should be easy too.

@iwittkau iwittkau changed the title Remote Taskfiles: redact credentials of git URLs in prompts and logs Remote Taskfiles: redact credentials of remote URLs in prompts and logs Feb 9, 2025
@@ -22,7 +22,7 @@ type Node interface {
Remote() bool
ResolveEntrypoint(entrypoint string) (string, error)
ResolveDir(dir string) (string, error)
FilenameAndLastDir() (string, string)
FilenameAndLastDir() (lastDir string, file string) // TODO the return order is implemented opposite to the naming
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this caused some bugs? #1317 (comment)

@iwittkau iwittkau marked this pull request as draft February 9, 2025 10:38
@iwittkau
Copy link
Contributor Author

iwittkau commented Feb 9, 2025

I've turned this into a draft for now.

@@ -122,5 +121,5 @@ func (node *GitNode) ResolveDir(dir string) (string, error) {
}

func (node *GitNode) FilenameAndLastDir() (string, string) {
return filepath.Base(node.path), filepath.Base(filepath.Dir(node.path))
return filepath.Base(filepath.Dir(node.filepath)), filepath.Base(node.filepath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

taskfile/cache.go uses it like this:

lastDir, filename := node.FilenameAndLastDir()

@iwittkau iwittkau marked this pull request as ready for review February 9, 2025 21:02
@iwittkau
Copy link
Contributor Author

Compiling it and running this as a development version actually breaks my own git-based Remote Taskfiles setup 😅

Back to draft, I guess.

@iwittkau iwittkau marked this pull request as draft February 10, 2025 11:27
u.Path = basePath
gitURL.RawQuery = ""
gitURL.Path = urlPath
baseURL := gitURL.Redacted()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We actually have to use the unredacted URL here.

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.

3 participants