Skip to content

fix: EB Firebase 인증 파일 자동 생성 - #63

Merged
hyeoniss merged 1 commit into
developfrom
fix/eb-firebase
Aug 11, 2026
Merged

hyeoniss merged 1 commit into
developfrom
fix/eb-firebase

Conversation

@hyeoniss

@hyeoniss hyeoniss commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

📌 관련 이슈


🔎 What is this PR?


✨ Changes

EB가 배포 시 새 EC2 인스턴스를 생성하는 상황이라, 기존 인스턴스에 수동으로 저장한 Firebase service account JSON이 새 인스턴스에는 존재하지 않아 배포가 실패했습니다.

새 인스턴스에서도 자동으로 인증 파일이 생성되도록, 배포 전 Secrets Manager의 daytodo/firebase-service-account 값을 가져와 /opt/daytodo/firebase-service-account.json으로 저장하는 EB predeploy hook을 추가했습니다.

📷 Result


💬 To. Reviewer


✅ 체크 리스트

  • base 브랜치(develop 또는 main) 최신 상태 pull 및 충돌 확인 완료
  • Reviewers 설정
  • Assignees 설정
  • Labels 설정

Summary by CodeRabbit

  • Chores
    • Added an automated predeployment step to securely retrieve and configure Firebase service credentials.
    • Applied restricted file permissions and ownership to protect the credentials.
    • Added cleanup handling for temporary deployment files.

@hyeoniss hyeoniss linked an issue Aug 11, 2026 that may be closed by this pull request
2 tasks
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds an Elastic Beanstalk predeploy hook. The hook retrieves Firebase credentials from AWS Secrets Manager, validates them, installs them atomically, applies restricted ownership and permissions, and removes temporary files on exit.

Changes

Firebase credential deployment

Layer / File(s) Summary
Credential retrieval and secure installation
.platform/hooks/predeploy/10-firebase-credentials.sh
The strict Bash hook creates the credential directory, retrieves and validates the secret, installs the file atomically, sets root:webapp ownership and restricted permissions, and cleans up temporary files through an exit trap.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: automatic generation of the Firebase authentication file in the EB deployment environment.
Linked Issues check ✅ Passed The added EB predeploy script implements the directly linked issue's objective by automating Firebase authentication file creation [#62].
Out of Scope Changes check ✅ Passed The changes are limited to the EB predeploy script and directly support the linked issue's deployment objective [#62].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/eb-firebase

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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 @.platform/hooks/predeploy/10-firebase-credentials.sh:
- Around line 14-19: Update the predeploy credential setup before the aws
secretsmanager call to check FIREBASE_ENABLED, and skip the entire Firebase
credential retrieval when Firebase is disabled. Preserve the existing secret
retrieval behavior when Firebase is enabled, including the current secret_id,
aws_region, and temporary_path handling.
- Line 21: Replace the non-empty check in the Firebase credential installation
flow with validation that parses the service-account JSON and verifies all
required fields before chown and mv. Ensure the validator is available on the
Elastic Beanstalk image by provisioning jq through .ebextensions-dev or using
another guaranteed validator, while preserving failure handling for invalid
credentials.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 488b2bf6-0bc5-4d97-907b-ded2aa71352a

📥 Commits

Reviewing files that changed from the base of the PR and between 7b605ed and d270cf2.

📒 Files selected for processing (1)
  • .platform/hooks/predeploy/10-firebase-credentials.sh

Comment on lines +14 to +19
aws secretsmanager get-secret-value \
--secret-id "${secret_id}" \
--region "${aws_region}" \
--query SecretString \
--output text \
--no-cli-pager > "${temporary_path}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- hook ---'
cat -n .platform/hooks/predeploy/10-firebase-credentials.sh

printf '%s\n' '--- Firebase configuration references ---'
rg -n -C 3 'FIREBASE_ENABLED|FirebaseConfig|getApplicationDefault|credential_dir|temporary_path|secret_id|aws_region' \
  .platform . 2>/dev/null | head -n 300

printf '%s\n' '--- related platform files ---'
git ls-files '.platform/*' '*application*.yml' '*FirebaseConfig*' '*firebase*' | head -n 200

Repository: DayTodo/DayTodo_BE

Length of output: 5790


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- deployment configuration and documentation ---'
git ls-files | rg '(^|/)(\.ebextensions|\.platform|Dockerfile|docker-compose|.*ya?ml|.*properties|README)' | head -n 300
rg -n -C 4 'FIREBASE_ENABLED|GOOGLE_APPLICATION_CREDENTIALS|firebase-service-account|secretsmanager|get-secret-value|AWS_REGION|environment|env' \
  .github .ebextensions .platform README.md src 2>/dev/null | head -n 400

printf '%s\n' '--- Firebase configuration and application resources ---'
cat -n src/main/java/com/daytodo/global/config/FirebaseConfig.java
sed -n '60,82p' src/main/resources/application.yml
sed -n '14,28p' README.md

Repository: DayTodo/DayTodo_BE

Length of output: 9313


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

hook = Path(".platform/hooks/predeploy/10-firebase-credentials.sh").read_text()
config = Path("src/main/resources/application.yml").read_text()
firebase = Path("src/main/java/com/daytodo/global/config/FirebaseConfig.java").read_text()

aws_call = re.search(r'(?m)^\s*aws\s+secretsmanager\s+get-secret-value\s+\\', hook)
guard = re.search(r'(?ms)if\s+\[\[.*?FIREBASE_ENABLED.*?\]\];\s*then.*?exit\s+0', hook)
default_disabled = re.search(r'(?m)^\s*enabled:\s*\$\{FIREBASE_ENABLED:false\}', config)
conditional = re.search(
    r'`@ConditionalOnProperty`\(prefix\s*=\s*"firebase",\s*name\s*=\s*"enabled",\s*havingValue\s*=\s*"true"\)',
    firebase,
)

print({
    "unconditional_secrets_manager_call_present": bool(aws_call),
    "firebase_disabled_guard_present_before_call": bool(guard and guard.start() < aws_call.start()) if aws_call else False,
    "application_default_is_false": bool(default_disabled),
    "firebase_config_requires_enabled_true": bool(conditional),
})
assert aws_call
assert not (guard and guard.start() < aws_call.start())
assert default_disabled
assert conditional
PY

Repository: DayTodo/DayTodo_BE

Length of output: 348


Skip credential retrieval when Firebase is disabled.

The predeploy hook always calls Secrets Manager. FIREBASE_ENABLED defaults to false, and FirebaseConfig loads only when firebase.enabled=true. Add a guard before credential setup so disabled environments do not require the secret or IAM permission.

🤖 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 @.platform/hooks/predeploy/10-firebase-credentials.sh around lines 14 - 19,
Update the predeploy credential setup before the aws secretsmanager call to
check FIREBASE_ENABLED, and skip the entire Firebase credential retrieval when
Firebase is disabled. Preserve the existing secret retrieval behavior when
Firebase is enabled, including the current secret_id, aws_region, and
temporary_path handling.

--output text \
--no-cli-pager > "${temporary_path}"

test -s "${temporary_path}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

file=".platform/hooks/predeploy/10-firebase-credentials.sh"
printf '%s\n' "--- hook ---"
cat -n "$file"

printf '%s\n' "--- related references ---"
rg -n --hidden -S \
  'temporary_path|FIREBASE|GoogleCredentials|getApplicationDefault|firebase|jq|webapp' \
  -g '!node_modules' -g '!dist' -g '!build' . | head -300

printf '%s\n' "--- jq availability ---"
if command -v jq >/dev/null 2>&1; then
  jq --version
else
  echo "jq: unavailable"
fi

Repository: DayTodo/DayTodo_BE

Length of output: 5369


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' "--- deployment configuration ---"
git ls-files | rg '(^|/)(Dockerfile|docker-compose|.*ebextensions.*|.*platform.*|.*workflow.*|.*ya?ml$|.*json$)' | head -300

printf '%s\n' "--- validator and platform references ---"
rg -n --hidden -S \
  'jq|yum|dnf|apt|amazon linux|platform|Elastic Beanstalk|aws-elasticbeanstalk|predeploy|SecretString' \
  .platform .ebextensions-dev .github README.md build.gradle 2>/dev/null || true

printf '%s\n' "--- proposed jq predicate behavior ---"
python3 - <<'PY'
import json
from pathlib import Path
fixtures = {
    "valid service account": {
        "type": "service_account",
        "project_id": "p",
        "client_email": "x@example.com",
        "private_key": "-----BEGIN PRIVATE KEY-----\\nkey\\n-----END PRIVATE KEY-----\\n",
    },
    "malformed JSON": '{"type":"service_account"',
    "unrelated object": {"kind": "config", "value": "not credentials"},
    "nonempty scalar": "secret",
    "missing private_key": {
        "type": "service_account",
        "project_id": "p",
        "client_email": "x@example.com",
    },
}
for name, value in fixtures.items():
    path = Path("/tmp") / ("firebase-" + name.replace(" ", "-") + ".json")
    if isinstance(value, str) and value.startswith("{"):
        path.write_text(value)
    else:
        path.write_text(json.dumps(value))
    print(f"{name}: {path}")
PY

predicate='
  type == "object" and
  .type == "service_account" and
  (.project_id | type == "string") and
  (.client_email | type == "string") and
  (.private_key | type == "string")
'
for file in /tmp/firebase-*.json; do
  if jq -e "$predicate" "$file" >/dev/null 2>&1; then
    printf 'accepted: %s\n' "$file"
  else
    printf 'rejected: %s\n' "$file"
  fi
done

Repository: DayTodo/DayTodo_BE

Length of output: 1565


🌐 Web query:

AWS Elastic Beanstalk Amazon Linux 2 platform jq preinstalled package

💡 Result:

The jq command-line JSON processor is not preinstalled on AWS Elastic Beanstalk platforms running Amazon Linux 2 [1][2][3]. Because jq is frequently required to parse configuration data or environment variables on these platforms [4][1][5][3], users must explicitly include it in their environment configuration. To install jq on an Elastic Beanstalk environment using Amazon Linux 2, you can add it to your.ebextensions configuration file using the packages key [2][3][6]: packages: yum: jq: [] While Elastic Beanstalk documentation now recommends using Buildfile, Procfile, and platform hooks for configuration on Amazon Linux 2 environments [7], adding jq via.ebextensions remains a standard and widely used approach for ensuring the tool is available on the instance [1][3][6].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' "--- deployment workflow ---"
cat -n .github/workflows/dev-deploy.yml

printf '%s\n' "--- Elastic Beanstalk configuration ---"
for file in .ebextensions-dev/00-makefiles.config .ebextensions-dev/01-set-timezone.config; do
  printf '%s\n' "--- $file ---"
  cat -n "$file"
done

printf '%s\n' "--- credential path consumers and environment wiring ---"
rg -n --hidden -S \
  'GOOGLE_APPLICATION_CREDENTIALS|firebase-service-account|credential_path|/opt/daytodo|FIREBASE_ENABLED|GoogleCredentials' \
  . \
  -g '!node_modules' -g '!dist' -g '!build'

Repository: DayTodo/DayTodo_BE

Length of output: 4412


Validate the Firebase service-account JSON before installation.

test -s accepts malformed JSON and unrelated non-empty values. Validate the JSON and required service-account fields before chown and mv. jq is not installed by default on Elastic Beanstalk, so provision it in .ebextensions-dev or use a validator guaranteed on the target image.

🤖 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 @.platform/hooks/predeploy/10-firebase-credentials.sh at line 21, Replace the
non-empty check in the Firebase credential installation flow with validation
that parses the service-account JSON and verifies all required fields before
chown and mv. Ensure the validator is available on the Elastic Beanstalk image
by provisioning jq through .ebextensions-dev or using another guaranteed
validator, while preserving failure handling for invalid credentials.

@kwonwnsduf kwonwnsduf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

@hyeoniss
hyeoniss merged commit 2260307 into develop Aug 11, 2026
1 check passed
@hyeoniss
hyeoniss deleted the fix/eb-firebase branch August 11, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: EB 배포 스크립트 추가

2 participants