-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Delete Public SSH Key tmp file after calculating fingerprint #1855
Conversation
Signed-off-by: Magnus Lindvall <magnus@dnmgns.com>
LGTM |
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.
It should be after check for error as on error writeTmpKeyFile
will return empty string.
@lafriks - Yeah, nice catch. And if |
Signed-off-by: Magnus Lindvall <magnus@dnmgns.com>
models/ssh_key.go
Outdated
@@ -382,6 +382,7 @@ func calcFingerprint(publicKeyContent string) (string, error) { | |||
} else if len(stdout) < 2 { | |||
return "", errors.New("not enough output for calculating fingerprint: " + stdout) | |||
} | |||
os.Remove(tmpPath) |
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 should still use defer before executing ssh-keygen (after checking empty string) since if the check failed the file is not removed otherwise.
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.
See SSHKeyGenParsePublicKey
on where to place defer remove
models/ssh_key.go
Outdated
@@ -382,6 +382,7 @@ func calcFingerprint(publicKeyContent string) (string, error) { | |||
} else if len(stdout) < 2 { | |||
return "", errors.New("not enough output for calculating fingerprint: " + stdout) | |||
} | |||
os.Remove(tmpPath) |
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.
See SSHKeyGenParsePublicKey
on where to place defer remove
Signed-off-by: Magnus Lindvall <magnus@dnmgns.com>
Signed-off-by: Magnus Lindvall <magnus@dnmgns.com>
LGTM |
When using LDAP User Synchronization (#1478) with LDAP Public SSH Keys synchronization (#1844), the public key fingerprint calculation might be running with a quite high frequency.
As the tmp-files for calculating public key fingerprint is not deleted, the system could end up with lots of public tmp files causing inode issue and running out of disk space.
This PR addresses this issue by cleaning up the tmp file after the fingerprint has been calculated.