Skip to content

Bind secret files to random temp paths#534

Merged
jglick merged 1 commit into
jenkinsci:masterfrom
jglick:secret-files
Jul 9, 2026
Merged

Bind secret files to random temp paths#534
jglick merged 1 commit into
jenkinsci:masterfrom
jglick:secret-files

Conversation

@jglick

@jglick jglick commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fixes #532. Alternative to #533.

@jglick
jglick requested a review from a team as a code owner July 8, 2026 19:52
@jglick jglick added the bug label Jul 8, 2026

@Kevin-CB Kevin-CB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to aid debugging, use the type there (its a Certificate so will be a keystore, but could also be called cert)

Suggested change
final FilePath secret = secrets.getDirPath().createTempFile("file", null);
final FilePath secret = secrets.getDirPath().createTempFile("keystore", null);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternative to above

Suggested change
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FilePath keyFile = keyDir.getDirPath().createTempFile("file", null);
FilePath keyFile = keyDir.getDirPath().createTempFile("id", null);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

String baseName = new FilePath(new File(credentials.getFileName())).getName();

FilePath secret = dir.child(baseName);
FilePath secret = dir.createTempDir("file", null);

@jtnord jtnord Jul 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use an extension for zips?

Suggested change
FilePath secret = dir.createTempDir("file", null);
FilePath secret = dir.createTempDir("file", "zip");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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$'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on accepting previous suggestions:

Suggested change
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$'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or depending on accepting previous suggestions:

Suggested change
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$'

@jglick
jglick enabled auto-merge July 9, 2026 19:24
@jglick
jglick merged commit 902a273 into jenkinsci:master Jul 9, 2026
16 of 17 checks passed
@jglick
jglick deleted the secret-files branch July 9, 2026 19:39
@timja

timja commented Jul 17, 2026

Copy link
Copy Markdown
Member

User report of issue in #539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSH and Certificate file can leave the expected directory

4 participants