python.ephemeral_filesystem_write
Stability
Medium
/mnt/persistent/output.txt
Detects writes to local filesystem paths that may be ephemeral in containerized or serverless environments (Docker, Kubernetes, Lambda, etc.).
Why It Matters
Section titled “Why It Matters”In modern cloud environments, the local filesystem is typically ephemeral:
- Container restarts — Data written to the container filesystem is lost on restart
- Serverless functions — Lambda/Cloud Functions have no persistent local storage
- Horizontal scaling — Different instances don’t share local files
- Deployment updates — New container images don’t have data from old containers
Example
Section titled “Example”# ❌ Before (ephemeral write)with open("output.txt", "w") as f: f.write(data)
import picklewith open("model.pkl", "wb") as f: pickle.dump(model, f)# ✅ After (persistent storage)# Option 1: Use object storageimport boto3s3 = boto3.client('s3')s3.put_object(Bucket='my-bucket', Key='output.txt', Body=data)
# Option 2: Use mounted volumewith open("/mnt/persistent/output.txt", "w") as f: f.write(data)
# Option 3: Use databasedb.execute("INSERT INTO files (name, content) VALUES (?, ?)", ['output.txt', data])What Unfault Detects
Section titled “What Unfault Detects”open()with write modes (‘w’, ‘a’, ‘x’, ‘wb’, etc.)pathlib.Path.write_text()andwrite_bytes()tempfile.NamedTemporaryFile,mkstemp,mkdtempos.mkdir,os.makedirsshutil.copy,shutil.movepickle.dump,json.dump,torch.save,joblib.dump
Auto-Fix
Section titled “Auto-Fix”Unfault generates patches with comments suggesting persistent storage alternatives:
# Fix: Use object storage instead of local filesystem:# s3 = boto3.client('s3')# s3.put_object(Bucket='my-bucket', Key='output.txt', Body=data)Persistent Path Patterns
Section titled “Persistent Path Patterns”These paths are considered persistent and won’t trigger findings:
/mnt/— Mounted volumes/data/,/var/data/— Common data directories/efs/,/nfs/— Network filesystemss3://,gs://,az://— Cloud storage URIs- Environment variable paths (configurable locations)