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?

More than 1 year has passed since last update.

OCI Container InstancesのSecurity機能を確認する

Posted at

はじめ

OCI Container Instancesにセキュリティ機能が追加になったので確認します。

マニュアルを見ると、指定できるのは以下の4つです。

  • User ID
  • Group ID
  • run as non-root user
  • read-only root filesystem

KubernetesのSecurity Contextと同じようですが、fsGroupとCapabilitiesはないようです。

コンテナイメージの作成

Container Instance作成後に動作確認するために以下のコンテナイメージを作成します。

$ ls -l
total 8
-rw-rw-r--. 1 opc opc 58 Aug 22 02:07 Dockerfile
-rwxrwxr-x. 1 opc opc 40 Aug 22 02:08 cmd
FROM ubuntu
COPY cmd ./cmd
RUN chmod +x cmd
CMD ["./cmd"]
#!/bin/sh

id
ps -ef
whoami
touch /file

BuildしてTag付けします。

$ docker image build -t ubuntu-secure .
[+] Building 2.4s (8/8) FINISHED                                                                                                                                                                                            
 => [internal] load .dockerignore                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                        0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                   0.0s
 => => transferring dockerfile: 154B                                                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                                                                       1.3s
 => [internal] load build context                                                                                                                                                                                      0.0s
 => => transferring context: 129B                                                                                                                                                                                      0.0s
 => CACHED [1/3] FROM docker.io/library/ubuntu@sha256:ec050c32e4a6085b423d36ecd025c0d3ff00c38ab93a3d71a460ff1c44fa6d77                                                                                                 0.0s
 => [2/3] COPY cmd ./cmd                                                                                                                                                                                               0.0s
 => [3/3] RUN chmod +x cmd                                                                                                                                                                                             0.5s
 => exporting to image                                                                                                                                                                                                 0.6s
 => => exporting layers                                                                                                                                                                                                0.6s
 => => writing image sha256:8ccd042f21d11eedf04650b42ef46e4f700decc769e4fbd44e4d31a7419e9844                                                                                                                           0.0s
 => => naming to docker.io/library/ubuntu-secure     
$ docker tag ubuntu-secure lhr.ocir.io/orasejapan/lhr-containerinstance-secure/ubuntu-secure:1.0
$ docker image ls
REPOSITORY                                                                           TAG       IMAGE ID       CREATED         SIZE
ubuntu-secure                                                                        latest    8ccd042f21d1   4 minutes ago   77.8MB
lhr.ocir.io/orasejapan/lhr-containerinstance-secure/ubuntu-secure                    1.0       8ccd042f21d1   4 minutes ago   77.8MB

OCIRにログインして、リポジトリにPushします。リポジトリは事前に作成済みです。

$ docker login lhr.ocir.io
$ docker image push lhr.ocir.io/orasejapan/lhr-containerinstance-secure/ubuntu-secure:1.0
The push refers to repository [lhr.ocir.io/orasejapan/lhr-containerinstance-secure/ubuntu-secure]
5f70bf18a086: Pushed 
0e2057e66f1b: Pushed 
bce45ce613d3: Pushed 
1.0: digest: sha256:4454f900afd4711824647056f5140513b69cc2b66f2a203a87c4facb6eead11d size: 942

Container Instanceの作成

OCIコンソールからContainer Instanceを作成します。

コンテナの構成イメージは先ほどOCIRにPushしたイメージを指定します。

スクリーンショット 2023-08-22 11.19.41.png

同じ画面の拡張オプションの表示をクリックして、セキュリティタブで以下のように設定します。

スクリーンショット 2023-08-22 11.19.49.png

比較として、同じイメージを使用して、セキュリティを何も設定しないコンテナも同じInstanceに作成します。

スクリーンショット 2023-08-22 13.12.33.png

確認

各コンテナのログの表示からログを確認します。

スクリーンショット 2023-08-22 13.14.16.png

セキュリティ設定あり

  • UserID/GroupID
    • 設定したuid=1000 gid=2000になっています。
  • run as non-root user
    • プロセスを実行しているUserIDが1000になっています。
  • read-only root filesystem
    • Read Onlyのため、ファイルの作成に失敗しています。
2023-08-22T02:20:57.031407518Z stdout F uid=1000 gid=2000 groups=2000
2023-08-22T02:20:57.035159775Z stdout F UID          PID    PPID  C STIME TTY          TIME CMD
2023-08-22T02:20:57.03516813Z stdout F 1000           1       0  1 02:20 ?        00:00:00 /bin/sh ./cmd
2023-08-22T02:20:57.035170585Z stdout F 1000           8       1  0 02:20 ?        00:00:00 ps -ef
2023-08-22T02:20:57.035480123Z stderr F whoami: cannot find name for user ID 1000
2023-08-22T02:20:57.035944819Z stderr F touch: cannot touch '/file': Read-only file system

セキュリティ設定なし

デフォルトのrootユーザで実行されていることがわかります。
ファイルの作成は作成後にlsで確認してないのでわかりませんが、エラーが出てないので作成できているでしょう。(きっと)

2023-08-22T02:20:57.106237099Z stdout F uid=0(root) gid=0(root) groups=0(root)
2023-08-22T02:20:57.107988323Z stdout F UID          PID    PPID  C STIME TTY          TIME CMD
2023-08-22T02:20:57.107998631Z stdout F root           1       0  0 02:20 ?        00:00:00 /bin/sh ./cmd
2023-08-22T02:20:57.108001366Z stdout F root           8       1  0 02:20 ?        00:00:00 ps -ef
2023-08-22T02:20:57.108525431Z stdout F root
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?