-
Notifications
You must be signed in to change notification settings - Fork 25
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
Mounting secret - reading credentials from file #746
Conversation
Welcome @GunaKKIBM! |
Hi @GunaKKIBM. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Will update the tests if the code changes are ok. |
@@ -60,7 +61,16 @@ func NewPowerVSCloud(cloudInstanceID, zone string, debug bool) (Cloud, error) { | |||
} | |||
|
|||
func newPowerVSCloud(cloudInstanceID, zone string, debug bool) (Cloud, error) { | |||
apikey := os.Getenv("IBMCLOUD_API_KEY") |
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 you are completely removing the reading the API key from the env which is a breaking change, please keep both the ways.
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.
Done
/ok-to-test |
@@ -252,3 +256,31 @@ func (p *powerVSCloud) GetDiskByID(volumeID string) (disk *Disk, err error) { | |||
CapacityGiB: int64(*v.Size), | |||
}, nil | |||
} | |||
|
|||
func readCredentials() (string, error) { | |||
apiKey, err := readCredentialsFromFile() |
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.
you are ignoring all the errors which might be problematic when program genuinely failed to read the file content.
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.
https://github.com/kubernetes-sigs/ibm-powervs-block-csi-driver/pull/746/files#diff-27059fbf8e5d8f0370d7993eabd010230eb1cef170edd78aea391fb6f55953b2R285 - updated here, other than, is not exists, any other reading error, it is returning error, but ideally, If API_KEY_PATH is defined and if the file does not exist, that should also error out I think. Please let me know your thought.
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.
yes, file not found should also be error
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.
Done
pkg/cloud/powervs.go
Outdated
return apiKey, nil | ||
} | ||
|
||
apikey := os.Getenv("IBMCLOUD_API_KEY") |
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.
same variable name with just a smallcase may create a confusion, you can reuse the first variable itself
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.
Sorry, I didn't understand this comment, earlier the env variable that was used in the code (in current main branch), is IBMCLOUD_API_KEY itself
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 meant this
apikey := os.Getenv("IBMCLOUD_API_KEY") | |
apiKey = os.Getenv("IBMCLOUD_API_KEY") |
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.
Missed it for a typo. Updated
@@ -252,3 +256,31 @@ func (p *powerVSCloud) GetDiskByID(volumeID string) (disk *Disk, err error) { | |||
CapacityGiB: int64(*v.Size), | |||
}, nil | |||
} | |||
|
|||
func readCredentials() (string, error) { | |||
apiKey, err := readCredentialsFromFile() |
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.
adding a warning logging is better instead of no logs
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.
pkg/cloud/powervs.go
Outdated
@@ -42,6 +42,7 @@ const ( | |||
PollInterval = 5 * time.Second | |||
VolumeInUseState = "in-use" | |||
VolumeAvailableState = "available" | |||
secretPath = "/var/secrets/IBMCLOUD_API_KEY" |
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.
where is this been used? I'm not sure why such mistakes aren't caught in the CI..
created #751 to track
key: IBMCLOUD_API_KEY | ||
optional: true | ||
- name: API_KEY_PATH | ||
value: /var/secrets/IBMCLOUD_API_KEY |
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.
is /var
a standard path for the credential?
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.
As far as I know, there's no one standard path as such, it could be /etc, /var, /mnt.
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.
/etc looks to be better place..
pkg/cloud/powervs.go
Outdated
|
||
func readCredentialsFromFile() (string, error) { | ||
apiKeyPath := os.Getenv("API_KEY_PATH") | ||
if len(apiKeyPath) == 0 { |
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.
if len(apiKeyPath) == 0 { | |
if apiKeyPath == "" { |
if len(apiKey) != 0 { | ||
return apiKey, nil | ||
} | ||
|
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.
klog.Info("Falling back to read IBMCLOUD_API_KEY environment variable for the key") |
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.
Done
Hi @GunaKKIBM, |
@kishen-v: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
klog.Info("Falling back to read IBMCLOUD_API_KEY environment variable for the key") | ||
apiKey = os.Getenv("IBMCLOUD_API_KEY") | ||
if apiKey == "" { | ||
return "", fmt.Errorf("IBMCLOUD_API_KEY is not provided") |
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.
nit:
We could switch to errors.New as the error string is static + has minor gains in op time. We can track this in a separate issue, altogether.
return "", fmt.Errorf("IBMCLOUD_API_KEY is not provided") | |
return "", errors.New("IBMCLOUD_API_KEY is not provided") |
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.
#755 - created a GHE to track this
env: | ||
- name: API_KEY_PATH | ||
value: /etc/secrets/IBMCLOUD_API_KEY |
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.
Is there any reason for adding the key to this controller?
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.
After looking unto the code, it looks like, the node update controller also needs the apikey (it is also initialising the authenticator), this apikey is needed to GetPVMInstancedetails. Hence, added here too
@GunaKKIBM please squash your commits. Overall the changes looks good. |
7810d21
to
d57e884
Compare
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: GunaKKIBM, yussufsh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Rather than getting apikey from env, the secret needs to be mounted inside controller and node server pod according CIS kubernetes benchmark
Which issue(s) this PR fixes:
#727