-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix: Check of write permission of atKeys file path when submitting enroll request #690
fix: Check of write permission of atKeys file path when submitting enroll request #690
Conversation
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.
@sitaram-kalluri I think the logic here is faulty. Consider the following scenario.
. User onboards an atsign using onboard command - standard atKeys file created
. On the same host, the user attempts an enrollment using the enroll command leaving the keys file as default
. isWritable confirms the standard atKeys file is writable, and then deletes it
. the original atKeys file is now gone
@gkc : The keys file is mandatory for the enroll command. Attaching the log snippet below
The below condition in the enroll method ensure the atKeys file path is mandatory: @visibleForTesting
Future<void> enroll(ArgResults argResults, {AtOnboardingService? svc}) async {
if (!argResults.wasParsed(AuthCliArgs.argNameAtKeys)) {
throw ArgumentError('The --${AuthCliArgs.argNameAtKeys} option is'
' mandatory for the "enroll" command');
} Further, if the user gives the same atKeys filepath for enroll command as of the original atKeys, then it would return an error stating the atKeys file exists but does not delete the original atKeys file. |
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.
@sitaram-kalluri you state
Further, if the user gives the same atKeys filepath for enroll command as of the original atKeys, then it would return an error stating the atKeys file exists but does not delete the original atKeys file.
However, you have removed that specific check for the file already existing
@@ -1,3 +1,5 @@ | |||
## 1.7.1 | |||
- When submitting an enrollment request, check for write permissions of AtKeys file path. |
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.
add 'fix: ' at the start of this comment please
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.
Added "fix:" in the changelog.md
…le-is-writeable-before-finalizing-pkam-apkam
… the enroll method.
…finalizing-pkam-apkam
// "exclusive" is set to true to check if the file already exists; if it does, | ||
// an error will be logged and returned. | ||
file.createSync(recursive: true, exclusive: true); | ||
file.createSync(recursive: true); |
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 believe we should keep the exclusive:true
here also, but allow the PathExistsException to be thrown. I'm a bit uncomfortable with a method called 'isWritable' possibly deleting a file
Maybe a better approach would be for this method to handle each case (file exists, file doesn't exist) differently
- if file exists, try opening it for FileMode.writeOnlyAppend
- if file doesn't already exist, try creating it and then removing it
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.
@gkc :
- Renamed "isWritable" method name to "canCreateFile".
- Added
exclusive:true
when creating a file and rethrowing the PathExistsException.
Please review and let me know if any further changes are required.
- What I did
- How I did it
AtOnboardingServiceImpl._generateAtKeysFile
method, there is a check which returns error if the file already exists. Therefore, delete the file here after checking for write permissions.- How to verify it
- Description for the changelog