-
Notifications
You must be signed in to change notification settings - Fork 496
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
Allow Athens to Propagate Authentication to Mod Download #1650
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f176967
Allow Athens to Propagate Authentication to Mod Download
marwan-at-work b1163a2
update readme
marwan-at-work 91a789b
add pattern matching to auth propagation
marwan-at-work 2c57b4e
Propagate authentication to pre declared static host
marwan-at-work d78de1b
quote redis test
marwan-at-work 295f31d
fix flaky redis error message
marwan-at-work f5c13e3
fix config tests
marwan-at-work 161c4df
fix config tests
marwan-at-work da67900
Merge branch 'main' into customauth
twexler 026f2a1
Update config.dev.toml
marwan-at-work 73a31ed
Merge branch 'main' into customauth
marwan-at-work 375eff2
gofmt
marwan-at-work File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/gomods/athens/pkg/errors" | ||
) | ||
|
||
type authkey struct{} | ||
|
||
// BasicAuth is the embedded credentials in a context | ||
type BasicAuth struct { | ||
User, Password string | ||
} | ||
|
||
// SetAuthInContext sets the auth value in context | ||
func SetAuthInContext(ctx context.Context, auth BasicAuth) context.Context { | ||
return context.WithValue(ctx, authkey{}, auth) | ||
} | ||
|
||
// FromContext retrieves the auth value | ||
func FromContext(ctx context.Context) (BasicAuth, bool) { | ||
auth, ok := ctx.Value(authkey{}).(BasicAuth) | ||
return auth, ok | ||
} | ||
|
||
// WriteNETRC writes the netrc file to the specified directory | ||
func WriteNETRC(path, host, user, password string) error { | ||
const op errors.Op = "auth.WriteNETRC" | ||
fileContent := fmt.Sprintf("machine %s login %s password %s\n", host, user, password) | ||
if err := ioutil.WriteFile(path, []byte(fileContent), 0600); err != nil { | ||
return errors.E(op, fmt.Errorf("netrcFromToken: could not write to file: %v", err)) | ||
} | ||
return nil | ||
} | ||
|
||
// WriteTemporaryNETRC writes a netrc file to a temporary directory, returning | ||
// the directory it was written to. | ||
func WriteTemporaryNETRC(host, user, password string) (string, error) { | ||
const op errors.Op = "auth.WriteTemporaryNETRC" | ||
dir, err := ioutil.TempDir("", "netrcp") | ||
marwan-at-work marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return "", errors.E(op, err) | ||
} | ||
rcp := filepath.Join(dir, GetNETRCFilename()) | ||
err = WriteNETRC(rcp, host, user, password) | ||
if err != nil { | ||
return "", errors.E(op, err) | ||
} | ||
return dir, nil | ||
} | ||
|
||
// GetNETRCFilename returns the name of the netrc file | ||
// according to the contextual platform | ||
func GetNETRCFilename() string { | ||
if runtime.GOOS == "windows" { | ||
return "_netrc" | ||
} | ||
return ".netrc" | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure if I like the default here, from a security perspective. Perhaps just
["localhost"]
?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.
@twexler you're right. I removed this whole functionality in favor of static hosts. This should eliminate the possibility of accidentally leaking credentials to any host other host than the pre declared one.