Skip to content

Commit e1ee40b

Browse files
authored
Fix WorkingDir missing in securityPolicyContainer (#1321)
When creating internal representation of security policy for a container WorkingDir field wasn't properly initialized, which broke the policy enforcement. Update README.md for security policy tool. Signed-off-by: Maksim An <maksiman@microsoft.com>
1 parent 041d23c commit e1ee40b

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

internal/tools/securitypolicy/README.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ be downloaded, turned into an ext4, and finally a dm-verity root hash calculated
1818

1919
```toml
2020
[[container]]
21-
name = "rust:1.52.1"
21+
image_name = "rust:1.52.1"
2222
command = ["rustc", "--help"]
23+
working_dir = "/home/user"
2324

2425
[[container.env_rule]]
2526
strategy = "re2"
@@ -49,28 +50,28 @@ represented in JSON.
4950
"length": 6,
5051
"elements": {
5152
"0": {
52-
"strategy": "re2",
53-
"rule": "PREFIX_.+=.+"
54-
},
55-
"1": {
5653
"strategy": "string",
5754
"rule": "PATH=/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
5855
},
59-
"2": {
56+
"1": {
6057
"strategy": "string",
6158
"rule": "RUSTUP_HOME=/usr/local/rustup"
6259
},
63-
"3": {
60+
"2": {
6461
"strategy": "string",
6562
"rule": "CARGO_HOME=/usr/local/cargo"
6663
},
67-
"4": {
64+
"3": {
6865
"strategy": "string",
6966
"rule": "RUST_VERSION=1.52.1"
7067
},
71-
"5": {
68+
"4": {
7269
"strategy": "string",
7370
"rule": "TERM=xterm"
71+
},
72+
"5": {
73+
"strategy": "re2",
74+
"rule": "PREFIX_.+=.+"
7475
}
7576
}
7677
},
@@ -84,7 +85,8 @@ represented in JSON.
8485
"4": "e769d7487cc314d3ee748a4440805317c19262c7acd2fdbdb0d47d2e4613a15c",
8586
"5": "1b80f120dbd88e4355d6241b519c3e25290215c469516b49dece9cf07175a766"
8687
}
87-
}
88+
},
89+
"working_dir": "/home/user"
8890
},
8991
"1": {
9092
"command": {
@@ -111,7 +113,8 @@ represented in JSON.
111113
"elements": {
112114
"0": "16b514057a06ad665f92c02863aca074fd5976c755d26bff16365299169e8415"
113115
}
114-
}
116+
},
117+
"working_dir": "/"
115118
}
116119
}
117120
}
@@ -136,7 +139,7 @@ to the TOML definiton for that image. For example:
136139

137140
```toml
138141
[[image]]
139-
name = "rust:1.52.1"
142+
image_name = "rust:1.52.1"
140143
command = ["rustc", "--help"]
141144

142145
[auth]
@@ -159,4 +162,3 @@ isn't in the TOML configuration.
159162
If the version of the pause container changes from 3.1, you will need to update
160163
the hardcoded root hash by running the `dmverity-vhd` to compute the root hash
161164
for the new container and update this tool accordingly.
162-

pkg/securitypolicy/securitypolicyenforcer.go

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func (c Container) toInternal() (securityPolicyContainer, error) {
164164
Command: command,
165165
EnvRules: envRules,
166166
Layers: layers,
167+
// No need to have toInternal(), because WorkingDir is a string both
168+
// internally and in the policy.
169+
WorkingDir: c.WorkingDir,
167170
}, nil
168171
}
169172

test/vendor/github.com/Microsoft/hcsshim/pkg/securitypolicy/securitypolicyenforcer.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)