Skip to content

Implement the authentication.bin trie mmap format#1061

Open
jviotti wants to merge 5 commits into
mainfrom
authentication-bin
Open

Implement the authentication.bin trie mmap format#1061
jviotti wants to merge 5 commits into
mainfrom
authentication-bin

Conversation

@jviotti

@jviotti jviotti commented Jun 16, 2026

Copy link
Copy Markdown
Member

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Review in cubic

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti jviotti force-pushed the authentication-bin branch from 5f59dc4 to 1f123bc Compare June 16, 2026 14:59
jviotti added 2 commits June 16, 2026 11:18
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti jviotti marked this pull request as ready for review June 16, 2026 15:35
@augmentcode

augmentcode Bot commented Jun 16, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR implements a memory-mappable trie format for authentication.bin and updates routing/search to consult the new matcher.

Changes:

  • Implemented mmap-based loading and prefix-trie matching in Authentication (fail-open only when the artifact is absent; fail-fast on malformed files).
  • Added a stable on-disk format (AuthenticationHeader, nodes/edges/string blob) plus a path-segmentation helper.
  • Introduced Authentication::save() to compile configured policies into the binary artifact.
  • Updated router artifact resolution and schema search actions to call authentication.admits(path, credential) directly.
  • Extended unit tests to cover scoped prefixes, nested prefixes, multiple prefixes per policy, and the 64-policy maximum.

Technical Notes: Matching walks path segments and binary-searches each node’s sorted edge list; decisions currently treat the policy set as an allow-list (any governing policy grants public access).

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

throw std::runtime_error("The authentication policy artifact is malformed");
}

this->nodes_ = view->as<AuthenticationNode>(header->nodes_offset);

@augmentcode augmentcode Bot Jun 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/authentication/authentication.cc:34 — Since sourcemeta::core::FileView::as<T>() only has assert bounds checks (and requires caller-provided alignment), a corrupted artifact with correct magic/version but bad offsets/counts could cause OOB/UB when mapping nodes_/edges_/strings_ and later in match(). Consider validating node_count > 0, offset+size ranges against view->size(), and alignment for AuthenticationNode (and that edge child/segment ranges are within the declared sections) before storing the section bases.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.


auto Authentication::save(std::span<const Authentication::Policy> policies,
const std::filesystem::path &path) -> void {
assert(policies.size() <= Authentication::MAXIMUM_POLICIES);

@augmentcode augmentcode Bot Jun 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/authentication/authentication_save.cc:49 — Guarding policies.size() <= MAXIMUM_POLICIES with assert means release builds can still hit UB (e.g., 1ULL << index shifting by >= 64) if configuration ever supplies too many policies. Consider enforcing this limit at runtime so production behavior is deterministic and fail-closed.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

stream.write(garbage.data(), garbage.size());
stream.close();

EXPECT_THROW(const sourcemeta::one::Authentication authentication{path},

@augmentcode augmentcode Bot Jun 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/unit/authentication/authentication_test.cc:43 — The malformed-artifact test only covers “garbage header” (magic/version mismatch); it might be worth adding a case where magic/version are correct but offsets/counts are invalid to ensure the loader rejects structurally-corrupt artifacts without crashing.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 9 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/authentication/authentication_save.cc
Comment thread src/authentication/authentication.cc
Comment thread src/authentication/authentication_format.h
Comment thread src/authentication/authentication_save.cc Outdated
Comment thread test/unit/authentication/authentication_test.cc
jviotti added 2 commits June 16, 2026 11:42
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant