-
Notifications
You must be signed in to change notification settings - Fork 31
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
Split the functionality in node/mounter
into smaller packages
#328
Open
unexge
wants to merge
10
commits into
main
Choose a base branch
from
unexge/podmounter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a20262
Move `ReplaceFile` function to `util` package from `driver` package
unexge b8eea57
Move `TargetPath` into its own package
unexge 73fbc70
Create `mountpoint.Args` for parsing and accessing Mountpoint args
unexge 96752b4
Add `envprovider` package for accessing environment variables
unexge 2018ca3
Add `volumecontext` package for accessing volume context from CSI
unexge 7518590
Move STS region detection into `regionprovider` package
unexge bcc72d4
Create `credentialprovider` package for getting AWS credentials
unexge 4c7f236
Use newly created packages in `SystemdMounter`
unexge 545e24d
Ensure to link documentations if some configuration is missing
unexge b7e02ac
Ignore nil errors in `SystemdMounter.ensureCredentialsDirExists`
unexge 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -9,50 +9,51 @@ import ( | |
"path/filepath" | ||
"strings" | ||
"unicode" | ||
|
||
"github.com/google/renameio" | ||
) | ||
|
||
const ( | ||
awsProfileName = "s3-csi" | ||
awsProfileConfigFilename = "s3-csi-config" | ||
awsProfileCredentialsFilename = "s3-csi-credentials" | ||
awsProfileFilePerm = fs.FileMode(0400) // only owner readable | ||
) | ||
|
||
// ErrInvalidCredentials is returned when given AWS Credentials contains invalid characters. | ||
var ErrInvalidCredentials = errors.New("aws-profile: Invalid AWS Credentials") | ||
|
||
// An AWSProfile represents an AWS profile with it's credentials and config files. | ||
type AWSProfile struct { | ||
Name string | ||
ConfigPath string | ||
CredentialsPath string | ||
Name string | ||
ConfigFilename string | ||
CredentialsFilename string | ||
} | ||
|
||
// CreateAWSProfile creates an AWS Profile with credentials and config files from given credentials. | ||
// Created credentials and config files can be clean up with `CleanupAWSProfile`. | ||
func CreateAWSProfile(basepath string, accessKeyID string, secretAccessKey string, sessionToken string) (AWSProfile, error) { | ||
func CreateAWSProfile(basepath string, accessKeyID string, secretAccessKey string, sessionToken string, filePerm fs.FileMode) (AWSProfile, error) { | ||
if !isValidCredential(accessKeyID) || !isValidCredential(secretAccessKey) || !isValidCredential(sessionToken) { | ||
return AWSProfile{}, ErrInvalidCredentials | ||
} | ||
|
||
name := awsProfileName | ||
|
||
configPath := filepath.Join(basepath, awsProfileConfigFilename) | ||
err := writeAWSProfileFile(configPath, configFileContents(name)) | ||
err := writeAWSProfileFile(configPath, configFileContents(name), filePerm) | ||
if err != nil { | ||
return AWSProfile{}, fmt.Errorf("aws-profile: Failed to create config file %s: %v", configPath, err) | ||
} | ||
|
||
credentialsPath := filepath.Join(basepath, awsProfileCredentialsFilename) | ||
err = writeAWSProfileFile(credentialsPath, credentialsFileContents(name, accessKeyID, secretAccessKey, sessionToken)) | ||
err = writeAWSProfileFile(credentialsPath, credentialsFileContents(name, accessKeyID, secretAccessKey, sessionToken), filePerm) | ||
if err != nil { | ||
return AWSProfile{}, fmt.Errorf("aws-profile: Failed to create credentials file %s: %v", credentialsPath, err) | ||
} | ||
|
||
return AWSProfile{ | ||
Name: name, | ||
ConfigPath: configPath, | ||
CredentialsPath: credentialsPath, | ||
Name: name, | ||
ConfigFilename: awsProfileConfigFilename, | ||
CredentialsFilename: awsProfileCredentialsFilename, | ||
}, nil | ||
} | ||
|
||
|
@@ -75,14 +76,8 @@ func CleanupAWSProfile(basepath string) error { | |
return nil | ||
} | ||
|
||
func writeAWSProfileFile(path string, content string) error { | ||
err := os.WriteFile(path, []byte(content), awsProfileFilePerm) | ||
if err != nil { | ||
return err | ||
} | ||
// If the given file exists, `os.WriteFile` just truncates it without changing it's permissions, | ||
// so we need to ensure it always has the correct permissions. | ||
return os.Chmod(path, awsProfileFilePerm) | ||
Comment on lines
-83
to
-85
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.
|
||
func writeAWSProfileFile(path string, content string, filePerm os.FileMode) error { | ||
return renameio.WriteFile(path, []byte(content), filePerm) | ||
} | ||
|
||
func credentialsFileContents(profile string, accessKeyID string, secretAccessKey string, sessionToken string) string { | ||
|
Oops, something went wrong.
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.
This logic has been moved to credentials_sts_web_identity.go. Since we enabled
requiresRepublish
as part of Pod-level identity support, Kubernetes will callNodePublishVolume
periodically to update existing service account tokens before they expire, and the credential provider will be called as part of this method. Another reason for this change is that, this assumes a single location for service account tokens for Driver-level identity, but with containerization this won't be the case. See the note regarding credential provider in the original PR description for more context.