1. 程式人生 > >Zookeeper官網文件—第二章 2.概述-概述

Zookeeper官網文件—第二章 2.概述-概述

ZooKeeper使用ACLs控制訪問

ZooKeeper使用ACL來控制訪問znodes(Zookeeper資料樹上的資料節點). ACL的實現與UNIX的檔案訪問許可權十分相似: 它使用許可權bit來允許/拒絕一個節點和位元許可範圍的各種操作. 不同於傳統的UNITX許可權系統,一個Zookeeper節點沒有三個傳統作用域的限制:user(檔案所屬使用者)、group,和world(其他). ZooKeeper沒有節點所有者的概念. 而是ACL指定集合,與該許可權相關的ID集合.

也要注意ACL僅適用於一個特定的znode. 它不適用於其子節點.例如,如果/appp僅僅被ip為172.16.16.1的讀取,/app/status是有開放全部讀取許可權的,任何人都可以讀取/app/status;ACLs不是遞迴的.

Zookeeer支援可插拔式的外掛認證方案. Ids指定使用這個形式scheme:id,shceme是ID對應的認證方案. 例如, ip:172.16.16.1是一個主機地址為172.16.16.1的ID.

當客戶端連線Zookeeper並進行認證,Zookeeper將與符合這個客戶端的所有ids關聯起來. 當客戶端試圖訪問一個節點時,這些ids會檢查znodes節點的ALC.  ACLs是由成對組成的(scheme:expression,perms). ACLs are made up of pairs of (scheme:expression, perms). 表示式的格式指定了許可權. 例如,這個鍵值對給所有19.22開頭的客戶端體哦概念股了讀取許可權.

ACL許可權

ZooKeeper支援如下許可權:

  • CREATE: 你可以建立一個子節點.

  • READ: 你可以讀取節點的資料和獲得子節點列表.

  • WRITE: 你可以設定節點的資料

  • DELETE: 你可以刪除一個子節點

  • ADMIN: 你可以設定許可權

CREATE和DELETE許可權從WRITE許可權中分離開來,為了更好的訪問控制. CREATEDELETE的情況如下:

你想要A有許可權設定節點資料,而不能CREATEDELETE子節點.

CREATE而無DELETE: 客戶端在父目錄發起建立Zookeeper節點的請求.你想要所有客戶端都能夠新增,但是隻有發起該請求的能夠刪除.(這個情況類似與追加檔案許可權)

而且,ADMIN許可權存在是因為Zookeeper沒有檔案所有者的概念. 某種意義上,ADMIN許可權就相當於檔案所有者. ZooKeeper不支援LOOKUP許可權(目錄上執行許可權位允許你檢視,即使你不能列出目錄). 所有人都隱含LOOKUP許可權. 允許你檢視節點狀態,但是不能進行其他操作.(有些問題,在一個不存在的節點上執行呼叫zoo_exists(),沒有許可權進行安全檢查.)

內建的ACL方案

ZooKeeeper有如下內建構建:

  • world 有一個獨立ID, 代表任意一個人.

  • auth 不使用任何ID,代表任何許可權使用者.

  • digest 使用使用者名稱:密碼字串生成一個MD5,當作時ACL ID. 認證時通過傳送使用者名稱:密碼的明文來進行的. 當使用ACL時,表示式將會使用使用者名稱:base64,base64時SHA1密碼加密.

  • ip 使用客戶端IP作為一個ACL ID身份. 這個ACL表示式的格式為addr/bits ,此時addr中的有效位與客戶端addr中的有效位進行比對.

ZooKeeper C client API

The following constants are provided by the ZooKeeper C library:

  • const int ZOO_PERM_READ; //can read node’s value and list its children

  • const int ZOO_PERM_WRITE;// can set the node’s value

  • const int ZOO_PERM_CREATE; //can create children

  • const int ZOO_PERM_DELETE;// can delete children

  • const int ZOO_PERM_ADMIN; //can execute set_acl()

  • const int ZOO_PERM_ALL;// all of the above flags OR’d together

The following are the standard ACL IDs:

  • struct Id ZOO_ANYONE_ID_UNSAFE; //(‘world’,’anyone’)

  • struct Id ZOO_AUTH_IDS;// (‘auth’,’’)

ZOO_AUTH_IDS empty identity string should be interpreted as “the identity of the creator”.

ZooKeeper client comes with three standard ACLs:

  • struct ACL_vector ZOO_OPEN_ACL_UNSAFE; //(ZOO_PERM_ALL,ZOO_ANYONE_ID_UNSAFE)

  • struct ACL_vector ZOO_READ_ACL_UNSAFE;// (ZOO_PERM_READ, ZOO_ANYONE_ID_UNSAFE)

  • struct ACL_vector ZOO_CREATOR_ALL_ACL; //(ZOO_PERM_ALL,ZOO_AUTH_IDS)

The ZOO_OPEN_ACL_UNSAFE is completely open free for all ACL: any application can execute any operation on the node and can create, list and delete its children. The ZOO_READ_ACL_UNSAFE is read-only access for any application. CREATE_ALL_ACL grants all permissions to the creator of the node. The creator must have been authenticated by the server (for example, using “digest” scheme) before it can create nodes with this ACL.

The following ZooKeeper operations deal with ACLs:

  • int zoo_add_auth (zhandle_t *zh,const char* scheme,const char* cert, int certLen, void_completion_t completion, const void *data);

The application uses the zoo_add_auth function to authenticate itself to the server. The function can be called multiple times if the application wants to authenticate using different schemes and/or identities.

  • int zoo_create (zhandle_t *zh, const char *path, const char *value,int valuelen, const struct ACL_vector *acl, int flags,char *realpath, int max_realpath_len);

zoo_create(...) operation creates a new node. The acl parameter is a list of ACLs associated with the node. The parent node must have the CREATE permission bit set.

  • int zoo_get_acl (zhandle_t *zh, const char *path,struct ACL_vector *acl, struct Stat *stat);

This operation returns a node’s ACL info.

  • int zoo_set_acl (zhandle_t *zh, const char *path, int version,const struct ACL_vector *acl);

This function replaces node’s ACL list with a new one. The node must have the ADMIN permission set.

Here is a sample code that makes use of the above APIs to authenticate itself using the “foo” scheme and create an ephemeral node “/xyz” with create-only permissions.

Note

This is a very simple example which is intended to show how to interact with ZooKeeper ACLs specifically. See .../trunk/src/c/src/cli.c for an example of a C client implementation

#include <string.h>
#include <errno.h>

#include "zookeeper.h"

static zhandle_t *zh;

/**
 * In this example this method gets the cert for your
 *   environment -- you must provide
 */
char *foo_get_cert_once(char* id) { return 0; }

/** Watcher function -- empty for this example, not something you should
 * do in real code */
void watcher(zhandle_t *zzh, int type, int state, const char *path,
             void *watcherCtx) {}

int main(int argc, char argv) {
  char buffer[512];
  char p[2048];
  char *cert=0;
  char appId[64];

  strcpy(appId, "example.foo_test");
  cert = foo_get_cert_once(appId);
  if(cert!=0) {
    fprintf(stderr,
            "Certificate for appid [%s] is [%s]\n",appId,cert);
    strncpy(p,cert, sizeof(p)-1);
    free(cert);
  } else {
    fprintf(stderr, "Certificate for appid [%s] not found\n",appId);
    strcpy(p, "dummy");
  }

  zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);

  zh = zookeeper_init("localhost:3181", watcher, 10000, 0, 0, 0);
  if (!zh) {
    return errno;
  }
  if(zoo_add_auth(zh,"foo",p,strlen(p),0,0)!=ZOK)
    return 2;

  struct ACL CREATE_ONLY_ACL[] = {{ZOO_PERM_CREATE, ZOO_AUTH_IDS}};
  struct ACL_vector CREATE_ONLY = {1, CREATE_ONLY_ACL};
  int rc = zoo_create(zh,"/xyz","value", 5, &CREATE_ONLY, ZOO_EPHEMERAL,
                      buffer, sizeof(buffer)-1);

  /** this operation will fail with a ZNOAUTH error */
  int buflen= sizeof(buffer);
  struct Stat stat;
  rc = zoo_get(zh, "/xyz", 0, buffer, &buflen, &stat);
  if (rc) {
    fprintf(stderr, "Error %d for %s\n", rc, __LINE__);
  }

  zookeeper_close(zh);
  return 0;
}
      

相關推薦

Zookeeper第二 2.概述-概述

ZooKeeper使用ACLs控制訪問ZooKeeper使用ACL來控制訪問znodes(Zookeeper資料樹上的資料節點). ACL的實現與UNIX的檔案訪問許可權十分相似: 它使用許可權bit來允許/拒絕一個節點和位元許可範圍的各種操作. 不同於傳統的UNITX許可權系統,一個Zookeeper節點沒

ASP.NET Core 中文 第二 指南(2)用 Visual Studio 和 ASP.NET Core MVC 建立首個 Web API

HTTP 協議不僅僅提供網頁服務。它也是一個構建公開服務和資料 API 的強大平臺。HTTP 協議是簡單、靈活、無處不在的。幾乎你能想到的任何平臺上都有 HTTP 支援,所以 HTTP 服務能夠傳送到多種客戶端, 包括瀏覽器,移動裝置和傳統的桌面應用程式。 在本教程中,你將建立一個簡單的 Web API 來

Memcache精選整理

MemCache全名可以看做MemoryCache。功能是做快取。為什麼不說他是一個快取資料庫呢,因為它很輕量,只是儲存一般的K-V鍵值對,相比Redis而言,Redis功能更多,比如分散式、持久化、支援的資料結構多這些特點而言,MemCache更簡單,只基於LruCache做快取。

【Maven】Optional & Exclusion Maven中的可選依賴和依賴性排除

本節介紹Maven中的可選依賴和依賴性排除功能。 【原文連結】 Optional 依賴 如果明確一個 project 無論出於什麼原因考慮都不可能繼續分割成子專案,則其依賴可以使用 optional。 如果其他 project 依賴了 使用 optional 的

yolov3 設計到編譯,訓練,map等引數測試,windows和linux均有說明

GitHub原文:https://github.com/AlexeyAB/darknet#how-to-compile-on-linux 參考部落格原址: https://blog.csdn.net/qq_34806812/article/details/813851

ASP.NET Core 中文 第二 指南(1)用 Visual Studio Code 在 macOS 上建立首個 ASP.NET Core 應用程式

本文已更新,最後更新於2017年4月28日 聯絡我們: QQ Group: 436035237 (dotNet Core Studying Group) GitHub Repo: https://github.com/dotnetcore/aspnetcore-doc-cn/ 以下為老翻譯存檔 本節將

ASP.NET Core 中文 第二 指南 (09) 使用 Swagger 生成 ASP.NET Web API 線上幫助測試

對於開發人員來說,構建一個消費應用程式時去了解各種各樣的 API 是一個巨大的挑戰。 在你的 Web API 專案中使用 Swagger 的 .NET Core 封裝 Swashbuckle 可以幫助你建立良好的文件和幫助頁面。 Swashbuckle 可以通過修改 Startup.cs 作為一組 NuGe

ASP.NET Core 中文 第二 指南(4.10)檢查自動生成的Detail方法和Delete方法

開啟 Movie 控制器並檢視 Details 方法: // GET: Movies/Details/5 public async Task<IActionResult> Details(int? id) { if (id == null) { return No

ASP.NET Core 中文 第二 指南(8) 使用 dotnet watch 開發 ASP.NET Core 應用程式

本文已更新,最後更新於2017年4月27日 以下為老翻譯存檔 介紹 dotnet watch 是一個開發階段在原始檔發生變動的情況下使用 dotnet 命令的工具。 當代碼發生變動的時候可以用來執行編譯,執行測試,或者釋出操作。 在本教程中,我們將使用一個現有的計算兩個數字之和以及乘積的 WebAp

ASP.NET Core 中文 第二 指南(4.1)ASP.NET Core MVC 與 Visual Studio 入門

這篇教程將告訴你如何使用 Visual Studio 2015 構建一個 ASP.NET Core MVC Web 應用程式的基礎知識。 安裝 Visual Studio 和 .NET Core 安裝 Visual Studio Community 2015。選擇 Community 下載並執行預設安裝

ASP.NET Core 中文 第二 指南(4.6)Controller 方法與檢視

我們已經初步的建立了一個 movie 應用程式,但是展示並不理想。我們不希望看到 release date 欄位顯示時間並且 ReleaseDate 應該是兩個單詞。 開啟 Models/Movie.cs 檔案並新增下面高亮的程式碼行: public class Movie { public in

ASP.NET Core 中文 第二 指南(5) 在 Nano Server 上執行ASP.NET Core

注意:本教程使用 Windows Server Technical Preview 5 的預發行版本的 Nano Server 安裝選項。 你可以在虛擬硬碟映像中用來內部演示和評估,但不能在生產環境中使用該軟體。可通過 https://go.microsoft.com/fwlink/?LinkId=624

ASP.NET Core 中文 第二 指南(4.5)使用 SQL Server LocalDB

ApplicationDbContext 類負責連線資料庫並將 Movie 物件和資料記錄進行對映。 Startup.cs 檔案中,資料庫上下文是在 ConfigureServices 方法中用 Dependency Injection 容器進行註冊的。 // This method gets called

ASP.NET Core 中文 第二 指南(3)用 Visual Studio 釋出一個 Azure 雲 Web 應用程式

設定開發環境 注意 如果你的機器之前任何依賴都沒有安裝過,SDK 的安裝時間將會超過30分鐘。 建立一個 Web 應用程式 在 Visual Studio 的 Start 頁面,點選 New Project。 另外,你也可以通過選單新建專案。點選 File > New > Proje

Unity shader 全方位學習(一)

What?? Shader,看起來好高階的樣子,是的,這是Unity中高階進階的必備。因此,兄弟我就在此記下我學習官網的一些心得。 此為一。主要介紹些Surface Shaders的知識。具體的大家也可去官網(如下)學習。 一、概念篇 1.基準:unity裡的s

Jenkins 翻譯彙總

使用者手冊 使用 Jenkins 使用憑證 管理 Jenkins 配置系統 管理安全 管理工具 管理外掛 Jenkins CLI 命令列介面 Script Console 指令碼終端

[譯]webpack :指南 -- 7.程式碼分割

原創翻譯,轉載請註明出處。  原文地址:https://webpack.js.org/guides/code-splitting-import/ 動態引入 目前,一個把類函式的模組載入語法import()新增到ECMAScript的提議,正在討論中。 ES2015載入器細則定義import()為一個能在執

Objective-C 程式語言(五)-屬性的宣告

Declared Properties The Objective-C declared properties feature provides a simple way to declare and implement an object’s accessor methods. Ov

Objective-C 程式語言(十三 終結篇)-詞彙表

Glossary abstract class   A class that’s defined solely so that other classes can inherit from it. Programs don’t use instances of an abstract class; the

ABP vNext EventBus For RabbitMQ 分散式事件匯流排使用注意事項_補充

![](https://img2020.cnblogs.com/blog/2193154/202101/2193154-20210109141150930-150842908.png) [https://docs.abp.io/zh-Hans/abp/latest/Distributed-Event-Bus