When custom CKAN authorization rules are worth building
Custom CKAN authorization rules are written as an extension that implements IAuthFunctions, which lets your code replace the authorization check behind a CKAN action. They decide who can perform an action and leave how datasets are stored untouched. Build them when the access question is one that CKAN's built-in roles cannot express. For example, an approval step might allow a dataset to move from draft to published only after a named reviewer in a separate team signs off. Another case is department-wide read access, where staff in one department must see private datasets owned by several organizations without becoming members of each one. Both needs go beyond the owner, editor and admin roles that organizations use.
Many access problems look like they need custom code but have a simpler answer. If a few named users need to edit one dataset, the dataset collaborator feature covers that without an extension. If a whole team needs to see private records, first check whether a different organization membership or role is enough. If the requirement is that some users can find certain datasets while others cannot, IPermissionLabels is usually the better first step, because it controls what appears in search through labels in the search index and requires a reindex after changes. Custom authorization is the heavier choice, since your extension then owns the rule, its tests and its upgrade path across CKAN releases.
Before you commit, confirm how each authorization function you plan to override behaves in the exact CKAN version you run. Function names, arguments and defaults can change between minor releases, and the CKAN release policy explains which versions receive fixes. Write each rule down as a case table listing the actor, the action, the dataset state and the expected result. Then test those cases on a staging copy that holds private datasets across several organizations. Only move the rule to production once every case behaves as the table says, and repeat the tests after each CKAN upgrade.
What custom CKAN authorization rules can override
CKAN checks permission in each action through a named authorization function, and an extension can change that check through the IAuthFunctions interface. The five capabilities below describe how far that control reaches, from replacing one function to applying conditions to web and API access alike. Confirm the exact function names and decorator helpers in the plugin interface and source of your target CKAN version before writing any code.
Overriding a named authorization function
CKAN runs each action through a named authorization function, and an extension can supply its own version of that function through the IAuthFunctions interface. This is the route for rules the built-in roles cannot express, such as department-wide read access. Match the override to the exact action name in your target version, because an override registered under the wrong name never replaces the core check. Test it with an account from each role you expect to see.
Chaining a new check onto the core check
A chained override keeps CKAN's own decision in place and runs your additional condition on top of it, so an approval step or a state restriction can narrow access. Chaining is the safer pattern when you want existing permissions to keep applying. Confirm how the chaining helper passes the core result back to your function in the target version, because the return value shape decides whether a denial from your check is honored. Write one test for an allowed user and one for a blocked user.
Scoping rules by action
CKAN keeps permissions for viewing, creating, updating and deleting datasets and other objects as separate checks, so a rule can target one action and leave the rest alone. A department rule might allow view for everyone in the organization while update stays with editors. Map every action in your policy to its function name before coding, and list the actions your rule does not cover so that no path is left open by accident.
Rules based on dataset state or workflow stage
A rule can read the current state of a dataset, such as draft, active or private, and decide access from that state. This is how a release can be held until a reviewer signs off. Workflow stages usually live in a custom field that your metadata schema defines, so confirm where that field is stored and that your check reads the saved value from the database. Test each stage transition, including the step where a dataset moves back to an earlier stage.
Applying rules to API calls and web pages
Authorization functions sit beneath CKAN's action layer, so one rule can cover both web forms and the Action API when both call the same action. Test both paths, because a rule that only hides a button in the web interface leaves the API open. Run each test as a sysadmin, an organization member and an anonymous request, and confirm that token-based API calls in your version follow the same checks.
CKAN source repositoryChoosing where an authorization rule should live
This table compares the four places an authorization rule can live in CKAN, plus the sysadmin bypass that applies to any of them. Read each row from left to right: the first column names the option, then when it fits, what it cannot express, and what it costs to maintain across web and API use. The main takeaway is to use the simplest mechanism that meets the rule and to override a core function only when chaining cannot express it.
| Option | When it fits | What it cannot express | Maintenance and API reach |
|---|---|---|---|
| Built-in organization roles | Publishers who should edit every dataset their department owns | Rights on one dataset for outsiders, or read access across organizations | No code. Member, editor and admin rules apply to web and API calls alike. |
| Dataset collaborators | A few named people who need editor or member rights on single datasets | Rules for a whole group, approval states or department-wide access | Grants are per dataset and need review when staff or datasets change. Enforced by the same checks as the web interface. |
| IPermissionLabels for search visibility | Showing or hiding datasets in search for named groups, such as shared access across organizations | Edit, approval or publishing rights, which labels do not govern | Labels live in the search index, so each change needs a reindex and a search test per user group. Test API search separately. |
| IAuthFunctions override | Rules the built-in roles cannot express, such as an approval step before publishing | Logic that needs data outside CKAN, unless your code fetches and caches it | Replaces core logic for that action. You own it through each CKAN upgrade, on web and API paths. |
| IAuthFunctions chained check | Adding a condition to a core right, such as a department or approval check | Granting access the core check refuses, when the wrapper calls core first | Core logic stays in place and is inherited. Review after upgrades, because the wrapped function may change. |
| Sysadmin bypass kept in place | Support, recovery and emergency work by a small, named sysadmin group | A rule that binds sysadmins too, since their bypass skips your check | Keep the group small and documented. Test your rules with a non-sysadmin account. |
| Sysadmin bypass removed in an override | Rules that must bind every account, including administrators | Break-glass access during an incident, unless a separate documented path exists | Higher upkeep: test every admin workflow after each change and each upgrade. |
How an authorization override reaches every request path
Web pages and API calls in CKAN both pass through the same authorization functions, so an override written in your extension's IAuthFunctions class applies to both paths without a second implementation. Verifying this comes first, and it is quick to test. Create a dataset that the new rule should hide, then request it as a blocked user in the browser, as the same user through the API with that user's token, and through any resource download URL your portal serves. Repeat with a user the rule should allow and with an anonymous visitor. Record each result. If the browser and the API disagree, the override is not reaching one of the paths, and you should find out why before you write any more rules.
The gap that catches teams is search. An authorization check on a single dataset decides whether a user can open that dataset, but it does not, by itself, control what appears in result lists. Dataset listings and package_search results come from the Solr index, so a blocked user can still see a dataset's title or organization in a list unless the index holds information that search can filter on. In CKAN this is usually handled through permission labels stored in the index and matched against each user's labels at query time. Any change to labels or rules then requires a reindex before the results reflect it. Plan search visibility as a separate workstream with its own tests, and confirm this interaction on your CKAN version before you promise restricted visibility to anyone.
Once both parts are in place, run the same user matrix against the dataset page, the API, the search page and the organization page, and check that blocked users never see the dataset in any of them. Keep the CKAN version, the extension versions and the date of the last reindex with the test results. A CKAN upgrade, a change to the override or a change to labels can reopen the gap, so repeat the matrix after each of them. Ask the team that runs the portal to confirm which search filters are active on their installed version, because that answer decides how much of the search behavior your rule can rely on.
Authorization decisions run in extension code before CKAN core
The diagram starts with a user or API token request calling a CKAN action. Before the action runs, the authorization override in your extension gets the first decision: it can allow, deny, or defer to the core check. Deferred requests reach CKAN core, where sysadmin status and organization roles are evaluated. The two subgraphs mark the trust boundary between your code and core, so check what the override does with sysadmin users and whether every deny path is intentional. Search takes a separate route: a query is filtered by the permission labels written into the search index, so label changes only take effect after a reindex.
Authorization path for an action request, and separately for a search query.
How to roll out custom CKAN authorization rules safely
The sequence turns access rules that the built-in roles cannot express into a tested CKAN extension your team can review, deploy and maintain. Each step ends with a document or artifact you keep, so the rules stay auditable after handover.
Agree the rules in a decision table
Start by writing each access rule as a row in a decision table: who the user is (organization role, sysadmin, anonymous visitor or a named group), what they want to do, which datasets or organizations the rule covers, and the outcome. Data owners review and approve every row before any code is written, including approval steps and department-wide read access. Open questions go in the table with a named owner. Output: the signed-off decision table. The step is done when each data owner has approved their rows in writing.
Map each rule to CKAN actions
Go through the decision table and list the CKAN actions each rule touches, such as viewing a dataset, creating or editing one, publishing, reading a private resource or calling an API action. Check which authorization functions each action passes through in the CKAN version you run, and record any action a rule could affect without anyone intending it. Output: a rule-to-action matrix kept alongside the decision table. The step is done when every rule maps to at least one action and every action in the matrix has a recorded decision from the data owners.
Build the extension on a staging copy
Create the extension in a staging copy of the portal, using the same CKAN version, extensions and database schema as production. Implement IAuthFunctions only for the authorization functions named in the matrix, and keep each override short enough that a reviewer can compare it with the decision table line by line. Output: a versioned extension repository and a staging build record naming the CKAN and extension versions it was built against. The step is done when the extension loads on staging and the logs show no startup errors.
Write automated tests for each rule
Write automated tests that call each mapped action as every role in the decision table, including anonymous requests and the boundary cases where two rules meet, such as a private dataset owned by a second organization. Each test asserts the outcome recorded in the table, so any later change to a rule fails the build and goes through review. Output: a test suite in the extension repository, plus a traceability listing that maps each test to its decision table row. The step is done when every row has at least one passing test and the suite runs on every change.
Verify each role with test accounts
Create one test account for each organization role (member, editor and admin), one sysadmin, one user with no organization and anonymous visitors. Then walk through the mapped actions with each account on staging and compare what it can see and do against the decision table. Log each mismatch as a defect and fix it before moving on. Output: a verification record listing each account, the actions tried, the expected and observed results and the tester. The step is done when the record shows no open mismatches.
Review logs for unexpected denials
Run normal portal activity on staging, including the verification accounts and scripted API calls, then review the CKAN and web server logs for authorization denials the decision table does not predict. Confirm first which denials your logging setup records, because some authorization failures may only appear at a more verbose log level. Each unexpected denial is either a gap to fix in the table and code or a correct denial to document. Output: a log review note listing each denial pattern, its cause and the decision taken. The step is done when every pattern has a recorded cause.
Deploy to production with a rollback plan
Deploy the tested extension to production during a change window your team approves, following the same steps rehearsed on staging. Before the change, write a rollback plan that names the previous extension version, the configuration to restore and the person who makes the rollback call, then rehearse it on staging. Confirm whether the change needs a search index rebuild, since search results depend on the index. Output: a deployment record and the rollback plan, both kept by your team. The step is done when a smoke test with the test accounts passes on production.
Hand over the rules and test suite
Transfer the decision table, the rule-to-action matrix, the extension source, the test suite, the verification record, the log review note and the rollback plan to your team. Walk them through how to add or change a rule, agree who owns each rule and who approves changes, and confirm that the tests run in your own pipeline. Output: a handover package and a short record of the walkthrough. The step is done when your team has run the full test suite without DeployOpen involved.
Testing overrides before publishers depend on them
Build a test matrix before any override reaches production, and make it cover every identity that can reach the rule. Rows should include each organization role (member, editor and admin), a sysadmin, an anonymous visitor and an API token. Columns should include each action the override touches (for example read, create, update, delete or the approval step you added) and each dataset state the rule depends on, such as public, private, draft and deleted. Each cell needs an expected result written down before the test runs. Three failure types matter most. Privilege escalation means a lower role gets an action it should not have. Blocked publishing means a legitimate editor is denied a step in the normal workflow. Search leakage means a private dataset appears in search results or API responses for someone who should not see it, which can happen even when the action check is correct, so test search and the dataset API separately.
Repeat the full matrix whenever CKAN changes underneath the extension. The CKAN release policy says patch releases should not break backwards compatibility, but minor releases may include backwards-incompatible changes, so a minor upgrade can silently change the functions your override wraps. Run the matrix against a staging copy of the portal on the target version, and read the release notes for the functions your extension overrides before upgrading production. Keep the matrix as automated tests in the extension's repository so the same checks run on every patch. The CKAN release policy is the right reference for which release types carry which compatibility promises.
Decide who signs off on the results before the first run, not after. A common arrangement is a sign-off from the data owner who defined the approval rule, the security lead who owns access decisions, and the platform owner who runs the upgrade. Ask whether the sign-off should come from someone who did not write the override, since the author tends to test the cases they already had in mind. The signed record should name the CKAN version, the extension commit, the date and any failed cells with their disposition. Any later change to the override or an upgrade of CKAN should reopen the sign-off, and publishers should not depend on the rule until the record is complete.
What drives the effort of a custom authorization build
This table lists the factors that raise or lower the effort of a custom CKAN authorization build, with a way to keep each one down. No effort figures appear here; the quote follows from the written scope. The biggest lever is agreeing the policy in writing before any code is written.
| Driver | Why it raises effort | How to keep it down |
|---|---|---|
| Actions and dataset states | Each overridden action and each dataset state it covers, such as draft, active or private, adds rules and tests. | Limit the rule to a short list of actions and states, and write down anything outside that list as a separate change. |
| Approval workflow state | CKAN stores dataset state and extras, but a multi-step approval may need history or sign-off records it does not hold. | Confirm with your CKAN version whether extras are enough, and decide the approval steps and sign-off roles before coding. |
| Search visibility | Rules that change who can find a dataset also affect the search index and may require a reindex to take effect. | Decide early whether visibility changes are in scope, and check search results for each role after every change. |
| Extensions already installed | Other extensions may implement the same authorization functions, and their load order in the plugin list can decide which rule applies. | List every installed extension that touches the same actions before the build starts, and test them together. |
| Quality of the written policy | Vague rules such as department-wide read access turn into guesses in code, which then need rework after review. | Agree a written policy with the data owners that names roles, actions, states and exceptions before coding starts. |
| Depth of the test matrix | Each combination of role, action and dataset state needs a test, and the matrix grows with every added role. | Agree the role-by-action test matrix in writing, and test the most sensitive combinations, such as private datasets, first. |
How authorization rules connect to the rest of the portal
A custom authorization rule does not work alone. Each card names a part of the portal that the rule must agree with, from search visibility and organization roles to SSO attributes, tokens, upgrades and audit records. Confirm each dependency with the portal owner before writing the rule.
Search visibility with IPermissionLabels
A custom rule that allows a read can still leave a dataset out of search if the permission labels in the index disagree with it. IPermissionLabels decides which labels a user holds, and CKAN filters search results against them, so your override and the label logic must describe the same people. Check that the labels your rule assumes are the labels the index actually stores, and that users who can view a private dataset also find it in search. Confirm with the portal owner which labels exist and plan a reindex after any change.
Organization roles and collaborators
Built-in roles already decide who can edit or publish in each organization, and dataset collaborators add named exceptions on top. An override that grants access to a whole department must not quietly widen rights for a collaborator who was given member rights on one dataset, or narrow an editor's rights in another organization. Test each rule against every role and collaborator case before go-live, including users with no organization. Confirm with the portal owner which roles the rule should grant and whether collaborator admin rights are enabled.
SSO attributes from SAML2
With ckanext-saml2auth, group or role values can arrive as SAML2 attributes in the login assertion, and a rule that checks department or clearance would depend on them. If the attribute is missing, renamed by the identity provider, or written only when the account is first created, the rule will decide on stale or empty data. Confirm the exact attribute names and whether they refresh on every login. Ask who maintains the identity provider mapping and how a change in group membership reaches CKAN.
API tokens and expiry
A token request runs through the same authorization functions as a browser session, so your rule decides what a script can read or change. Tokens belong to a user, which means they keep working after that person changes roles unless someone revokes them or sets an expiry. Confirm the token lifetime policy and who revokes tokens when someone leaves a department or changes role. Check that automated publishers and harvesters still pass your rule after tokens are renewed, and confirm the header name your CKAN version expects.
Function names and extensions
Overrides bind to the names and signatures of CKAN's built-in authorization functions, and a change to those in a later release can silently stop your rule from applying. Patch releases do not break backwards compatibility, but minor releases may include backwards-incompatible changes, so a rule that works on one minor version needs retesting on the next. Pin your override to a tested CKAN version and check every other extension that overrides the same functions for conflicts. Confirm the upgrade window and who owns the retest.
CKAN release policyAudit trail for authorization decisions
Reviewers usually ask who could see or change a dataset on a given date and why, and a custom rule adds decisions that the built-in activity record may not explain. Log each grant or denial your override makes, with the user, dataset, action and rule that decided it, and send those entries to the same store as your portal and identity logs. Confirm where the logs live, who can read them and how long they are kept with the portal owner and security team before the rule goes live.
Questions buyers ask before building custom CKAN authorization rules
How much does a custom CKAN authorization rule cost to build?
The cost depends on how many rules you need, how many CKAN authorization functions they override, and how much testing each rule needs before it reaches production. A single check, such as organization membership, is a small change in an extension. Rules for approval steps, department-wide read access or changes to dataset states involve more overrides, more test cases and more review by policy owners. Ask for a quote that separates one-time work (extension code, test suite, staging deployment, documentation and handover) from recurring work (retesting after upgrades and ongoing support). Ask which functions are in scope, what test matrix will be delivered and what format the handover takes. DeployOpen does not publish prices. A quote follows from the written scope.
How long does it take to write and test a custom CKAN auth rule?
The timeline is usually set by policy decisions and environment access more than by the code itself. The main drivers are how quickly policy owners confirm who may read, edit or approve each dataset, whether a staging portal with matching organizations and roles is available, how many functions the rule overrides, and how many test scenarios must pass. Edge cases, such as a dataset moved to another organization while an approval is open, need a decision before the code can be finished. Plan a review round with the security or data governance team before deployment. DeployOpen works to fixed-scope engagements with scope, deliverables and timelines agreed in writing before work starts, so ask for milestones tied to policy sign-off, staging deployment and the final retest.
What does the client need to provide for a custom CKAN authorization project?
Three groups of inputs control how smoothly the work moves. First, policy owners must state in writing who may view, edit, publish and approve datasets for each organization and dataset type. Second, provide test accounts for every role: anonymous users, members, editors, organization admins and sysadmins, plus a user in another department to confirm denial. Third, provide a staging CKAN portal that runs the same CKAN version, extensions and schema as production, with representative datasets loaded. Also provide access to the extension repository, the deployment pipeline, the Solr index and a named technical contact. Confirm whether data protection rules allow a copy of production data in staging. Gaps in any of these items usually extend the schedule.
Can an in-house developer build custom CKAN authorization rules without a partner?
Yes, if your team has Python developers who can work with CKAN's plugin interface and test suite. The developer must understand how the IAuthFunctions interface overrides CKAN's authorization functions, how the plugin is enabled in the site configuration, and how to write tests for both allowed and denied paths. The harder skills are policy design and regression testing after each upgrade. Compare the cost of building those skills in-house with a fixed-scope engagement that includes a written deliverable. Before you decide, confirm who will maintain the extension after handover, who reviews changes to authorization code, and whether a staging portal exists for testing. Ask any partner to show how the handover and retest are documented.
Will a custom CKAN authorization rule survive a CKAN upgrade?
It can, but only if you test it against each target version. CKAN patch releases do not break backwards compatibility and exclude schema changes and new features, while minor releases may include backwards-incompatible changes. CKAN 2.12.0 was released on August 26, 2026, and the project supports the latest patch of the current minor version and the previous minor version. Plan an upgrade check around every function you override: confirm the function signatures, the helper calls they depend on and the expected results in your test suite before production moves. Ask whether the scope includes a retest after each upgrade. Review CKAN's release policy before you set an upgrade schedule.
Does a CKAN authorization override hide datasets from search results?
Not by itself. An authorization override controls whether a user can perform an action, such as viewing a dataset page or calling an API action. Search results come from the search index, so a dataset can still appear in lists or facets for a user who cannot open it. Hiding datasets from search normally needs a separate mechanism, such as permission labels that filter the index, followed by a reindex after changes. Confirm this in your own environment. Log in as each test account, check the dataset list, the API search results and the facet counts, and try to open each dataset page. Repeat the checks after every reindex and after any change to organization membership or dataset visibility.
How DeployOpen scopes and delivers custom authorization rules
DeployOpen treats each custom authorization rule as a written, testable change to your CKAN extension. We start from the access rules your organizations need, such as approval steps or department-wide read access, and map each one to the CKAN authorization functions it overrides. Engagements are fixed-scope, so the scope, deliverables and timeline are agreed in writing before work starts.
How we scope
- The written scope names each authorization function you override and the users, organizations and dataset states it affects.
- Approval steps and department-wide read rules are listed as separate requirements with the roles and states each one needs.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts; ongoing support is available as a retainer.
How we build and test
- Rules are added in a CKAN extension that overrides the matching auth functions, so the change is tracked in version control.
- Each override delegates to the core check for cases outside its scope, so unrelated access behavior stays unchanged.
- Tests cover allowed and denied cases for each role, including sysadmins, organization admins, members and anonymous users.
How we hand over
- You receive the extension source, configuration notes and a record of which auth functions are overridden and why.
- A test suite and a permissions matrix show who can read, edit and administer datasets under each custom rule.
- Operating notes list what to re-test after each CKAN upgrade, since minor releases may include backwards-incompatible changes.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, so custom rules keep pace with CKAN releases.
- Under a retainer, upgrades can be re-tested against the authorization matrix before the new version goes live.
- Confirm with your CKAN version's release notes which auth function signatures and defaults changed before you upgrade.

