Skip to content

feat(jans-cedarling): add C bindings support#13542

Merged
moabu merged 59 commits intomainfrom
jans-cedarling-11754
Apr 15, 2026
Merged

feat(jans-cedarling): add C bindings support#13542
moabu merged 59 commits intomainfrom
jans-cedarling-11754

Conversation

@haileyesus2433
Copy link
Copy Markdown
Contributor

@haileyesus2433 haileyesus2433 commented Mar 20, 2026

Prepare


Description

Target issue

closes #11754

Implementation Details


Test and Document the changes

  • Static code analysis has been run locally and issues have been fixed
  • Relevant unit and integration tests have been added/updated
  • Relevant documentation has been updated if any (i.e. user guides, installation and configuration guides, technical design docs etc)

Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with docs: to indicate documentation changes or if the below checklist is not selected.

  • I confirm that there is no impact on the docs due to the code changes in this PR.

Summary by CodeRabbit

  • New Features

    • C bindings packaged as shared/static libraries exposing init, instance lifecycle, authorization (unsigned & multi‑issuer), context data API, logging, trusted‑issuer inspection, error/ memory helpers, and example programs.
  • Documentation

    • New C getting‑started tutorial, integrated C snippets in the main guide, and a dedicated C bindings README.
  • Tests

    • End‑to‑end C test suite, example Makefiles, and runnable C examples.
  • Chores

    • CI updated to add C test job and minor CI formatting fix.

- Introduced new `cedarling_c` package with a `Cargo.toml` file for configuration.
- Implemented `build.rs` for generating C bindings using `cbindgen`.
- Created `c_interface.rs` to manage Cedarling instances and authorization functions.
- Added `types.rs` for defining error codes and result structures.
- Included `lib.rs` as the main entry point for the C interface.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…ation engine

- Introduced comprehensive documentation for the new C bindings, detailing features, installation steps, usage examples, and API reference.
- Included instructions for building from source, linking, and utilizing the Context Data API for policy evaluation.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
- Introduced a new Makefile for building and running tests for the Cedarling C bindings.
- Added `test_cedarling.c` containing comprehensive tests for library initialization, instance creation, and authorization functionalities.
- Implemented assertions to validate test outcomes and error handling.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…ng C bindings

- Introduced three new example files: `authorize_multi_issuer.c`, `authorize_unsigned.c`, and `basic_example.c` to demonstrate various authorization scenarios using Cedarling C bindings.
- Each example includes detailed comments and configurations for multi-issuer JWT authorization and unsigned authorization with custom principals.
- Added a Makefile to facilitate building and running the examples.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
- Introduced a new tutorial document for Cedarling C bindings, covering installation, configuration, and usage examples.
- Included detailed instructions for building from source, linking applications, and utilizing the Context Data API.
- Updated the existing getting started guide to reference the new C tutorial.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
- Introduced a new job `c_tests` in the CI workflow to build and run C tests for the Cedarling C bindings.
- Added steps for installing necessary tools including Protoc and Rust, caching Rust dependencies, and building the Rust C library.
- Implemented commands to compile and execute the C tests, enhancing the testing coverage for the project.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
- Updated the mkdocs configuration to include a link to the new C tutorial in the Tutorials section, enhancing navigation for users seeking information on Cedarling C bindings.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
@haileyesus2433 haileyesus2433 added this to the 2.0.0 milestone Mar 20, 2026
@haileyesus2433 haileyesus2433 self-assigned this Mar 20, 2026
@haileyesus2433 haileyesus2433 requested a review from moabu as a code owner March 20, 2026 06:51
@haileyesus2433 haileyesus2433 marked this pull request as draft March 20, 2026 06:51
@mo-auto
Copy link
Copy Markdown
Member

mo-auto commented Mar 20, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new Cedarling C bindings crate (cdylib/staticlib) with generated C headers, extensive C FFI exports, examples, tests, docs/tutorial pages, and a CI c_tests job; also fixes a trailing-newline artifact in the existing CI workflow.

Changes

Cohort / File(s) Summary
CI Workflow
\.github/workflows/test-cedarling.yml
Adds a top-level c_tests job (checkout with runner hardening, install protoc, install stable Rust, cache Rust workspace, install pinned cbindgen, build cedarling_c release, verify target/include/cedarling_c.h, run C tests with LD_LIBRARY_PATH), and adds a trailing newline to golang_tests.
C Bindings Crate & Build
jans-cedarling/bindings/cedarling_c/Cargo.toml, .../build.rs, .../cbindgen.toml
New crate manifest (cdylib/staticlib) with deps and build-dep on cbindgen; build.rs generates header to target/include/; cbindgen.toml configures exported symbols, naming, must-use, and OS preprocessor defines.
FFI Core: types & interface
jans-cedarling/bindings/cedarling_c/src/types.rs, .../c_interface.rs, .../lib.rs
Adds C-ABI types (error codes, result structs, string-array), thread-local last-error, helpers to convert/allocate C strings, a process-wide instance registry, ~25+ extern "C" exports covering runtime/instance lifecycle, authorization, context data API, logging, trusted-issuer inspection, and memory utilities.
Examples & Makefiles
jans-cedarling/bindings/cedarling_c/examples/basic_example.c, .../authorize_unsigned.c, .../authorize_multi_issuer.c, jans-cedarling/bindings/cedarling_c/examples/makefile
Adds three C example programs demonstrating init/instance/authorize/log retrieval/cleanup and a Makefile supporting dynamic/static linking, platform libs, run targets, and rpath/LD_LIBRARY_PATH handling.
Tests & Test Makefile
jans-cedarling/bindings/cedarling_c/tests/test_cedarling.c, jans-cedarling/bindings/cedarling_c/tests/makefile
Adds an end-to-end C test harness covering success/error paths, context API, logging, trusted-issuer queries, memory utilities, lifecycle, plus a Makefile to build/run tests with rpath/LD_LIBRARY_PATH handling.
Documentation & Navigation
docs/cedarling/tutorials/c.md, docs/cedarling/tutorials/cedarling-getting-started.md, jans-cedarling/bindings/cedarling_c/README.md, mkdocs.yml
Adds comprehensive C bindings tutorial and examples, augments getting-started with a C tab, introduces crate README/API reference, and inserts the C tutorial into mkdocs navigation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • dagregi
  • moabu
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(jans-cedarling): add C bindings support' clearly and concisely summarizes the main change—adding C bindings to Cedarling to enable C developers to use the authorization engine.
Description check ✅ Passed The PR description follows the required template, includes the target issue (#11754), confirms code analysis was run, documents that tests were added/updated, confirms documentation was updated, and indicates no doc impact.
Linked Issues check ✅ Passed The PR fully addresses the linked issue #11754 objective by providing a complete C-compatible API that exposes Cedarling functionality to C applications through FFI bindings, runtime management, authorization APIs, context data management, and logging functions.
Out of Scope Changes check ✅ Passed All changes are directly scoped to adding C bindings support: Rust FFI layer, C examples, build configuration, CI/CD test automation, and corresponding documentation. No unrelated refactoring or feature creep is present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jans-cedarling-11754

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mo-auto mo-auto added area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request labels Mar 20, 2026
@haileyesus2433
Copy link
Copy Markdown
Contributor Author

the failing C tests will be resolved once #13538 is merged its currently blocked by that

haileyesus2433 and others added 6 commits March 20, 2026 16:01
…C interface

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…s to C interface

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…ionality

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…ation

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
@haileyesus2433 haileyesus2433 marked this pull request as ready for review March 27, 2026 14:08
…darling API. Updated README to clarify error reporting mechanisms, including the use of `cedarling_get_last_error()` for specific error cases. Simplified error handling in example files by removing redundant error messages. Improved consistency in error handling across API functions to ensure clarity and robustness.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…ieve full data entries with metadata. Updated README and tests to reflect this new functionality

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
… clarify safety requirements and parameter expectations. Improved descriptions for initialization, instance creation, authorization, and context data management functions, ensuring consistency and clarity for C callers.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
@haileyesus2433 haileyesus2433 dismissed stale reviews from dagregi and coderabbitai[bot] via c98458f April 6, 2026 07:36
Copy link
Copy Markdown

@tareknaser tareknaser left a comment

Choose a reason for hiding this comment

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

Thank you for the great work so far. I left a couple of final commits.

Comment thread jans-cedarling/bindings/cedarling_c/src/c_interface.rs
Comment thread docs/cedarling/tutorials/c.md Outdated
haileyesus2433 and others added 5 commits April 9, 2026 13:47
- Removed the cbindgen installation step from the GitHub Actions workflow.
- Updated documentation to reflect the removal of cbindgen usage in the build process for the Rust C library, clarifying the steps for building and copying artifacts.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…agement for freeing string arrays to use `Box::from_raw`

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
- Introduced a new function `cedarling_result_from_data_error` to map `DataError` to `CedarlingErrorCode`, improving error handling consistency across context functions.
- Updated error handling in `context_push`, `context_get`, `context_get_entry`, `context_remove`, `context_clear`, `context_list`, and `context_stats` to utilize the new mapping function.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
…process for linking against the shared library and building the project in release mode.

Signed-off-by: haileyesus2433 <haileyesusbe@gmail.com>
Copy link
Copy Markdown

@tareknaser tareknaser left a comment

Choose a reason for hiding this comment

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

Thank you for the great work. I have no further comments

@haileyesus2433
Copy link
Copy Markdown
Contributor Author

@coderabbitai could u please approve if u dont have any suggestions

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Tip

For best results, initiate chat on the files or code changes.

@haileyesus2433, thanks for reaching out! A couple of things to note:

  1. Approval command: To trigger an approval from me, you need to post @coderabbitai approve as a top-level PR comment (not a reply in a thread).

  2. Outstanding items before approval: There are a couple of things still pending on this PR that I'd recommend addressing first:

    • Failing C tests: You've noted these are blocked by PR #13538. It would be best to get that merged and confirm CI is green before approval.
    • Pending human review: @tareknaser has indicated they have review comments in progress and plan to submit their review in the next couple of days. It would be good to wait for and address their feedback first.

Once the dependent PR is merged, CI passes, and the human reviewer's feedback is addressed, feel free to post @coderabbitai approve as a top-level comment and I'll take another look!


🧠 Learnings used
Learnt from: olehbozhok
Repo: JanssenProject/jans PR: 13173
File: jans-cedarling/bindings/cedarling_python/src/context_data_api/data_entry.rs:12-34
Timestamp: 2026-02-04T20:09:55.585Z
Learning: In jans-cedarling Python bindings (jans-cedarling/bindings/cedarling_python/**/*.rs), Python-style documentation with explicit sections like "Attributes" and Python type hints is acceptable because these bindings expose Rust to Python consumers who benefit from Python-style documentation conventions.

Learnt from: olehbozhok
Repo: JanssenProject/jans PR: 13173
File: jans-cedarling/bindings/cedarling_python/src/context_data_api/data_store_stats.rs:9-33
Timestamp: 2026-02-04T20:10:06.440Z
Learning: In jans-cedarling Python bindings (jans-cedarling/bindings/cedarling_python/**/*.rs), Python-style documentation with explicit sections like "Attributes" and detailed field descriptions is acceptable and preferred because these bindings expose Rust to Python consumers who benefit from Python-style documentation conventions.

Learnt from: olehbozhok
Repo: JanssenProject/jans PR: 12903
File: jans-cedarling/bindings/cedarling_wasm/src/lib.rs:83-97
Timestamp: 2025-12-26T17:33:20.543Z
Learning: In jans-cedarling WASM bindings (jans-cedarling/bindings/cedarling_wasm/**/*.rs), explicit documentation sections like `# Arguments` and `# Example` are acceptable because these bindings expose Rust to JavaScript consumers who benefit from more explicit parameter documentation and JavaScript usage examples.

@haileyesus2433
Copy link
Copy Markdown
Contributor Author

Thank you for the great work. I have no further comments

thank you verymuch for the reviews

@haileyesus2433
Copy link
Copy Markdown
Contributor Author

@coderabbitai approve

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

✅ Actions performed

Comments resolved and changes approved.

@moabu moabu merged commit a871e1c into main Apr 15, 2026
3 checks passed
@moabu moabu deleted the jans-cedarling-11754 branch April 15, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(jans-cedarling): Add C Bindings Support

6 participants