Bind secret files to random temp paths#534
Conversation
Kevin-CB
left a comment
There was a problem hiding this comment.
Yeah, using random temp is a better approach, there is no reason to involve user input in the ondisk filename at all.. it closes the vector more cleanly that sanitizing.
I confiormed locally that was working properly.
Closing #533 in favor of this one.
Thanks Jesse!
| if (workspace != null) { | ||
| final UnbindableDir secrets = UnbindableDir.create(workspace); | ||
| final FilePath secret = secrets.getDirPath().child("keystore-" + keystoreVariable); | ||
| final FilePath secret = secrets.getDirPath().createTempFile("file", null); |
There was a problem hiding this comment.
to aid debugging, use the type there (its a Certificate so will be a keystore, but could also be called cert)
| final FilePath secret = secrets.getDirPath().createTempFile("file", null); | |
| final FilePath secret = secrets.getDirPath().createTempFile("keystore", null); |
There was a problem hiding this comment.
I thought about it but settled on just a generic filename in all cases. As noted in #533, the actual filename is concealed from the logs anyway, so there is no real advantage to picking a particular prefix.
| if (workspace != null) { | ||
| final UnbindableDir secrets = UnbindableDir.create(workspace); | ||
| final FilePath secret = secrets.getDirPath().child("keystore-" + keystoreVariable); | ||
| final FilePath secret = secrets.getDirPath().createTempFile("file", null); |
There was a problem hiding this comment.
alternative to above
| final FilePath secret = secrets.getDirPath().createTempFile("file", null); | |
| final FilePath secret = secrets.getDirPath().createTempFile("cert", null); |
| SSHUserPrivateKey sshKey = getCredentials(build); | ||
| UnbindableDir keyDir = UnbindableDir.create(workspace); | ||
| FilePath keyFile = keyDir.getDirPath().child("ssh-key-" + keyFileVariable); | ||
| FilePath keyFile = keyDir.getDirPath().createTempFile("file", null); |
There was a problem hiding this comment.
| FilePath keyFile = keyDir.getDirPath().createTempFile("file", null); | |
| FilePath keyFile = keyDir.getDirPath().createTempFile("id", null); |
| String baseName = new FilePath(new File(credentials.getFileName())).getName(); | ||
|
|
||
| FilePath secret = dir.child(baseName); | ||
| FilePath secret = dir.createTempDir("file", null); |
There was a problem hiding this comment.
use an extension for zips?
| FilePath secret = dir.createTempDir("file", null); | |
| FilePath secret = dir.createTempDir("file", "zip"); |
There was a problem hiding this comment.
No because this is a dir not a ZIP file.
|
|
||
| # check it was where we would expect it to be | ||
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/keystore-MY_KEYSTORE$' | ||
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/file.\+[.]tmp$' |
There was a problem hiding this comment.
depending on accepting previous suggestions:
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/file.\+[.]tmp$' | |
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/keystore.\+[.]tmp$' |
|
|
||
| # check it was where we would expect it to be | ||
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/keystore-MY_KEYSTORE$' | ||
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/file.\+[.]tmp$' |
There was a problem hiding this comment.
or depending on accepting previous suggestions:
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/file.\+[.]tmp$' | |
| echo "$keystore_path" | grep -q '/workspace/p@tmp/secretFiles/[-0-9a-f]\{36\}/cert.\+[.]tmp$' |
|
User report of issue in #539 |
Fixes #532. Alternative to #533.