fix: run OpenSearch security setup on every container start#1641
Conversation
WalkthroughThis PR updates the CPU-only development environment to rebuild Docker images on stack startup and configures OpenSearch to run security initialization during container startup. The Makefile adds the ChangesCPU Development Environment Setup
🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Line 17: The container startup currently ignores failures from
setup-security.sh because the command uses a semicolon and a trailing wait;
change the startup command so that a failure in
/usr/share/opensearch/setup-security.sh causes the container to exit (e.g.,
chain the scripts with && or enable exit-on-error before running them) so that
"/usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch" runs only if
setup-security.sh succeeds; update the invocation around
opensearch-docker-entrypoint.sh and setup-security.sh to use a failing-safe
chain (for example replace the semicolon with && or add set -e) so
setup-security.sh failures are not ignored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3af6438d-0a25-47ca-8f61-93b2a3c33cd9
📒 Files selected for processing (2)
Makefiledocker-compose.yml
| entrypoint: | ||
| - /bin/bash | ||
| - -c | ||
| - "/usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch & /usr/share/opensearch/setup-security.sh; wait" |
There was a problem hiding this comment.
Fail fast when setup-security.sh fails (currently failure is ignored).
At Line 17, setup-security.sh is followed by ; wait, so a failed security setup does not fail container startup. That can leave OpenSearch running without OIDC/JWT config while appearing up.
Suggested fix
- - "/usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch & /usr/share/opensearch/setup-security.sh; wait"
+ - "/usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch & os_pid=$$!; /usr/share/opensearch/setup-security.sh || { kill $$os_pid; wait $$os_pid; exit 1; }; wait $$os_pid"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docker-compose.yml` at line 17, The container startup currently ignores
failures from setup-security.sh because the command uses a semicolon and a
trailing wait; change the startup command so that a failure in
/usr/share/opensearch/setup-security.sh causes the container to exit (e.g.,
chain the scripts with && or enable exit-on-error before running them) so that
"/usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch" runs only if
setup-security.sh succeeds; update the invocation around
opensearch-docker-entrypoint.sh and setup-security.sh to use a failing-safe
chain (for example replace the semicolon with && or add set -e) so
setup-security.sh failures are not ignored.
Problem
setup-security.sh(which applies the OIDC config and role mappings viasecurityadmin) was only executed once — at initial container creation. On anydocker compose restartor--force-recreate, it was never called again, leaving OpenSearch without the OIDC/JWT authentication config. This caused all JWT-authenticated requests (ingestion, search) to return401 Unauthorized.Root cause chain:
setup-security.shskipped → OIDC config not appliedJWT_SIGNING_KEYformat), OpenSearch cached the empty key set and never re-fetched, making JWTauth permanently broken until a restart
Fix
Override the OpenSearch container
entrypointindocker-compose.ymlto runsetup-security.shon every start:OpenSearch starts in the background,
setup-security.shwaits for it to be ready then applies the OIDC config, and wait keeps the container alive. This is idempotent: re-applying the config has no side effects.Also adds
--buildto thedev-cpumake target to ensure local image changes are picked up.Test plan
docker compose restart opensearch→ JWT auth still works after restartdocker compose up -d --force-recreate opensearch→ JWT auth works on fresh containerSummary by CodeRabbit