Commit a35fa46
authored
fix(operator): apply_ecs missing taskRoleArn/executionRoleArn/logConfiguration (#1280)
* fix(operator): apply_ecs never set taskRoleArn, executionRoleArn, or logConfiguration
oabctl apply_ecs registered ECS task definitions with none of
taskRoleArn, executionRoleArn, or a log driver, and set an unused
CONFIG_S3_PATH env var that nothing ever read. Found and fixed while
deploying a Telegram bot with spec.ingress + spec.secrets end-to-end
against a real AWS account (crates/openab/oab cluster, not the separate
Terraform-managed openab-chaodu fleet, which already sets these
correctly and is unaffected by this change).
Five fixes, in the order they were uncovered:
1. Missing executionRoleArn. Any manifest using spec.secrets failed
task registration outright: "you must also specify a value for
'executionRoleArn'". Resolved from bootstrap state (S3
bootstrap/state.json), matching how cluster/subnets/task role are
already sourced from bootstrap rather than the manifest.
2. Execution role missing secretsmanager:GetSecretValue. ECS uses the
EXECUTION role, not the task role, to fetch spec.secrets values
before the container starts. bootstrap.rs only granted this policy
to the task role, so step 1's fix alone still failed with
AccessDeniedException. Added the same oab-secrets policy to
oab-task-execution in bootstrap.rs, applied unconditionally (not
just on first creation) so `oabctl bootstrap` self-heals existing
installs too -- verified by detaching the policy and re-running
bootstrap, which reattached it automatically.
3. No logConfiguration. Container failures were completely opaque --
not even an empty CloudWatch log stream was created, which is what
made the next two bugs so hard to diagnose. Wired the container to
the /oab/agents log group bootstrap already creates.
4. CONFIG_S3_PATH was dead code. apply_ecs set this env var but nothing
in the codebase ever reads it -- the image's default CMD points
openab at a local /etc/openab/config.toml that nothing populates.
openab actually has native s3:// config-source support (config-s3
feature, in the default feature set + unified), so the real fix is
passing configFrom directly as the `-c` argument to `openab run`,
no download step needed.
5. Missing taskRoleArn -- the actual root cause of the remaining crash
loop after 1-4. ECS only provisions the
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI credentials endpoint (and
injects that env var into the container) when a task role is set on
the task definition. Without it the running `openab` process has no
AWS credentials for its own SDK calls at all -- it fell through
env/profile/webidentity/ECS credential providers and finally tried
IMDS, which doesn't exist on Fargate, failing with an opaque
"dispatch failure". Confirmed via two controlled debug ECS tasks
(one plain, one wrapped in tini matching the real image's
entrypoint) that environment variable inheritance through fork() is
NOT gated on PID 1 -- ruling out an initial incorrect hypothesis --
then confirmed the actual difference by diffing describe-task-definition
JSON between a working debug task and the failing one: taskRoleArn
was null. Resolved from bootstrap state like executionRoleArn.
Also added a "no bootstrap task role found" guard mirroring the
existing executionRoleArn guard, and documented both IAM roles'
permissions in operator/README.md (previously only the task role's
policies were listed; the execution role's requirements were entirely
undocumented).
Verified end-to-end against a live AWS account:
- Applied a Telegram bot manifest with spec.ingress + spec.secrets.
- After fixes 1-4: task registered and ran, but crash-looped with
"failed to fetch S3 config ... dispatch failure".
- Enabled RUST_LOG=debug via a temporary task-def revision to see the
AWS credential chain fall through every provider.
- After fix 5: `oabctl apply --wait` reported "is stable"; service
reached steady state and stayed at runningCount=1 for 90+ seconds
(previously crash-looped within 10-90s every time); curl through the
printed webhook URL reached the running task.
- Cleaned up all test/debug ECS task definitions and scaled the test
service to 0 afterward.
build + clippy --all-targets -D warnings + cargo test (15 passed) on
an M4 (macmini), in a nested workspace layout mirroring the CI
`operator` job.
* fix(review): address PR review findings
- F1: load_bootstrap_state now resolves bucket via OabConfig (respects
custom bucket config/env var) before falling back to STS-derived name
- F2: Add explicit eprintln warnings for each failure mode in
load_bootstrap_state (STS failure, missing account, state not found,
S3 read error) instead of silently returning None
- F3: Compute effective_region that falls back to bootstrap_state.region
when config.region() is None — ensures AWS_REGION env var and
logConfiguration are set even without explicit SDK region config
---------
Co-authored-by: chaodu-agent <chaodu-agent@users.noreply.github.com>1 parent 33610f5 commit a35fa46
3 files changed
Lines changed: 157 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
377 | 379 | | |
378 | 380 | | |
379 | 381 | | |
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
383 | 397 | | |
384 | 398 | | |
385 | 399 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
18 | 37 | | |
19 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
20 | 49 | | |
21 | 50 | | |
22 | 51 | | |
| |||
216 | 245 | | |
217 | 246 | | |
218 | 247 | | |
219 | | - | |
220 | | - | |
221 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
222 | 254 | | |
223 | 255 | | |
224 | 256 | | |
| |||
233 | 265 | | |
234 | 266 | | |
235 | 267 | | |
236 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
237 | 285 | | |
238 | 286 | | |
239 | 287 | | |
240 | 288 | | |
241 | 289 | | |
242 | 290 | | |
243 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
244 | 326 | | |
245 | 327 | | |
246 | 328 | | |
| |||
254 | 336 | | |
255 | 337 | | |
256 | 338 | | |
257 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
258 | 357 | | |
259 | 358 | | |
260 | 359 | | |
261 | 360 | | |
262 | 361 | | |
263 | 362 | | |
264 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
265 | 380 | | |
266 | 381 | | |
267 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
276 | 291 | | |
277 | 292 | | |
278 | 293 | | |
| |||
0 commit comments