Skip to content

Commit 43b8944

Browse files
committed
fix(policy): address Cedar review follow-ups
Engine: - Reject Cedar policies that test which process the principal is. Every request is evaluated as one placeholder process, so such a test never matches, and a forbid written that way never applied. - Deny hosts with an empty DNS label before evaluating policies. Host globs matched them, but inspection did not select them, so glob HttpRequest forbids were skipped. - Bound the work of one request's query-value combinations by the size of the evaluated policy set (16,384 policy evaluations, at most 1,024 combinations). - Summarize CedarEngine in Debug instead of walking every policy's expression tree outside the grown stack. Build and CI: - Reject a second stacker version in cargo-deny; Cedar's stack checks share its thread-local. - Require the Cedar crates in Cedar-enabled gateway and supervisor binaries, a positive control for the stable forbidden-crates check. CLI: print Cedar policy text without YAML highlighting. Docs: `tls: skip` for clients that pin certificates or present client certificates, and the new principal, host, and query limits. Signed-off-by: Johnny Greco <[email protected]>
1 parent 1265969 commit 43b8944

17 files changed

Lines changed: 440 additions & 61 deletions

File tree

‎.github/actions/build-rust-binary/action.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ inputs:
3333
description: Space-separated crate names that must not appear in the binary's embedded cargo-auditable dependency list
3434
required: false
3535
default: ""
36+
required-crates:
37+
description: Space-separated crate names that must appear in the binary's embedded cargo-auditable dependency list
38+
required: false
39+
default: ""
3640
entitlements-file:
3741
description: Path to an entitlements plist for macOS ad-hoc codesigning (skipped when empty or not on macOS)
3842
required: false
@@ -70,6 +74,7 @@ runs:
7074
INPUTS_BINARY: ${{ inputs.binary }}
7175
INPUTS_TRIPLE: ${{ inputs.triple }}
7276
INPUTS_FORBIDDEN_CRATES: ${{ inputs.forbidden-crates }}
77+
INPUTS_REQUIRED_CRATES: ${{ inputs.required-crates }}
7378
run: |
7479
binary="target/${INPUTS_TRIPLE}/release/${INPUTS_BINARY}"
7580
# Confirm the binary runs and reports the expected name.
@@ -90,6 +95,19 @@ runs:
9095
echo "::error::${INPUTS_BINARY} (${INPUTS_TRIPLE}) embeds forbidden crates: ${found[*]}" >&2
9196
exit 1
9297
fi
98+
# Require crates this build must link, such as the Cedar policy engine
99+
# in Cedar-enabled builds, so the check above cannot pass vacuously.
100+
read -ra required_crates <<< "${INPUTS_REQUIRED_CRATES}"
101+
missing=()
102+
for crate in "${required_crates[@]}"; do
103+
if ! grep -Fq "\"pkg:cargo/${crate}@" <<< "$sbom"; then
104+
missing+=("$crate")
105+
fi
106+
done
107+
if [ "${#missing[@]}" -gt 0 ]; then
108+
echo "::error::${INPUTS_BINARY} (${INPUTS_TRIPLE}) lacks required crates: ${missing[*]}" >&2
109+
exit 1
110+
fi
93111
94112
- name: Codesign with entitlements
95113
if: inputs.entitlements-file != '' && runner.os == 'macOS'

‎.github/workflows/branch-e2e.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
cargo-version: ${{ needs.version.outputs.cargo }}
111111
# Match Release Dev, which enables the Cedar policy engine.
112112
extra-cargo-features: cedar
113+
required-crates: cedar-policy openshell-policy-cedar
113114
secrets:
114115
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
115116

‎.github/workflows/build-binaries.yml‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ on:
3131
required: false
3232
type: string
3333
default: ""
34+
required-crates:
35+
description: >-
36+
Space-separated crate names that must appear in the
37+
openshell-gateway and openshell-supervisor binaries' embedded
38+
dependency lists, such as the crates extra-cargo-features enables.
39+
required: false
40+
type: string
41+
default: ""
3442
secrets:
3543
CACHIX_AUTH_TOKEN:
3644
required: true
@@ -40,9 +48,11 @@ permissions:
4048

4149
env:
4250
EXTRA_CARGO_FLAGS: ""
43-
# Jobs that build openshell-gateway or openshell-supervisor override this
44-
# with inputs.extra-cargo-features. No other package defines those features.
51+
# Jobs that build openshell-gateway or openshell-supervisor override these
52+
# with inputs.extra-cargo-features and inputs.required-crates. No other
53+
# package defines those features.
4554
EXTRA_CARGO_FEATURES: ""
55+
REQUIRED_CRATES: ""
4656

4757
jobs:
4858
cli:
@@ -79,6 +89,7 @@ jobs:
7989
supervisor-image-tag: ${{ inputs.supervisor-image-tag }}
8090
extra-cargo-flags: ${{ env.EXTRA_CARGO_FLAGS }}${{ env.EXTRA_CARGO_FEATURES != '' && format(' --features {0}', env.EXTRA_CARGO_FEATURES) || '' }}
8191
forbidden-crates: ${{ inputs.forbidden-crates }}
92+
required-crates: ${{ env.REQUIRED_CRATES }}
8293

8394
prover:
8495
name: openshell-prover (${{ matrix.triple }})
@@ -104,6 +115,7 @@ jobs:
104115
PACKAGE: openshell-gateway
105116
BINARY: openshell-gateway
106117
EXTRA_CARGO_FEATURES: ${{ inputs.extra-cargo-features }}
118+
REQUIRED_CRATES: ${{ inputs.required-crates }}
107119
strategy:
108120
matrix:
109121
include:
@@ -125,6 +137,7 @@ jobs:
125137
# openshell-sandbox has no cedar or dev feature; only the supervisor
126138
# entries take the extra features.
127139
EXTRA_CARGO_FEATURES: ${{ matrix.package == 'openshell-supervisor' && inputs.extra-cargo-features || '' }}
140+
REQUIRED_CRATES: ${{ matrix.package == 'openshell-supervisor' && inputs.required-crates || '' }}
128141
strategy:
129142
matrix:
130143
include:

‎.github/workflows/release-dev.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
# Release Dev publishes the Cedar policy engine in the gateway and
7272
# supervisor. Stable releases leave it off.
7373
extra-cargo-features: cedar
74+
required-crates: cedar-policy openshell-policy-cedar
7475
secrets:
7576
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
7677

‎CI.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ The bot's full administrator documentation is internal to NVIDIA. The only comma
657657
|---|---|
658658
| `.github/workflows/branch-checks.yml` | Required non-E2E checks. Triggers on `push: pull-request/[0-9]+` for PR mirrors and `merge_group` for queued merges. |
659659
| `.github/workflows/branch-e2e.yml` | Standard, GPU, Kubernetes HA, and Kubernetes credential-driver E2E. PR mirror pushes use `test:e2e`, `test:e2e-gpu`, and `test:e2e-kubernetes` labels; merge groups do not run E2E. |
660-
| `.github/workflows/build-binaries.yml`, `build-vm-driver.yml` | Shared binary matrices used by branch and release workflows. The VM driver remains separate because its build consumes the runtime binaries. `extra-cargo-features` applies only to the gateway and supervisor builds; Release Dev and branch E2E pass `cedar`. `forbidden-crates` fails the build when a binary's embedded dependency list contains a named crate. |
660+
| `.github/workflows/build-binaries.yml`, `build-vm-driver.yml` | Shared binary matrices used by branch and release workflows. The VM driver remains separate because its build consumes the runtime binaries. `extra-cargo-features` applies only to the gateway and supervisor builds; Release Dev and branch E2E pass `cedar`. `forbidden-crates` fails the build when a binary's embedded dependency list contains a named crate, and `required-crates` fails a gateway or supervisor build when its list lacks one. |
661661
| `.github/workflows/build-images.yml` | Builds and pushes multi-platform images, then uploads the same OCI images as workflow artifacts. |
662662
| `.github/workflows/package-release-binaries.yml` | Packages raw build artifacts into release tarballs without rebuilding them. |
663663
| `.github/workflows/e2e-docker-test.yml`, `e2e-podman-test.yml`, `e2e-vm-test.yml`, `e2e-kubernetes-test.yml` | Reusable runtime lanes called directly by branch and release workflows. Callers select suites and declare only the artifacts each runtime consumes. Docker callers set `cedar-suites` to add the Cedar suites, which need Cedar-enabled builds. |

‎Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ cedar-policy = { git = "https://github.com/ai-openshell/cedar.git", rev = "3cba2
104104
# Runs Cedar parsing, analysis, and evaluation on a grown stack; Cedar
105105
# recurses once per expression level and per character of a delimited `like`.
106106
# Keep the version Cedar uses: its own stack checks read the same
107-
# thread-local, which a second `stacker` in Cargo.lock would not share.
107+
# thread-local, which a second `stacker` in Cargo.lock would not share
108+
# (deny.toml rejects a second version).
108109
stacker = "0.1.25"
109110

110111
# HTTP client

‎crates/openshell-cli/src/commands/common.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,19 @@ pub fn print_yaml_line(line: &str) {
244244
pub fn print_sandbox_policy(policy: &SandboxPolicy) {
245245
println!("{}", "Policy:".cyan().bold());
246246
println!();
247-
if let Ok(yaml_str) = openshell_policy::serialize_sandbox_policy(policy) {
248-
for line in yaml_str.lines() {
247+
if let Ok(text) = openshell_policy::serialize_sandbox_policy(policy) {
248+
// A Cedar policy serializes as its Cedar text, which is not YAML.
249+
let cedar = !policy.cedar_policy_source.is_empty();
250+
for line in text.lines() {
249251
if line == "---" {
250252
continue;
251253
}
252254
print!(" ");
253-
print_yaml_line(line);
255+
if cedar {
256+
println!("{line}");
257+
} else {
258+
print_yaml_line(line);
259+
}
254260
}
255261
}
256262
}

‎crates/openshell-policy-cedar/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ Its Lean specification and proofs are in `ai-openshell/cedar-spec`.
191191
keys separately for deciding policies (all but staged) and for the staged
192192
comparison (all policies). Only keys the relevant policies name literally
193193
enter the entity, so other keys' values do not multiply evaluations, unless
194-
a policy computes a key. More than `MAX_QUERY_COMBINATIONS` (4096)
195-
combinations for deciding policies is an error, which the supervisor turns
196-
into a denial with that reason. Audit paths use the same combined decision.
194+
a policy computes a key. Each combination evaluates every policy, so more
195+
than `MAX_QUERY_COMBINATIONS` (1024) combinations, or more than
196+
`MAX_QUERY_POLICY_EVALUATIONS` (16,384) divided by the number of deciding
197+
policies, is an error, which the supervisor turns into a denial with that
198+
reason. Audit paths use the same combined decision.
197199
Staged comparisons use a separate combination budget; exceeding it or
198200
encountering an evaluation error skips the comparison and preserves the
199201
enforcing decision.

‎crates/openshell-policy-cedar/src/analysis.rs‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@
128128
//! - **Process identity.** Every request carries the same placeholder
129129
//! `principal.user` and `principal.group`, since the sandbox's run-as
130130
//! identity is not yet available to policies, so a policy that reads
131-
//! either is rejected rather than evaluated against a constant.
131+
//! either is rejected rather than evaluated against a constant. Every
132+
//! request is also evaluated as the same placeholder process, so a policy
133+
//! that tests which process the principal is, with a scope other than
134+
//! `principal` or `principal is Sandbox::Process`, or with `==`, `!=`,
135+
//! `in`, a `contains` method, or `is` on it in its conditions, is rejected
136+
//! too: it could never match a real process.
132137
//!
133138
//! Before any of that, the policy set is validated against the schema in
134139
//! strict mode, so a typo such as `context.binray_path` is a load error
@@ -813,6 +818,7 @@ pub fn analyze(schema: &Schema, policies: &PolicySet) -> Result<PolicyAnalysis,
813818
)?;
814819
check_delimited_patterns(conditions, &policy_id)?;
815820
check_principal_identity(conditions, &policy_id)?;
821+
check_principal_constraints(policy, conditions, &policy_id)?;
816822
let scope = ActionScope::of(policy);
817823
check_has_tests(conditions, policy, &policy_id, &scope, schema, &declared)?;
818824
let touches_filesystem = (scope.includes(actions::READ_FILE)
@@ -1443,6 +1449,67 @@ fn check_principal_identity(expr: &Value, policy_id: &str) -> Result<(), CedarEn
14431449
}
14441450
}
14451451

1452+
/// Rejects a test of which process the principal is, in the scope or within
1453+
/// `conditions`; see the module docs.
1454+
///
1455+
/// The scope may only be `principal` or `principal is Sandbox::Process`. In
1456+
/// `conditions`, an `==`, `!=`, `in`, or `contains`-family operand, or the
1457+
/// receiver of an `is` other than a bare `is Sandbox::Process`, counts when
1458+
/// it can evaluate to a `Process`, as for [`check_principal_identity`].
1459+
///
1460+
/// # Errors
1461+
///
1462+
/// Returns [`CedarEngineError::UnsupportedPolicy`] for the first such test.
1463+
fn check_principal_constraints(
1464+
policy: &Policy,
1465+
conditions: &Value,
1466+
policy_id: &str,
1467+
) -> Result<(), CedarEngineError> {
1468+
let unconstrained = match policy.principal_constraint() {
1469+
PrincipalConstraint::Any => true,
1470+
PrincipalConstraint::Is(entity_type) => entity_type.to_string() == entity_types::PROCESS,
1471+
_ => false,
1472+
};
1473+
if unconstrained && !tests_principal(conditions) {
1474+
return Ok(());
1475+
}
1476+
Err(CedarEngineError::UnsupportedPolicy {
1477+
policy_id: policy_id.to_string(),
1478+
reason: "it tests which process the principal is, but every request is evaluated \
1479+
with the same placeholder process, so the test cannot tell processes apart; \
1480+
use `principal` or `principal is Sandbox::Process`"
1481+
.to_string(),
1482+
})
1483+
}
1484+
1485+
/// Returns whether `expr` compares a value that may be a `Process` with
1486+
/// `==`, `!=`, `in`, or a `contains` method, or tests its type other than
1487+
/// as a bare `is Sandbox::Process`.
1488+
fn tests_principal(expr: &Value) -> bool {
1489+
match expr {
1490+
Value::Object(fields) => fields.iter().any(|(name, value)| {
1491+
let compares = match name.as_str() {
1492+
"==" | "!=" | "in" | "contains" | "containsAll" | "containsAny" => {
1493+
["left", "right"]
1494+
.iter()
1495+
.any(|operand| value.get(operand).is_some_and(may_be_process))
1496+
}
1497+
"is" => {
1498+
value.get("in").is_some_and(may_be_process)
1499+
|| value.get("left").is_some_and(may_be_process)
1500+
&& (value.get("in").is_some()
1501+
|| value.get("entity_type").and_then(Value::as_str)
1502+
!= Some(entity_types::PROCESS))
1503+
}
1504+
_ => false,
1505+
};
1506+
compares || tests_principal(value)
1507+
}),
1508+
Value::Array(values) => values.iter().any(tests_principal),
1509+
_ => false,
1510+
}
1511+
}
1512+
14461513
/// Returns whether `expr` contains `principal` or a `Process` entity
14471514
/// literal, so it may evaluate to a `Process`.
14481515
fn may_be_process(expr: &Value) -> bool {

‎crates/openshell-policy-cedar/src/error.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ pub enum CedarEngineError {
387387
/// A request's repeated query keys have more value combinations than
388388
/// Cedar evaluates for one request.
389389
///
390-
/// Each combination is a separate Cedar evaluation, so the count is
391-
/// capped and a request over it is denied.
390+
/// Each combination is a separate Cedar evaluation of every policy, so
391+
/// the count is capped, lower for a larger policy set, and a request
392+
/// over it is denied.
392393
#[error(
393394
"request query parameters have {combinations} value combinations, more than the \
394395
{limit} Cedar evaluates for one request"
@@ -397,7 +398,10 @@ pub enum CedarEngineError {
397398
TooManyQueryCombinations {
398399
/// The number of combinations, saturating at `usize::MAX`.
399400
combinations: usize,
400-
/// The cap, [`crate::MAX_QUERY_COMBINATIONS`].
401+
/// The cap for the evaluated policy set:
402+
/// [`crate::MAX_QUERY_COMBINATIONS`], or
403+
/// [`crate::MAX_QUERY_POLICY_EVALUATIONS`] divided by its number of
404+
/// policies when that is smaller, and at least 1.
401405
limit: usize,
402406
},
403407

0 commit comments

Comments
 (0)