{"id":340955,"date":"2022-11-08T15:00:45","date_gmt":"2022-11-08T15:00:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=340955"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=340955","title":{"rendered":"<span>\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/78e\/36a\/275\/78e36a2750999d20cbbe177479925d95.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/78e\/36a\/275\/78e36a2750999d20cbbe177479925d95.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0421 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Compatible_Time-Sharing_System\">CTSS<\/a> (Compatible Time-Sharing System) \u041c\u0430\u0441\u0441\u0430\u0447\u0443\u0441\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0438\u0442\u0443\u0442\u0430 \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0432 1961 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043a \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0443. \u0412\u0441\u043a\u043e\u0440\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0438, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u0430\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443 \u043e\u0431\u0449\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c \u0438 \u0434\u0430\u043d\u043d\u044b\u043c. \u042d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044e \u043f\u0435\u0440\u0432\u044b\u0445 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u043e\u0432 \u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430\u0449\u0438\u0442\u0430 \u0441\u0442\u0430\u043b\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u041e\u0421 <a href=\"https:\/\/www.multicians.org\/\">Multics<\/a>. \u0421\u043f\u0443\u0441\u0442\u044f \u0433\u043e\u0434\u044b \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u0443\u0441\u043a\u0430 Multics, \u0417\u0430\u043b\u044c\u0442\u0446\u0435\u0440 (Saltzer) \u0438 \u0428\u0440\u0435\u0434\u0435\u0440 (Schroeder) \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0438 \u043a\u043d\u0438\u0433\u0443 &#171;<a href=\"https:\/\/www.cs.virginia.edu\/~evans\/cs551\/saltzer\/\">\u0417\u0430\u0449\u0438\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445<\/a>&#171;, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u0438 \u0443\u0447\u0442\u0435\u043d\u044b \u0443\u0440\u043e\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0435\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0418\u0445 \u0440\u0430\u0431\u043e\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0446\u0438\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0440\u0430\u0431\u043e\u0442 \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0432\u043e\u0439, \u0433\u0434\u0435 \u0431\u044b\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043c\u043d\u043e\u0433\u0438\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u043e\u043d\u044f\u0442\u0438\u0435 &#171;\u041d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0430\u044f \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f&#187;.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4b3\/f75\/657\/4b3f75657150e599a552708e5ed8969c.png\" width=\"583\" height=\"434\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4b3\/f75\/657\/4b3f75657150e599a552708e5ed8969c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044e \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 (ACL) &#8212; \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432 Multics &#8212; \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0434\u043e\u0441\u0442\u0443\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u043e\u043b\u0435\u0439 (RBAC), \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 (ABAC). \u0412 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0446\u0435\u043b\u0435\u0439 (Purpose Based Access Control, PBAC), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e <a href=\"https:\/\/www.cs.purdue.edu\/homes\/ninghui\/papers\/pbac_vldbj.pdf\">\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0432 2008 \u0433\u043e\u0434\u0443<\/a>, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u044f \u0441\u0442\u0430\u043b\u0430 \u0443\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. PBAC \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0441 \u0446\u0435\u043b\u0435\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u041e\u043d \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 RBAC \u0438 ABAC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c PBAC, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b RBAC \u0438 ABAC. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0433\u043e-\u043b\u0438\u0431\u043e \u0432 \u043a\u043e\u0434\u0435, \u043c\u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u042f \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0441\u044c \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0432 \u0441\u043e\u0437\u043d\u0430\u043d\u0438\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python.<\/p>\n<p>\u041c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a RBAC, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0443\u0447\u0438\u0432 ACL, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 RBAC \u0431\u044b\u043b \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 ACL. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">from types import NoneType from typing import Callable, TypeVar, Generic, Optional from dataclasses import dataclass from enum import Enum  PrincipalId = int  # Represents an individual seeking access (e.g. an engineer responding to an # incident) @dataclass class Principal:     id: PrincipalId     name: str   # Different access control methods require different types of metadata  # attached to records (e.g. ACLs, opt-in information) RecordMetadata = TypeVar(\"RecordMetadata\") RecordId = int   # Single patient record @dataclass class Record(Generic[RecordMetadata]):     id: RecordId     patient_name: str     dob: int     metadata: Optional[RecordMetadata] = None   # An action the principal would take on a `Record` or `Record`s class Action(Enum):     READ = 1     WRITE = 2<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0442\u0440\u0435\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c.<\/p>\n<ol>\n<li>\n<p><em>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043b (Principal)<\/em> &#8212; \u043b\u0438\u0446\u043e, \u043f\u044b\u0442\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c AWS (Amazon Web Services) IAM (Identity and Access Management) \u0434\u043b\u044f \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430 \u0438\u0437 \u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d.<\/p>\n<\/li>\n<li>\n<p><em>\u0417\u0430\u043f\u0438\u0441\u044c (Record)<\/em> &#8212; \u043e\u0431\u044a\u0435\u043a\u0442, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f Principal. \u0412 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0431\u043e\u043b\u0435\u0437\u043d\u0438, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u0438\u043b\u0438 \u043f\u0430\u043f\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a S3 \u0438\u043b\u0438 EC2 \u043e\u0442 AWS, \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u043e\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u0433\u0440\u0430\u0435\u0442 Record \u0432 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a object \u0438\u043b\u0438 resource \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438\u043b\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0445 \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u042f \u0432\u044b\u0431\u0440\u0430\u043b Record, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0431\u043e\u043b\u0435\u0437\u043d\u0438.<\/p>\n<\/li>\n<li>\n<p><em>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (Action)<\/em> &#8212; \u0442\u043e, \u0447\u0442\u043e Principal \u0445\u043e\u0447\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 Record.<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u044c \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: &#171;\u0418\u043c\u0435\u0435\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 Principal \u043f\u0440\u0430\u0432\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0430\u043a\u043e\u0435 Action \u0441 \u044d\u0442\u043e\u0439 Record?&#187;. ACL, RBAC \u0438 ABAC \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c\u044e \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u043c \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c System (\u0441\u0438\u0441\u0442\u0435\u043c\u0430), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c Action \u043d\u0430\u0434 \u043d\u0430\u0448\u0438\u043c\u0438 Record.<\/p>\n<pre><code class=\"python\">Authorizer = Callable[[Principal, Action, Record], bool]  class System:     def __init__(self, records: list[Record], authorizer: Authorizer):         self.records = records         self.is_authorized = authorizer      def get(         self,         record_id: RecordId,         principal: Principal         ) -> Optional[Record]:         \"\"\"Return a record if the Principal has Action.READ access to it and         return None if not         \"\"\"         for record in self.records:             if record_id == record.id and self.is_authorized(                 principal, Action.READ, record             ):                 return record         return None      def update(         self,         record_id: RecordId,         principal: Principal,         updates: dict         ):         \"\"\"Update the Record with id equal to record_id only if the         Principal has Action.WRITE access. Otherwise do nothing.         \"\"\"         for record in self.records:             if record.id == record_id and self.is_authorized(                 principal, Action.WRITE, record             ):                 for (k, v) in updates.items():                     setattr(record, k, v)<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 System \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f record \u0438 Authorizer (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0442\u043e\u0440). \u0418\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c. \u0412 ACL \u0438 ABAC \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043a \u043d\u0430\u0448\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044f\u043c, \u0430 \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RBAC \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 Record. \u041d\u043e \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u0438\u043c\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 authorizer \u0438 \u0435\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0443\u0441\u043f\u0435\u0445\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043e\u043a. \u0426\u0435\u043b\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f System \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0442\u0435\u0441\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f\u0445 Authorizer. \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0449\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"python\">import pytest  # Members of your engineering team. @pytest.fixture def principals() -> tuple[Principal, Principal]:     return (Principal(1, \"Alice\"), Principal(2, \"Bob\"))  # Patient records we need to protect. @pytest.fixture def records() -> list[Record[NoneType]]:     return [         Record[NoneType](1, \"Alyssa\", 1965),         Record[NoneType](2, \"Ben\", 1974),     ]  # In some cases, we are going to want metadata on our records. For example, # ACLs will be attached to records and ABAC will allow us to use any # attribute we want to attach to any record def records_with_metadata(     metadata: tuple[RecordMetadata, RecordMetadata]     ) -> list[Record[RecordMetadata]]:          return [         Record[RecordMetadata](1, \"Alyssa\", 1965, metadata[0]),         Record[RecordMetadata](2, \"Ben\", 1974, metadata[1]),     ]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043b\u0430\u043d \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2ee\/38e\/4eb\/2ee38e4ebae3214b365b0032a8f1edd9.png\" width=\"965\" height=\"180\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2ee\/38e\/4eb\/2ee38e4ebae3214b365b0032a8f1edd9.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">def authorizer_tests(authorized: Authorizer, records: list[Record]):     \"\"\"Asserts that:     1. Alice gets READ and WRITE access to both records.     2. Bob only gets READ access to Ben's record.     \"\"\"     system = System(records, authorized)      assert records[0] == system.get(records[0].id, ALICE)     assert not system.get(records[0].id, BOB)     assert records[1] == system.get(records[1].id, BOB)      system.update(records[0].id, ALICE, {\"dob\": 1994})     assert 1994 == system.get(records[0].id, ALICE).dob      system.update(records[1].id, BOB, {\"dob\": 2006})     assert 1974 == system.get(records[1].id, BOB).dob<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 System, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u041e\u0434\u043d\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043c\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c \u044f\u0432\u043d\u044b\u0435 \u043e\u0442\u043a\u0430\u0437\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c. \u0421\u0442\u043e\u0438\u0442 \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u044f\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u0435\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0440\u043e\u043b\u0435\u0439 RBAC \u0438 \u043f\u0440\u0430\u0432\u0438\u043b ABAC, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f.\u0412\u0441\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0438\u0436\u0435, \u0431\u0443\u0434\u0443\u0442 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435\u043c \u0434\u043e\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e Action.<\/p>\n<p><strong>\u0421\u043f\u0438\u0441\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c (ACL)<\/strong><\/p>\n<p>ACL \u0431\u044b\u043b\u0438 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b Multics \u0432 1965 \u0433\u043e\u0434\u0443. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043e\u043d\u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445. <a href=\"https:\/\/blog.symops.com\/2022\/06\/24\/aws-whats-new-iam\/\">\u041f\u0435\u0440\u0432\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0434\u043b\u044f S3 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u044b\u043b\u0438 ACL<\/a>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043e \u043f\u0430\u0446\u0438\u0435\u043d\u0442\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 ACL. ACL \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 Record). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u0435\u0436\u0434\u0443 Record \u0438 ACL \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443.<\/p>\n<p>\u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0442\u044c \u043d\u0430\u0448\u0438 ACL \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a Record, \u0430 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, record_id: RecordId) \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 ACL. \u0425\u043e\u0442\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ACL \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u043e\u0439, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b ACL \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0438 \u0441\u043b\u0430\u0431\u044b\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u0445 ACL \u0438 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c.<\/p>\n<pre><code class=\"python\">def test_acl(principals: tuple[Principal, Principal]):     @dataclass     class AccessControl:         principal: Principal         actions: set[Action]      (alice, bob) = principals     alice_rw = AccessControl(alice, {Action.READ, Action.WRITE})     bob_r = AccessControl(bob, {Action.READ})      # Create new records with ACLs directly attached     records: list[Record[list[AccessControl]]] = records_with_metadata(         ([alice_rw], [alice_rw, bob_r])     )      def acl_authorizer(         principal: Principal,         action: Action,         record: Record[list[AccessControl]],     ) -> bool:         from collections.abc import Iterable          if isinstance(record.metadata, Iterable):             for acl in record.metadata:                 if acl.principal.id == principal.id and action in acl.actions:                     return True         return False      # main.py::test_acl PASSED     authorizer_tests(acl_authorizer, records, principals)<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u042d\u0442\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 ACL. System \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0430\u0448\u0443 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Authorizer \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0440\u0430\u0432\u0438\u043b AccessControl, \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0445 \u043a Record, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u043b\u0438 Principal \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c Action \u043d\u0430\u0434 \u044d\u0442\u043e\u0439 Record.<\/p>\n<p>\u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u043e. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0432\u0430\u0441 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 Record. \u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 ACL \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0444\u0438\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u044e\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0441\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b Principal, \u0430 \u043d\u0435 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 Principal<\/p>\n<\/li>\n<li>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u0438\u043b\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 Record, \u0430 \u043d\u0435 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 Record.<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 Principal \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Group, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a Principal (\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 Group), \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u044b \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c Principal \u0432\/\u0438\u0437 Group \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044f ACL. Group \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0438 \u043d\u043e\u0441\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u043f\u043e\u043c\u043e\u0433\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0442\u043e \u0438 \u043a \u0447\u0435\u043c\u0443 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c Record (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Table (\u0442\u0430\u0431\u043b\u0438\u0446\u0430) \u0438\u043b\u0438 Folder (\u043f\u0430\u043f\u043a\u0430)), \u0442\u043e \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 Record \u0431\u0435\u0437 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u0438\u0445 ACL. \u0421\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 ACL, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u044b \u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 RBAC. \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0435\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0431\u044b\u043b\u043e \u0431\u044b \u044d\u043a\u0441\u0442\u0435\u0440\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c Action, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 Record, \u0438 \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 ACL. RBAC \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p><strong>\u0414\u043e\u0441\u0442\u0443\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u043e\u043b\u0435\u0439 (RBAC)<\/strong><\/p>\n<p>RBAC \u0431\u044b\u043b\u0430 <a href=\"https:\/\/csrc.nist.gov\/CSRC\/media\/Publications\/conference-paper\/1992\/10\/13\/role-based-access-controls\/documents\/ferraiolo-kuhn-92.pdf\">\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 1992 \u0433\u043e\u0434\u0443<\/a>, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 Principal \u0438 Record, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c. \u0420\u043e\u043b\u0438 (Roles) \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (Users) \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (Objects) \u0438\u043b\u0438, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430 Principal \u0438 Record. \u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 Action, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 Principal \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0430\u0434 \u044d\u0442\u0438\u043c\u0438 Record.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f79\/110\/67a\/f7911067adc99798e17f00b2b0c3a72d.png\" width=\"1180\" height=\"386\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f79\/110\/67a\/f7911067adc99798e17f00b2b0c3a72d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 1992 \u0433\u043e\u0434\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e RBAC<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0438\u0432\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e RBAC, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445.<\/p>\n<pre><code class=\"python\">def test_rbac(     principals: tuple[Principal, Principal],     records: list[Record[NoneType]]     ):      # The Role allows us to define relationships between many Principals and     # many Records in one place.     @dataclass     class Role:         name: str         principal_ids: set[PrincipalId]         permissions: list[tuple[set[Action], set[RecordId]]]          def has_principal(self, id: PrincipalId) -> bool:             return id in self.principal_ids          def has_action_for_record(             self, action: Action, record_id: RecordId         ) -> bool:             for (actions, record_ids) in self.permissions:                 if action in actions and record_id in record_ids:                     return True             return False      # Convenience method to pull ids out of records.     def get_ids(records) -> set[RecordId]:         return set(map(lambda r: r.id, records))      (alice, bob) = principals     roles = [         Role(             \"Admin\",             {alice.id},             [ ({Action.READ, Action.WRITE}, get_ids(records)) ],         ),         Role(             \"ReadOne\",             {bob.id},             [ ( { Action.READ }, get_ids(records[1:])) ]         ),     ]      def rbac_authorizer(         principal: Principal, action: Action, record: Record[NoneType]     ) -> bool:         for role in roles:             if (role.has_principal(principal.id) and                 role.has_action_for_record(action, record.id)             ):                 return True         return False      # main.py::test_rbac PASSED     authorizer_tests(rbac_authorizer, records, principals)<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0443 \u043d\u0430\u0448\u0438\u0445 record \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 metadata (\u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445), \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u043d\u0430\u0448\u0438 ACL. \u042d\u0442\u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Role, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 Record \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 RecordId. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e Record. RBAC \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0436\u0438\u0437\u043d\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0434\u0438\u043d Role \u0441 \u044d\u0442\u0438\u043c \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0442\u0435 \u0436\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a AccessControl \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 Record.<\/p>\n<p>\u0424\u0438\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u043d\u044b \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0440\u043e\u043b\u0435\u0432\u044b\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438, \u0433\u0434\u0435 Role \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0442 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u043a\u043e\u0432. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u0447\u0430\u0441\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 HR-\u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438, \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0432 \u043e\u0431\u0449\u0438\u0445 \u0447\u0435\u0440\u0442\u0430\u0445 \u0441\u0445\u0435\u043c\u0430\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438. \u0415\u0449\u0435 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u0438\u044f &#171;\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (active)&#187; \u0440\u043e\u043b\u0438 (Role). \u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u0441\u0435 Role, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u043c\u0443 Principal \u0438 Record. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0434\u0435\u0442\u0430\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0443\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0439 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435: \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c RBAC \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0433\u0440\u0443\u043f\u043f\u044b Principal, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f Principal \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 Role.<\/p>\n<p><strong>RBAC \u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0430\u044f \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f<\/strong><\/p>\n<p>RBAC \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438 \u043f\u0440\u043e\u0448\u043b\u0430 \u0434\u043e\u043b\u0433\u0438\u0439 \u043f\u0443\u0442\u044c \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440, \u043a\u0430\u043a \u0431\u044b\u043b\u0430 \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 1992 \u0433\u043e\u0434\u0443. \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c\u0438 \u043f\u043e \u043c\u0435\u0440\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043b\u0430\u043d. \u0421\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 Role \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u043f\u0435\u0440\u043c\u0443\u0442\u0430\u0446\u0438\u0439, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e Role, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u041f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e <a href=\"https:\/\/docs.aws.amazon.com\/service-authorization\/latest\/reference\/list_amazons3.html#amazons3-actions-as-permissions\">\u0434\u043b\u044f S3 \u0432 AWS \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 243 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 Actions (\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f)<\/a>. \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043d\u043e\u0432\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0449\u0438\u0442\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, IP-\u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u043e\u0433\u043e, \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u0432\u0440\u0435\u043c\u044f. \u0412 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 RBAC \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u044d\u0442\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439. \u0422\u043e\u0433\u0434\u0430 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 ABAC.<\/p>\n<p><strong>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 (ABAC)<\/strong><\/p>\n<p>RBAC \u0438 ACL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 (Principal) \u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 (Record). ABAC \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. \u0422\u0430\u043a\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442 Principal, System \u0438\u043b\u0438 \u0441\u0430\u043c\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u043e \u0436\u0435\u0441\u0442\u043a\u043e\u0439 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c\u044e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u043e\u0433\u0430\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 ABAC \u043e\u0447\u0435\u043d\u044c \u043c\u043e\u0449\u043d\u044b\u043c.<\/p>\n<p>ABAC \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u0430\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u0427\u0442\u043e\u0431\u044b \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 Policy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 Rule (\u043f\u0440\u0430\u0432\u0438\u043b), \u0430 \u0442\u0430\u043a\u0436\u0435 Principal \u0438 Record, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u043e\u0439\u0442\u0438 \u0442\u0435\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438.<\/p>\n<pre><code class=\"python\">def test_abac(     principals: tuple[Principal, Principal],     records: list[Record[NoneType]]     ):      import operator as op      # Comparison operators for comparing attributes to values in our Policies     operators = {         \"=\": op.eq,         \"!=\": op.ne,         \"any\": lambda _1, _2: True,         \"true\": lambda x, _: bool(x),         \"false\": lambda x, _: not x,     }      # A Rule holds the information required to look up an attribute in the     # right entity and compare it to a given value. An example of a rule     # could be \"RecordAttributes.email_opt_out = True\" to represent a record     # related to a user who has opted out of email correspondence.     @dataclass     class Rule:         entity_name: str         attribute_name: str         operator: str         compare_value: Optional[Any] = None      # Policy has Principals and Actions but not Records. Whether a Principal     # has access to a given record is determined by the conditions defined     # in the Rules     @dataclass     class Policy:         name: str         principal_ids: set[PrincipalId]         actions: set[Action]         rules: list[Rule]          def has_principal(self, id: PrincipalId) -> bool:             return id in self.principal_ids          def has_action(self, action: Action) -> bool:             return action in self.actions      (alice, bob) = principals      # Define policies to pass our tests (even if this is not a realistic use     # case for ABAC)     policies = [         Policy(             \"Admin\",             {alice.id},             {Action.READ, Action.WRITE},             [Rule(\"Record\", \"id\", \"any\")],         ),         Policy(             \"ReadOne\",             {bob.id},             {Action.READ},             [Rule(\"Record\", \"id\", \"=\", 2)],         ),     ]      # This will evaluate a policy for every record passed in. We're only     # going to support attributes in Records to get the tests to pass.     def abac_authorizer(         principal: Principal, action: Action, record: Record[NoneType]     ) -> bool:         for policy in policies:             if (policy.has_principal(principal.id) and                 policy.has_action(action)             ):                 for rule in policy.rules:                     if rule.entity_name == \"Record\":                         # Evaluate the Rule by pulling the attribute from the                         # Record and comparing it to the value in the Rule                         record_value = getattr(record, rule.attribute_name)                         if operators[rule.operator](                             record_value, rule.compare_value                         ):                             return True         return False      # main.py::test_abac PASSED     authorizer_tests(abac_authorizer, records, principals)<\/code><\/pre>\n<p>\u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0448\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 RecordId. \u042d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u043c \u0438\u043b\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c ABAC, \u043d\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442, \u043a\u0430\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 RBAC \u0438 ACL. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0438\u0441\u0442\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 ABAC \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 RBAC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c Rule \u0434\u043b\u044f Role \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 PrincipalId. \u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0433\u0438\u0431\u0440\u0438\u0434\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 ABAC\/RBAC, \u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0431\u044b, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0430\u0448\u0438 Role \u0434\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u043b\u0438\u0441\u044c \u043e Rule.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a\u043e\u0439 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043b\u0443\u0447\u0448\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0432\u0441\u044e \u043c\u043e\u0449\u044c ABAC? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430 \u043c\u0438\u043d\u0443\u0442\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0435\u0431\u0435 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b, \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043f\u043e\u043b\u0438\u0442\u0438\u043a.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3d6\/2cb\/e79\/3d62cbe79ed2e1cde9f88fd83830f7ae.png\" width=\"1600\" height=\"614\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3d6\/2cb\/e79\/3d62cbe79ed2e1cde9f88fd83830f7ae.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u0435 ABAC<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u0434 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043c\u0435\u0442\u043e\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u043e\u0447\u044c \u043d\u0430\u043c \u0433\u043b\u0443\u0431\u0436\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0430 ABAC.<\/p>\n<pre><code class=\"python\"># Convenience function to get the value of an attribute that a rule is     # referring to (e.g. `Environment.business_hours`)     def get_attribute_value_from_entity(rule: Rule, entities: list):         for entity in entities:             if rule.entity_name == type(entity).__name__:                 return getattr(entity, rule.attribute_name)      # A class to hold System attributes     @dataclass     class Environment:         business_hours: bool  # Is the current time within business hours      # We want to test a few individual policies. We'll do that by redefining     # abac_authorizer with different combinations of Policy and Environment     # objects     def get_system(         policy: Policy,         records: list[Record],         env: Environment = Environment(True)         ) -> System:          def abac_authorizer(             principal: Principal, action: Action, record: Record[NoneType]         ) -> bool:             if (policy.has_principal(principal.id) and                 policy.has_action(action)):                  for rule in policy.rules:                     value = get_attribute_value_from_entity(                         rule, [record, record.metadata, env, principal]                     )                     if operators[rule.operator](value, rule.compare_value):                         return True             return False          return System(records, abac_authorizer)      # Let's see if we can create some interesting policies ...      # Policy 1: Alice can only access Records during business hours     business_hours_policy = Policy(         \"BusinessHoursAccess\",         {alice.id},         {Action.READ},         [Rule(\"Environment\", \"business_hours\", \"true\")],     )      # Should be able to access during business hours     system = get_system(business_hours_policy, records, Environment(True))     assert system.get(1, alice)      # Should not be able to access after business hours     system = get_system(business_hours_policy, records, Environment(False))     assert not system.get(1, alice)      # Policy 2: Make sure we ignore `Record`s where the user opted out      # Let's start by attaching opt out attributes to each record     @dataclass     class RecordAttributes:         user_opt_out: bool      # Create a set of `Record`s with an attribute that indicates whether the     # user has opted out of email correspondence     opt_outs: list[Record[RecordAttributes]] = records_with_metadata(         (RecordAttributes(True), RecordAttributes(False))     )      opt_out_policy = Policy(         \"IgnoreOptOuts\",         {alice.id},         {Action.READ},         [Rule(\"RecordAttributes\", \"user_opt_out\", \"false\")],     )     system = get_system(opt_out_policy, opt_outs)      # Should not be able to access the first record (user_opt_out == True)     assert not system.get(1, alice)      # Should be able to access the second record (user_opt_out == False)     assert system.get(2, alice)      # Policy 3: Sorry Bob     no_bobs = Policy(         \"NoBobs\",         {bob.id},         {Action.READ},         [Rule(\"Principal\", \"name\", \"!=\", bob.name)],     )     system = get_system(no_bobs, records)     assert not system.get(1, bob)     assert not system.get(2, bob)      bob.name = \"Robert\"     assert system.get(1, bob)      # Still passing!     # main.py::test_abac PASSED<\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u0430\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0441\u0438\u043b\u0435 \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 ABAC. \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b ABAC \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 RBAC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0449\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u043b\u0438\u0442\u0438\u043a \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439. \u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u044d\u043a\u0441\u043f\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a, \u043d\u0435\u0436\u0435\u043b\u0438 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0437\u0434\u0435\u0441\u044c. \u0412\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/XACML\">XACML<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 ABAC.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c, \u0432\u044b \u043f\u043e\u0447\u0442\u0438 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0435 \u0438\u043b\u0438 \u0438\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 ABAC \u0438 RBAC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u044b. \u0421\u0443\u0442\u044c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0443 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0446\u0435\u043b\u0435\u0439 (PBAC), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 ABAC \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0440\u043e\u043b\u0435\u0439. \u0418\u0449\u0438\u0442\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 PBAC \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432.<\/p>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0443\u0440\u043e\u043a \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/VBKN\/\">Python Developer. Profeddional<\/a>, \u0433\u0434\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043c\u043e\u043a\u0438 \u0438 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438, high \u0438 low gear \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/VBKN\/\">\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0443\u0440\u043e\u043a<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/698080\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/698080\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0421 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Compatible_Time-Sharing_System\">CTSS<\/a> (Compatible Time-Sharing System) \u041c\u0430\u0441\u0441\u0430\u0447\u0443\u0441\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0438\u0442\u0443\u0442\u0430 \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0432 1961 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043a \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0443. \u0412\u0441\u043a\u043e\u0440\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0438, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u0430\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443 \u043e\u0431\u0449\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c \u0438 \u0434\u0430\u043d\u043d\u044b\u043c. \u042d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044e \u043f\u0435\u0440\u0432\u044b\u0445 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u043e\u0432 \u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430\u0449\u0438\u0442\u0430 \u0441\u0442\u0430\u043b\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u041e\u0421 <a href=\"https:\/\/www.multicians.org\/\">Multics<\/a>. \u0421\u043f\u0443\u0441\u0442\u044f \u0433\u043e\u0434\u044b \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u0443\u0441\u043a\u0430 Multics, \u0417\u0430\u043b\u044c\u0442\u0446\u0435\u0440 (Saltzer) \u0438 \u0428\u0440\u0435\u0434\u0435\u0440 (Schroeder) \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0438 \u043a\u043d\u0438\u0433\u0443 &#171;<a href=\"https:\/\/www.cs.virginia.edu\/~evans\/cs551\/saltzer\/\">\u0417\u0430\u0449\u0438\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445<\/a>&#171;, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u0438 \u0443\u0447\u0442\u0435\u043d\u044b \u0443\u0440\u043e\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0435\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0418\u0445 \u0440\u0430\u0431\u043e\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0446\u0438\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0440\u0430\u0431\u043e\u0442 \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0432\u043e\u0439, \u0433\u0434\u0435 \u0431\u044b\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043c\u043d\u043e\u0433\u0438\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u043e\u043d\u044f\u0442\u0438\u0435 &#171;\u041d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0430\u044f \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f&#187;.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044e \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 (ACL) &#8212; \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432 Multics &#8212; \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0434\u043e\u0441\u0442\u0443\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u043e\u043b\u0435\u0439 (RBAC), \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 (ABAC). \u0412 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0446\u0435\u043b\u0435\u0439 (Purpose Based Access Control, PBAC), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e <a href=\"https:\/\/www.cs.purdue.edu\/homes\/ninghui\/papers\/pbac_vldbj.pdf\">\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0432 2008 \u0433\u043e\u0434\u0443<\/a>, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u044f \u0441\u0442\u0430\u043b\u0430 \u0443\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. PBAC \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0441 \u0446\u0435\u043b\u0435\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u041e\u043d \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 RBAC \u0438 ABAC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c PBAC, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b RBAC \u0438 ABAC. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0433\u043e-\u043b\u0438\u0431\u043e \u0432 \u043a\u043e\u0434\u0435, \u043c\u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u042f \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0441\u044c \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0432 \u0441\u043e\u0437\u043d\u0430\u043d\u0438\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python.<\/p>\n<p>\u041c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a RBAC, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0443\u0447\u0438\u0432 ACL, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 RBAC \u0431\u044b\u043b \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 ACL. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">from types import NoneType from typing import Callable, TypeVar, Generic, Optional from dataclasses import dataclass from enum import Enum  PrincipalId = int  # Represents an individual seeking access (e.g. an engineer responding to an # incident) @dataclass class Principal:     id: PrincipalId     name: str   # Different access control methods require different types of metadata  # attached to records (e.g. ACLs, opt-in information) RecordMetadata = TypeVar(\"RecordMetadata\") RecordId = int   # Single patient record @dataclass class Record(Generic[RecordMetadata]):     id: RecordId     patient_name: str     dob: int     metadata: Optional[RecordMetadata] = None   # An action the principal would take on a `Record` or `Record`s class Action(Enum):     READ = 1     WRITE = 2<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0442\u0440\u0435\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c.<\/p>\n<ol>\n<li>\n<p><em>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043b (Principal)<\/em> &#8212; \u043b\u0438\u0446\u043e, \u043f\u044b\u0442\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c AWS (Amazon Web Services) IAM (Identity and Access Management) \u0434\u043b\u044f \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430 \u0438\u0437 \u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d.<\/p>\n<\/li>\n<li>\n<p><em>\u0417\u0430\u043f\u0438\u0441\u044c (Record)<\/em> &#8212; \u043e\u0431\u044a\u0435\u043a\u0442, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f Principal. \u0412 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0431\u043e\u043b\u0435\u0437\u043d\u0438, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u0438\u043b\u0438 \u043f\u0430\u043f\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a S3 \u0438\u043b\u0438 EC2 \u043e\u0442 AWS, \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u043e\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u0433\u0440\u0430\u0435\u0442 Record \u0432 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a object \u0438\u043b\u0438 resource \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438\u043b\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0445 \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u042f \u0432\u044b\u0431\u0440\u0430\u043b Record, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0431\u043e\u043b\u0435\u0437\u043d\u0438.<\/p>\n<\/li>\n<li>\n<p><em>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (Action)<\/em> &#8212; \u0442\u043e, \u0447\u0442\u043e Principal \u0445\u043e\u0447\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 Record.<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u044c \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: &#171;\u0418\u043c\u0435\u0435\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 Principal \u043f\u0440\u0430\u0432\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0430\u043a\u043e\u0435 Action \u0441 \u044d\u0442\u043e\u0439 Record?&#187;. ACL, RBAC \u0438 ABAC \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c\u044e \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u043c \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c System (\u0441\u0438\u0441\u0442\u0435\u043c\u0430), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c Action \u043d\u0430\u0434 \u043d\u0430\u0448\u0438\u043c\u0438 Record.<\/p>\n<pre><code class=\"python\">Authorizer = Callable[[Principal, Action, Record], bool]  class System:     def __init__(self, records: list[Record], authorizer: Authorizer):         self.records = records         self.is_authorized = authorizer      def get(         self,         record_id: RecordId,         principal: Principal         ) -> Optional[Record]:         \"\"\"Return a record if the Principal has Action.READ access to it and         return None if not         \"\"\"         for record in self.records:             if record_id == record.id and self.is_authorized(                 principal, Action.READ, record             ):                 return record         return None      def update(         self,         record_id: RecordId,         principal: Principal,         updates: dict         ):         \"\"\"Update the Record with id equal to record_id only if the         Principal has Action.WRITE access. Otherwise do nothing.         \"\"\"         for record in self.records:             if record.id == record_id and self.is_authorized(                 principal, Action.WRITE, record             ):                 for (k, v) in updates.items():                     setattr(record, k, v)<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 System \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f record \u0438 Authorizer (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0442\u043e\u0440). \u0418\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c. \u0412 ACL \u0438 ABAC \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043a \u043d\u0430\u0448\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044f\u043c, \u0430 \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RBAC \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 Record. \u041d\u043e \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u0438\u043c\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 authorizer \u0438 \u0435\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0443\u0441\u043f\u0435\u0445\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043e\u043a. \u0426\u0435\u043b\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f System \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0442\u0435\u0441\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f\u0445 Authorizer. \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0449\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"python\">import pytest  # Members of your engineering team. @pytest.fixture def principals() -> tuple[Principal, Principal]:     return (Principal(1, \"Alice\"), Principal(2, \"Bob\"))  # Patient records we need to protect. @pytest.fixture def records() -> list[Record[NoneType]]:     return [         Record[NoneType](1, \"Alyssa\", 1965),         Record[NoneType](2, \"Ben\", 1974),     ]  # In some cases, we are going to want metadata on our records. For example, # ACLs will be attached to records and ABAC will allow us to use any # attribute we want to attach to any record def records_with_metadata(     metadata: tuple[RecordMetadata, RecordMetadata]     ) -> list[Record[RecordMetadata]]:          return [         Record[RecordMetadata](1, \"Alyssa\", 1965, metadata[0]),         Record[RecordMetadata](2, \"Ben\", 1974, metadata[1]),     ]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043b\u0430\u043d \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">def authorizer_tests(authorized: Authorizer, records: list[Record]):     \"\"\"Asserts that:     1. Alice gets READ and WRITE access to both records.     2. Bob only gets READ access to Ben's record.     \"\"\"     system = System(records, authorized)      assert records[0] == system.get(records[0].id, ALICE)     assert not system.get(records[0].id, BOB)     assert records[1] == system.get(records[1].id, BOB)      system.update(records[0].id, ALICE, {\"dob\": 1994})     assert 1994 == system.get(records[0].id, ALICE).dob      system.update(records[1].id, BOB, {\"dob\": 2006})     assert 1974 == system.get(records[1].id, BOB).dob<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 System, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u041e\u0434\u043d\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043c\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c \u044f\u0432\u043d\u044b\u0435 \u043e\u0442\u043a\u0430\u0437\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c. \u0421\u0442\u043e\u0438\u0442 \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u044f\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u0435\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0440\u043e\u043b\u0435\u0439 RBAC \u0438 \u043f\u0440\u0430\u0432\u0438\u043b ABAC, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f.\u0412\u0441\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0438\u0436\u0435, \u0431\u0443\u0434\u0443\u0442 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435\u043c \u0434\u043e\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e Action.<\/p>\n<p><strong>\u0421\u043f\u0438\u0441\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c (ACL)<\/strong><\/p>\n<p>ACL \u0431\u044b\u043b\u0438 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b Multics \u0432 1965 \u0433\u043e\u0434\u0443. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043e\u043d\u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445. <a href=\"https:\/\/blog.symops.com\/2022\/06\/24\/aws-whats-new-iam\/\">\u041f\u0435\u0440\u0432\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0434\u043b\u044f S3 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u044b\u043b\u0438 ACL<\/a>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043e \u043f\u0430\u0446\u0438\u0435\u043d\u0442\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 ACL. ACL \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 Record). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u0435\u0436\u0434\u0443 Record \u0438 ACL \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443.<\/p>\n<p>\u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0442\u044c \u043d\u0430\u0448\u0438 ACL \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a Record, \u0430 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, record_id: RecordId) \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 ACL. \u0425\u043e\u0442\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ACL \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u043e\u0439, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b ACL \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0438 \u0441\u043b\u0430\u0431\u044b\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u0445 ACL \u0438 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c.<\/p>\n<pre><code class=\"python\">def test_acl(principals: tuple[Principal, Principal]):     @dataclass     class AccessControl:         principal: Principal         actions: set[Action]      (alice, bob) = principals     alice_rw = AccessControl(alice, {Action.READ, Action.WRITE})     bob_r = AccessControl(bob, {Action.READ})      # Create new records with ACLs directly attached     records: list[Record[list[AccessControl]]] = records_with_metadata(         ([alice_rw], [alice_rw, bob_r])     )      def acl_authorizer(         principal: Principal,         action: Action,         record: Record[list[AccessControl]],     ) -> bool:         from collections.abc import Iterable<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-340955","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340955"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340955\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}