{"id":17109562,"url":"https://github.com/monken/node-pbac","last_synced_at":"2025-04-11T15:20:32.437Z","repository":{"id":35802931,"uuid":"40084769","full_name":"monken/node-pbac","owner":"monken","description":"Policy Based Access Control","archived":false,"fork":false,"pushed_at":"2024-06-20T01:13:56.000Z","size":120,"stargazers_count":51,"open_issues_count":5,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-02T02:02:52.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monken.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"monken"}},"created_at":"2015-08-02T16:04:57.000Z","updated_at":"2025-02-10T20:52:31.000Z","dependencies_parsed_at":"2022-09-13T08:51:35.359Z","dependency_job_id":"2c0a52e3-6738-4d68-9fbe-6ee3ab877714","html_url":"https://github.com/monken/node-pbac","commit_stats":{"total_commits":48,"total_committers":4,"mean_commits":12.0,"dds":"0.45833333333333337","last_synced_commit":"df53aa31a1827258e76f28cb74aa33e77853843f"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monken%2Fnode-pbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monken%2Fnode-pbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monken%2Fnode-pbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monken%2Fnode-pbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monken","download_url":"https://codeload.github.com/monken/node-pbac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248429129,"owners_count":21101786,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T16:23:36.795Z","updated_at":"2025-04-11T15:20:32.398Z","avatar_url":"https://github.com/monken.png","language":"JavaScript","funding_links":["https://github.com/sponsors/monken"],"categories":[],"sub_categories":[],"readme":"[![npm](http://img.shields.io/npm/v/pbac.svg?style=flat-square)](https://npmjs.org/package/pbac) [![npm](http://img.shields.io/npm/dm/pbac.svg?style=flat-square)](https://npmjs.org/package/pbac) [![Build Status](https://img.shields.io/travis/monken/node-pbac/master.svg?style=flat-square)](https://travis-ci.org/monken/node-pbac) ![license](https://img.shields.io/badge/license-mit-blue.svg?style=flat-square)\n\n# Policy Based Access Control\n\n**AWS IAM Policy inspired and (mostly) compatible evaluation engine**\n\nUse the power and flexibility of the AWS IAM Policy syntax in your own application to manage access control. For more details on AWS IAM Policies have a look at https://docs.aws.amazon.com/IAM/latest/UserGuide/policies_overview.html.\n\n## Installation\n\n```\nnpm install pbac\n```\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\nContents\n\n- [Synopsis](#synopsis)\n- [Constructor](#constructor)\n  - [Properties](#properties)\n- [Methods](#methods)\n  - [evaluate(params)](#evaluateparams)\n  - [validate(policy)](#validatepolicy)\n- [Reference](#reference)\n  - [Context](#context)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Synopsis\n\n```javascript\nvar PBAC = require('pbac');\n\nvar policies = [{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [{\n    \"Sid\": \"OptionalDescription\",\n    \"Effect\": \"Allow\",\n    \"Action\": [\n      \"iam:CreateUser\",\n      \"iam:UpdateUser\",\n      \"iam:DeleteUser\"\n    ],\n    \"Resource\": [\n      \"arn:aws:iam:::user/${req:UserName}\"\n    ],\n    \"Condition\": {\n      \"IpAddress\": {\n        \"req:IpAddress\": \"10.0.20.0/24\"\n      }\n    }\n  }]\n}];\n\nvar pbac = new PBAC(policies);\n\n// returns true\npbac.evaluate({\n  action: 'iam:CreateUser',\n  resource: 'arn:aws:iam:::user/testuser',\n  context: {\n    req: {\n      IpAddress: '10.0.20.51',\n      UserName: 'testuser',\n    }\n  }\n});\n```\n\n## Constructor\n\n```javascript\nvar pbac = new PBAC(policies, [options]);\n```\n\nConstructs a policy evaluator.\n\n### Properties\n\n\n* **`policies`** (Array|Object)\n  Either an array of policies or a single policy document. Have a look at https://docs.aws.amazon.com/IAM/latest/UserGuide/AccessPolicyLanguage_ElementDescriptions.html for a description of the policy syntax.\n* **`options`** (Object)\n    * `schema` (Object) - JSON schema that describes the policies. Defaults to the contents of schema.json that ships with this module.\n    * `validateSchema` (Boolean) - Validate the schema when the object is constructed. This can be disabled in production environment if it can be assumed that the schema is valid to improve performance when constructing new objects.\n    * `validatePolicies` (Boolean) - Policies passed to the constructor will be validated against the `schema`. Defaults to `true`. Can be disabled to improve performance if the policies can be assumed to be valid.\n    * `conditions` (Object) - Object of conditions that are supported in the `Conditions` attribute of policies. Defaults to `conditions.js` in this module. If conditions are passed to the constructor they will be merged with the conditions of the `conditions.js` module (with `conditions.js` taking precedence).\n\n\n## Methods\n\n\n### evaluate(params)\n\nTests an object against the policies and determines if the object passes.\nThe method will first try to find a policy with an explicit `Deny` for the combination of\n`resource`, `action` and `condition` (matching policy). If such policy exists, `evaluate` returns false.\nIf there is no explicit deny the method will look for a matching policy with an explicit `Allow`.\n`evaluate` will return `true` if such a policy is found. If no matching can be found at all,\n`evaluate` will return `false`. Please find a more thorough explanation of this process at https://docs.aws.amazon.com/IAM/latest/UserGuide/AccessPolicyLanguage_EvaluationLogic.html.\n\n```javascript\npbac.evaluate({\n  action: 'iam:CreateUser',\n  resource: 'arn:aws:iam:::user/testuser',\n  context: {\n    req: {\n      IpAddress: '10.0.20.51',\n      UserName: 'testuser',\n    }\n  }\n});\n```\n\n**Parameters**\n\n* **`params`** (Object)\n    * `action` (String) - Action to validate\n    * `resource` (String) - Resource to validate\n    * `context` (Object) - Nested object of context for interpolation of policy context. See [Context](#context).\n\n**Returns**: `boolean`, Returns `true` if `params` passes the policies, `false` otherwise\n\n### validate(policy)\n\nValidates one or many policies against the schema provided in the constructor.\nWill throw an error if validation fails.\n\n**Parameters**\n\n* **`policy`** (Array|Object)\n  Array of policies or a single policy object\n\n**Returns**: `boolean`, Returns `true` if the policies are valid\n\n\n## Reference\n\n### Context\n\nHave a look at https://docs.aws.amazon.com/IAM/latest/UserGuide/Policycontext.html to understand what policy context are, where they can be used and how they are interpreted. The `evaluate` method expects a `context` parameter which is a nested object that translates to colon-separated context.\n\n**Example:**\n\n```javascript\nvar context = {\n    req: {\n      IpAddress: '10.0.20.51',\n      UserName: 'testuser',\n    },\n    session: {\n      LoggedInDate: '2015-09-29T15:12:42Z',\n  },\n};\n```\n\nThis would translate to the context `req:IpAddress`, `req:UserName` and `session:LoggedInDate`.\n\n\n* * *\nThe MIT License (MIT)\n\nCopyright (c) 2018 Moritz Onken\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonken%2Fnode-pbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonken%2Fnode-pbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonken%2Fnode-pbac/lists"}