Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Assume Role/KMS] Using Assume Role to make the other AWS Account access all KMS that/this AWS Account.

Posted on September 24, 2022May 24, 2023 By nim No Comments on [Assume Role/KMS] Using Assume Role to make the other AWS Account access all KMS that/this AWS Account.

Như mình cũng đã hướng dẫn các bạn cách setup để access vào KMS của AWS account khác.
https://nimtechnology.com/2022/09/04/aws-encrypting-your-data-easily-via-kms-on-aws/#45_KMS_Other_account

Nhưng nếu sếp bạn muốn AWS Account A access tạo bộ KMS của AWS Account B
thì chúng ta phải sử dụng Assume Role.

Contents

Toggle
  • 1) Create Assume Role on Destination Account.
    • 1.1) Create Policy
    • 1.2) Create Role and attach the previous Policy
  • 2) Setup at Source Account
    • 2.2) Create Policy
  • 3) Switch Role to Testing.

1) Create Assume Role on Destination Account.

1.1) Create Policy

Đầu tiên cần tạo 1 Policy

Bạn chọn Service STS và Actions: Write
bạn click vào ARN
arn:aws:iam::25088768XXX:role/KMSDemoAssumeRole
sau đó bạn click ADD
Trong ý định của mình là mình sẽ cấp quyền cho Account AWS khách access được KMS của account 25088768XXX
Config assume role có các quyền access vào KMS
trường hợp của mình chọn all vì application dev gen nhiều kms và ID thì nó không có particular string.

1.2) Create Role and attach the previous Policy

Giờ create 1 role

Mình sẽ add thêm ID của account AWS khác.
chọn cái policy vừa mới tạo, rồi nhấn next
Role name: KMSDemoAssumeRole chúng ta sẽ sử dụng lại cái tên này.
Vì chúng ta đã có khai báo nó ở các bước trên.
Nhấn create role
Hiện giờ thì chúng ta đang cho phép tất cả các user trong account 31336350XXXX được access KMS của account 250887682577

2) Setup at Source Account

Mình sẽ đứng ở account này access vào KMS của account trước đó
Minh gọi đây là source account.

2.2) Create Policy

Bước tiếp theo là bạn tìm đến User và attach policy trên vào user đó.

3) Switch Role to Testing.

Vì chúng ta sử dụng kĩ thuật Assume Role nền đứng ở User nguồn chúng ta cần đứng ở Source Account và Switch Role sang Destination Account.
https://serverfault.com/questions/933078/how-to-switch-role-in-aws-cli

Bạn sẽ chỉnh file credential của AWS.

[k8s-nimtechnology-staging] #look at(1)
aws_access_key_id = AKIAUR5PLRU2AXXXXXX
aws_secret_access_key = bkRcgx0+QB4AJpzE20GV5LVS5AtzXXXXXXXXXX
[k8s-nimtechnology-staging-sts]
role_arn = arn:aws:iam::25088768XXXXX:role/KMSDemoAssumeRole ##Need you change this line
source_profile = k8s-nimtechnology-staging #follow look at (1)


root@LP11-D7891:~/demo-kms# aws sts get-caller-identity --profile k8s-nimtechnology-staging
{
    "UserId": "AIDAUR5PLRU2IBJXXXXX",
    "Account": "3133635XXXXXX",
    "Arn": "arn:aws:iam::313363XXXXXX:user/CloudOpsAutomation"
}
root@LP11-D7891:~/demo-kms# aws sts get-caller-identity --profile k8s-nimtechnology-staging-sts
{
    "UserId": "AROATU2QSHIIY3IOLCPIM:botocore-session-1664036610",
    "Account": "2508876XXXXXX",
    "Arn": "arn:aws:sts::25088768XXXXXX:assumed-role/KMSDemoAssumeRole/botocore-session-1664036610"
}

Giờ bạn có thể Run encrypt

aws kms \
    --region us-east-1 \
    --profile k8s-nimtechnology-staging-sts \
    --key-id arn:aws:kms:us-east-1:250887682577:key/e2a615c5-3689-420d-9445-ffd5feb78adb \
    --plaintext fileb://data.txt \
    --output text \
    --query CiphertextBlob | base64 \
    --decode > dataEncryptedFile
AWS - Amazon Web Service

Post navigation

Previous Post: [AWS] Encrypting data when stored in S3
Next Post: [Kubernetes] Lesson6: k8s Easy – Deployment

More Related Articles

[S3/AWS] How to reduce S3’s cost by the gateway and interface endpoints (PrivateLink) AWS - Amazon Web Service
[AWS] How to increase the disk size of a Windows EC2 machine? AWS - Amazon Web Service
[Github-Action] Let’s use GitHub Action to build and push the docker image to the docker hub. AWS - Amazon Web Service
[Demo] Instructing configure AssumeRole – IAM on AWS AWS - Amazon Web Service
[Terraform] Infrastructure Automation With Terraform – Lesson 1: Setup AWS AWS - Amazon Web Service
[AWS] Creating AWS Certificate Manager (ACM) AWS - Amazon Web Service

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure/Loadbalancer] Creating an internal load balancer on Azure Kubernetes Service (AKS). May 13, 2025
  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.