Skip to content

Commit

Permalink
fixes SECURITY-2521 (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Jul 12, 2022
1 parent bd85216 commit c564958
Showing 1 changed file with 3 additions and 20 deletions.
Expand Up @@ -6,12 +6,10 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.FilePath;
import hudson.remoting.VirtualChannel;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.stapler.DataBoundConstructor;

public class VaultTokenFileCredential extends AbstractVaultTokenCredential {
Expand All @@ -28,24 +26,9 @@ public VaultTokenFileCredential(@CheckForNull CredentialsScope scope, @CheckForN

@Override
public String getToken(Vault vault) {
FilePath file = new FilePath(new File(filepath));
try {
return file.act(new FilePath.FileCallable<String>() {
@Override
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
//not needed
}

@Override
public String invoke(File f, VirtualChannel channel) {
try {
return FileUtils.readFileToString(f);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).trim();
} catch (IOException | InterruptedException e) {
return FileUtils.readFileToString(new File(filepath), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new VaultPluginException("Failed to read token from file", e);
}
}
Expand Down

0 comments on commit c564958

Please sign in to comment.