Skip to content

Commit e57bd40

Browse files
committed
RPC: Delete cookie file before replacing it
Unclear if this is the best thing to do, but due to v26.1.knots20240325 creating it read-only, it is somewhat necessary for now
1 parent 783fbaf commit e57bd40

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/rpc/request.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie
126126
file.close();
127127

128128
fs::path filepath = GetAuthCookieFile(false);
129+
try {
130+
fs::remove(filepath);
131+
} catch (const fs::filesystem_error& e) {
132+
// ignore
133+
}
129134
if (!RenameOver(filepath_tmp, filepath)) {
130135
LogWarning("Unable to rename cookie authentication file %s to %s", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
131136
return false;

test/functional/rpc_users.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ def run_test(self):
210210
assert cookie_path.exists()
211211
self.stop_node(0)
212212

213+
cookie_path.mkdir()
214+
cookie_path_subdir = cookie_path / "subdir"
215+
cookie_path_subdir.mkdir()
216+
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
217+
cookie_path_subdir.rmdir()
218+
cookie_path.rmdir()
219+
220+
self.log.info('Check that a non-writable cookie file will get replaced gracefully')
221+
cookie_path.mkdir(mode=1)
222+
self.restart_node(0)
223+
self.stop_node(0)
224+
213225
self.test_rpccookieperms()
214226

215227
self.test_norpccookiefile(cookie_path)

0 commit comments

Comments
 (0)