iam身份驗證以及訪問控制_如何將受限訪問IAM用戶添加到EKS群集

iam身份驗證以及訪問控制

介紹 (Introduction)

Elastic Kubernetes Service (EKS) is the fully managed Kubernetes service from AWS. It is deeply integrated with many AWS services, such as AWS Identity and Access Management (IAM) (for authentication to the cluster), Amazon CloudWatch (for logging), Auto Scaling Groups (for scaling worker nodes), and Amazon Virtual Private Cloud (VPC) (for networking). Many companies trust Amazon EKS to run their containerized workloads.

Elastic Kubernetes服務(EKS)是AWS的完全托管的Kubernetes服務。 它與許多AWS服務深度集成,例如AWS Identity and Access Management(IAM)(用于對集群進行身份驗證),Amazon CloudWatch(用于日志記錄),Auto Scaling Groups(用于擴展工作節點)和Amazon Virtual Private Cloud( VPC)(用于聯網)。 許多公司信任Amazon EKS來運行其容器化工作負載。

EKS uses IAM to provide authentication to your Kubernetes cluster (via the aws eks get-token command, or the AWS IAM Authenticator for Kubernetes). For authorization it relies on native Kubernetes Role Based Access Control (RBAC). IAM is used for authentication to your EKS Cluster. And you can manage the permissions for interacting with your cluster’s Kubernetes API through the native Kubernetes RBAC system.

EKS使用IAM為您的Kubernetes集群提供身份驗證(通過aws eks get-token eks aws eks get-token命令或適用于Kubernetes的AWS IAM Authenticator )。 對于授權,它依賴于本地Kubernetes基于角色的訪問控制(RBAC) 。 IAM用于對EKS群集進行身份驗證。 而且,您可以通過本地Kubernetes RBAC系統管理與群集的Kubernetes API交互的權限。

如何創建IAM用戶 (How to create an IAM User)

Go to your AWS Console where you will find the IAM service listed under the “Security, Identity & Compliance” group. Inside the IAM dashboard click on the Users tab and click the “Add User” button.

轉到您的AWS控制臺 ,您將在其中找到“安全性,身份和合規性”組下列出的IAM服務 。 在IAM儀表板內,單擊“用戶”選項卡,然后單擊“添加用戶”按鈕。

Create a new user and allow the user programmatic access by clicking on the "Programmatic access" checkbox. You do not need any particular permission for your user to access EKS. You can go ahead without selecting any permission.

創建一個新用戶,并通過單擊“程序訪問”復選框來允許該用戶以程序訪問 。 您不需要用戶的任何特殊權限即可訪問EKS。 您無需選擇任何權限即可繼續操作。

After the user is created, you will have access to the user's Access Key ID and Secret Access Key. You will be required to use these keys in the next step.

創建用戶后,您將有權訪問用戶的訪問密鑰ID秘密訪問密鑰 。 您將需要在下一步中使用這些鍵。

配置AWS CLI (Configure the AWS CLI)

Configuring your AWS CLI with a new user is as simple as running the aws configure command and providing the AWS Access Key ID and the AWS Secret Access Key. The Default region name and Default Output format are optional, though.

使用新用戶配置AWS CLI就像運行aws configure命令并提供AWS Access Key IDAWS Secret Access Key 。 但是, Default region nameDefault Output format是可選的。

$ aws configure --profile eks-user
AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text

Once configured you can test to see if the user is properly configured using the aws sts get-caller-identity command:

配置完成后,您可以使用aws sts get-caller-identity命令測試是否正確配置了用戶:

$ aws sts get-caller-identity --profile eks-user

If the user is properly configured with the aws cli utility you should see a response like the one shown below:

如果使用aws cli實用程序正確配置了用戶,您應該會看到如下所示的響應:

{"UserId": "AIDAX7JPBEM4A6FTJRTMB","Account": "123456789012","Arn": "arn:aws:iam::123456789012:user/eks-user"
}

為用戶創建角色和RoleBinding (Creating a Role and RoleBinding for the user)

With your IAM user properly configured, you can go ahead and create a role for the user. This snippet of code creates a role named eks-user-role with a modest list permission to the pods resource in your cluster.

正確配置IAM用戶后,您可以繼續為該用戶創建角色。 此代碼段創建一個名為eks-user-role ,對集群中的pods資源具有適度的list權限。

kind: Role
metadata:name: eks-user-role
rules:
- apiGroups: [""]resources: ["pods"]verbs: ["list"]

Save the above snippet of code in a file and then apply the Role to your Kubernetes cluster:

將上述代碼片段保存在文件中,然后apply Role應用于您的Kubernetes集群:

$ kubectl apply -f role.yaml

With the role configured you need to create a corresponding RoleBinding:

配置了角色后,您需要創建相應的RoleBinding:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:name: eks-user-role-binding
subjects:
- kind: Username: eks-userapiGroup: rbac.authorization.k8s.io
roleRef:kind: Rolename: eks-user-roleapiGroup: rbac.authorization.k8s.io

Save the above snippet of code in a file and then apply the Role Binding to your Kubernetes cluster:

將上述代碼片段保存在文件中,然后apply角色綁定應用于您的Kubernetes集群:

$ kubectl apply -f role-binding.yaml

將用戶添加到aws-auth配置圖 (Adding the user to the aws-auth configmap)

If you want to grant additional AWS users or roles the ability to interact with your EKS cluster, you must add the users/roles to the aws-auth ConfigMap within Kubernetes in the kube-system namespace.

如果要授予其他AWS用戶或角色與EKS集群進行交互的能力,則必須將用戶/角色添加到kube-system命名空間中Kubernetes中的aws-auth ConfigMap中。

You can do this by either editing it using the kubectl edit command:

您可以使用kubectl edit命令kubectl edit

$ kubectl edit configmap aws-auth -n kube-system

Or by importing the aws-auth ConfigMap and applying the changes:

或通過導入aws-auth ConfigMap并應用更改:

$ kubectl get configmap aws-auth -n kube-system -o yaml > aws-auth.yaml

Add the user under the mapUsers as an item in the aws-auth ConfigMap:

將用戶添加到mapUsers下,作為aws-auth ConfigMap中的一項:

data:mapUsers: |- userarn: arn:aws:iam::123456789012:user/eks-userusername: eks-usergroups:- eks-role

If the user is properly configured you should be able to list pods in the Cluster:

如果正確配置了用戶,則您應該能夠在集群中列出Pod:

$ kubectl get pods --as eks-user

The --as flag impersonates the request to Kubernetes as the given user. You can use this flag to test permissions for any given user.

--as標志以給定用戶身份向Kubernetes發出請求。 您可以使用此標志來測試任何給定用戶的權限。

配置用戶權限 (Configuring permissions for the user)

The role which you defined previously only had permission to list pods. The eks-user cannot access any other Kubernetes resources like Deployments, ConfigMaps, Events, Secrets, logs or even shell into a given pod.

您先前定義的角色僅具有列出窗格的權限。 eks eks-user無法訪問任何其他Kubernetes資源,如Deployments,ConfigMap,Events,Secrets,日志甚至是shell到給定的pod中。

In a real-world scenario, you will need to provide permissions to a user to access the required resources. The below snippet of code provides access to resources such as events, pods, deployments, configmaps and secrets.

在實際情況下,您將需要向用戶提供訪問所需資源的權限。 下面的代碼段提供對資源的訪問,例如eventspodsdeploymentsconfigmapssecrets

rules:
- apiGroups: [""]resources: ["events"]verbs: ["get", "list", "watch"]
- apiGroups: [""]resources: ["pods", "pods/log", "pods/exec"]verbs: ["list", "get", "create", "update", "delete"]
- apiGroups: ["extensions", "apps"]resources: ["deployments"]verbs: ["list", "get", "create", "update", "delete"]
- apiGroups: [""]resources: ["configmaps"]verbs: ["list", "get", "create", "update", "delete"]
- apiGroups: [""]resources: ["secrets"]verbs: ["list", "get", "create", "update", "delete"]

Add the above permissions to the role.yaml file and apply the changes, using kubectl apply -f.

使用kubectl apply -f將以上權限添加到role.yaml文件并應用更改。

測試,測試和測試! (Test, test and test!)

Now go ahead and test to see if the permissions have been properly applied to the eks-user. You can test the same using the above mentioned --as USERNAME flag or set the eks-user as the default profile for the aws cli.

現在繼續進行測試,以查看權限是否已正確地應用于eks-user 。 您可以使用上面提到的--as USERNAME標志進行測試,或者將--as USERNAME eks-user設置為aws cli的默認配置文件。

$ export AWS_PROFILE=eks-user

Once configured you can test to see if the user is properly configured using the aws sts get-caller-identity command:

配置完成后,您可以使用aws sts get-caller-identity命令測試用戶是否配置正確:

$ aws sts get-caller-identity

You should see a response like the following, indicating the user is properly configured with your aws cli utility:

您應該看到類似以下的響應,表明已使用aws cli實用程序正確配置了用戶:

{"UserId": "AIDAX7JPBEM4A6FTJRTMB","Account": "123456789012","Arn": "arn:aws:iam::123456789012:user/eks-user"
}

Test the permissions of the user with the below-mentioned commands.

使用以下命令測試用戶的權限。

$ kubectl get pods
$ kubectl get secrets
$ kubectl get configmaps
$ kubectl get deployments
$ kubectl logs <pod-name>
$ kubectl exec -it <pod-name> sh
$ kubectl create configmap my-cm --from-literal=db_username=<USERNAME> --from-literal=db_host=<HOSTNAME>
$ kubectl create secret generic my-secret --from-literal=db_password=<SOME_STRONG_PASSWORD>

Simply put, the eks-user user should be able to perform all the actions specified in the verbs array for pods, secrets, configmaps, deployments, and events. You can read more about it here Kubernetes Authorization Overview.

簡而言之, eks-user用戶應該能夠執行verbs數組中針對podssecretsconfigmapsdeploymentsevents所指定的所有動作。 您可以在此處閱讀有關Kubernetes授權概述的更多信息。

是否可以 (Can-I or Not)

You can use auth can-i to check if you have permission to a resource. To see if you have the permission to get pods simply run:

您可以使用auth can-i來檢查您是否有權使用資源。 要查看您是否有權獲得吊艙,只需運行:

$ kubectl auth can-i get pods

The answer will be a simple yes or no. Amazing, isn’t it?

答案將是簡單的yesno 。 太神奇了,不是嗎?

Wanna check if you have cluster-admin permissions? Fire this:

想檢查您是否具有cluster-admin權限? 觸發此:

$ kubectl auth can-i "*" "*"

結語 (Wrap up)

EKS provides the Kubernetes control plane with the backend persistence layer. The Kubernetes API server and the master nodes are provisioned and scaled across various availability zones, resulting in high availability and eliminating a single point of failure. An AWS-managed Kubernetes cluster can withstand the loss of an availability zone.

EKS為??Kubernetes控制平面提供了后端持久層。 Kubernetes API服務器和主節點在各種可用性區域中進行配置和擴展,從而實現了高可用性并消除了單點故障。 由AWS管理的Kubernetes集群可以承受可用性區域的丟失。

Access and authorization controls are critical for any security system. Kubernetes provides us with an awesome robust RBAC permission mechanism.

訪問和授權控制對于任何安全系統都是至關重要的。 Kubernetes為我們提供了強大的RBAC許可機制。

Originally published at faizanbashir.me

最初發表在 faizanbashir.me

翻譯自: https://www.freecodecamp.org/news/adding-limited-access-iam-user-to-eks-cluster/

iam身份驗證以及訪問控制

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390685.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390685.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390685.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

一步一步構建自己的管理系統①

2019獨角獸企業重金招聘Python工程師標準>>> 系統肯定要先選一個基礎框架。 還算比較熟悉Spring. 就選Spring boot postgres mybatis. 前端用Angular. 開始搭開發環境&#xff0c;開在window上整的。 到時候再放到服務器上。 自己也去整了個小服務器&#xff0c;…

面向對象面向過程

1、面向語句&#xff1a; 直接寫原生的sql語句&#xff0c;但是這樣代碼不容易維護。改一個方法會導致整個項目都要改動&#xff0c; 2、面向過程 定義一些函數&#xff0c;用的時候就調用不用就不調用。但是這也有解決不了的問題&#xff0c;如果要維護需要改動代碼&#xff0…

python邊玩邊學_邊聽邊學數據科學

python邊玩邊學Podcasts are a fun way to learn new stuff about the topics you like. Podcast hosts have to find a way to explain complex ideas in simple terms because no one would understand them otherwise &#x1f642; In this article I present a few episod…

react css多個變量_如何使用CSS變量和React上下文創建主題引擎

react css多個變量CSS variables are really cool. You can use them for a lot of things, like applying themes in your application with ease. CSS變量真的很棒。 您可以將它們用于很多事情&#xff0c;例如輕松地在應用程序中應用主題。 In this tutorial Ill show you …

vue 自定義 移動端篩選條件

1.創建組件 components/FilterBar/FilterBar.vue <template><div class"filterbar" :style"{top: top px}"><div class"container"><div class"row"><divclass"col":class"{selected: ind…

PSP

姓名&#xff1a;袁亞琴 日期&#xff1a;11月27日 教師&#xff1a;王建民 課程&#xff1a;PSP 項目計劃日志&#xff1a; PSP Planning . Estimate Development . Analysis . Design Spec . Design Review . …

如何在Windows中打開和使用命令提示符

入門 (Getting started) Windows, MacOS and Linux have command line interfaces. Windows’ default command line is the command prompt. The command prompt allows users to use their computer without pointing and clicking with a mouse. Windows&#xff0c;MacOS和…

ACM-ICPC北京賽區2017網絡同步賽H

http://hihocoder.com/contest/icpcbeijing2017/problem/8 預處理暴力枚舉修改的點 #include <bits/stdc.h> using namespace std; const int maxn 159; const int inf 0x3f3f3f3f; int a[maxn][maxn]; int colsum[maxn][maxn]; int rowsum[maxn][maxn]; int dp[maxn];…

PPPOE撥號上網流程及密碼竊取具體實現

樓主學生黨一枚&#xff0c;最近研究netkeeper有些許心得。 關于netkeeper是調用windows的rasdial來進行上網的東西&#xff0c;網上已經有一大堆&#xff0c;我就不贅述了。 本文主要講解rasdial的部分核心過程&#xff0c;以及我們可以利用它來干些什么。 netkeeper中rasdial…

leetcode 160. 相交鏈表(雙指針)

給你兩個單鏈表的頭節點 headA 和 headB &#xff0c;請你找出并返回兩個單鏈表相交的起始節點。如果兩個鏈表沒有交點&#xff0c;返回 null 。 圖示兩個鏈表在節點 c1 開始相交&#xff1a; 題目數據 保證 整個鏈式結構中不存在環。 注意&#xff0c;函數返回結果后&#…

android開發入門_Android開發入門

android開發入門Android is an open source, Linux-based mobile operating system. Android was developed by the Open Handset Alliance, which was lead by Google and featured contributions from many other companies.Android是基于Linux的開放源代碼移動操作系統。 An…

新購阿里云服務器ECS創建之后無法ssh連接的問題處理

作者&#xff1a;13 GitHub&#xff1a;https://github.com/ZHENFENG13 版權聲明&#xff1a;本文為原創文章&#xff0c;未經允許不得轉載。 問題描述 由于原服務器將要到期&#xff0c;因此趁著阿里云搞促銷活動重新購買了一臺ECS服務器&#xff0c;但是在初始化并啟動后卻無…

數據下發非標準用戶權限測試

與同事一起溝通了下MDM的Oracle權限部分: create user cx default tablespace cwbaseoe73 identified by Test6530 grant select,update,delete,insert on lcoe739999.lsbzdw to cx grant create table to cx alter user cx quota unlimited on cwbaseoe73 grant create sessio…

leetcode 474. 一和零(dp)

給你一個二進制字符串數組 strs 和兩個整數 m 和 n 。 請你找出并返回 strs 的最大子集的大小&#xff0c;該子集中 最多 有 m 個 0 和 n 個 1 。 如果 x 的所有元素也是 y 的元素&#xff0c;集合 x 是集合 y 的 子集 。 示例 1&#xff1a; 輸入&#xff1a;strs [“10”…

邊緣計算 ai_在邊緣探索AI!

邊緣計算 ai介紹 (Introduction) What is Edge (or Fog) Computing?什么是邊緣(或霧)計算&#xff1f; Gartner defines edge computing as: “a part of a distributed computing topology in which information processing is located close to the edge — where things a…

JavaScript中的全局變量介紹

Global variables are declared outside of a function for accessibility throughout the program, while local variables are stored within a function using var for use only within that function’s scope. If you declare a variable without using var, even if it’…

初識spring-boot

使用Spring或者SpringMVC的話依然有許多東西需要我們進行配置&#xff0c;這樣不僅徒增工作量而且在跨平臺部署時容易出問題。 使用Spring Boot可以讓我們快速創建一個基于Spring的項目&#xff0c;而讓這個Spring項目跑起來我們只需要很少的配置就可以了。Spring Boot主要有如…

leetcode 879. 盈利計劃(dp)

這是我參與更文挑戰的第9天 &#xff0c;活動詳情查看更文挑戰 題目 集團里有 n 名員工&#xff0c;他們可以完成各種各樣的工作創造利潤。 第 i 種工作會產生 profit[i] 的利潤&#xff0c;它要求 group[i] 名成員共同參與。如果成員參與了其中一項工作&#xff0c;就不能…

區塊鏈101:區塊鏈的應用和用例是什么?

區塊鏈技術是一場記錄系統的革命。 比特幣是歷史上第一個永久的、分散的、全球性的、無信任的記錄分類帳。自其發明以來&#xff0c;世界各地各行各業的企業家都開始明白這一發展的意義。 區塊鏈技術的本質讓人聯想到瘋狂&#xff0c;因為這個想法現在可以應用到任何值得信賴的…

java請求接口示例_用示例解釋Java接口

java請求接口示例介面 (Interfaces) Interface in Java is a bit like the Class, but with a significant difference: an interface can only have method signatures, fields and default methods. Since Java 8, you can also create default methods. In the next block y…