levalencia commited on
Commit
04fd216
·
1 Parent(s): 3ad7261
Files changed (2) hide show
  1. Dockerfile +7 -5
  2. test_permissions.py +23 -8
Dockerfile CHANGED
@@ -75,8 +75,9 @@ RUN mkdir -p /app/.streamlit /tmp/docling_temp /tmp/easyocr_models /tmp/cache /t
75
  chmod 777 /tmp/models
76
 
77
  COPY requirements.txt ./
 
78
  COPY src/ ./src/
79
- COPY test_permissions.py ./
80
 
81
  # Create Streamlit config directly in Dockerfile to avoid copy issues
82
  RUN echo '[global]' > /app/.streamlit/config.toml && \
@@ -141,13 +142,14 @@ RUN echo '#!/bin/bash' > /app/start.sh && \
141
  echo 'echo "HF_HUB_CACHE: $HF_HUB_CACHE"' >> /app/start.sh && \
142
  echo 'echo "HF_CACHE_HOME: $HF_CACHE_HOME"' >> /app/start.sh && \
143
  echo 'echo "TEMP_DIR: $TEMP_DIR"' >> /app/start.sh && \
144
- echo 'echo "Running environment test..."' >> /app/start.sh && \
145
- echo 'python test_permissions.py' >> /app/start.sh && \
146
  echo 'if [ $? -eq 0 ]; then' >> /app/start.sh && \
147
- echo ' echo "Environment test passed, starting Streamlit app..."' >> /app/start.sh && \
 
148
  echo ' exec streamlit run src/streamlit_app.py --server.port=8501 --server.address=0.0.0.0' >> /app/start.sh && \
149
  echo 'else' >> /app/start.sh && \
150
- echo ' echo "Environment test failed, exiting..."' >> /app/start.sh && \
151
  echo ' exit 1' >> /app/start.sh && \
152
  echo 'fi' >> /app/start.sh && \
153
  chmod +x /app/start.sh
 
75
  chmod 777 /tmp/models
76
 
77
  COPY requirements.txt ./
78
+ COPY pyproject.toml ./
79
  COPY src/ ./src/
80
+ COPY README.md ./
81
 
82
  # Create Streamlit config directly in Dockerfile to avoid copy issues
83
  RUN echo '[global]' > /app/.streamlit/config.toml && \
 
142
  echo 'echo "HF_HUB_CACHE: $HF_HUB_CACHE"' >> /app/start.sh && \
143
  echo 'echo "HF_CACHE_HOME: $HF_CACHE_HOME"' >> /app/start.sh && \
144
  echo 'echo "TEMP_DIR: $TEMP_DIR"' >> /app/start.sh && \
145
+ echo 'echo "Testing cache directory access..."' >> /app/start.sh && \
146
+ echo 'mkdir -p $HF_HUB_CACHE $HF_CACHE_HOME $TRANSFORMERS_CACHE $HF_DATASETS_CACHE $TORCH_HOME $TENSORFLOW_HOME $KERAS_HOME' >> /app/start.sh && \
147
  echo 'if [ $? -eq 0 ]; then' >> /app/start.sh && \
148
+ echo ' echo "Cache directories created successfully"' >> /app/start.sh && \
149
+ echo ' echo "Starting Streamlit app..."' >> /app/start.sh && \
150
  echo ' exec streamlit run src/streamlit_app.py --server.port=8501 --server.address=0.0.0.0' >> /app/start.sh && \
151
  echo 'else' >> /app/start.sh && \
152
+ echo ' echo "Failed to create cache directories, exiting..."' >> /app/start.sh && \
153
  echo ' exit 1' >> /app/start.sh && \
154
  echo 'fi' >> /app/start.sh && \
155
  chmod +x /app/start.sh
test_permissions.py CHANGED
@@ -71,20 +71,23 @@ def test_cache_directories():
71
  return all_good
72
 
73
  def test_root_filesystem_access():
74
- """Test that we cannot access root filesystem."""
75
  print("\n" + "=" * 60)
76
- print("Testing Root Filesystem Access Prevention")
77
  print("=" * 60)
78
 
79
- root_paths = [
80
- '/.cache',
81
- '/root',
82
- '/etc/test',
83
- '/var/test'
 
 
 
84
  ]
85
 
86
  all_good = True
87
- for path in root_paths:
88
  try:
89
  os.makedirs(path, exist_ok=True)
90
  print(f"❌ {path}: SUCCESSFULLY CREATED (SHOULD FAIL)")
@@ -94,6 +97,18 @@ def test_root_filesystem_access():
94
  except Exception as e:
95
  print(f"⚠️ {path}: OTHER ERROR - {e}")
96
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  return all_good
98
 
99
  def test_temp_directory():
 
71
  return all_good
72
 
73
  def test_root_filesystem_access():
74
+ """Test that we cannot access critical root filesystem paths."""
75
  print("\n" + "=" * 60)
76
+ print("Testing Critical Root Filesystem Access Prevention")
77
  print("=" * 60)
78
 
79
+ # Only test critical paths that the application might try to access
80
+ critical_root_paths = [
81
+ '/.cache', # This is the main one that causes issues
82
+ '/.config',
83
+ '/.local',
84
+ '/.huggingface',
85
+ '/.cache/huggingface',
86
+ '/.cache/transformers',
87
  ]
88
 
89
  all_good = True
90
+ for path in critical_root_paths:
91
  try:
92
  os.makedirs(path, exist_ok=True)
93
  print(f"❌ {path}: SUCCESSFULLY CREATED (SHOULD FAIL)")
 
97
  except Exception as e:
98
  print(f"⚠️ {path}: OTHER ERROR - {e}")
99
 
100
+ # Test that we can access our temp directory (this is what matters)
101
+ print(f"\nTesting temp directory access: {os.environ.get('TEMP_DIR', '/tmp/docling_temp')}")
102
+ try:
103
+ temp_test_file = os.path.join(os.environ.get('TEMP_DIR', '/tmp/docling_temp'), 'test_access.txt')
104
+ with open(temp_test_file, 'w') as f:
105
+ f.write('test')
106
+ os.remove(temp_test_file)
107
+ print(f"✅ Temp directory is writable (CRITICAL)")
108
+ except Exception as e:
109
+ print(f"❌ Temp directory not writable: {e}")
110
+ all_good = False
111
+
112
  return all_good
113
 
114
  def test_temp_directory():