Skip to content

Commit

Permalink
Fix master pull socket permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Aug 13, 2024
1 parent bd89384 commit dbbc8c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions salt/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def ipc_publish_client(node, opts, io_loop):
if node == "master":
kwargs.update(
path=os.path.join(opts["sock_dir"], "master_event_pub.ipc"),
pub_path_perms=0o660,
)
else:
id_hash = _minion_hash(
Expand Down
10 changes: 9 additions & 1 deletion salt/transport/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import errno
import logging
import multiprocessing
import os
import queue
import select
import socket
Expand Down Expand Up @@ -1327,6 +1328,8 @@ def __init__(
pull_host=None,
pull_port=None,
pull_path=None,
pull_path_perms=0o600,
pub_path_perms=0o600,
ssl=None,
):
self.opts = opts
Expand All @@ -1337,6 +1340,8 @@ def __init__(
self.pull_host = pull_host
self.pull_port = pull_port
self.pull_path = pull_path
self.pull_path_prems = pull_path_perms
self.pub_path_prems = pub_path_perms
self.ssl = ssl

@property
Expand Down Expand Up @@ -1406,7 +1411,9 @@ async def publisher(
log.debug(
"Publish server binding pub to %s ssl=%r", self.pub_path, self.ssl
)
sock = tornado.netutil.bind_unix_socket(self.pub_path)
with salt.utils.files.set_umask(0o177):
sock = tornado.netutil.bind_unix_socket(self.pub_path)
os.chmod(self.pub_path, self.pub_path_perms)
else:
log.debug(
"Publish server binding pub to %s:%s ssl=%r",
Expand Down Expand Up @@ -1446,6 +1453,7 @@ async def publisher(
# Securely create socket
with salt.utils.files.set_umask(0o177):
self.pull_sock.start()
os.chmod(self.pull_path, self.pull_path_perms)

def pre_fork(self, process_manager):
"""
Expand Down
14 changes: 12 additions & 2 deletions salt/transport/ws.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import logging
import multiprocessing
import os
import socket
import time
import warnings
Expand Down Expand Up @@ -259,6 +260,8 @@ def __init__(
pull_host=None,
pull_port=None,
pull_path=None,
pull_path_perms=0o600,
pub_path_perms=0o600,
ssl=None,
):
self.opts = opts
Expand All @@ -268,6 +271,8 @@ def __init__(
self.pull_host = pull_host
self.pull_port = pull_port
self.pull_path = pull_path
self.pull_path_perms = pull_path_perms
self.pub_path_perms = pub_path_perms
self.ssl = ssl
self.clients = set()
self._run = None
Expand All @@ -291,6 +296,8 @@ def __getstate__(self):
"pull_host": self.pull_host,
"pull_port": self.pull_port,
"pull_path": self.pull_path,
"pull_path_perms": self.pull_path_perms,
"pub_path_perms": self.pub_path_perms,
}

def publish_daemon(
Expand Down Expand Up @@ -338,8 +345,10 @@ async def publisher(
server = aiohttp.web.Server(self.handle_request)
runner = aiohttp.web.ServerRunner(server)
await runner.setup()
site = aiohttp.web.UnixSite(runner, self.pub_path, ssl_context=ctx)
log.info("Publisher binding to socket %s", self.pub_path)
with salt.utils.files.set_umask(0o177):
log.info("Publisher binding to socket %s", self.pub_path)
site = aiohttp.web.UnixSite(runner, self.pub_path, ssl_context=ctx)
os.chmod(self.pub_path, self.pub_path_perms)
else:
sock = _get_socket(self.opts)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand All @@ -360,6 +369,7 @@ async def publisher(
self.puller = await asyncio.start_unix_server(
self.pull_handler, self.pull_path
)
os.chmod(self.pull_path, self.pull_path_perms)
else:
self.puller = await asyncio.start_server(
self.pull_handler, self.pull_host, self.pull_port
Expand Down
8 changes: 6 additions & 2 deletions salt/transport/zeromq.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@ def __init__(
pull_host=None,
pull_port=None,
pull_path=None,
pull_path_perms=0o600,
pub_path_perms=0o600,
):
self.opts = opts
self.pub_host = pub_host
Expand All @@ -864,6 +866,8 @@ def __init__(
self.pull_host = pull_host
self.pull_port = pull_port
self.pull_path = pull_path
self.pub_path_perms = pub_path_perms
self.pull_path_perms = pull_path_perms
if pull_path:
self.pull_uri = f"ipc://{pull_path}"
else:
Expand Down Expand Up @@ -930,14 +934,14 @@ def _get_sockets(self, context, ioloop):
if self.pub_path:
os.chmod( # nosec
self.pub_path,
0o600,
self.pub_path_perms,
)
log.info("Starting the Salt Puller on %s", self.pull_uri)
pull_sock.bind(self.pull_uri)
if self.pull_path:
os.chmod( # nosec
self.pull_path,
0o600,
self.pull_path_perms,
)
return pull_sock, pub_sock, monitor

Expand Down

0 comments on commit dbbc8c8

Please sign in to comment.