From 77f915b7ef3eef3737bf4d83b6b0c4d7b448401f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Wed, 18 Jun 2025 13:02:36 +0200 Subject: [PATCH 1/7] Add an example of ls-file-collection In the page about datalad-based deposition to the catalog, the solution based on datalad status is replaced by a more "modern" one which uses DataLad-next's ls-file collection. A script is included directly, as a Python code block. The catppuccin-latte color scheme is used because it fits pretty nicely with the website's light theme -- much more so than Hugo's default monokai (dark). It would appear that the code block style only kicks in when the language is specified. See: https://gohugo.io/quick-reference/syntax-highlighting-styles/ Closes #4 --- content/catalog/datalad-based-deposition.md | 97 ++++++++++++++++----- 1 file changed, 77 insertions(+), 20 deletions(-) diff --git a/content/catalog/datalad-based-deposition.md b/content/catalog/datalad-based-deposition.md index 6126477..545b09b 100644 --- a/content/catalog/datalad-based-deposition.md +++ b/content/catalog/datalad-based-deposition.md @@ -113,31 +113,88 @@ steps 1 through 3. ### 2. \[Optional\] Create the `files` table -The [files -table]({{% relref "register-data#table-files" %}}) is -an optional addition to the tabby record and lists one or more files -that form part of the DataLad dataset. Such a file listing can be easily -generated based on the output of `datalad status` - see the -[status2tabby.py](https://github.com/sfb1451/tabby-utils/blob/main/status2tabby.py) -script, which uses the `datalad-next` extension, for an example -implementation that you can also use directly: +The [files table]({{% relref "register-data#table-files" %}}) is an +optional addition to the tabby record and lists one or more files that +form part of the DataLad dataset. Such a file listing can be easily +generated based on the output of +[ls_file_collection](https://docs.datalad.org/projects/next/en/latest/generated/datalad.api.ls_file_collection.html) +provided by Datalad-next. Below, we present an example implementation, +which you can also use directly. -``` None -usage: status2tabby.py [-h] dataset outfile +Note that files which are present will be checksummed; for annexed +files which are not present locally the checksum will be taken from +the annex key. This assumes that DataLad's default backend (MD5E) is +used; adjust the code for different checksums if necessary. -positional arguments: - dataset Dataset for which files will be listed - outfile Name of tsv file to write -options: - -h, --help show this help message and exit +```python {lineNos=true, style=catppuccin-latte} +"""Generate a TSV file listing the files in a dataset + +Usage: + + python this_file.py dataset outfile + +""" + +from argparse import ArgumentParser +from csv import DictWriter +from pathlib import Path +import re +from datalad.api import ls_file_collection + + +def match_md5(key): + """Report MD5 checksum contained in annex key + + Assumes MD5E backend (DataLad's default). + https://git-annex.branchable.com/internals/key_format/ + + """ + m = re.match(r"MD5E-s\d+--([a-f0-9]{32})", key) + return m.group(1) if m is not None else None + + +def transform_result(res): + """Transform results to get required information + + Processes the outputs of ls_file_collection to get relative path, + size in bytes, and md5 checksum. For annex keys which are not + present, the checksum will be taken from the annex key, if + possible. Keys match the sfb1451 tabby specification. + + """ + path = res["item"].relative_to(res["collection"]).as_posix() + size = res["annexsize"] if res["type"] == "annexed file" else res["size"] + checksum = res.get("hash-md5") + + if checksum is None and res["type"] == "annexed file": + checksum = match_md5(res["annexkey"]) + + return {"path[POSIX]": path, "size[bytes]": size, "checksum[md5]": checksum} + + +parser = ArgumentParser() +parser.add_argument("dataset", type=Path, help="Dataset for which files will be listed") +parser.add_argument("outfile", type=Path, help="Name of the tsv file to write") +args = parser.parse_args() + +fc = ls_file_collection( + "annexworktree", + args.dataset, + hash="md5", + result_renderer="disabled", + result_xfm=transform_result, + return_type="generator", +) + +with args.outfile.open("w", encoding="utf-8", newline="") as tsvfile: + fieldnames = ["path[POSIX]", "size[bytes]", "checksum[md5]"] + writer = DictWriter(tsvfile, delimiter="\t", fieldnames=fieldnames) + writer.writeheader() + for row in fc: + writer.writerow(row) ``` -> [!INFO] -> Another (more performant) alternative is to use the -> [ls_file_collection](http://docs.datalad.org/projects/next/en/latest/generated/datalad.api.ls_file_collection.html) -> function from DataLad-next, and transform its output. - ### 3. Publish the metadata For manual deposition, copy and send all tabby records to the INF -- 2.54.1 From 51980b122be9b66cc7815a2cc5245f913566cf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Wed, 18 Jun 2025 19:27:42 +0200 Subject: [PATCH 2/7] Add a walkthrough for forgejo with encryption --- content/walkthroughs/forgejo-encryption.md | 191 +++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 content/walkthroughs/forgejo-encryption.md diff --git a/content/walkthroughs/forgejo-encryption.md b/content/walkthroughs/forgejo-encryption.md new file mode 100644 index 0000000..f5913de --- /dev/null +++ b/content/walkthroughs/forgejo-encryption.md @@ -0,0 +1,191 @@ ++++ +date = '2025-06-17T18:45:00+02:00' +draft = false +title = 'Forgejo with encryption' ++++ + +This walkthrough demonstrates how to encrypt annexed file content in Forgejo, +a bare Git repository, or another Git hosting platform with annex support. + +## Introduction + +When storing DataLad datasets on third party infrastructure, Git +remotes and git-annex special remotes are often configured pointing to +different services. However, some repository hosting services +(e.g. G-node GIN, or some instances of Forgejo), as well as bare Git +repositories[^1] on systems with git-annex installed, support storing +annex objects alongside the Git repository, which makes them very +convenient in terms of configuration and usage. Throughout the +article, we will refer to remotes supporting both Git and annex +content as "git+annex". For background, see DataLad handbook's chapter +[Beyond shared +infrastructure](https://handbook.datalad.org/en/latest/basics/101-138-sharethirdparty.html). + +Some of the SFB1451 datasets may require using data encryption at rest +to guarantee data privacy or access control. Git-annex [supports +encryption](https://git-annex.branchable.com/encryption/) and it can +be very easy to set up. However, encryption is configured for *special +remotes* and as such it would not apply to such "git+annex" remotes[^2]. + +This has been addressed in [git-annex v.10.20250520](https://git-annex.branchable.com/news/version_10.20250520/) +by the addition of the [mask special remote](https://git-annex.branchable.com/special_remotes/mask/). + +With the mask special remote, setting up encrypted storage for +git+annex comes down to the following steps: + +- set up a Git remote, +- set up a mask special remote with encryption enabled, +- make sure that annexed contents are pushed only to the latter. + +The model use case for this workflow is publishing datasets on Forgejo +instances with git-annex support. [Forgejo](https://forgejo.org/) is +a "self-hosted lightweight software forge", which can be used to set +up and maintain a platform similar to GitHub or GitLab. +[Forgejo-aneksajo](https://codeberg.org/forgejo-aneksajo/forgejo-aneksajo) +is a lightly modified version of Forgejo which adds git-annex support. +While no public instances are readily available, and the SFB1451 does +not (currently) maintain its own instance, it is nevertheless very +relevant for the SFB1451 community because Forgejo-aneksajo can be +deployed by individual groups (see [Collaborative infrastructure for a +lab: Forgejo](https://blog.datalad.org/posts/lab-infra-forgejo/) for +more background information). + +## Prerequisites + +- git-annex v.10.20250520 or newer +- gpg, and a generated private/public key +- DataLad-next (optional but highly recommended) + +## Walkthrough + +### Initial set-up and publishing + +Publishing a dataset requires having a dataset in the first place. +In this example we create a dataset with one file in Git (README) and one file annexed (an image). + +``` +datalad create foo +cd foo +echo "Hello world" > README +datalad download https://images.pexels.com/photos/21533358/pexels-photo-21533358.jpeg +datalad save --to-git -m "Add a readme" README +datalad save -m "Add a photo of a penguin" pexels-photo-21533358.jpeg +``` + +Add a Git remote pointing to a valid address -- for example, an empty Forgejo-aneksajo repository, +or (for easier testing) a local bare git repository. + +{{< tabs >}} +{{% tab title="forgejo" %}} +``` +git remote add origin https://hub.example.com/user/dataset.git +``` +{{% /tab %}} +{{% tab title="local" %}} +``` +git init --bare /tmp/foo.git +git remote add origin /tmp/foo.git +``` +{{% /tab %}} +{{< /tabs >}} + +Push (only the Git part -- we do not want to send unencrypted data) +to ensure that the remote repository is initialized with annex UUID. + +``` +datalad push --to origin --data nothing +``` + +At this point, the remote should be recognized by Git-annex, and have an annex UUID. +You can check this with `git annex info origin`. +If the UUID is present, the mask remote can be set up[^3]. +Replace the value of the `keyid` parameter with the ID (either e-mail or the numeric key ID) of your GPG key. + +``` +git annex initremote encrypted-origin type=mask remote=origin encryption=hybrid keyid=me@example.com +``` + +With the remote configuration, the annexed content and the Git content can be pushed *separately* to these remotes. + +``` +datalad push --to encrypted-origin +datalad push --data nothing --to origin +``` + +That's it! The repository is a regular repository, but the annexed content can not be accessed. +The web interface will show the file tree, but report that the files are unavailable. +Cloning the repository is possible, but getting the annexed content requires possession of a private GPG key +for which the encryption has been enabled[^4]. + +### Automating + +Remembering to push to the mask remote first, and to use `--data nothing` with the unencrypted remote +can be tedious and error prone. +However, both of these behaviors can be automated. +Git-annex wanted mechanism can be used to state that no data are wanted by the unencrypted remote. +DataLad's publication dependency can be used to say that the encrypted remote should be pushed automatically +when a push to origin is requested. + +``` +git annex wanted origin "exclude=*" +datalad siblings configure -s origin --publish-depends encrypted-origin +``` + +With this, it is sufficient to `datalad push --to origin`[^5]. + +This can be taken even further. +For example, only *some* annexed files can be pushed encrypted. +It is advisable to configure the encrypted and regular remotes with opposite settings to avoid duplicating the storage. +For example, consider a situation where raw images are stored encrypted, but jpegs are not: + +``` +git annex wanted origin include=*jpeg +git annex wanted encrypted-origin include=*arw +``` + +## Looking under the hood + +Although we used Forgejo as an example (due to its potential relevance), +the walkthrough is valid for any "git+annex" repository. Using a local +bare Git repository is a good way to "look under the hood" and see that +the annex keys in the bare repository are indeed stored encrypted, +with HMAC hashing of the filenames. + +The example below shows the annex objects directory with three files, +two encrypted and one unencrypted. + +``` +❱ tree ../foo.git/annex/objects +../foo.git/annex/objects +├── 39e +│   └── bcf +│   └── GPGHMACSHA1--2c4b73cff92c9d186065f338551f8c5c8ec94b5b +│   └── GPGHMACSHA1--2c4b73cff92c9d186065f338551f8c5c8ec94b5b +├── 727 +│   └── f52 +│   └── GPGHMACSHA1--fbcb8f7931cb90c8fa9930368bfae671f36fec6b +│   └── GPGHMACSHA1--fbcb8f7931cb90c8fa9930368bfae671f36fec6b +└── a45 + └── ab5 + └── SHA256E-s2273030--fbeaece1f05264c39781adeac159ba33fbc1f4d2aea273106600bc4e3e3aa6c7.jpeg + └── SHA256E-s2273030--fbeaece1f05264c39781adeac159ba33fbc1f4d2aea273106600bc4e3e3aa6c7.jpeg +``` + +In Forgejo, the layout would be identical. + + +[^1]: Bare Git repository is a repository which does not contain a working directory. + It can be cloned from and pushed to. + See [Git on the server](https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server) in the Pro Git book. +[^2]: Git annex does have a [git special remote](https://git-annex.branchable.com/special_remotes/git/), + but its purpose is to record a Git remote URL in the repository (normally, Git remote URL is a local configuration) + and optionally autoenable it. It does not provide a way to set up encryption. +[^3]: In Forgejo-aneksajo versions prior to 11.0-0-git-annex2, the UUID was not always assigned immediately; + see discussion in [forgejo-aneksajo/issues/22](https://codeberg.org/forgejo-aneksajo/forgejo-aneksajo/issues/22). + A workaround was to perform any action (including viewing the page) in the web interface. + If the UUID is empty, visit the repository page in a browser (or refresh it) and try `git annex info origin` again. +[^4]: In the hybrid encryption scheme, data is encrypted using a symmetric cipher, + and that cipher is asymmetrically encrypted (to selected GPG keys) and stored in the Git repository. + This means that new recipient keys can be added without having to re-encrypt the data. + See the documentation for [git annex encryption](https://git-annex.branchable.com/encryption/). +[^5]: or `git annex push` which by default pushes to all available remotes -- 2.54.1 From 766f3ae277db93ffd124a949fe092f1a5d8cbb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Thu, 24 Jul 2025 12:19:34 +0200 Subject: [PATCH 3/7] Reorder pages in the Z03 chapter It makes more sense to place the general introduction first. --- content/z03/digital-signatures/_index.md | 2 +- content/z03/encrypted-workflow.md | 2 +- content/z03/local-copies.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/z03/digital-signatures/_index.md b/content/z03/digital-signatures/_index.md index f2880dc..f57f207 100644 --- a/content/z03/digital-signatures/_index.md +++ b/content/z03/digital-signatures/_index.md @@ -2,7 +2,7 @@ date = '2025-02-12T18:01:06+01:00' draft = false title = 'Digital signatures' -weight = 1 +weight = 2 +++ The data entry form supports the submission of a digital signature for diff --git a/content/z03/encrypted-workflow.md b/content/z03/encrypted-workflow.md index e2e9b60..f4416f2 100644 --- a/content/z03/encrypted-workflow.md +++ b/content/z03/encrypted-workflow.md @@ -2,7 +2,7 @@ date = '2025-02-12T18:01:59+01:00' draft = false title = 'Encrypted workflow' -weight = 3 +weight = 1 +++ We are using DataLad to track and move around the motor assessment diff --git a/content/z03/local-copies.md b/content/z03/local-copies.md index 9a58820..4eb8800 100644 --- a/content/z03/local-copies.md +++ b/content/z03/local-copies.md @@ -2,7 +2,7 @@ date = '2025-02-12T18:01:47+01:00' draft = false title = 'Local copies' -weight = 2 +weight = 3 +++ The contents of all form fields (except signature) can be saved -- 2.54.1 From 0d04ed56da55724b9f9d4bbefa9c662fcf296d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Thu, 24 Jul 2025 13:46:46 +0200 Subject: [PATCH 4/7] Add detailed instructions for Z03 data access This uses pre-written iffmd document which was previously shared with Z03 via e-mail. --- content/z03/access-data.md | 269 +++++++++++++++++++++++++++++++++++++ 1 file changed, 269 insertions(+) create mode 100644 content/z03/access-data.md diff --git a/content/z03/access-data.md b/content/z03/access-data.md new file mode 100644 index 0000000..c300e59 --- /dev/null +++ b/content/z03/access-data.md @@ -0,0 +1,269 @@ ++++ +date = '2025-02-12T18:01:59+01:00' +draft = false +title = 'Accessing motor assesment data collection on Windows' +weight = 4 ++++ + +This note will explain in detail how to set-up your local copy of the aggregated motor assesment data, and help deal with potential configuration-dependent obstacles. + +Overview of the encrypted workflow and prerequisites are explained in the [encrypted workflow](z3-encrypted-workflow/) page. It is highly recommended that you read it first. + +The note assumes that you are working on Windows and using cmd shell. It also assumes that you have access to the shared Sciebo folder, and the data is being encrypted to your GPG key. + +## Before you begin + +### GPG + +If you install Git (which is a requirement for using DataLad), it comes with its own `gpg` executable. If you install gpg4win (which is the solution recommended for digital signatures in our docs on [Input signing](digital-signatures) it naturally comes with a separate `gpg` executable. This means it is possible to have two GPG programs... which store their data (e.g. keys) in completely different locations on your computer. + +What's more, in this case, git-annex operations will default to using the one which came with Git, while user operations (be it via Kleopatra GUI or the command line) will more than likely[^1] use the one which came with gpg4win. This can become confusing. Fortunately, git-annex behaviour is configurable. The goal here is to have both the user and git-annex interact with the same `gpg` executable. + +If you do not have gpg4win: you probably do not need to do anything. + +If you have gpg4win and used it to generate (or import) your private key, you need to configure Git and git-annex to use this one. + +First, find out the path to the gpg executable. The path components would tell you whether it came with Git or gpg4win - the latter is more likely. + +``` +where gpg +``` + +Then (if it is gpg4win) tell Git to use this one. Git-annex obeys the same setting. Replace `PATH/TO/GPG` with the path reported by the previous command. + +``` +git config gpg.program PATH/TO/GPG +``` + + +### GPG-agent + +Operations which use your secret key (like downloading encrypted data with git-annex or listing your secret keys with `gpg --list-secret-keys`) require interactions with a program called `gpg-agent` [^2]. Normally, `gpg-agent` should be running in the background, and there is nothing to do. + +If you notice gpg-agent is not running (e.g. `get` fails with an error message which says that gpg-agent is not running, or you can not list your secret keys), you can start the gpg-agent with: + +``` +gpg-connect-agent reloadagent /bye +``` + +### Sciebo token (app password) + +Instead of using your pasword (the one you use to log in to Sciebo), it is recommended to generate a token for use with DataLad & git-annex. Tokens are like passwords, but they are generated by the website rather than created by the user. A token can be revoked when it is no longer used or there is a risk that it got exposed. + +To generate a token: + +- log in to Sciebo +- click your username on the upper right and go to settings +- select Security +- scroll down to App passwords / tokens +- enter a token name and click "Create new app passcode" +- copy (and store safely) the username and token + +The token name can be anything - it is only for your information, and will be displayed in the list of tokens, with the date of last use and an option to delete (revoke) the token. + + +### Save credentials for DataLad in advance + +We have seen that DataLad's prompt for password can behave weirdly in cmd, in that it does not show any indication of characters being typed or pasted. To reduce errors, we recommend saving a DataLad credential [^3] upfront, and verifying that it is saved correctly. + +To save the credential, use the `datalad credentials set` command, replacing the placeholders marked with angle brackets (`< >`): + +``` +datalad credentials set type=user_password user= realm= +``` + +e.g. + +``` +datalad credentials set sciebo type=user_password user=m.szczepanik@fz-juelich.de realm=https://fz-juelich.sciebo.de/sciebo +``` + +(note: the realm needs to end with `/sciebo`). + +You will be prompted for the password. Type or paste and hit enter. You will be prompted to enter the password again. + +To see what was saved, run the following (with a name given in the previous step): + +``` +datalad -f json_pp credentials get sciebo +``` + +The output will look like this. +``` +{ + "action": "credentials", + "cred_realm": "https://fz-juelich.sciebo.de/sciebo", + "cred_secret": "[YOUR TOKEN SHOULD BE HERE]", + "cred_type": "user_password", + "cred_user": "m.szczepanik@fz-juelich.de", + "name": "sciebo", + "status": "ok" +} +``` + +If something seems wrong, repeat the `datalad credentials set` step, adjusting as necessary. + +You can use `datalad credentials get` whenever you need to remind yourself of the token. + +## WebDAV URLs + +When using DataLad & git-annex, you will connect to Sciebo through a protocol called WebDAV. For this, you need to know your WebDAV URL, which is slightly different than the URL you use to visit Sciebo's web interface. + +### Base WebDAV URL + +To find your WebDAV address: + +- go to Sciebo (file view) +- click ⚙️ Settings in the lower left corner +- a "drawer" will slide up, showing your WebDAV URL + +The WebDAV URL will look like this: + +``` +https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/ +``` + +### WebDAV URLs to folders + +The URL above is pointing to your home directory. To access a specific folder, you will need to add some path components manually. + +Most likely, a folder named `Z03` will be shared with you. It will contain some folders; two which are relevant are: `motor_export_repo`, and `motor_export_data`. + +The folder path relative to your home directory will depend on whether you move the shared folder or not. Assuming that `Z03` is in your home directory on Sciebo, the relative paths will be `Z03/motor_export_repo` and `Z03/motor_export_data`, respectively. + +For use with DataLad, you will need to put the base URL and the relative paths together. Using the examples below: + +- repo URL (for clone): `https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Z03/motor_export_repo` +- data URL (for initremote) `https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Z03/motor_export_data` + + +## Initial setup + +### Clone the dataset + +The clone URL will be composed of two parts: + +- constant part (tells Datalad what we are cloning): `datalad-annex::?type=webdav&encryption=none&exporttree=no&url=` +- your repo URL (see above) + +To clone, substitute `` with your repo URL and `` with the target folder (do not include the angle brackets `<>`): +``` +datalad clone "datalad-annex::?type=webdav&encryption=none&exporttree=no&url=" motor_export +``` + +e.g. +``` +datalad clone "datalad-annex::?type=webdav&encryption=none&exporttree=no&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Z03/motor_export_repo" motor_export +``` + +Then change your working directory to go into the dataset: +``` +cd motor_export +``` + +Note: it is important to use double quotes (`""`) as cmd distinguishes between single and double quotes. + +Note: do not worry about the constant part containing `encryption=none`. The repository ("Git part") of the dataset is stored unencrypted, but the file contents ("annex part") are stored encrypted in Sciebo. This step deals only with the repository. + +### Initialize sciebo remote + +Git-annex special remotes represent methods of accessing data, and special remote configuration contains things like access URL or encryption type to be used. + +One weaknes of the Sciebo setup is that WebDAV URLs contain user names and instance names, so will be different for each user (even though the shared folder is, in principle, the same). The dataset already has a sciebo remote, but it points to FZJ's sciebo and Michał Szczepanik's user account. There is no easy way to reconfigure it, other than each user initializing a new remote pointing to *their* sciebo URL. + +The trick is to initialize a special remote, and mark it *same as* the one above (meaning that we expect to reach exactly the same place, just through different means). + +This is by far the most involved part of the setup. + +#### Let git-annex know your token + +DataLad does not have a relevant interface, so we need to run this operation directly with `git-annex`. This means DataLad would not supply the credentials which we stored in the previous step, and we need to provide them via environment variables. Set the environment variables with the `set` command (substitute your Sciebo username and token): + +``` +set WEBDAV_USERNAME=m.szczepanik@fz-juelich.de +set WEBDAV_PASSWORD=XXXXX-XXXXX-XXXXX-XXXXX +``` + +Important: do not put the password in quotes (`""`), because `set` command treats them literally. + +Tip: If you don't have your token, retrieve it using DataLad: `datalad -f json_pp credentials get sciebo`. + +Tip: you can check value of an environment variable with `echo`, e.g. `echo %WEBDAV_USERNAME%`. + +#### (optional): check available remotes +Each special remote has its own ID and assigned name, which can be used interchangeably with git-annex commands. To list remotes known to the dataset, run: + +``` +git annex info +``` + +Pending future changes, the remote we want to enable is going to be named sciebo, i.e. it will be this one: +``` +325dd4e6-e71b-4512-bce6-0eb574b6ed15 -- sciebo-storage +``` + +#### Initialize your own private remote + +As explained above, you will need to initialize a special remote for yourself, and mark it "same as" the one above. + +Here's the command broken up into multiple lines with a caret (`^`) for readability: + +``` +git annex initremote my-sciebo-data^ + --private^ + --sameas sciebo-storage^ + type=webdav^ + url="https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Projects/Z03/motor_export_data" +``` + +And here it is in one line + +``` +git annex initremote my-sciebo-data --private --sameas sciebo-storage type=webdav url="https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Projects/Z03/motor_export_data" +``` + +Substitute the `url` with your data URL (the one which ends with `motor_export_data`)! + +#### Troubleshooting + +- If the error message complains about credentials (bearer authentication), most likely the credentials (environment variables) are incorrect. +- If the error message complains about gpg-agent not running, it is either not running or git-annex is using a different gpg than intended. See sections on gpg and gpg-agent above. +- If there is seemingly no error but data can not be downloaded, then probably the URL given to initremote was incorrect. Make sure that the URL points to `motor_export_data` (not `repo`). + + +## Data access + +{{% notice style="note" %}} +This assumes your working directory is in the dataset (that you `cd`'ed into the dataset). +{{% /notice %}} + +To download data, use: + +``` +datalad get output +``` + +To remove your local copy of the data, use `drop` which does the opposite of `get`: + +``` +datalad drop output +``` + +To obtain the latest version of the data, use: + +``` +datalad update --how merge +datalad get output +``` + +To see when the data (according to your local state) last changed, use `git log` (up/down arrows scroll, `Q` quits): + +``` +git log +``` + + + +[^1]: It would, at least in theory, be possible to modify the [PATH variable](https://en.wikipedia.org/wiki/PATH_(variable)) so that running `gpg` would use the Git-bundled gpg instead of the gpg4win gpg. +[^2]: You call `datalad get`, DataLad calls `git annex get`; git-annex calls `gpg --decrypt`, and gpg asks gpg-agent for a matching secret key. +[^3]: The credential name and username are stored in global (i.e. user) Git configuration, the password is stored in Windows' secret storage. -- 2.54.1 From f34d672ed5d56c91570d516b12617954b694add4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Fri, 25 Jul 2025 19:12:04 +0200 Subject: [PATCH 5/7] Change Z03 data access description to git-remote-annex --- content/z03/access-data.md | 122 +++++++++++++++---------------------- 1 file changed, 48 insertions(+), 74 deletions(-) diff --git a/content/z03/access-data.md b/content/z03/access-data.md index c300e59..d2a49d4 100644 --- a/content/z03/access-data.md +++ b/content/z03/access-data.md @@ -62,49 +62,6 @@ To generate a token: The token name can be anything - it is only for your information, and will be displayed in the list of tokens, with the date of last use and an option to delete (revoke) the token. -### Save credentials for DataLad in advance - -We have seen that DataLad's prompt for password can behave weirdly in cmd, in that it does not show any indication of characters being typed or pasted. To reduce errors, we recommend saving a DataLad credential [^3] upfront, and verifying that it is saved correctly. - -To save the credential, use the `datalad credentials set` command, replacing the placeholders marked with angle brackets (`< >`): - -``` -datalad credentials set type=user_password user= realm= -``` - -e.g. - -``` -datalad credentials set sciebo type=user_password user=m.szczepanik@fz-juelich.de realm=https://fz-juelich.sciebo.de/sciebo -``` - -(note: the realm needs to end with `/sciebo`). - -You will be prompted for the password. Type or paste and hit enter. You will be prompted to enter the password again. - -To see what was saved, run the following (with a name given in the previous step): - -``` -datalad -f json_pp credentials get sciebo -``` - -The output will look like this. -``` -{ - "action": "credentials", - "cred_realm": "https://fz-juelich.sciebo.de/sciebo", - "cred_secret": "[YOUR TOKEN SHOULD BE HERE]", - "cred_type": "user_password", - "cred_user": "m.szczepanik@fz-juelich.de", - "name": "sciebo", - "status": "ok" -} -``` - -If something seems wrong, repeat the `datalad credentials set` step, adjusting as necessary. - -You can use `datalad credentials get` whenever you need to remind yourself of the token. - ## WebDAV URLs When using DataLad & git-annex, you will connect to Sciebo through a protocol called WebDAV. For this, you need to know your WebDAV URL, which is slightly different than the URL you use to visit Sciebo's web interface. @@ -139,21 +96,41 @@ For use with DataLad, you will need to put the base URL and the relative paths t ## Initial setup +#### Let git-annex know your token + +Git-annex needs WebDAV credentials to access the stored repository and data. +It expects them to be provided via environment variables. +Set the environment variables with the `set` command (substitute your Sciebo username and token): + +``` +set WEBDAV_USERNAME=m.szczepanik@fz-juelich.de +set WEBDAV_PASSWORD=XXXXX-XXXXX-XXXXX-XXXXX +``` + +Important: do not put the password in quotes (`""`), because `set` command treats them literally. + +Tip: you can check value of an environment variable with `echo`, e.g. `echo %WEBDAV_USERNAME%`. + +These password will be cached in a owner-read-only file in the clone, +so the environment variables should not be needed for updates. + ### Clone the dataset The clone URL will be composed of two parts: -- constant part (tells Datalad what we are cloning): `datalad-annex::?type=webdav&encryption=none&exporttree=no&url=` -- your repo URL (see above) +- constant part (what we are cloning and how): `"annex::5e2afb7c-2985-454d-a12e-4ec5dcfb3623?encryption=none&type=webdav&url=` +- your repo URL (see above -- where we are cloning from) + +Additionally, we need to specify the branch name to check out (git-remote-annex has no default branch). To clone, substitute `` with your repo URL and `` with the target folder (do not include the angle brackets `<>`): ``` -datalad clone "datalad-annex::?type=webdav&encryption=none&exporttree=no&url=" motor_export +git clone --branch master "annex::5e2afb7c-2985-454d-a12e-4ec5dcfb3623?encryption=none&type=webdav&url=" ``` e.g. ``` -datalad clone "datalad-annex::?type=webdav&encryption=none&exporttree=no&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Z03/motor_export_repo" motor_export +git clone --branch master "annex::5e2afb7c-2985-454d-a12e-4ec5dcfb3623?encryption=none&type=webdav&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Projects/Z03/motor_export_annexrepo" motor_export ``` Then change your working directory to go into the dataset: @@ -165,7 +142,7 @@ Note: it is important to use double quotes (`""`) as cmd distinguishes between s Note: do not worry about the constant part containing `encryption=none`. The repository ("Git part") of the dataset is stored unencrypted, but the file contents ("annex part") are stored encrypted in Sciebo. This step deals only with the repository. -### Initialize sciebo remote +### Initialize sciebo remote(s) Git-annex special remotes represent methods of accessing data, and special remote configuration contains things like access URL or encryption type to be used. @@ -173,22 +150,10 @@ One weaknes of the Sciebo setup is that WebDAV URLs contain user names and insta The trick is to initialize a special remote, and mark it *same as* the one above (meaning that we expect to reach exactly the same place, just through different means). +Because the Git repository is *also* stored in a git-annex special remote, we need to set up *two* such remotes. + This is by far the most involved part of the setup. -#### Let git-annex know your token - -DataLad does not have a relevant interface, so we need to run this operation directly with `git-annex`. This means DataLad would not supply the credentials which we stored in the previous step, and we need to provide them via environment variables. Set the environment variables with the `set` command (substitute your Sciebo username and token): - -``` -set WEBDAV_USERNAME=m.szczepanik@fz-juelich.de -set WEBDAV_PASSWORD=XXXXX-XXXXX-XXXXX-XXXXX -``` - -Important: do not put the password in quotes (`""`), because `set` command treats them literally. - -Tip: If you don't have your token, retrieve it using DataLad: `datalad -f json_pp credentials get sciebo`. - -Tip: you can check value of an environment variable with `echo`, e.g. `echo %WEBDAV_USERNAME%`. #### (optional): check available remotes Each special remote has its own ID and assigned name, which can be used interchangeably with git-annex commands. To list remotes known to the dataset, run: @@ -197,32 +162,41 @@ Each special remote has its own ID and assigned name, which can be used intercha git annex info ``` -Pending future changes, the remote we want to enable is going to be named sciebo, i.e. it will be this one: +Pending future changes, the remotes we want to enable are going to be named sciebo-storage and sciebo-annexrepo, +i.e. it will be these two: + ``` 325dd4e6-e71b-4512-bce6-0eb574b6ed15 -- sciebo-storage +5e2afb7c-2985-454d-a12e-4ec5dcfb3623 -- sciebo-annexrepo [origin] ``` -#### Initialize your own private remote +#### Initialize your own private remotes As explained above, you will need to initialize a special remote for yourself, and mark it "same as" the one above. -Here's the command broken up into multiple lines with a caret (`^`) for readability: +Here's the command broken up into multiple lines with a caret (`^`) for readability. First, `-annexrepo`: ``` -git annex initremote my-sciebo-data^ +git annex initremote --with-url my-sciebo-annexrepo ^ + --private^ + --sameas sciebo-annexrepo^ + type=webdav^ + url="" +``` + +Substitute `` with your repo URL (the one which ends with `motor_export_annexrepo`)! + +And then, `-storage`: + +``` +git annex initremote my-sciebo-storage^ --private^ --sameas sciebo-storage^ type=webdav^ - url="https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Projects/Z03/motor_export_data" + url="" ``` -And here it is in one line - -``` -git annex initremote my-sciebo-data --private --sameas sciebo-storage type=webdav url="https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Projects/Z03/motor_export_data" -``` - -Substitute the `url` with your data URL (the one which ends with `motor_export_data`)! +Substitute the `` with your data URL (the one which ends with `motor_export_data`)! #### Troubleshooting -- 2.54.1 From 633b3e9de4d2d0b33cdff7c69de15cac976e05af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Fri, 1 Aug 2025 19:01:04 +0200 Subject: [PATCH 6/7] Change Z03 data access instructions to clone from jugit Encrypting the data and storing them in access-restricted Sciebo folder allowed us to make the repository public, thus simplifying the access and update procedure. --- content/z03/access-data.md | 81 ++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/content/z03/access-data.md b/content/z03/access-data.md index d2a49d4..5c5ea2d 100644 --- a/content/z03/access-data.md +++ b/content/z03/access-data.md @@ -77,21 +77,24 @@ To find your WebDAV address: The WebDAV URL will look like this: ``` -https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/ +https://fz-juelich.sciebo.de/remote.php/dav/files/j.doe%40fz-juelich.de/ ``` ### WebDAV URLs to folders The URL above is pointing to your home directory. To access a specific folder, you will need to add some path components manually. -Most likely, a folder named `Z03` will be shared with you. It will contain some folders; two which are relevant are: `motor_export_repo`, and `motor_export_data`. +Most likely, a folder named `Z03` will be shared with you. It will contain some folders; `motor_export_data` is the relevant one. The folder path relative to your home directory will depend on whether you move the shared folder or not. Assuming that `Z03` is in your home directory on Sciebo, the relative paths will be `Z03/motor_export_repo` and `Z03/motor_export_data`, respectively. -For use with DataLad, you will need to put the base URL and the relative paths together. Using the examples below: +For use with DataLad, you will need to put the base URL and the relative paths together. Using the example above, +and assuming that the shared folder is in the top-level directory, the data folder URL (for initremote) is: -- repo URL (for clone): `https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Z03/motor_export_repo` -- data URL (for initremote) `https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Z03/motor_export_data` + +``` +https://fz-juelich.sciebo.de/remote.php/dav/files/j.doe%40fz-juelich.de/Z03/motor_export_data +``` ## Initial setup @@ -103,34 +106,25 @@ It expects them to be provided via environment variables. Set the environment variables with the `set` command (substitute your Sciebo username and token): ``` -set WEBDAV_USERNAME=m.szczepanik@fz-juelich.de +set WEBDAV_USERNAME=j.doe@fz-juelich.de set WEBDAV_PASSWORD=XXXXX-XXXXX-XXXXX-XXXXX ``` Important: do not put the password in quotes (`""`), because `set` command treats them literally. -Tip: you can check value of an environment variable with `echo`, e.g. `echo %WEBDAV_USERNAME%`. +Tip: you can check the value of an environment variable with `echo`, e.g. `echo %WEBDAV_USERNAME%`. -These password will be cached in a owner-read-only file in the clone, -so the environment variables should not be needed for updates. +The environment variables persist until you close your cmd. +However, these credentials will later be cached in a owner-read-only file in the clone, +so re-entering the credentials should not be needed for subsequent updates. ### Clone the dataset -The clone URL will be composed of two parts: +Clone the (lightweight) dataset from JuGit (using the URL below) into a directory with a name of your choice +(here: `motor_export`): -- constant part (what we are cloning and how): `"annex::5e2afb7c-2985-454d-a12e-4ec5dcfb3623?encryption=none&type=webdav&url=` -- your repo URL (see above -- where we are cloning from) - -Additionally, we need to specify the branch name to check out (git-remote-annex has no default branch). - -To clone, substitute `` with your repo URL and `` with the target folder (do not include the angle brackets `<>`): ``` -git clone --branch master "annex::5e2afb7c-2985-454d-a12e-4ec5dcfb3623?encryption=none&type=webdav&url=" -``` - -e.g. -``` -git clone --branch master "annex::5e2afb7c-2985-454d-a12e-4ec5dcfb3623?encryption=none&type=webdav&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/Projects/Z03/motor_export_annexrepo" motor_export +datalad clone https://jugit.fz-juelich.de/m.szczepanik/motor-assesment.git motor_export ``` Then change your working directory to go into the dataset: @@ -138,11 +132,7 @@ Then change your working directory to go into the dataset: cd motor_export ``` -Note: it is important to use double quotes (`""`) as cmd distinguishes between single and double quotes. - -Note: do not worry about the constant part containing `encryption=none`. The repository ("Git part") of the dataset is stored unencrypted, but the file contents ("annex part") are stored encrypted in Sciebo. This step deals only with the repository. - -### Initialize sciebo remote(s) +### Initialize sciebo remote Git-annex special remotes represent methods of accessing data, and special remote configuration contains things like access URL or encryption type to be used. @@ -150,11 +140,8 @@ One weaknes of the Sciebo setup is that WebDAV URLs contain user names and insta The trick is to initialize a special remote, and mark it *same as* the one above (meaning that we expect to reach exactly the same place, just through different means). -Because the Git repository is *also* stored in a git-annex special remote, we need to set up *two* such remotes. - This is by far the most involved part of the setup. - #### (optional): check available remotes Each special remote has its own ID and assigned name, which can be used interchangeably with git-annex commands. To list remotes known to the dataset, run: @@ -162,31 +149,18 @@ Each special remote has its own ID and assigned name, which can be used intercha git annex info ``` -Pending future changes, the remotes we want to enable are going to be named sciebo-storage and sciebo-annexrepo, -i.e. it will be these two: +Pending future changes, the remote we want to enable is going to be named sciebo-storage, +i.e. it will be this one: ``` 325dd4e6-e71b-4512-bce6-0eb574b6ed15 -- sciebo-storage -5e2afb7c-2985-454d-a12e-4ec5dcfb3623 -- sciebo-annexrepo [origin] ``` -#### Initialize your own private remotes +#### Initialize your own private special remote As explained above, you will need to initialize a special remote for yourself, and mark it "same as" the one above. -Here's the command broken up into multiple lines with a caret (`^`) for readability. First, `-annexrepo`: - -``` -git annex initremote --with-url my-sciebo-annexrepo ^ - --private^ - --sameas sciebo-annexrepo^ - type=webdav^ - url="" -``` - -Substitute `` with your repo URL (the one which ends with `motor_export_annexrepo`)! - -And then, `-storage`: +Here's the command broken up into multiple lines with a caret (`^`) for readability. ``` git annex initremote my-sciebo-storage^ @@ -196,8 +170,20 @@ git annex initremote my-sciebo-storage^ url="" ``` +And this is the same as a one-liner: + +``` +git annex initremote my-sciebo-storage --private --sameas sciebo-storage type=webdav url="" +``` + Substitute the `` with your data URL (the one which ends with `motor_export_data`)! +{{% notice style="note" %}} +In the example above, we enclosed the URL with double quotes (`"...")`. +Keep in mind that cmd distinguishes single- and double quotes and treats them differently! +Find out more in https://ss64.com/nt/syntax-esc.html +{{% /notice %}} + #### Troubleshooting - If the error message complains about credentials (bearer authentication), most likely the credentials (environment variables) are incorrect. @@ -237,7 +223,6 @@ git log ``` - [^1]: It would, at least in theory, be possible to modify the [PATH variable](https://en.wikipedia.org/wiki/PATH_(variable)) so that running `gpg` would use the Git-bundled gpg instead of the gpg4win gpg. [^2]: You call `datalad get`, DataLad calls `git annex get`; git-annex calls `gpg --decrypt`, and gpg asks gpg-agent for a matching secret key. [^3]: The credential name and username are stored in global (i.e. user) Git configuration, the password is stored in Windows' secret storage. -- 2.54.1 From cefaae9adb9ab9e747d7fa4c2600cbf4fd0c069e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Fri, 1 Aug 2025 20:30:56 +0200 Subject: [PATCH 7/7] Add mermaid graph explaining JuGit plus Sciebo setup. --- content/z03/access-data.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/content/z03/access-data.md b/content/z03/access-data.md index 5c5ea2d..20b7ca6 100644 --- a/content/z03/access-data.md +++ b/content/z03/access-data.md @@ -97,6 +97,31 @@ https://fz-juelich.sciebo.de/remote.php/dav/files/j.doe%40fz-juelich.de/Z03/moto ``` +## Distributed storage + +There are two components to the dataset: + +- The Git repository (which we can call a "lightweight dataset") contains information about content identity and availability, but does not contain the actual data. +- The content managed by git-annex ("annexed data"), i.e. the actual data. + +For technical reasons they are stored and shared separately. +In the chart below, a square box symbolizes a Git remote, and cylinders symbolize Git-annex special remotes. + +```mermaid +flowchart TD + A(Your local dataset clone) + A ---o |clone, update| B["**JuGit** (public)"] + A ---o |initremote, get| C[("**Sciebo** + (restricted, encrypted)")] + A ---o |"🚫"| D[("**INM-7 storage** + (restricted, encrypted)")] +``` + +Retrieving data requires interacting with both the Git remote and the Git-annex special remote (key commands are shown over the lines). +Because no data are stored in JuGit, the repository can be made public, and fetching information from JuGit requires no credentials. +However, access to the data stored in Sciebo requires not only credentials, but also posession of a GPG key for which the data are encrypted. +Note that the Git repository also indexes data stored in INM7-storage, but that special remote is not accessible outside INM-7. + ## Initial setup #### Let git-annex know your token -- 2.54.1