# 4. OSMO 구성 (Credential, Config, Queue)

OSMO CLI를 통해 시스템을 설정합니다. OSMO가 S3에 접근하는 방법, 워크플로 로그를 어디에 저장할지, 어떤 GPU 플랫폼을 사용할지 등을 정의합니다.

**설정 흐름:**

```
IAM 사용자 생성 → Credential 등록 → Config 설정 → Queue 생성
                    (S3 접근키)        (저장소 경로)    (GPU 쿼터)
```

**런타임 동작:** Credential과 Config는 워크플로 실행 시 다음과 같이 사용됩니다:

* **Credential** (4.3): 워크플로 Pod가 S3에 데이터를 읽고 쓸 때 OSMO가 이 키를 주입합니다
* **Config WORKFLOW** (4.4): ctrl sidecar가 워크플로 로그와 결과물을 S3에 저장할 경로를 결정합니다
* **Config SERVICE**: ctrl sidecar가 작업 완료/실패 상태를 보고할 내부 URL을 지정합니다
* **Config POOL**: 워크플로의 `platform` 필드가 어떤 GPU 노드에 스케줄될지 매핑합니다
* Credential 없이 워크플로를 실행하면 `Workflow data credential is not set` 에러가 발생합니다

***

### 4.1 OSMO CLI 로그인

```bash
# Port-forward — kubectl을 통해 로컬에서 OSMO API에 접근할 수 있게 합니다
kubectl port-forward -n osmo-minimal svc/osmo-service 9001:9001 &

# dev-login — 개발 환경용 간편 로그인 (프로덕션에서는 OAuth 사용)
osmo login --url http://localhost:9001 --dev-login
```

{% hint style="info" %}
로그인 후 `~/.config/osmo/login.yaml`에 연결 정보가 저장됩니다.
{% endhint %}

***

### 4.2 S3 접근용 IAM 사용자 생성

**왜 필요한가?** OSMO 워크플로는 S3에 학습 데이터를 읽고, 워크플로 로그를 저장합니다. 이를 위한 전용 IAM 사용자와 Access Key가 필요합니다.

```bash
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
BUCKET_NAME=$(aws s3api list-buckets \
  --query "Buckets[?starts_with(Name,'osmo-data')].Name" --output text)

echo "S3 Bucket: $BUCKET_NAME"

# OSMO 전용 IAM 사용자 생성
aws iam create-user --user-name osmo-workflow-user

# S3 접근 + SimulatePrincipalPolicy 권한 부여
# (OSMO가 credential 등록 시 SimulatePrincipalPolicy로 접근 권한을 검증합니다)
aws iam put-user-policy --user-name osmo-workflow-user \
  --policy-name osmo-s3-access \
  --policy-document "{
    \"Version\": \"2012-10-17\",
    \"Statement\": [
      {
        \"Effect\": \"Allow\",
        \"Action\": [\"s3:*\"],
        \"Resource\": [
          \"arn:aws:s3:::${BUCKET_NAME}\",
          \"arn:aws:s3:::${BUCKET_NAME}/*\"
        ]
      },
      {
        \"Effect\": \"Allow\",
        \"Action\": [\"iam:SimulatePrincipalPolicy\"],
        \"Resource\": \"arn:aws:iam::${ACCOUNT_ID}:user/osmo-workflow-user\"
      }
    ]
  }"

# Access Key 발급
aws iam create-access-key --user-name osmo-workflow-user
```

{% hint style="warning" %}
출력된 `AccessKeyId`와 `SecretAccessKey`를 기록하세요. 이후 단계에서 사용합니다.

IAM 사용자가 생성된 직후에는 전파 지연(\~10초)이 있을 수 있습니다. 다음 단계에서 에러가 나면 잠시 후 재시도하세요.
{% endhint %}

***

### 4.3 OSMO Credential 등록

**왜 필요한가?** OSMO에 S3 접근 키를 등록하면, 워크플로 실행 시 자동으로 이 키를 사용해 데이터를 읽고 씁니다.

```bash
osmo credential set DATA \
  --type DATA \
  --payload \
    access_key_id=YOUR_ACCESS_KEY_ID \
    access_key=YOUR_SECRET_ACCESS_KEY \
    endpoint=s3://${BUCKET_NAME} \
    region=us-west-2
```

{% hint style="info" %}
`YOUR_ACCESS_KEY_ID`와 `YOUR_SECRET_ACCESS_KEY`를 4.2에서 발급받은 값으로 교체하세요.
{% endhint %}

***

### 4.4 OSMO Config 설정

**왜 필요한가?** OSMO는 여러 설정 파일(Config)을 통해 동작을 제어합니다:

* **WORKFLOW** — 워크플로 실행 데이터와 로그를 어디에 저장할지
* **DATASET** — 학습 데이터셋 버킷 경로
* **SERVICE** — 내부 통신 URL (ctrl sidecar → logger)
* **POOL** — GPU 플랫폼 정의

```bash
# WORKFLOW 설정 — 워크플로 실행 데이터/로그 저장 경로
cat > /tmp/workflow-config.json <<EOF
{
  "workflow_data": {
    "credential": {
      "endpoint": "s3://${BUCKET_NAME}/workflows",
      "region": "us-west-2",
      "access_key_id": "YOUR_ACCESS_KEY_ID",
      "access_key": "YOUR_SECRET_ACCESS_KEY"
    },
    "websocket_timeout": 1440,
    "data_timeout": 10,
    "download_type": "download"
  },
  "workflow_log": {
    "credential": {
      "endpoint": "s3://${BUCKET_NAME}/logs",
      "region": "us-west-2",
      "access_key_id": "YOUR_ACCESS_KEY_ID",
      "access_key": "YOUR_SECRET_ACCESS_KEY"
    }
  }
}
EOF
osmo config update WORKFLOW --file /tmp/workflow-config.json

# DATASET 설정 — 학습 데이터셋이 저장될 S3 경로
cat > /tmp/dataset-config.json <<EOF
{
  "buckets": {
    "osmo": {
      "dataset_path": "s3://${BUCKET_NAME}/datasets",
      "region": "us-west-2",
      "mode": "read-write"
    }
  },
  "default_bucket": "osmo"
}
EOF
osmo config update DATASET --file /tmp/dataset-config.json

# SERVICE 설정 — ctrl sidecar의 상태 보고 대상 URL
# ctrl sidecar는 각 워크플로 Pod 안에서 실행되며, 작업 완료/실패 상태를 이 URL로 보고합니다
cat > /tmp/service-config.json <<EOF
{
  "service_base_url": "http://osmo-logger.osmo-minimal.svc.cluster.local"
}
EOF
osmo config update SERVICE --file /tmp/service-config.json

# POOL 설정 — 사용 가능한 GPU 플랫폼 정의
cat > /tmp/pool-config.json <<EOF
{
  "pools": {
    "default": {
      "name": "default",
      "description": "Default pool",
      "status": "ONLINE",
      "backend": "default",
      "default_platform": "gpu-train",
      "common_pod_template": ["default_ctrl", "default_user"],
      "platforms": {
        "gpu-train": {
          "description": "GPU training platform (L40S)",
          "default_variables": {"USER_GPU": 1}
        },
        "gpu-sim": {
          "description": "GPU simulation platform (A10G)",
          "default_variables": {"USER_GPU": 1}
        }
      }
    }
  }
}
EOF
osmo config update POOL --file /tmp/pool-config.json
```

{% hint style="info" %}
`YOUR_ACCESS_KEY_ID`와 `YOUR_SECRET_ACCESS_KEY`를 실제 값으로 교체하세요.
{% endhint %}

***

### 4.5 Kai Scheduler Queue 생성

**왜 필요한가?** Kai Scheduler는 Queue CRD로 GPU 리소스 쿼터를 관리합니다. Queue가 없으면 워크플로가 `QueueDoesNotExist` 에러로 실패합니다.

Queue 이름은 `osmo-pool-{workflow_namespace}-{pool_name}` 형식을 따릅니다.

```bash
kubectl apply -f - <<'EOF'
apiVersion: scheduling.run.ai/v2
kind: Queue
metadata:
  name: osmo-pool-osmo-workflows-default
  namespace: kai-scheduler
spec:
  parentQueue: default
  priority: 100
  resources:
    gpu:
      quota: 4
      limit: 8
    cpu:
      quota: 48000
      limit: 96000
    memory:
      quota: 192000000000
      limit: 384000000000
EOF
```

{% hint style="info" %}
`cpu`와 `memory`는 millicores와 bytes 단위입니다. 48000 = 48 cores, 192000000000 = \~192GB.
{% endhint %}

***

### Troubleshooting

| 증상                                    | 원인             | 해결                            |
| ------------------------------------- | -------------- | ----------------------------- |
| `Workflow data credential is not set` | Credential 미설정 | 4.3 실행                        |
| `QueueDoesNotExist`                   | Kai Queue 미생성  | 4.5 실행                        |
| `InvalidClientTokenId`                | IAM 키 전파 지연    | 10초 후 재시도                     |
| `SimulatePrincipalPolicy` 에러          | IAM 정책 누락      | 4.2의 정책에 해당 권한 포함 확인          |
| OSMO CLI 404                          | 잘못된 포트 포워딩     | `svc/osmo-service` 포트 9001 확인 |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hi-space.gitbook.io/physical-ai-on-aws/physical-ai-on-aws-guide/nvidia-osmo-on-aws/4.-osmo-config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
