Last active
April 17, 2026 14:16
-
-
Save burgerdev/304dd0ab0fff1665b7c27e18a30cf96e to your computer and use it in GitHub Desktop.
Workaround for Contrast v1.19.0 CopyFile policy vulnerability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 1c1b4d3fc034f05e1a220f73c92b757e02268a32 Mon Sep 17 00:00:00 2001 | |
| From: Markus Rudy <mr@edgeless.systems> | |
| Date: Thu, 9 Apr 2026 16:02:14 +0200 | |
| Subject: [PATCH] genpolicy: restrict symlinks in CopyFile | |
| Allowing arbitrary symlinks in the shared directory is unsafe for | |
| confidential VM use cases. In order to make CopyFile safe both for the | |
| VM as well for the consuming containers, we implement the following | |
| rules for symlinks (in addition to the existing rules for other files): | |
| 1. Symlinks may not be placed directly into the shared directory. | |
| 2. Symlinks must not point 'upwards', i.e. contain `..` as a path | |
| element. | |
| 3. Symlinks must be relative. | |
| These rules ensure that all writes initiated by CopyFile are restricted | |
| to the shared directory (protecting the VM), and that symlinks can't | |
| point outside their mount points (protecting the container). | |
| These new restrictions mean that we can't support arbitrary mount | |
| sources (which might not follow these rules), but the usual k8s suspects | |
| (ConfigMap, Secret, ServiceAccountToken) should still pass. | |
| Signed-off-by: Markus Rudy <mr@edgeless.systems> | |
| --- | |
| src/tools/genpolicy/rules.rego | 35 +++++ | |
| 1 file changed, 35 insertions(+) | |
| diff --git a/src/tools/genpolicy/rules.rego b/src/tools/genpolicy/rules.rego | |
| index b8070b1ca2..42b2fe3443 100644 | |
| --- a/src/tools/genpolicy/rules.rego | |
| +++ b/src/tools/genpolicy/rules.rego | |
| @@ -1519,6 +1519,8 @@ CopyFileRequest if { | |
| check_directory_traversal(input.path) | |
| + allow_copy_file(input.path, input.file_mode, input.data) | |
| + | |
| some regex1 in policy_data.request_defaults.CopyFileRequest | |
| regex2 := replace(regex1, "$(sfprefix)", policy_data.common.sfprefix) | |
| regex3 := replace(regex2, "$(cpath)", policy_data.common.cpath) | |
| @@ -1530,6 +1532,39 @@ CopyFileRequest if { | |
| print("CopyFileRequest: true") | |
| } | |
| +allow_copy_file(path, mode, data) if { | |
| + print("allow_copy_file regular") | |
| + | |
| + bits.and(mode, 61440) == 32768 | |
| + | |
| + print("allow_copy_file regular: true") | |
| +} | |
| + | |
| +allow_copy_file(path, mode, data) if { | |
| + print("allow_copy_file dir") | |
| + | |
| + bits.and(mode, 61440) == 16384 | |
| + | |
| + print("allow_copy_file dir: true") | |
| +} | |
| + | |
| +allow_copy_file(path, mode, data) if { | |
| + print("allow_copy_file symlink") | |
| + | |
| + bits.and(mode, 61440) == 40960 | |
| + | |
| + target := concat("", [sprintf("%c", [c]) | c := data[_]]) | |
| + check_directory_traversal(target) | |
| + not startswith(target, "/") | |
| + | |
| + regex1 := concat("", [policy_data.common.sfprefix, ".*/.+"]) | |
| + regex2 := replace(regex1, "$(cpath)", policy_data.common.cpath) | |
| + regex3 := replace(regex2, "$(bundle-id)", "[a-z0-9]{64}") | |
| + regex.match(regex3, path) | |
| + | |
| + print("allow_copy_file symlink: true") | |
| +} | |
| + | |
| CreateSandboxRequest if { | |
| print("CreateSandboxRequest: input.guest_hook_path =", input.guest_hook_path) | |
| count(input.guest_hook_path) == 0 |
Comments are disabled for this gist.