Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ secrets.yaml
official.csv
fact.png
jupyterhub/.env-dev
/migration-output/
/migration-checkpoint.json
**/migration-checkpoint.json
**/user-api-keys.json
**/generated-owner-passwords.json
5 changes: 4 additions & 1 deletion backend/app/routers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ async def get_dataset_folders(
public: bool = Depends(CheckStatus("PUBLIC")),
skip: int = 0,
limit: int = 10,
admin=Depends(get_admin),
enable_admin: bool = False,
admin_mode: bool = Depends(get_admin_mode),
allow: bool = Depends(Authorization("viewer")),
):
if (
Expand All @@ -716,7 +719,7 @@ async def get_dataset_folders(
)
)
) is not None:
if authenticated or public:
if authenticated or public or (admin and admin_mode):
query = [
FolderDBViewList.dataset_id == PydanticObjectId(dataset_id),
]
Expand Down
9 changes: 8 additions & 1 deletion backend/app/search/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ class IndexSettings:
"folder_id": {"type": "text", "index": False},
"bytes": {"type": "long"},
# metadata fields
# Use "flattened" rather than "object": arbitrary user/extractor
# metadata has unpredictable value types for the same key across
# documents (e.g. one doc has a numeric "Number pixels", another has
# the string "2.53266M"). A dynamic "object" mapping infers a type
# from the first value it sees per key and then rejects conflicting
# documents with mapper_parsing_exception. "flattened" indexes every
# leaf as a keyword under a single field, so no type conflicts occur.
"metadata": {
"type": "object",
"type": "flattened",
},
}
}
Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ services:
- "traefik.http.routers.swagger.rule=PathPrefix(`/docs`)"
- "traefik.http.services.backend.loadbalancer.server.port=80"
- "traefik.http.routers.backend.priority=5"
- "traefik.http.middlewares.limit.buffering.maxRequestBodyBytes=0" # 0 = unlimited
- "traefik.http.routers.backend.middlewares=limit"

frontend:
image: "clowder/clowder2-frontend:2.0.0-beta.4"
Expand Down Expand Up @@ -130,10 +132,12 @@ services:
- rabbitmq

mongo:
image: mongo:5.0
image: mongo:6
restart: unless-stopped
networks:
- clowder2
ports:
- "127.0.0.1:27017:27017" # host-only access for the migration tool
volumes:
- mongo:/data/db

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"elasticsearch==8.7.0",
"rocrate==0.7.0",
"itsdangerous==2.1.2",
"httpx==0.24.0",
"setuptools",
"boto3>=1.37.8",
]
Expand All @@ -40,7 +41,6 @@ dev = [
"ruff>=0.8.0",
"pre-commit>=4.0.1",
"shellcheck-py>=0.10.0.1",
"httpx==0.24.0",
]
docs = [
"mkdocs-material"
Expand Down
77 changes: 77 additions & 0 deletions scripts/v1_to_v2_migration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Clowder v1 to v2 migration

Move datasets, files, folders, metadata, tags, users, and spaces from a
Clowder v1 instance into Clowder v2.

```bash
python -m scripts.v1_to_v2_migration api
python -m scripts.v1_to_v2_migration api --limit 5
python -m scripts.v1_to_v2_migration api-inventory --print
python -m scripts.v1_to_v2_migration cleanup-keys
python -m scripts.v1_to_v2_migration mongo-bridge
```

Set `MIGRATION_DRY_RUN=1` to walk the source without writing to v2.

## Environment

API path:

| Variable | Purpose |
|---|---|
| `CLOWDER1_BASE_URL` | v1 API base URL |
| `CLOWDER1_API_KEY` | v1 admin API key (`superAdmin` is sent on every v1 call) |
| `CLOWDER1_USERNAME` / `CLOWDER1_PASSWORD` | optional v1 Basic auth |
| `CLOWDER2_BASE_URL` | v2 backend API (`…/api/v2`, not the frontend) |
| `CLOWDER2_API_KEY` | v2 admin API key |
| `CLOWDER2_ADMIN_EMAIL` / `CLOWDER2_ADMIN_PASSWORD` | used when no v2 admin API key is set |
| `CLOWDER2_OWNER_PASSWORDS` | optional JSON map of `{email: password}` for existing v2 users |
| `CLOWDER2_LICENSE_ID` | optional; otherwise the first standard license is used |
| `MIGRATION_CHECKPOINT` | default `migration-checkpoint.json` |
| `MIGRATION_OUTPUT_DIR` | default `migration-output` |

Mongo path additionally needs `CLOWDER1_MONGODB_URL`, `CLOWDER2_MONGODB_URL`,
MinIO settings, and optionally Elasticsearch.

## Credential files

The migrator writes secrets under `MIGRATION_OUTPUT_DIR`:

- `generated-owner-passwords.json` — plaintext passwords for users created during migration
- `user-api-keys.json` — raw v2 API keys named `migration` (present only while a run is in progress)

Those files are created with mode `0600`. Gitignore covers the default output
directory plus `**/generated-owner-passwords.json`, `**/user-api-keys.json`,
and `**/migration-checkpoint.json` so a custom output path is less likely to
be committed.

Treat the output directory as sensitive:

1. Restrict who can read the host (and any volume the directory lives on).
2. Do not copy credential files into tickets, CI logs, or shared drives.
3. After a successful migration, delete `generated-owner-passwords.json` once
users have rotated passwords (or Keycloak accounts have been provisioned).
4. The API path revokes `migration` keys at the end of each run. If a run
crashes, run `cleanup-keys` so leftover keys do not remain valid.

`api-inventory --print` emits only dataset ids and a count, not full v1
dataset objects.

## API path behavior that affects security

- Per-owner v2 API keys expire after 7 days and are deleted when the run
finishes. They are created only for users who own a dataset being migrated.
- A dataset is **not** migrated under the admin account if the owner's key
cannot be created. Fix that owner's password (via `CLOWDER2_OWNER_PASSWORDS`
or the generated file) and resume.
- The v1 admin API key used here can list and download all v1 data. Store it
in the environment, not in source, and rotate it after migration.

## Mongo path passwords

Mongo-bridge users get a unique random local password (never a shared default)
written to `generated-owner-passwords.json`. Login in Clowder v2 is Keycloak
backed, and these users are inserted with `keycloak_id` unset, so they cannot
sign in until an operator provisions them in Keycloak and rotates credentials.
Do not hand out the generated file as a long-term password store; delete it
after accounts are provisioned.
1 change: 1 addition & 0 deletions scripts/v1_to_v2_migration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Migration helpers for moving data from Clowder v1 to Clowder v2."""
7 changes: 7 additions & 0 deletions scripts/v1_to_v2_migration/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Run the Clowder v1 to v2 migration CLI as a module."""

from .cli import main


if __name__ == "__main__":
raise SystemExit(main())
Loading
Loading