-
Notifications
You must be signed in to change notification settings - Fork 391
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
[JENKINS-73305] Create .ssh directory with owner only permissions #1150
base: master
Are you sure you want to change the base?
[JENKINS-73305] Create .ssh directory with owner only permissions #1150
Conversation
When the JGit implementation needs to create a `.ssh` directory, create it with permissions only allowing access to the directory owner. That is the common pattern used by the OpenSSH project and by POSIX systems to reduce access to the sensitive information stored in the directory. Testing done Ran the CredentialsTest in a debugger with a configured 'auth-data` directory and confirmed that the modified lines are executed on my RHEL 8 development computer. Confirmed that the resulting directory permissions were read, write, and execute for only the owner, with no other permissions.
d518e26
to
a09e86f
Compare
.getKnownHostsFile() | ||
.getParentFile() | ||
.toPath()); | ||
if (isWindows()) { |
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.
Here be dragons.
Don't assume that POSIX file systems == non windows systems.
You can be on Linux and have a non POSIX FS (and the inverse).
And there was (and iirc) still is a bug where when you ask for the filesystem for a path you get the default even if it should be different!
This the only reliable way to do this is to actually try, catch the exception and do a fallback unless that big is fixed.
Set<PosixFilePermission> ownerOnly = PosixFilePermissions.fromString("rwx------"); | ||
FileAttribute<Set<PosixFilePermission>> fileAttribute = | ||
PosixFilePermissions.asFileAttribute(ownerOnly); | ||
Files.createDirectories( |
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 think you want createDirectory here (and possibly a different call to create any missing parents of this directory)?
(At least you don't want all directories up to the parent to be created with these perms do you?)
5069b72
to
a09e86f
Compare
JENKINS-73305 Create .ssh directory with owner only permissions
When the JGit implementation needs to create a
.ssh
directory, create it with permissions only allowing access to the directory owner. That is the common pattern used by the OpenSSH project and by POSIX systems to reduce access to the sensitive information stored in the directory.Testing done
Ran the CredentialsTest in a debugger with a configured 'auth-data` directory and confirmed that the modified lines are executed on my RHEL 8 development computer. Confirmed that the resulting directory permissions were read, write, and execute for only the owner, with no other permissions.
The coverage report on the ci.jenkins.io job also shows that the newly added statements are executed by automated tests.
Checklist
Types of changes
What types of changes does your code introduce?