jrrribeiro commited on
Commit
3f60fb7
·
verified ·
1 Parent(s): 7df33f3

Sync app from GitHub Actions (feature/project-state-security-privacy-review)

Browse files
README.md CHANGED
@@ -206,7 +206,7 @@ The HF administrator-owned storage mode is intended for confidential projects ru
206
 
207
  The Space stores the administrator storage credential as a protected secret. Validators log in with their own Hugging Face identity and are invited or assigned inside the app; they do not need repository or Bucket permissions, organization membership, or the administrator token. Resource operations are performed server-side only after the app confirms the user's project role.
208
 
209
- When this mode is enabled it takes precedence over any existing Supabase settings: project ACL/invites are restored from private `*_state` repositories and validations are read and written in the project's private Bucket.
210
 
211
  Recommended administrator-owned Space settings:
212
 
 
206
 
207
  The Space stores the administrator storage credential as a protected secret. Validators log in with their own Hugging Face identity and are invited or assigned inside the app; they do not need repository or Bucket permissions, organization membership, or the administrator token. Resource operations are performed server-side only after the app confirms the user's project role.
208
 
209
+ When this mode is enabled it takes precedence over any existing Supabase settings: project ACL/invites are restored from private `*_state` repositories and validations are read and written in the project's private Bucket. Configuring the dedicated `BIRDNET_HF_STORAGE_TOKEN` Secret also enables this mode automatically, preventing a configured private-storage credential from remaining unused behind a legacy backend.
210
 
211
  Recommended administrator-owned Space settings:
212
 
docs/TEMP_HF_ADMIN_OWNED_PRIVATE_STORAGE_DELIVERY_PLAN.md CHANGED
@@ -43,7 +43,7 @@ For public distribution to independent administrators, this model is not suffici
43
 
44
  ## Implemented Behavior
45
 
46
- 1. `BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED=true` activates this mode.
47
  2. `BIRDNET_HF_STORAGE_TOKEN` is read server-side and never saved in project records or shown in the UI. `HF_TOKEN` remains a compatibility fallback.
48
  3. New projects require a private dataset in the personal namespace belonging to the configured storage credential.
49
  4. New projects automatically initialize a private validation Bucket and private companion `_state` repository.
 
43
 
44
  ## Implemented Behavior
45
 
46
+ 1. `BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED=true` activates this mode; configuring `BIRDNET_HF_STORAGE_TOKEN` also activates it automatically.
47
  2. `BIRDNET_HF_STORAGE_TOKEN` is read server-side and never saved in project records or shown in the UI. `HF_TOKEN` remains a compatibility fallback.
48
  3. New projects require a private dataset in the personal namespace belonging to the configured storage credential.
49
  4. New projects automatically initialize a private validation Bucket and private companion `_state` repository.
src/config/runtime_config.py CHANGED
@@ -113,7 +113,11 @@ class RuntimeConfig:
113
  raw_hf_bucket_validations = (os.getenv("BIRDNET_HF_BUCKET_VALIDATIONS_ENABLED") or "").strip().lower()
114
  hf_bucket_validations_enabled = raw_hf_bucket_validations in {"1", "true", "yes", "on"}
115
  raw_hf_admin_storage_mode = (os.getenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED") or "").strip().lower()
116
- hf_admin_storage_mode_enabled = raw_hf_admin_storage_mode in {"1", "true", "yes", "on"}
 
 
 
 
117
  raw_hf_project_state_repos = (os.getenv("BIRDNET_HF_PROJECT_STATE_REPOS") or "").strip()
118
  hf_project_state_repos = tuple(
119
  repo.strip()
 
113
  raw_hf_bucket_validations = (os.getenv("BIRDNET_HF_BUCKET_VALIDATIONS_ENABLED") or "").strip().lower()
114
  hf_bucket_validations_enabled = raw_hf_bucket_validations in {"1", "true", "yes", "on"}
115
  raw_hf_admin_storage_mode = (os.getenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED") or "").strip().lower()
116
+ has_dedicated_hf_storage_secret = bool((os.getenv("BIRDNET_HF_STORAGE_TOKEN") or "").strip())
117
+ hf_admin_storage_mode_enabled = (
118
+ raw_hf_admin_storage_mode in {"1", "true", "yes", "on"}
119
+ or has_dedicated_hf_storage_secret
120
+ )
121
  raw_hf_project_state_repos = (os.getenv("BIRDNET_HF_PROJECT_STATE_REPOS") or "").strip()
122
  hf_project_state_repos = tuple(
123
  repo.strip()
src/ui/app_factory.py CHANGED
@@ -1969,14 +1969,14 @@ def _audio_fetch_error_message(dataset_repo: str, exc: Exception, hf_token: str
1969
  access_markers = ("401", "403", "404", "repository not found", "unauthorized", "forbidden")
1970
  if any(marker in lower_message for marker in access_markers):
1971
  identity_hint = (
1972
- "The signed-in Hugging Face account does not have read access"
1973
  if (hf_token or "").strip()
1974
- else "No personal Hugging Face token is active for this session"
1975
  )
1976
  return (
1977
  f"Cannot read audio dataset '{dataset_repo}'. {identity_hint}. "
1978
- "For collaborative validation, make the audio dataset public or gated and grant this Hugging Face "
1979
- "account access, then sign in with that account's token."
1980
  )
1981
  return f"Failed to load audio: {raw_message}"
1982
 
 
1969
  access_markers = ("401", "403", "404", "repository not found", "unauthorized", "forbidden")
1970
  if any(marker in lower_message for marker in access_markers):
1971
  identity_hint = (
1972
+ "The credential used by the app does not have read access"
1973
  if (hf_token or "").strip()
1974
+ else "No credential with private dataset read access was provided"
1975
  )
1976
  return (
1977
  f"Cannot read audio dataset '{dataset_repo}'. {identity_hint}. "
1978
+ "For administrator-owned private storage, confirm `BIRDNET_HF_STORAGE_TOKEN` is configured in the "
1979
+ "Space and belongs to the personal account that owns this private dataset."
1980
  )
1981
  return f"Failed to load audio: {raw_message}"
1982
 
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -385,7 +385,7 @@ def test_fetch_selected_audio_validates_repo() -> None:
385
  assert "Provide dataset repo" in status
386
 
387
 
388
- def test_fetch_selected_audio_explains_private_dataset_access_for_authenticated_user() -> None:
389
  path, cache_key, status = _fetch_selected_audio(
390
  audio_service=InaccessibleAudioService(),
391
  dataset_repo="owner/private-audio",
@@ -397,11 +397,11 @@ def test_fetch_selected_audio_explains_private_dataset_access_for_authenticated_
397
 
398
  assert path is None
399
  assert cache_key == ""
400
- assert "signed-in Hugging Face account does not have read access" in status
401
- assert "public or gated" in status
402
 
403
 
404
- def test_fetch_selected_audio_explains_missing_user_token_for_private_dataset() -> None:
405
  _, _, status = _fetch_selected_audio(
406
  audio_service=InaccessibleAudioService(),
407
  dataset_repo="owner/private-audio",
@@ -410,7 +410,7 @@ def test_fetch_selected_audio_explains_missing_user_token_for_private_dataset()
410
  previous_cache_key="old",
411
  )
412
 
413
- assert "No personal Hugging Face token is active" in status
414
 
415
 
416
  def test_cleanup_selected_audio() -> None:
 
385
  assert "Provide dataset repo" in status
386
 
387
 
388
+ def test_fetch_selected_audio_explains_private_dataset_access_uses_backend_credential() -> None:
389
  path, cache_key, status = _fetch_selected_audio(
390
  audio_service=InaccessibleAudioService(),
391
  dataset_repo="owner/private-audio",
 
397
 
398
  assert path is None
399
  assert cache_key == ""
400
+ assert "credential used by the app does not have read access" in status
401
+ assert "BIRDNET_HF_STORAGE_TOKEN" in status
402
 
403
 
404
+ def test_fetch_selected_audio_explains_missing_private_dataset_credential() -> None:
405
  _, _, status = _fetch_selected_audio(
406
  audio_service=InaccessibleAudioService(),
407
  dataset_repo="owner/private-audio",
 
410
  previous_cache_key="old",
411
  )
412
 
413
+ assert "No credential with private dataset read access was provided" in status
414
 
415
 
416
  def test_cleanup_selected_audio() -> None:
tests/unit/test_runtime_config.py CHANGED
@@ -43,7 +43,17 @@ def test_runtime_config_reads_hf_admin_storage_mode_flag(monkeypatch) -> None:
43
 
44
  def test_runtime_config_disables_hf_admin_storage_mode_by_default(monkeypatch) -> None: # noqa: ANN001
45
  monkeypatch.delenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED", raising=False)
 
46
 
47
  config = RuntimeConfig.from_env()
48
 
49
  assert config.hf_admin_storage_mode_enabled is False
 
 
 
 
 
 
 
 
 
 
43
 
44
  def test_runtime_config_disables_hf_admin_storage_mode_by_default(monkeypatch) -> None: # noqa: ANN001
45
  monkeypatch.delenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED", raising=False)
46
+ monkeypatch.delenv("BIRDNET_HF_STORAGE_TOKEN", raising=False)
47
 
48
  config = RuntimeConfig.from_env()
49
 
50
  assert config.hf_admin_storage_mode_enabled is False
51
+
52
+
53
+ def test_runtime_config_enables_hf_admin_storage_mode_when_dedicated_secret_exists(monkeypatch) -> None: # noqa: ANN001
54
+ monkeypatch.delenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED", raising=False)
55
+ monkeypatch.setenv("BIRDNET_HF_STORAGE_TOKEN", "hf_storage_secret")
56
+
57
+ config = RuntimeConfig.from_env()
58
+
59
+ assert config.hf_admin_storage_mode_enabled is True