33
44.. versionadded:: 3008.0
55
6- The ``localfs_keys_backcompat `` is a shim driver meant to allow the salt.cache
6+ The ``localfs_key `` is a shim driver meant to allow the salt.cache
77subsystem to interact with the existing master pki folder/file structure
88without any migration from previous versions of salt. It is not meant for
99general purpose use and should not be used outside of the master auth system.
@@ -123,7 +123,7 @@ def store(bank, key, data, cachedir, user, **kwargs):
123123 savefn = Path (cachedir ) / base / key
124124 base = savefn .parent
125125
126- if not clean_path (cachedir , savefn , subdir = True ):
126+ if not clean_path (cachedir , str ( savefn ) , subdir = True ):
127127 raise SaltCacheError (f"key { key } is not a valid key path." )
128128
129129 try :
@@ -191,6 +191,9 @@ def fetch(bank, key, cachedir, **kwargs):
191191 ]:
192192 keyfile = Path (cachedir , bank , key )
193193
194+ if not clean_path (cachedir , str (keyfile ), subdir = True ):
195+ raise SaltCacheError (f"key { key } is not a valid key path." )
196+
194197 if keyfile .is_file () and not keyfile .is_symlink ():
195198 with salt .utils .files .fopen (keyfile , "r" ) as fh_ :
196199 return {"state" : state , "pub" : fh_ .read ()}
@@ -200,6 +203,9 @@ def fetch(bank, key, cachedir, **kwargs):
200203 # with the filesystem, so return a list of 1
201204 pubfn_denied = os .path .join (cachedir , "minions_denied" , key )
202205
206+ if not clean_path (cachedir , pubfn_denied , subdir = True ):
207+ raise SaltCacheError (f"key { key } is not a valid key path." )
208+
203209 if os .path .isfile (pubfn_denied ):
204210 with salt .utils .files .fopen (pubfn_denied , "r" ) as fh_ :
205211 return [fh_ .read ()]
@@ -209,6 +215,9 @@ def fetch(bank, key, cachedir, **kwargs):
209215
210216 keyfile = Path (cachedir , key )
211217
218+ if not clean_path (cachedir , str (keyfile ), subdir = True ):
219+ raise SaltCacheError (f"key { key } is not a valid key path." )
220+
212221 if keyfile .is_file () and not keyfile .is_symlink ():
213222 with salt .utils .files .fopen (keyfile , "r" ) as fh_ :
214223 return fh_ .read ()
@@ -243,7 +252,7 @@ def updated(bank, key, cachedir, **kwargs):
243252 for dir in bases :
244253 keyfile = Path (cachedir , dir , key )
245254
246- if not clean_path (cachedir , keyfile , subdir = True ):
255+ if not clean_path (cachedir , str ( keyfile ) , subdir = True ):
247256 raise SaltCacheError (f"key { key } is not a valid key path." )
248257
249258 if keyfile .is_file () and not keyfile .is_symlink ():
@@ -336,10 +345,13 @@ def list_(bank, cachedir, **kwargs):
336345 )
337346 for item in items :
338347 # salt foolishly dumps a file here for key cache, ignore it
339- if bank in ["keys" , "denied_keys" ] and not valid_id (__opts__ , item ):
348+ keyfile = Path (cachedir , base , item )
349+
350+ if (
351+ bank in ["keys" , "denied_keys" ] and not valid_id (__opts__ , item )
352+ ) or not clean_path (cachedir , str (keyfile ), subdir = True ):
340353 log .error ("saw invalid id %s, discarding" , item )
341354
342- keyfile = Path (cachedir , base , item )
343355 if keyfile .is_file () and not keyfile .is_symlink ():
344356 ret .append (item )
345357 return ret
@@ -366,7 +378,7 @@ def contains(bank, key, cachedir, **kwargs):
366378 for base in bases :
367379 keyfile = Path (cachedir , base , key )
368380
369- if not clean_path (cachedir , keyfile , subdir = True ):
381+ if not clean_path (cachedir , str ( keyfile ) , subdir = True ):
370382 raise SaltCacheError (f"key { key } is not a valid key path." )
371383
372384 if keyfile .is_file () and not keyfile .is_symlink ():
0 commit comments