Custom dataset visibility in CKAN with IPermissionLabels

Permission labels let a CKAN portal decide which users can find which datasets in search, including datasets shared across organizations. This page explains the design choices, the build sequence, the reindex each change requires and what to hand over.

On this page

When CKAN dataset visibility needs IPermissionLabels

A portal team needs IPermissionLabels when datasets must be findable only by named groups that span organizations, which the built-in organization roles do not express on their own. IPermissionLabels is a CKAN plugin interface that lets an extension attach labels to datasets in the search index and filter results by the labels each user holds. Data governance offices, multi-agency programs, research consortia and health or statistics units sharing restricted records with partner bodies typically need it, because each dataset has one owning organization while the audience may be a list of people drawn from several. Organization membership controls what a user can do inside one owner organization, but it cannot express an audience made up of people from several organizations. The decision to build this is a governance decision first and a code decision second.

The work combines three parts: extension code that implements the interface and computes labels for each dataset, configuration that enables the plugin and sets how labels are read and matched, and a search index reindex so that existing datasets carry labels the search query can filter on. The reindex is not a one-time afterthought, because the labels live in the index and must be rebuilt when the labeling logic changes. Exact method names, label formats and the behavior of each hook must be confirmed against the CKAN release in use before anyone scopes the build. The code is written against that release's interface, so ask the developers to show which hooks they override and how the reindex is triggered on that release.

Decide three things before the build starts: who assigns labels (the owning publisher, an organization admin, or a rule that reads dataset metadata), what a dataset with no label is allowed to do in search, and whether the same labels should also gate the API and resource downloads or only the search listing. Each choice changes the test plan. Verify with one test account per group, one account outside every group, and a sysadmin account, then repeat the checks after each reindex and each CKAN upgrade. Illustrative example: a dataset labeled for a three-agency working group should appear for members of that group and stay absent from public search and from the results of an unlabeled user.

What the IPermissionLabels hook controls in CKAN

IPermissionLabels is the CKAN plugin interface that decides which search index entries each user can see. The cards below separate the two sides of that decision, the labels attached to each dataset and the labels attached to each user, then show how search applies them alongside organization roles and the private flag. Confirm every method name and behavior in the source for your release before you rely on it.

Labels computed for each dataset

The hook returns a set of label strings for every dataset when CKAN indexes it, and those strings are stored with the search record. Each dataset's labels are fixed at index time. Check what the hook returns for a public dataset, a private dataset, and a dataset owned by an organization, and confirm the method name and return format in the source for your release. Write the expected labels down before the build starts so reviewers can compare them against your access rules.

CKAN source code

Labels computed for each user

For each request, the hook returns the labels a signed-in user holds, based on account data your code can read. For example, organization membership or attributes passed through an SSO login could map to labels. Anonymous visitors need an explicit answer. Check what the hook returns when no user is logged in, when an API token is used, and when a sysadmin is signed in, because each path reaches search differently. Confirm the user-side method in the source before you map identity attributes to labels.

Search results filtered by labels

At query time, CKAN adds a filter so that a search returns only datasets whose stored labels overlap with the labels the user holds. Test every search path. Check this with test accounts through the web search page, the search API and any saved links, since a dataset that shows up in one path but is missing from another usually points to a label gap. Confirm in the source how the filter is built for your release and whether any core search path bypasses it.

Organization roles for actions

Organization roles decide what a user can do with a dataset, such as editing or publishing it, while labels decide whether the dataset appears in search at all. Roles and labels answer different questions. Check that a publisher who can edit a dataset can also find it, and that a user who gains access through a label can only search for the dataset and cannot edit it. Confirm how the authorization checks in your release combine with label-filtered search, since the two are enforced in different code paths.

Private flag as the baseline

A dataset marked private starts from a narrower visibility setting, and the label hook adds access on top of that setting. Any label rule that widens access should be written on purpose. Check which private datasets your label rules could expose to users outside their owning organization, and confirm in the release you run how the private flag and the label filter interact. Record the result as part of the access review so the baseline does not change without a decision.

Reindex after label changes

Labels live in the search index, so changing the hook's logic or an identity mapping does not update existing results until affected datasets are reindexed. Plan the reindex as part of every label change. Check which datasets a rule change touches, how long a full reindex takes on your portal, and whether users can see stale results in the meantime. Confirm the reindex command and its options in the documentation for your release.

How a dataset label reaches a user's search results

The diagram starts when a dataset is saved in CKAN. The IPermissionLabels plugin computes the dataset's labels, and those labels are written into the Solr index with the document. When a user signs in, the same plugin computes that user's labels, and a search query adds a label filter so Solr returns only datasets whose labels match. The boxed trust boundary marks where CKAN's web and API layer hands the query to the index. Check that dataset and resource pages run their own read permission check, because the label filter shapes search results and does not replace that check.

Labels are written on save and matched at search time.

Choosing how labels map to users and datasets

This table compares four ways to design permission labels in CKAN with IPermissionLabels: one per owning organization, one per collaboration group, one per embargo or classification level, and one derived from dataset fields. Read each row for when the design fits, how much ongoing work keeps membership data accurate, and where it usually fails. The main takeaway is that every label design is only as correct as the membership data behind it, so choose the design your team can keep current.

Design optionWhen it fitsEffort to keep membership accurateMain risk
One label per owning organizationFits when each organization's members are the only people who should find its datasets. Membership follows existing CKAN organization roles.Low. Membership comes from organization roles already maintained in CKAN, though departures and transfers still need prompt review.Too broad when part of an organization should not see the rest, since every member inherits the label.
One label per collaboration groupFits when access crosses organizations, such as a joint research project, and group membership comes from SSO attributes or a maintained list.High. Membership needs a feed from the identity provider or a maintained list. Confirm which changes need a reindex in your version.Stale membership: people who leave the project keep access until their attributes or list entries change.
One label per embargo or classification levelFits when releases are time-bound or sensitivity tiers govern access, such as an embargo group or a restricted classification.Medium. Labels change on release dates or reclassification, so dataset labels must be updated and reindexed on schedule.Too broad a label exposes data early to the wrong readers, while a missed release date keeps it hidden too long.
One label derived from dataset fieldsFits when a metadata field, such as a sensitivity flag, already records the access rule for each dataset.Medium. Little membership upkeep, but field values must be complete, and blank values need a defined default.A blank or mistyped value can silently widen or narrow who sees a dataset, so entry validation matters.

Implementation sequence for CKAN dataset visibility labels

Permission labels change what the search index returns, so the order of work matters: rules are agreed first, then code is built and tested, then the index is rebuilt and checked before any public change. Each phase ends with a named artifact that the next phase depends on.

  1. Write the access matrix with data owners

    Before any code, the data owners and the security or compliance lead agree who may find which datasets. The matrix lists each organization, group and special case, such as cross-organization sharing, anonymous access and private datasets, and states the label each dataset should carry. Ask the owners to sign and date it, and record who approves changes later. Done when the signed access matrix is stored with the project records and every dataset class has one owner-approved rule.

  2. Confirm CKAN version and interface methods

    Check the CKAN version running in staging and production, and confirm the IPermissionLabels methods that version exposes, along with the extension interfaces and any existing plugins that already implement labels. Read the release notes for the target version and the release policy so that the work is built against a supported patch. Record the version, the plugin list and the method signatures in the build notes. Done when the team can name the exact version and the methods the extension will implement, and an engineer has confirmed both against the installed source.

  3. Build and unit test the label functions

    In a development extension, implement the label functions the access matrix requires, so each dataset receives its labels at index time and each user receives the labels they are entitled to. Keep the rules in one module so auditors can read them against the matrix. Write unit tests for every row of the matrix, including anonymous users, members of each organization, collaborators and sysadmins. Run the tests in a clean development instance. Done when the extension is in version control, the tests pass, and the test report is attached to the change request.

  4. Configure and reindex on staging

    Install the extension on staging with the same configuration planned for production, then rebuild the search index so that existing datasets pick up their labels. Run the rebuild with the CKAN search index command on a copy of production data, and keep the full output as a log. Compare a sample of dataset counts in the search results against the matrix before and after the rebuild. Done when the staging reindex log shows no errors, and the sample comparison matches the signed matrix for every organization and group.

  5. Test with accounts for each role

    Sign in to staging as a test account for each group in the matrix, plus an anonymous session, a member, an editor, an organization admin and a sysadmin. For each account, search the datasets and call the API, then record whether each private, restricted and cross-organization dataset appears or is hidden as the matrix requires. Also check direct dataset URLs and the API responses, because search and page access can differ. Log every mismatch as a defect. Done when the test results list every account and dataset class, and no defect remains open against the matrix.

  6. Go live with a rollback path

    Schedule the production change with the owners, deploy the tested extension, and run the same reindex used on staging. Before the change, save a database backup and the previous extension version, and write down the steps to disable the plugin, restore the previous index and confirm search results. Run the sample checks again on production and keep the output with the change record. Done when production search matches the signed matrix, and the rollback steps have been reviewed by the on-call team and the data owners.

What drives the cost and effort of label work

This table compares the main cost components of custom permission label work in CKAN and shows whether each one is paid once or again when a new group or dataset class is added. Read each row for what raises the effort and what to ask a partner to state in the written scope. The main takeaway is that the access matrix, the label rules and the reindex plan drive most of the effort, so settle them before development starts.

Cost componentOne-time or recurringWhat raises it and how to keep it downWhat to ask for in the written scope
Access matrix discoveryOne-time, then revisited when a new group or class is addedMany overlapping groups and unclear dataset ownership widen the work. Agree a short matrix of groups, classes and viewers first.Who signs off the matrix, and which groups and dataset classes are covered
Extension developmentOne-time for the first rules, recurring for each new dataset classEach new label rule is code to write and review. Keep it down with one documented label pattern reused for every class.Which label rules are built, how new classes are added, and who maintains the code
Mapping identity attributes to groupsRecurring when groups, roles or identity source attributes changePer-user exceptions multiply the work. Keep it down by mapping from a stable group attribute in the identity provider.Source attributes used, who owns the mapping, and how changes reach the search index
Test coverageOne-time build, recurring on every rule changeEach group needs positive and negative cases across search, API and dataset pages. Keep it down with generated test users run in CI.Which visibility cases are tested, and whether tests run on each upgrade
Reindex time relative to portal sizeRecurring whenever label changes affect existing datasetsReindex time grows with dataset count and index size. Keep it down by batching label changes and scheduling a maintenance window.Reindex procedure, expected search impact during the run, and who executes it
Upgrade work at CKAN minor version changeRecurring with each minor release you adoptMinor releases may include backwards-incompatible changes, so the extension needs review. Keep it down by pinning versions and testing on staging.Target CKAN versions, extension versions tested, and the upgrade test plan
Security review of label logicOne-time, plus review on each rule changeLabel rules are access control, so a leak is a security issue. Reduce rework by reviewing each rule before release and retesting after fixes.Whether a leakage test is included, and who signs off the findings

Testing visibility before anyone relies on it

A visibility test plan has to prove what each kind of user can reach, beyond what the search results show, so build it as a matrix before anyone relies on the labels. The rows are the user types: anonymous visitor, member, editor, organization admin, sysadmin, and one test account in each shared group that a label grants access to. The columns are datasets, one for each permission label in use plus a control dataset with no extra label, so every label is tested against every audience. Write the expected result for each cell before testing starts, based on the label design agreed with the data owners. A cell without an expected value cannot show a failure, so reviewers will treat its result as unverified.

For each cell, check four access paths. First, the search pages in the web interface, which show whether a dataset appears in listings and facets for that user. Second, the package search call in the API, made once without a token and once with a token belonging to the test account, because API tokens carry that user's rights and scripts and harvesters will make the same call. Third, the dataset page, which tests direct access by URL. Fourth, the resource download, because a user who cannot see a dataset in search may still reach its files through a direct link. A filtered result list does not confirm any of these direct paths. Run the full matrix again after every label change and after the search index rebuild finishes, since an index that has not been rebuilt can still show results from the old configuration.

Keep the evidence in a form the client's security and compliance team can review without a walkthrough. That means the completed matrix with expected and observed results for every cell, the CKAN version, the label configuration and the date of each run, the rebuild output for each change, and request and response captures for the API calls with tokens redacted. Add screenshots of the web results for each user type, the list of failed cells with the fix applied and the retest that closed each one, and the name of the person who accepted the final result. Ask the client's auditor which format and retention period they expect, since requirements vary by framework and this page does not set them. Store the evidence outside the portal so it survives a rebuild of the instance.

Reindex and label changes by situation

A new label rule changes which labels datasets carry in the search index, so existing datasets are only affected once their index entries are rebuilt. Treat a new rule as a change to what every user can find, and confirm the reindex approach for your installed version before you deploy the extension code.

  • Existing datasets: Datasets indexed before the rule was added keep their old labels until they are reindexed, so search results can lag behind the rule.
  • Plugin loading: Confirm that the extension containing the rule is enabled for every web and background worker process, because a rule loaded by only some processes produces inconsistent results.
  • Test accounts: Prepare accounts that represent each group the rule touches, so you can compare results before and after the change.
  • Version-specific steps: Look up the reindex command and its scope in the operations documentation for your CKAN version, and do not reuse commands from older guides.

Check that a sample of datasets returns the expected results for each test account in search, on dataset pages and through the API, and record the outcome in your change log.

How label rules connect to SSO, collaborators and the rest of the portal

Label rules are only as accurate as the data behind them. Each connection below feeds the permission labels that decide which users see which datasets in search, so a change in one system can quietly widen or narrow access in another. For each one, agree who owns the source of truth before you write the label function.

SSO attributes and group membership

The ckanext-saml2auth extension can assign users to organizations and roles from SAML2 attributes, so your identity provider may decide who belongs to a group that a label function reads. Attribute names and values must match exactly in the identity provider, the extension settings and the label logic. Check what happens when an attribute is missing or changes at login, and confirm when the index reflects the new membership. The identity team owns the attributes, and the CKAN team owns the mapping.

ckanext-saml2auth repository

Organization roles

Member, editor and admin roles decide who can publish to an organization, and label rules often check the same membership. Confirm that the role your label function checks is the role CKAN actually grants, so a user promoted to editor in one organization does not gain visibility into another. Membership changes should trigger a reindex in your version, so confirm that before relying on them. Organization admins own membership for their department, and the portal team owns the label logic that reads it.

Collaborators on individual datasets

Dataset collaborators receive member or editor rights on a single dataset, and those rights sit outside organization roles. If your labels only read organization membership, a collaborator may be able to edit a dataset that search hides from them. Decide whether collaborators should also receive visibility through labels, and write that decision down. Collaborator rights and label rules must agree. Dataset editors own the collaborator list, and the portal team owns whether labels honor it and when reindexing happens.

Private dataset flags

The private flag controls whether a dataset is hidden from people outside its owner organization. Label rules add a second path to visibility, so a dataset can be flagged private yet still reachable through a broader label, or the reverse. Check the private flag and the label together at every publishing step, especially when a release date moves a dataset to public. Publishers own the flag at creation and release, and the portal team owns the rule that reads it.

Harvesters and API tokens

Harvesters and publishing scripts create and update datasets through the API, and the owner organization they set decides which labels apply. A token tied to a sysadmin account can write to any organization, which can bypass the labels you planned for each department. Check that harvest jobs set the owner organization and privacy values you expect, and that each token belongs to an account whose membership is current. Every token should map to a named owner and a named organization. The platform team owns harvest jobs and tokens.

Solr search backend

Permission labels live in the Solr search index, so the index is where access decisions take effect in search results. After any change to label functions, group membership or the private flag, the affected datasets must be reindexed, or search may keep showing the old labels. Treat reindexing as part of every label change, and confirm the reindex procedure and its scope for your CKAN and Solr versions. Platform operations owns the Solr cluster and the reindex runs.

Questions buyers ask before hiring help with dataset visibility

How much does custom dataset visibility work in CKAN cost?

The cost follows from the written scope, and DeployOpen does not publish a price list, so a quote is built from the scope you agree in writing. The main drivers are the number of visibility rules, how many group sources feed user membership (such as CKAN organization roles, SAML2 attributes or a directory), whether an access matrix already exists, and how many CKAN environments must behave the same way. Work that includes a custom IPermissionLabels plugin, tests for each role and a reindex plan costs more than a configuration-only change. Ongoing upgrades and continuous testing are a separate recurring retainer. Ask for the quote to split one-time build work from recurring support, and to name who signs off on the test results.

How long does it take to add permission labels to CKAN?

The duration depends on access decisions as much as on code, so the first stage is often the longest. Before build work starts, the access matrix, group sources and test accounts need agreement, and that stage moves at the pace of your review cycle. The build then covers plugin logic, role-by-role tests, validation on staging and a reindex on a copy of production. The drivers are:

  • the number of distinct visibility rules and roles
  • how many identity sources feed group membership
  • the number of CKAN environments and the size of the catalog
  • the number of data owner review rounds

Ask for a timeline in the written scope with a milestone for each stage.

Can our internal team build CKAN dataset visibility labels without outside help?

Yes, a team with the right extension skills can build it, but the work spans several disciplines. The skills it needs are:

  • Python plugin development against CKAN's plugin interfaces, with automated tests
  • Solr, because labels live in the search index and query behavior must be checked there
  • identity provider attribute mapping, if roles come from SAML2 or LDAP
  • PostgreSQL and CKAN configuration for each environment

A team that has not built a CKAN extension before should plan for ramp-up time. Compare these skills with the scope you plan to sign, and decide early which parts your team will own after handover.

What does our team need to provide for a CKAN visibility project?

You provide the access decisions, the people who can make them and access to a staging copy of your portal. The inputs are:

  • an access matrix that states which roles and groups can see which datasets, by organization and dataset type
  • the group sources, meaning where membership lives, such as CKAN organization roles, SAML2 attributes or a directory
  • test accounts for each role on staging, with the same group memberships as production
  • named data owners who sign off on the expected results for their datasets
  • read access to the CKAN configuration and the search index on the staging copy

Gaps in these inputs slow the work, so confirm each one before the scope is signed.

Do permission labels replace CKAN organization roles?

No, the two complement each other. Organization roles decide what a member can create, edit or publish inside an organization. Labels decide which datasets a given user can find in search, including datasets shared with users outside the owning organization. Because the two layers interact, test each role against each dataset class and record the result. Confirm during testing how a label and a role combine in each case, and document the outcome so the data owners and the security team can review it.

Does a reindex take a CKAN portal offline during the change?

Confirm this for your CKAN version, your Solr setup and your catalog size before you schedule the change, because the answer depends on all three. Label changes require a reindex, so plan it as part of the rollout. Confirm the following with your team:

  • the reindex procedure and search behavior documented for your exact release
  • the time a full reindex takes on a staging copy with a production-sized catalog
  • whether search results can be stale or incomplete while the reindex runs
  • the change window, and the message your portal owners will publish to users

Run the timed test before you agree the window.

How DeployOpen scopes and delivers label-based visibility

DeployOpen plans, implements, tests, documents and supports self-hosted CKAN inside your own infrastructure, including the label rules that decide which users can find which datasets in the search index. Each engagement starts from a written scope agreed before work begins. The result is a visibility model your compliance and security teams can review.

How we scope

  • The written scope names which permission labels control search visibility, which organizations and users they cover, and who approves changes.
  • Scoping also records the datasets, cross-organization sharing cases and reindex steps that follow each label change.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts, and ongoing support available as a retainer.

How we build

  • Build the IPermissionLabels plugin that assigns labels to datasets and to user accounts, kept in your own extension code.
  • Test on staging with users from several organizations, checking search results, dataset pages and API responses.
  • Schedule the reindex after label logic changes so search results match the rules before users rely on them.

How we hand over

  • Handover includes the extension source, configuration notes, and the list of labels, their meaning and who may assign them.
  • The reindex runbook covers when to run it, how long it takes on your index and how to roll back.
  • Your team receives a written record of each label rule and its sign-off, usable as access design evidence.

How we support

  • Security testing can check whether users reach datasets outside their labels through search or the API.
  • Ongoing support can cover upgrades, extension compatibility checks and reindex runs after new labels or organizations are added.
  • Ask for the retest and the change log in the quote so later label changes are tested the same way.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.