0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Deadline Cloudで、オンプレミスのworkerを作るための、オンプレミス側IAM Roles Anywhereの設定

0
Posted at

自己紹介

株式会社digitalbigmoのテクニカルサポートの小池@plinecomです。
最近はDeadline Cloud と日々戦っています

オンプレミス側のマシンにはAWSから配布されているaws_signing_helperというプログラムを設置して、自分で作成した認証局から発行した証明書も設置します。その上で、AWS側で作成したRole, Trust Anchor, ProfileのARNを渡して上げます。

これによって、aws_cliコマンドや boto3、DeadlineCloud worker-agent を使った処理が、IAM Roles Anywhereに対応して動作するようになります。

オンプレ側のマシンのOSはRocky Linux想定です。たぶん、Amazon Linux 2023でもそのまま動くんじゃないかと思います。

### 必要となる最小限のパッケージをダウンロードして置く
- name: Install dependencies
  dnf:
    name:
      - python3
      - python3-pip
      - curl
    state: present

- name: Install dependencies
  pip:
    name:
      - boto3
      - botocore
    state: present

- name: Check if aws_signing_helper exists
  ansible.builtin.stat:
    path: "/usr/local/bin/aws_signing_helper"
  register: aws_signing_helper_stat
### aws_sign_helperプログラムをAWSからダウンロードしてきて設置する
- name: Download aws_signing_helper
  get_url:
    url: https://rolesanywhere.amazonaws.com/releases/1.8.0/X86_64/Linux/Amzn2023/aws_signing_helper
    dest: "/usr/local/bin/aws_signing_helper"
    mode: "0755"
  when: not aws_signing_helper_stat.stat.exists
### 証明書と秘密鍵を保存する場所を作る
- name: Create credential directory
  file:
    path: /etc/iam-ra
    state: directory
    mode: "0644"

- name: Install private key
  ansible.builtin.copy:
    src: /path/to/private/worker01.key.pem
    dest: /etc/iam-ra/worker.key.pem
    owner: root
    group: root
    mode: '0600'

- name: Install certificate
  ansible.builtin.copy:
    src: /path/to/certs/worker01.cert.pem
    dest: /etc/iam-ra/worker.cert.pem
    owner: root
    group: root
    mode: '0644'
### 設定ファイルの置き場所を作る
- name: Create .aws directory
  file:
    path: /root/.aws
    state: directory
    mode: "0700"
### ARNを保存しておいたファイルからARNを読み込む
- name: Load Roles Anywhere ARNs
  set_fact:
    rolesanywhere_data: "{{ lookup('file', 'rolesanywhere_output.json') | from_json }}"
### ARNを渡して設定ファイルを書く
- name: Create AWS config
  copy:
    dest: /root/.aws/config
    mode: "0600"
    content: |
      [profile rolesanywhere]
      region = {{ aws_region }}
      credential_process = /usr/local/bin/aws_signing_helper credential-process --certificate {{ worker_cert_path }} --private-key {{ worker_key_path }} --trust-anchor-arn {{ rolesanywhere_data.trust_anchor_arn }} --profile-arn {{ rolesanywhere_data.profile_arn }} --role-arn {{ rolesanywhere_data.role_arn }}

### 動作確認のために簡単なawsコマンドを実行してあげる
- name: Test AWS access using Roles Anywhere profile with amazon.aws
  amazon.aws.aws_caller_info:
    profile: rolesanywhere
    region: "{{ aws_region }}"
  register: aws_identity
  changed_when: false
### 動作確認結果を表示する
- name: Display caller identity
  debug:
    msg:
      account: "{{ aws_identity.account }}"
      arn: "{{ aws_identity.arn }}"
      user_id: "{{ aws_identity.user_id }}"

宣伝

株式会社digitalbigmoでは、ソフトの開発から、レンダーファームの構築まで手広くお仕事をしています。お困りの際はお気軽にお問い合わせください。相談は無料で承っております。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?