stages/mkdir: fix its schema

The items of an array are defined under the `items` key, not under `paths`.
Let's fix this.

Btw, this is possible because JSON Schema itself doesn't use
additionalProperties = false. This allows extending the schemas easily, but
is sadly a bit error-prone.

Sadly, since this issue effectively disabled validation of the stage options,
we also need to relax the schema a bit:

We found out that there are manifests in the wild, that use relative paths,
instead of absolute ones. Thus, this commit changes the validation regex to
allow relative paths. However, this now emits a warning and it's strongly
discouraged. The associated stage test was modified to accommodate for this.

Co-authored-by: Tomáš Hozza <thozza@redhat.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Ondřej Budai 2023-10-20 14:26:53 +02:00 committed by Achilleas Koutsou
parent 0c144fc4aa
commit 23de60cd23
10 changed files with 38 additions and 21 deletions

View file

@ -11,6 +11,15 @@ directories. If you want to change the mode of an existing
directory, you need to use the `org.osbuild.chmod` stage.
Mode is applied only to newly created directories and umask
value is taken into account.
In the initial version of this stage, there was a bug that caused
the stage to accept relative paths. This behaviour is kept for
backward compatibility, thus the following paths are equal:
/path/to/directory
path/to/directory
However, using relative paths is strongly discouraged.
"""
import os
@ -26,14 +35,14 @@ SCHEMA_2 = r"""
"paths": {
"type": "array",
"additionalItems": false,
"paths": {
"items": {
"type": "object",
"additionalProperties": false,
"required": ["path"],
"properties": {
"path": {
"type": "string",
"pattern": "^\\/(?!\\.\\.)((?!\\/\\.\\.\\/).)+$"
"pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$"
},
"mode": {
"type": "number",
@ -64,6 +73,9 @@ def main(tree, options):
parents = item.get("parents", False)
exist_ok = item.get("exist_ok", False)
if not path.startswith("/"):
print("WARNING: relative path used, this is discouraged!")
target = os.path.join(tree, path.lstrip("/"))
if not in_tree(target, tree):
raise ValueError(f"path {path} not in tree")

View file

@ -1921,7 +1921,7 @@
"options": {
"paths": [
{
"path": "LiveOS"
"path": "/LiveOS"
}
]
}

View file

@ -379,7 +379,7 @@ pipelines:
- type: org.osbuild.mkdir
options:
paths:
- path: LiveOS
- path: /LiveOS
- type: org.osbuild.truncate
options:
filename: LiveOS/rootfs.img

View file

@ -1921,7 +1921,7 @@
"options": {
"paths": [
{
"path": "LiveOS"
"path": "/LiveOS"
}
]
}

View file

@ -379,7 +379,7 @@ pipelines:
- type: org.osbuild.mkdir
options:
paths:
- path: LiveOS
- path: /LiveOS
- type: org.osbuild.truncate
options:
filename: LiveOS/rootfs.img

View file

@ -450,10 +450,10 @@
"options": {
"paths": [
{
"path": "a"
"path": "/a"
},
{
"path": "c/d",
"path": "/c/d",
"parents": true
}
]

View file

@ -13,6 +13,6 @@ pipelines:
- type: org.osbuild.mkdir
options:
paths:
- path: a
- path: c/d
- path: /a
- path: /c/d
parents: true

View file

@ -450,24 +450,27 @@
"options": {
"paths": [
{
"path": "a"
"path": "/a"
},
{
"path": "c/d",
"path": "/c/d",
"parents": true
},
{
"path": "a/b",
"path": "/a/b",
"mode": 448
},
{
"path": "b/c/d",
"path": "/b/c/d",
"parents": true
},
{
"path": "c",
"path": "/c",
"mode": 448,
"exist_ok": true
},
{
"path": "i_am_relative"
}
]
}

View file

@ -13,13 +13,14 @@ pipelines:
- type: org.osbuild.mkdir
options:
paths:
- path: a
- path: c/d
- path: /a
- path: /c/d
parents: true
- path: a/b
- path: /a/b
mode: 448
- path: b/c/d
- path: /b/c/d
parents: true
- path: c
- path: /c
mode: 448
exist_ok: true
- path: i_am_relative

View file

@ -3,7 +3,8 @@
"/a/b",
"/b",
"/b/c",
"/b/c/d"
"/b/c/d",
"/i_am_relative"
],
"deleted_files": [],
"differences": {}